"Fossies" - the Fresh Open Source Software Archive

Member "libisofs-1.5.4/libisofs/ecma119.h" (8 Jul 2020, 38681 Bytes) of package /linux/misc/libisofs-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ecma119.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.2_vs_1.5.4.

    1 /*
    2  * Copyright (c) 2007 Vreixo Formoso
    3  * Copyright (c) 2009 - 2019 Thomas Schmitt
    4  *
    5  * This file is part of the libisofs project; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License version 2 
    7  * or later as published by the Free Software Foundation. 
    8  * See COPYING file for details.
    9  */
   10 
   11 #ifndef LIBISO_ECMA119_H_
   12 #define LIBISO_ECMA119_H_
   13 
   14 #include "libisofs.h"
   15 #include "util.h"
   16 #include "buffer.h"
   17 
   18 #ifdef HAVE_STDINT_H
   19 #include <stdint.h>
   20 #else
   21 #ifdef HAVE_INTTYPES_H
   22 #include <inttypes.h>
   23 #endif
   24 #endif
   25 
   26 #include <pthread.h>
   27 
   28 #define BLOCK_SIZE      2048
   29 
   30 /*
   31  * Maximum file section size. Set to 4GB - 1 =  0xffffffff
   32  */
   33 #define MAX_ISO_FILE_SECTION_SIZE   0xffffffff
   34 
   35 /*
   36  * When a file need to be split in several sections, the maximum size
   37  * of such sections, but the last one. Set to a multiple of BLOCK_SIZE.
   38  * Default to 4GB - 2048 = 0xFFFFF800
   39  */
   40 #define ISO_EXTENT_SIZE             0xFFFFF800
   41 
   42 /*
   43  * The maximum number of partition images that can be registered. Depending
   44  * on the system area type, the effectively usable number may be smaller or
   45  * even 0.
   46  */
   47 #define ISO_MAX_PARTITIONS 8
   48 
   49 /*
   50  * The cylindersize with SUN Disk Label
   51  * (512 bytes/sector, 640 sectors/head, 1 head/cyl = 320 KiB).
   52  * Expressed in ECMA-119 blocks of 2048 bytes/block.
   53  */
   54 #define ISO_SUN_CYL_SIZE 160
   55 
   56 /*
   57  * Maximum length of a disc label text plus 1.
   58  */
   59 #define ISO_DISC_LABEL_SIZE 129
   60 
   61 
   62 /* The maximum length of an specs violating ECMA-119 file identifier.
   63    The theoretical limit is  254 - 34 - 28 (len of SUSP CE entry) = 192
   64    Currently the practical limit is 254 - 34 - 96 (non-CE RR entries) - 28 (CE)
   65 */
   66 #ifdef Libisofs_with_rrip_rR
   67 #define ISO_UNTRANSLATED_NAMES_MAX 92
   68 #else
   69 #define ISO_UNTRANSLATED_NAMES_MAX 96
   70 #endif
   71 
   72 
   73 /* The theoretical maximum number of Apple Partition Map entries in the
   74    System Area of an ISO image:
   75    Block0 plus 63 entries with block size 512
   76 */
   77 #define ISO_APM_ENTRIES_MAX 63
   78 
   79 /* The maximum number of MBR partition table entries.
   80 */
   81 #define ISO_MBR_ENTRIES_MAX  4
   82 
   83 /* The theoretical maximum number of GPT entries in the System Area of an
   84    ISO image:
   85    MBR plus GPT header block plus 248 GPT entries of 128 bytes each. 
   86 */
   87 #define ISO_GPT_ENTRIES_MAX 248
   88 
   89 
   90 /* How many warnings to issue about writing Joliet names which cannot be
   91    properly represented in UCS-2 and thus had to be defaulted to '_'.
   92 */
   93 #define ISO_JOLIET_UCS2_WARN_MAX 3
   94 
   95 
   96 /**
   97  * Holds the options for the image generation.
   98  */
   99 struct iso_write_opts {
  100 
  101     int will_cancel;
  102 
  103     int iso_level; /**< ISO level to write at. (ECMA-119, 10) */
  104 
  105     /** Which extensions to support. */
  106     unsigned int rockridge :1;
  107     unsigned int joliet :1;
  108     unsigned int iso1999 :1;
  109     unsigned int hfsplus :1;
  110     unsigned int fat :1;
  111 
  112     unsigned int aaip :1; /* whether to write eventual ACL and EAs */
  113 
  114     /* always write timestamps in GMT */
  115     unsigned int always_gmt :1;
  116 
  117     /*
  118      * Relaxed constraints. Setting any of these to 1 break the specifications,
  119      * but it is supposed to work on most moderns systems. Use with caution.
  120      */
  121 
  122     /**
  123      * Convert directory names for ECMA-119 the same way as other file names
  124      * but do not force dots or add version numbers.
  125      * This violates ECMA-119 by allowing one "." and especially ISO level 1
  126      * by allowing DOS style 8.3 names rather than only 8 characters.
  127      */
  128     unsigned int allow_dir_id_ext :1;
  129 
  130     /**
  131      * Omit the version number (";1") at the end of the ISO-9660 identifiers.
  132      * Version numbers are usually not used.
  133      * bit0= ECMA-119 and Joliet (for historical reasons)
  134      * bit1= Joliet
  135      */
  136     unsigned int omit_version_numbers :2;
  137 
  138     /**
  139      * Allow ISO-9660 directory hierarchy to be deeper than 8 levels.
  140      */
  141     unsigned int allow_deep_paths :1;
  142 
  143     /**
  144      * Allow path in the ISO-9660 tree to have more than 255 characters.
  145      */
  146     unsigned int allow_longer_paths :1;
  147 
  148     /**
  149      * Allow a single file or directory hierarchy to have up to 37 characters.
  150      * This is larger than the 31 characters allowed by ISO level 2, and the
  151      * extra space is taken from the version number, so this also forces
  152      * omit_version_numbers.
  153      */
  154     unsigned int max_37_char_filenames :1;
  155 
  156     /**
  157      * ISO-9660 forces filenames to have a ".", that separates file name from
  158      * extension. libisofs adds it if original filename doesn't has one. Set
  159      * this to 1 to prevent this behavior
  160      * bit0= ECMA-119
  161      * bit1= Joliet
  162      */
  163     unsigned int no_force_dots :2;
  164 
  165     /**
  166      * Allow lowercase characters in ISO-9660 filenames. By default, only
  167      * uppercase characters, numbers and a few other characters are allowed.
  168      */
  169     unsigned int allow_lowercase :1;
  170 
  171     /**
  172      * Allow all ASCII characters to be appear on an ISO-9660 filename. Note
  173      * that "/" and "\0" characters are never allowed, even in RR names.
  174      */
  175     unsigned int allow_full_ascii :1;
  176 
  177     /**
  178      * If not allow_full_ascii is set: allow all 7 bit characters that would
  179      * be allowed by allow_full_ascii. But still map lowercase to uppercase if
  180      * not allow_lowercase is set to 1.
  181      */
  182     unsigned int allow_7bit_ascii :1;
  183 
  184     /**
  185      * Allow all characters to be part of Volume and Volset identifiers on
  186      * the Primary Volume Descriptor. This breaks ISO-9660 constraints, but
  187      * should work on modern systems.
  188      */
  189     unsigned int relaxed_vol_atts :1;
  190 
  191     /**
  192      * Allow paths in the Joliet tree to have more than 240 characters.
  193      */
  194     unsigned int joliet_longer_paths :1;
  195 
  196     /**
  197      * Allow Joliet names up to 103 characters rather than 64.
  198      */
  199     unsigned int joliet_long_names :1;
  200 
  201     /**
  202      * Use UTF-16BE rather than its subset UCS-2
  203      */
  204     unsigned int joliet_utf16 :1;
  205 
  206     /**
  207      * Write Rock Ridge info as of specification RRIP-1.10 rather than
  208      * RRIP-1.12: signature "RRIP_1991A" rather than "IEEE_1282",
  209      *            field PX without file serial number
  210      */
  211     unsigned int rrip_version_1_10 :1;
  212 
  213     /**
  214      * Write field PX with file serial number even with RRIP-1.10
  215      */
  216     unsigned int rrip_1_10_px_ino :1;
  217 
  218     /**
  219      * See iso_write_opts_set_hardlinks()
  220      */
  221     unsigned int hardlinks:1;
  222 
  223     /**
  224      * Write AAIP as extension according to SUSP 1.10 rather than SUSP 1.12.
  225      * I.e. without announcing it by an ER field and thus without the need
  226      * to precede the RRIP fields by an ES and to precede the AA field by ES.
  227      * This saves bytes and might avoid problems with readers which dislike
  228      * ER fields other than the ones for RRIP.
  229      * On the other hand, SUSP 1.12 frowns on such unannounced extensions
  230      * and prescribes ER and ES. It does this since year 1994.
  231      *
  232      * In effect only if above flag .aaip is set to 1.
  233      */
  234     unsigned int aaip_susp_1_10 :1;
  235 
  236     /**
  237      * Store as ECMA-119 Directory Record timestamp the mtime of the source
  238      * rather than the image creation time. (The ECMA-119 prescription seems
  239      * to expect that we do have a creation timestamp with the source.
  240      * mkisofs writes mtimes and the result seems more suitable if mounted
  241      * without Rock Ridge support.)
  242      * bit0= ECMA-119, bit1= Joliet, bit2= ISO 9660:1999
  243      */
  244     unsigned int dir_rec_mtime :3;
  245 
  246     /**
  247      * This describes the directory where to store Rock Ridge relocated
  248      * directories.
  249      * If not relaxation "allow_deep_paths" is in effect, it is necessary to
  250      * relocate directories so that no ECMA-119 file path has more than
  251      * 8 components. For Rock Ridge the relocated directories are linked forth
  252      * and back to a placeholder at their original position in path level 8
  253      * (entries CL and PL). Directories marked by entry RE are to be considered
  254      * artefacts of relocation and shall not be read into a Rock Ridge tree.
  255      * For plain ECMA-119, the relocation directory is just a normal directory
  256      * which contains normal files and directories.
  257      */
  258     char *rr_reloc_dir;          /* IsoNode name in root directory */
  259     int rr_reloc_flags;          /* bit0= mark auto-created rr_reloc_dir by RE
  260                                     bit1= directory was auto-created
  261                                           (cannot be set via API)
  262                                  */
  263 
  264     /**
  265      * Compute MD5 checksum for the whole session and record it as index 0 of
  266      * the checksum blocks after the data area of the session. The layout and
  267      * position of these blocks will be recorded in xattr "isofs.ca" of the
  268      * root node. See see also API call iso_image_get_session_md5().
  269      */
  270     unsigned int md5_session_checksum :1;
  271 
  272     /**
  273      * Compute MD5 checksums for IsoFile objects and write them to blocks
  274      * after the data area of the session. The layout and position of these
  275      * blocks will be recorded in xattr "isofs.ca" of the root node.
  276      * The indice of the MD5 sums will be recorded with the IsoFile directory
  277      * entries as xattr "isofs.cx". See also API call iso_file_get_md5().
  278      * bit0= compute individual checksums
  279      * bit1= pre-compute checksum and compare it with actual one.
  280      *       Raise MISHAP if mismatch.
  281      */
  282     unsigned int md5_file_checksums :2;
  283 
  284     /** If files should be sorted based on their weight. */
  285     unsigned int sort_files :1;
  286 
  287     /**
  288      * The following options set the default values for files and directory
  289      * permissions, gid and uid. All these take one of three values: 0, 1 or 2.
  290      * If 0, the corresponding attribute will be kept as set in the IsoNode.
  291      * Unless you have changed it, it corresponds to the value on disc, so it
  292      * is suitable for backup purposes. If set to 1, the corresponding attrib.
  293      * will be changed by a default suitable value. Finally, if you set it to
  294      * 2, the attrib. will be changed with the value specified in the options
  295      * below. Note that for mode attributes, only the permissions are set, the
  296      * file type remains unchanged.
  297      */
  298     unsigned int replace_dir_mode :2;
  299     unsigned int replace_file_mode :2;
  300     unsigned int replace_uid :2;
  301     unsigned int replace_gid :2;
  302 
  303     mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */
  304     mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */
  305     uid_t uid; /** uid to use when replace_uid == 2. */
  306     gid_t gid; /** gid to use when replace_gid == 2. */
  307 
  308     /**
  309      * See API call iso_write_opts_set_old_empty().
  310      */ 
  311     unsigned int old_empty :1;
  312 
  313     /**
  314      * Extra Caution: This option breaks any assumptions about names that
  315      *                are supported by ECMA-119 specifications. 
  316      * Omit any translation which would make a file name compliant to the
  317      * ECMA-119 rules. This includes and exceeds omit_version_numbers,
  318      * max_37_char_filenames, no_force_dots bit0, allow_lowercase.
  319      * The maximum name length is given by this variable.
  320      * There is a length limit of ISO_UNTRANSLATED_NAMES_MAX characters,
  321      * because ECMA-119 allows 254 byte in a directory record, some
  322      * of them are occupied by ECMA-119, some more are needed for SUSP CE,
  323      * and some are fixely occupied by libisofs Rock Ridge code.
  324      * The default value 0 disables this feature.
  325      */
  326     unsigned int untranslated_name_len;
  327 
  328     /**
  329      * 0 to use IsoNode timestamps, 1 to use recording time, 2 to use
  330      * values from timestamp field. This has only meaning if RR extensions
  331      * are enabled.
  332      */
  333     unsigned int replace_timestamps :2;
  334     time_t timestamp;
  335 
  336     /**
  337      * Charset for the RR filenames that will be created.
  338      * NULL to use default charset, the locale one.
  339      */
  340     char *output_charset;
  341 
  342     /**
  343      * This flags control the type of the image to create. Libisofs support
  344      * two kind of images: stand-alone and appendable.
  345      *
  346      * A stand-alone image is an image that is valid alone, and that can be
  347      * mounted by its own. This is the kind of image you will want to create
  348      * in most cases. A stand-alone image can be burned in an empty CD or DVD,
  349      * or write to an .iso file for future burning or distribution.
  350      *
  351      * On the other side, an appendable image is not self contained, it refers
  352      * to several files that are stored outside the image. Its usage is for
  353      * multisession discs, where you add data in a new session, while the
  354      * previous session data can still be accessed. In those cases, the old
  355      * data is not written again. Instead, the new image refers to it, and thus
  356      * it's only valid when appended to the original. Note that in those cases
  357      * the image will be written after the original, and thus you will want
  358      * to use a ms_block greater than 0.
  359      *
  360      * Note that if you haven't import a previous image (by means of
  361      * iso_image_import()), the image will always be a stand-alone image, as
  362      * there is no previous data to refer to.
  363      */
  364     unsigned int appendable : 1;
  365 
  366     /**
  367      * Start block of the image. It is supposed to be the lba where the first
  368      * block of the image will be written on disc. All references inside the
  369      * ISO image will take this into account, thus providing a mountable image.
  370      *
  371      * For appendable images, that are written to a new session, you should
  372      * pass here the lba of the next writable address on disc.
  373      *
  374      * In stand alone images this is usually 0. However, you may want to
  375      * provide a different ms_block if you don't plan to burn the image in the
  376      * first session on disc, such as in some CD-Extra disc whether the data
  377      * image is written in a new session after some audio tracks.
  378      */
  379     uint32_t ms_block;
  380 
  381     /**
  382      * When not NULL, it should point to a buffer of at least 64KiB, where
  383      * libisofs will write the contents that should be written at the beginning
  384      * of a overwritable media, to grow the image. The growing of an image is
  385      * a way, used by first time in growisofs by Andy Polyakov, to allow the
  386      * appending of new data to non-multisession media, such as DVD+RW, in the
  387      * same way you append a new session to a multisession disc, i.e., without
  388      * need to write again the contents of the previous image.
  389      *
  390      * Note that if you want this kind of image growing, you will also need to
  391      * set appendable to "1" and provide a valid ms_block after the previous
  392      * image.
  393      *
  394      * You should initialize the buffer either with 0s, or with the contents of
  395      * the first blocks of the image you're growing. In most cases, 0 is good
  396      * enough.
  397      */
  398     uint8_t *overwrite;
  399 
  400     /**
  401      * Size, in number of blocks, of the FIFO buffer used between the writer
  402      * thread and the burn_source. You have to provide at least a 32 blocks
  403      * buffer.
  404      */
  405     size_t fifo_size;
  406 
  407     /**
  408      * This is not an option setting but a value returned after the options
  409      * were used to compute the layout of the image.
  410      * It tells the LBA of the first plain file data block in the image.
  411      */
  412     uint32_t data_start_lba;
  413 
  414     /**
  415      * If not empty: A text holding parameters "name" and "timestamp" for
  416      * a scdbackup stream checksum tag. See scdbackup/README appendix VERIFY.
  417      * It makes sense only for single session images which start at LBA 0.
  418      * Such a tag may be part of a libisofs checksum tag block after the
  419      * session tag line. It then covers the whole session up to its own start
  420      * position.
  421      */
  422     char scdbackup_tag_parm[100];
  423 
  424     /* If not NULL: A pointer to an application provided array with
  425        at least 512 characters. The effectively written scdbackup tag
  426        will be copied to this memory location.
  427      */
  428     char *scdbackup_tag_written;
  429 
  430     /*
  431      * See ecma119_image : System Area related information
  432      */
  433     char *system_area_data;
  434     int system_area_size;
  435     int system_area_options;
  436 
  437     /* User settable PVD time stamps */
  438     time_t vol_creation_time;
  439     time_t vol_modification_time;
  440     time_t vol_expiration_time;
  441     time_t vol_effective_time;
  442     /* To eventually override vol_creation_time and vol_modification_time
  443      * by unconverted string with timezone 0
  444      */
  445     char vol_uuid[17];
  446 
  447     /* The number of unclaimed 2K blocks before start of partition 1 as of
  448        the MBR in system area.
  449        Must be 0 or >= 16. (Actually >= number of voldescr + checksum tag)
  450     */
  451     uint32_t partition_offset;
  452     /* Partition table parameter: 1 to 63, 0= disabled/default */
  453     int partition_secs_per_head;
  454     /* 1 to 255, 0= disabled/default */
  455     int partition_heads_per_cyl;
  456 
  457 #ifdef Libisofs_with_libjtE
  458     /* Parameters and state of Jigdo Template Export environment.
  459     */
  460     struct libjte_env *libjte_handle;
  461 #endif /* Libisofs_with_libjtE */
  462 
  463     /* A trailing padding of zero bytes which belongs to the image
  464     */
  465     uint32_t tail_blocks;
  466 
  467     /* Eventual disk file path of a PreP partition which shall be prepended
  468        to HFS+/FAT and IsoFileSrc areas and marked by an MBR partition entry.
  469     */
  470     char *prep_partition;
  471     int prep_part_flag;
  472 
  473     /* Eventual disk file path of an EFI system partition image which shall
  474        be prepended to HFS+/FAT and IsoFileSrc areas and marked by a GPT entry.
  475     */
  476     char *efi_boot_partition;
  477     int efi_boot_part_flag;
  478 
  479     /* Disk file paths of prepared images which shall be appended
  480        after the ISO image and described by partition table entries in a MBR.
  481        NULL means unused.
  482     */
  483     char *appended_partitions[ISO_MAX_PARTITIONS]; 
  484     uint8_t appended_part_types[ISO_MAX_PARTITIONS];
  485     int appended_part_flags[ISO_MAX_PARTITIONS];
  486     uint8_t appended_part_type_guids[ISO_MAX_PARTITIONS][16];
  487 
  488     /* Flags in case that appended partitions show up in GPT:
  489        bit0= appended_part_type_guids is valid
  490     */
  491     uint8_t appended_part_gpt_flags[ISO_MAX_PARTITIONS];
  492 
  493     /* If 1: With appended partitions: create protective MBR and mark by GPT
  494      */
  495     int appended_as_gpt;
  496 
  497     /* If 1: With appended partitions: mark by APM partition
  498      */
  499     int appended_as_apm;
  500 
  501     /* If 1: Obey struct el_torito_boot_image.isolinux_options bit2-7 and bit8.
  502              I.e. mention boot image as partition in GPT and/or APM.
  503      */
  504     int part_like_isohybrid;
  505 
  506     /* The type to use for the mountable ISO partition if there is any and if
  507        the type is not mandatorily determined for particular circumstances like
  508        compliant GPT, CHRP, or PReP.
  509        -1 = use the default value (e.g. 0xcd, 0x83, 0x17)
  510        0x00 to 0xff = value to use if possible 
  511     */
  512     int iso_mbr_part_type;
  513 
  514     /* iso_write_opts_set_iso_type_guid
  515      */
  516     uint8_t iso_gpt_type_guid[16];
  517     /* bit0= iso_gpt_type_guid is valid
  518     */
  519     int iso_gpt_flag;
  520 
  521 
  522     /* Eventual name of the non-ISO aspect of the image. E.g. SUN ASCII label.
  523      */
  524     char ascii_disc_label[ISO_DISC_LABEL_SIZE];
  525 
  526     /* HFS+ image serial number.
  527      * 00...00 means that it shall be generated by libisofs.
  528      */
  529     uint8_t hfsp_serial_number[8];
  530 
  531     /* Allocation block size of HFS+ : 0= auto , 512, or 2048
  532      */
  533     int hfsp_block_size;
  534 
  535     /* Block size of and in APM : 0= auto , 512, or 2048
  536      */
  537     int apm_block_size;
  538 
  539     /* User defined GUID for GPT header and base of reproducible partition
  540        GUIDs. (Not to be confused with volume "UUID", which is actually a
  541        timestamp.)
  542        See API call iso_write_opts_set_gpt_guid().
  543      */
  544     uint8_t gpt_disk_guid[16];
  545     int gpt_disk_guid_mode;
  546 };
  547 
  548 typedef struct ecma119_image Ecma119Image;
  549 typedef struct ecma119_node Ecma119Node;
  550 typedef struct joliet_node JolietNode;
  551 typedef struct iso1999_node Iso1999Node;
  552 typedef struct hfsplus_node HFSPlusNode;
  553 typedef struct Iso_File_Src IsoFileSrc;
  554 typedef struct Iso_Image_Writer IsoImageWriter;
  555 
  556 struct ecma119_image
  557 {
  558     int refcount;
  559 
  560     IsoImage *image;
  561     Ecma119Node *root;
  562 
  563     IsoWriteOpts *opts;
  564 
  565     /** Whether El Torito data will be produced */
  566     unsigned int eltorito :1;
  567 
  568     /* The ECMA-119 directory node where to store Rock Ridge relocated
  569        directories. (Path is in IsoWriteOpts.rr_reloc_dir)
  570     */
  571     Ecma119Node *rr_reloc_node;  /* Directory node in ecma119_image */
  572 
  573     /*
  574      * Mode replace. If one of these flags is set, the correspodent values are
  575      * replaced with values below. Both get computed from IsoWriteOpts.
  576      */
  577     unsigned int replace_uid :1;
  578     unsigned int replace_gid :1;
  579     unsigned int replace_file_mode :1;
  580     unsigned int replace_dir_mode :1;
  581     unsigned int replace_timestamps :1;
  582 
  583     /* Mode replacement values. */ 
  584     uid_t uid;
  585     gid_t gid;
  586     mode_t file_mode;
  587     mode_t dir_mode;
  588     time_t timestamp;
  589 
  590     /* Effective charsets */
  591     char *input_charset;
  592     char *output_charset;
  593 
  594     time_t now; /**< Time at which writing began. */
  595 
  596     /* Total size of the output. Counted in bytes.
  597      * Includes ISO filesystem and appended data.
  598      */
  599     off_t total_size;
  600 
  601     /** Size actually governed by the ISO filesystem part of the output */
  602     uint32_t vol_space_size;
  603 
  604     /* 1= write the total size into the PVD of the ISO,
  605      * 0= write vol_space_size
  606      */
  607     int pvd_size_is_total_size;
  608 
  609     /* Bytes already written to image output */
  610     off_t bytes_written;
  611     /* just for progress notification */
  612     int percent_written;
  613 
  614     /*
  615      * Block being processed, either during image writing or structure
  616      * size calculation.
  617      */
  618     uint32_t curblock;
  619 
  620     /*
  621      * The address to be used for the content pointer of empty data files.
  622      */
  623     uint32_t empty_file_block;
  624 
  625     /*
  626      * The calculated block address after ECMA-119 tree and eventual
  627      * tree checksum tag.
  628      */
  629     uint32_t tree_end_block;
  630 
  631     /*
  632      * number of dirs in ECMA-119 tree, computed together with dir position,
  633      * and needed for path table computation in a efficient way
  634      */
  635     size_t ndirs;
  636     uint32_t path_table_size;
  637     uint32_t l_path_table_pos;
  638     uint32_t m_path_table_pos;
  639 
  640     /*
  641      * Joliet related information
  642      */
  643     JolietNode *joliet_root;
  644     size_t joliet_ndirs;
  645     uint32_t joliet_path_table_size;
  646     uint32_t joliet_l_path_table_pos;
  647     uint32_t joliet_m_path_table_pos;
  648     size_t joliet_ucs2_failures;
  649 
  650     /*
  651      * HFS+ related information
  652      * (by Vladimir Serbinenko, see libisofs/hfsplus.c)
  653      */
  654     HFSPlusNode *hfsp_leafs; 
  655     struct hfsplus_btree_level *hfsp_levels;
  656     uint32_t hfsp_nlevels; 
  657     uint32_t hfsp_part_start;
  658     uint32_t hfsp_nfiles;
  659     uint32_t hfsp_ndirs;
  660     uint32_t hfsp_cat_id;
  661     uint32_t hfsp_allocation_blocks;
  662     uint32_t hfsp_allocation_file_start;
  663     uint32_t hfsp_extent_file_start;
  664     uint32_t hfsp_catalog_file_start;
  665     uint32_t hfsp_total_blocks;
  666     uint32_t hfsp_allocation_size;
  667     uint32_t hfsp_nleafs;
  668     uint32_t hfsp_curleaf;
  669     uint32_t hfsp_nnodes;
  670     uint32_t hfsp_bless_id[ISO_HFSPLUS_BLESS_MAX];
  671     uint32_t hfsp_collision_count;
  672 
  673     /*
  674      * ISO 9660:1999 related information
  675      */
  676     Iso1999Node *iso1999_root;
  677     size_t iso1999_ndirs;
  678     uint32_t iso1999_path_table_size;
  679     uint32_t iso1999_l_path_table_pos;
  680     uint32_t iso1999_m_path_table_pos;
  681 
  682     /*
  683      * El-Torito related information
  684      */
  685     struct el_torito_boot_catalog *catalog;
  686     IsoFileSrc *cat; /**< location of the boot catalog in the new image */
  687 
  688     int num_bootsrc;
  689     IsoFileSrc **bootsrc; /* location of the boot images in the new image */
  690 
  691     int *boot_appended_idx; /* Appended partition which serve as boot images */
  692 
  693     uint32_t *boot_intvl_start;   /* In blocks of 2048 bytes */
  694     uint32_t *boot_intvl_size;    /* In blocks of  512 bytes */
  695 
  696     /*
  697      * System Area related information
  698      */
  699     /* Content of an embedded boot image. Valid if not NULL.
  700      * In that case it must point to a memory buffer at least 32 kB.
  701      */
  702     char *system_area_data;
  703     /*
  704      * bit0= Only with DOS MBR
  705      *       Make bytes 446 - 512 of the system area a partition
  706      *       table which reserves partition 1 from byte 63*512 to the
  707      *       end of the ISO image. Assumed are 63 secs/hed, 255 head/cyl.
  708      *       (GRUB protective msdos label.)
  709      *       This works with and without system_area_data.
  710      * bit1= Only with DOS MBR
  711      *       Apply isohybrid MBR patching to the system area.
  712      *       This works only with system_area_data plus ISOLINUX boot image
  713      *       and only if not bit0 is set.
  714      * bit2-7= System area type
  715      *       0= DOS MBR
  716      *       1= MIPS Big Endian Volume Header
  717      *       2= DEC Boot Block for MIPS Little Endian
  718      *       3= SUN Disk Label for SUN SPARC
  719      * bit8-9= Only with DOS MBR
  720      *       Cylinder alignment mode eventually pads the image to make it
  721      *       end at a cylinder boundary.
  722      *       0 = auto (align if bit1)
  723      *       1 = always align to cylinder boundary
  724      *       2 = never align to cylinder boundary
  725      *       3 = always align, additionally pad up and align partitions
  726      *           which were appended by iso_write_opts_set_partition_img()
  727      * bit10-13= System area sub type
  728      *       With type 0 = MBR:
  729      *         Gets overridden by bit0 and bit1.
  730      *         0 = no particular sub type
  731      *         1 = CHRP: A single MBR partition of type 0x96 covers the
  732      *                   ISO image. Not compatible with any other feature
  733      *                   which needs to have own MBR partition entries.
  734      */
  735     int system_area_options;
  736 
  737     /*
  738      * Number of pad blocks that we need to write. Padding blocks are blocks
  739      * filled by 0s that we put between the directory structures and the file
  740      * data. These padding blocks are added by libisofs to improve the handling
  741      * of image growing. The idea is that the first blocks in the image are
  742      * overwritten with the volume descriptors of the new image. These first
  743      * blocks usually correspond to the volume descriptors and directory
  744      * structure of the old image, and can be safety overwritten. However,
  745      * with very small images they might correspond to valid data. To ensure
  746      * this never happens, what we do is to add padding bytes, to ensure no
  747      * file data is written in the first 64 KiB, that are the bytes we usually
  748      * overwrite.
  749      */
  750     uint32_t mspad_blocks;
  751 
  752     size_t nwriters;
  753     IsoImageWriter **writers;
  754 
  755     /* tree of files sources */
  756     IsoRBTree *files;
  757 
  758     struct iso_filesrc_list_item *ecma119_hidden_list;
  759 
  760     unsigned int checksum_idx_counter;
  761     void *checksum_ctx;
  762     off_t checksum_counter;
  763     uint32_t checksum_rlsb_tag_pos;
  764     uint32_t checksum_sb_tag_pos;
  765     uint32_t checksum_tree_tag_pos;
  766     uint32_t checksum_tag_pos;
  767     char image_md5[16];
  768     char *checksum_buffer;
  769     uint32_t checksum_array_pos;
  770     uint32_t checksum_range_start;
  771     uint32_t checksum_range_size;
  772 
  773     char *opts_overwrite; /* Points to IsoWriteOpts->overwrite.
  774                              Use only underneath ecma119_image_new()
  775                              and if not NULL*/
  776 
  777     /* Buffer for communication between burn_source and writer thread */
  778     IsoRingBuffer *buffer;
  779 
  780     /* writer thread descriptor */
  781     pthread_t wthread;
  782     int wthread_is_running;
  783     pthread_attr_t th_attr;
  784 
  785     /* Effective partition table parameter: 1 to 63, 0= disabled/default */
  786     int partition_secs_per_head;
  787     /* 1 to 255, 0= disabled/default */
  788     int partition_heads_per_cyl;
  789 
  790     /* The currently applicable LBA offset. To be subtracted from any LBA
  791      *  that is mentioned in volume descriptors, trees, path tables,
  792      *  Either 0 or .partition_offset
  793      */
  794     uint32_t eff_partition_offset;
  795 
  796     /* The second ECMA-119 directory tree and path tables */
  797     Ecma119Node *partition_root;
  798     uint32_t partition_l_table_pos;
  799     uint32_t partition_m_table_pos;
  800 
  801     /* The second Joliet directory tree and path tables */
  802     JolietNode *j_part_root;
  803     uint32_t j_part_l_path_table_pos;
  804     uint32_t j_part_m_path_table_pos;
  805 
  806     /* Memorized ELF parameters from MIPS Little Endian boot file */
  807     uint32_t mipsel_e_entry;
  808     uint32_t mipsel_p_offset;
  809     uint32_t mipsel_p_vaddr;
  810     uint32_t mipsel_p_filesz;
  811 
  812     /* A data file of which the position and size shall be written after
  813        a SUN Disk Label.
  814     */
  815     IsoFileSrc *sparc_core_src;
  816 
  817     /* Trailing padding of ISO filesystem partition for cylinder alignment */
  818     /* Only in effect with Libisofs_part_align_writeR */
  819     uint32_t part_align_blocks;
  820     uint32_t alignment_end_block;
  821 
  822     /* Counted in blocks of 2048 */
  823     uint32_t appended_part_prepad[ISO_MAX_PARTITIONS];
  824     uint32_t appended_part_start[ISO_MAX_PARTITIONS];
  825     uint32_t appended_part_size[ISO_MAX_PARTITIONS];
  826     int have_appended_partitions;
  827 
  828     /* See IsoImage and libisofs.h */
  829     IsoNode *hfsplus_blessed[ISO_HFSPLUS_BLESS_MAX];
  830 
  831     /* Block sizes come from write options.
  832        Only change a block size if it is 0. Set only to 512 or 2048.
  833        If it stays 0 then it will become 512 or 2048 in time.
  834     */
  835 
  836     /* Allocation block size of HFS+
  837        May be defined to 512 or 2048 before hfsplus_writer_create().
  838     */
  839     int hfsp_cat_node_size; /* 2 * hfsp_block_size */
  840     int hfsp_iso_block_fac; /* 2048 / hfsp_block_size */
  841 
  842     /* Apple Partition Map description. To be composed during IsoImageWriter
  843        method ->compute_data_blocks() by calling iso_register_apm_entry().
  844        Make sure that the composing writers get registered before the
  845        gpt_tail_writer.
  846     */
  847     struct iso_apm_partition_request *apm_req[ISO_APM_ENTRIES_MAX];
  848     int apm_req_count;
  849     /* bit1= Do not fill gaps in Apple Partition Map 
  850        bit2= apm_req entries use apm_block_size in start_block and block_count.
  851              Normally these two parameters are counted in 2 KiB blocks.
  852     */
  853     int apm_req_flags;
  854 
  855     /* MBR partition table description. To be composed during IsoImageWriter
  856        method ->compute_data_blocks() by calling iso_register_mbr_entry().
  857     */
  858     struct iso_mbr_partition_request *mbr_req[ISO_MBR_ENTRIES_MAX];
  859     int mbr_req_count;
  860 
  861     /* Number of bytes which have to be added after the cylinder aligned end
  862        of the overall ISO partition because clinder size is not a multiple
  863        of 2048
  864     */
  865     int post_iso_part_pad;
  866 
  867     uint32_t prep_part_size;
  868 
  869     /* GPT description. To be composed during IsoImageWriter
  870        method ->compute_data_blocks() by calling iso_register_gpt_entry().
  871        Make sure that the composing writers get registered before the
  872        gpt_tail_writer.
  873     */
  874     struct iso_gpt_partition_request *gpt_req[ISO_GPT_ENTRIES_MAX];
  875     int gpt_req_count;
  876     /* bit0= GPT partitions may overlap */
  877     int gpt_req_flags;
  878 
  879     /* Whether the eventual backup GPT is not part of the ISO filesystem */
  880     int gpt_backup_outside;
  881 
  882     /* The base UUID for the generated GPT UUIDs */
  883     uint8_t gpt_uuid_base[16];
  884     /* The counter which distinguishes the GPT UUIDs */
  885     uint32_t gpt_uuid_counter;
  886 
  887     uint32_t efi_boot_part_size;
  888     IsoFileSrc *efi_boot_part_filesrc; /* Just a pointer. Do not free. */
  889 
  890     /* Messages from gpt_tail_writer_compute_data_blocks() to
  891        iso_write_system_area().
  892     */
  893     uint8_t gpt_disk_guid[16];
  894     int gpt_disk_guid_set;
  895     /* Start of GPT entries in System Area, block size 512 */
  896     uint32_t gpt_part_start;
  897     /* The ISO block number after the backup GPT header , block size 2048 */
  898     uint32_t gpt_backup_end; 
  899     uint32_t gpt_backup_size;
  900     uint32_t gpt_max_entries;
  901     int gpt_is_computed;
  902 
  903     /* Message from write_head_part1()/iso_write_system_area() to the
  904        write_data() methods of the writers.
  905     */
  906     uint8_t sys_area_as_written[16 * BLOCK_SIZE];
  907     int sys_area_already_written;
  908 
  909     /* Size of the filesrc_writer area (data file content).
  910        This is available before any IsoImageWriter.compute_data_blocks()
  911        is called.
  912     */
  913     uint32_t filesrc_start;
  914     uint32_t filesrc_blocks;
  915 
  916 };
  917 
  918 #define BP(a,b) [(b) - (a) + 1]
  919 
  920 /* ECMA-119, 8.4 */
  921 struct ecma119_pri_vol_desc
  922 {
  923     uint8_t vol_desc_type            BP(1, 1);
  924     uint8_t std_identifier           BP(2, 6);
  925     uint8_t vol_desc_version         BP(7, 7);
  926     uint8_t unused1                  BP(8, 8);
  927     uint8_t system_id                BP(9, 40);
  928     uint8_t volume_id                BP(41, 72);
  929     uint8_t unused2                  BP(73, 80);
  930     uint8_t vol_space_size           BP(81, 88);
  931     uint8_t unused3                  BP(89, 120);
  932     uint8_t vol_set_size             BP(121, 124);
  933     uint8_t vol_seq_number           BP(125, 128);
  934     uint8_t block_size               BP(129, 132);
  935     uint8_t path_table_size          BP(133, 140);
  936     uint8_t l_path_table_pos         BP(141, 144);
  937     uint8_t opt_l_path_table_pos     BP(145, 148);
  938     uint8_t m_path_table_pos         BP(149, 152);
  939     uint8_t opt_m_path_table_pos     BP(153, 156);
  940     uint8_t root_dir_record          BP(157, 190);
  941     uint8_t vol_set_id               BP(191, 318);
  942     uint8_t publisher_id             BP(319, 446);
  943     uint8_t data_prep_id             BP(447, 574);
  944     uint8_t application_id           BP(575, 702);
  945     uint8_t copyright_file_id        BP(703, 739);
  946     uint8_t abstract_file_id         BP(740, 776);
  947     uint8_t bibliographic_file_id    BP(777, 813);
  948     uint8_t vol_creation_time        BP(814, 830);
  949     uint8_t vol_modification_time    BP(831, 847);
  950     uint8_t vol_expiration_time      BP(848, 864);
  951     uint8_t vol_effective_time       BP(865, 881);
  952     uint8_t file_structure_version   BP(882, 882);
  953     uint8_t reserved1                BP(883, 883);
  954     uint8_t app_use                  BP(884, 1395);
  955     uint8_t reserved2                BP(1396, 2048);
  956 };
  957 
  958 /* ECMA-119, 8.5 */
  959 struct ecma119_sup_vol_desc
  960 {
  961     uint8_t vol_desc_type            BP(1, 1);
  962     uint8_t std_identifier           BP(2, 6);
  963     uint8_t vol_desc_version         BP(7, 7);
  964     uint8_t vol_flags                BP(8, 8);
  965     uint8_t system_id                BP(9, 40);
  966     uint8_t volume_id                BP(41, 72);
  967     uint8_t unused2                  BP(73, 80);
  968     uint8_t vol_space_size           BP(81, 88);
  969     uint8_t esc_sequences            BP(89, 120);
  970     uint8_t vol_set_size             BP(121, 124);
  971     uint8_t vol_seq_number           BP(125, 128);
  972     uint8_t block_size               BP(129, 132);
  973     uint8_t path_table_size          BP(133, 140);
  974     uint8_t l_path_table_pos         BP(141, 144);
  975     uint8_t opt_l_path_table_pos     BP(145, 148);
  976     uint8_t m_path_table_pos         BP(149, 152);
  977     uint8_t opt_m_path_table_pos     BP(153, 156);
  978     uint8_t root_dir_record          BP(157, 190);
  979     uint8_t vol_set_id               BP(191, 318);
  980     uint8_t publisher_id             BP(319, 446);
  981     uint8_t data_prep_id             BP(447, 574);
  982     uint8_t application_id           BP(575, 702);
  983     uint8_t copyright_file_id        BP(703, 739);
  984     uint8_t abstract_file_id         BP(740, 776);
  985     uint8_t bibliographic_file_id    BP(777, 813);
  986     uint8_t vol_creation_time        BP(814, 830);
  987     uint8_t vol_modification_time    BP(831, 847);
  988     uint8_t vol_expiration_time      BP(848, 864);
  989     uint8_t vol_effective_time       BP(865, 881);
  990     uint8_t file_structure_version   BP(882, 882);
  991     uint8_t reserved1                BP(883, 883);
  992     uint8_t app_use                  BP(884, 1395);
  993     uint8_t reserved2                BP(1396, 2048);
  994 };
  995 
  996 /* ECMA-119, 8.2 */
  997 struct ecma119_boot_rec_vol_desc
  998 {
  999     uint8_t vol_desc_type            BP(1, 1);
 1000     uint8_t std_identifier           BP(2, 6);
 1001     uint8_t vol_desc_version         BP(7, 7);
 1002     uint8_t boot_sys_id              BP(8, 39);
 1003     uint8_t boot_id                  BP(40, 71);
 1004     uint8_t boot_catalog             BP(72, 75);
 1005     uint8_t unused                   BP(76, 2048);
 1006 };
 1007 
 1008 /* ECMA-119, 9.1 */
 1009 struct ecma119_dir_record
 1010 {
 1011     uint8_t len_dr                   BP(1, 1);
 1012     uint8_t len_xa                   BP(2, 2);
 1013     uint8_t block                    BP(3, 10);
 1014     uint8_t length                   BP(11, 18);
 1015     uint8_t recording_time           BP(19, 25);
 1016     uint8_t flags                    BP(26, 26);
 1017     uint8_t file_unit_size           BP(27, 27);
 1018     uint8_t interleave_gap_size      BP(28, 28);
 1019     uint8_t vol_seq_number           BP(29, 32);
 1020     uint8_t len_fi                   BP(33, 33);
 1021     uint8_t file_id                  BP(34, 34); /* 34 to 33+len_fi */
 1022     /* padding field (if len_fi is even) */
 1023     /* system use (len_dr - len_su + 1 to len_dr) */
 1024 };
 1025 
 1026 /* ECMA-119, 9.4 */
 1027 struct ecma119_path_table_record
 1028 {
 1029     uint8_t len_di                   BP(1, 1);
 1030     uint8_t len_xa                   BP(2, 2);
 1031     uint8_t block                    BP(3, 6);
 1032     uint8_t parent                   BP(7, 8);
 1033     uint8_t dir_id                   BP(9, 9); /* 9 to 8+len_di */
 1034     /* padding field (if len_di is odd) */
 1035 };
 1036 
 1037 /* ECMA-119, 8.3 */
 1038 struct ecma119_vol_desc_terminator
 1039 {
 1040     uint8_t vol_desc_type            BP(1, 1);
 1041     uint8_t std_identifier           BP(2, 6);
 1042     uint8_t vol_desc_version         BP(7, 7);
 1043     uint8_t reserved                 BP(8, 2048);
 1044 };
 1045 
 1046 void ecma119_set_voldescr_times(IsoImageWriter *writer,
 1047                                 struct ecma119_pri_vol_desc *vol);
 1048 
 1049 /* Copies a data file into the ISO image output stream */
 1050 int iso_write_partition_file(Ecma119Image *target, char *path,
 1051                              uint32_t prepad, uint32_t blocks, int flag);
 1052 
 1053 void issue_ucs2_warning_summary(size_t failures);
 1054 
 1055 /* Tells whether ivr is a reader from imported_iso in a multi-session
 1056    add-on situation, and thus to be kept in place.
 1057 */
 1058 int iso_interval_reader_keep(Ecma119Image *target,
 1059                              struct iso_interval_reader *ivr,
 1060                              int flag);
 1061 
 1062 /* @return: ISO_SUCCESS = ok, ISO_SUCCESS + 1 = keep , < 0 = error */
 1063 int iso_interval_reader_start_size(Ecma119Image *t, char *path,
 1064                                    off_t *start_byte, off_t *byte_count,
 1065                                    int flag);
 1066 
 1067 /* Obtains start and end number of appended partition range and returns
 1068    the number of valid entries in the list of appended partitions.
 1069 */
 1070 int iso_count_appended_partitions(Ecma119Image *target,
 1071                                   int *first_partition, int *last_partition);
 1072 
 1073 /* Determines the range of valid partition numbers depending on partition
 1074    table type.
 1075 */
 1076 void iso_tell_max_part_range(IsoWriteOpts *opts,
 1077                              int *first_partition, int *last_partition,
 1078                              int flag);
 1079 
 1080 #endif /*LIBISO_ECMA119_H_*/