Home | History | Annotate | Line # | Download | only in dist
      1 /*
      2  * Header file mkisofs.h - assorted structure definitions and typecasts.
      3 
      4    Written by Eric Youngdale (1993).
      5 
      6    Copyright 1993 Yggdrasil Computing, Incorporated
      7 
      8    This program is free software; you can redistribute it and/or modify
      9    it under the terms of the GNU General Public License as published by
     10    the Free Software Foundation; either version 2, or (at your option)
     11    any later version.
     12 
     13    This program is distributed in the hope that it will be useful,
     14    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16    GNU General Public License for more details.
     17 
     18    You should have received a copy of the GNU General Public License
     19    along with this program; if not, write to the Free Software
     20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
     21 
     22 /*
     23  * 	Id: mkisofs.h,v 1.4 2015/09/09 20:02:31 miod Exp
     24  */
     25 
     26 /* APPLE_HYB James Pearson j.pearson (at) ge.ucl.ac.uk 12/3/99 */
     27 
     28 #include <stdio.h>
     29 #include <prototyp.h>
     30 
     31 /* This symbol is used to indicate that we do not have things like
     32    symlinks, devices, and so forth available.  Just files and dirs */
     33 
     34 #ifdef VMS
     35 #define NON_UNIXFS
     36 #endif
     37 
     38 #ifdef DJGPP
     39 #define NON_UNIXFS
     40 #endif
     41 
     42 #ifdef VMS
     43 #include <sys/dir.h>
     44 #define dirent direct
     45 #endif
     46 
     47 #ifdef _WIN32
     48 #define NON_UNIXFS
     49 #endif /* _WIN32 */
     50 
     51 #include <string.h>
     52 #include <sys/types.h>
     53 #include <sys/stat.h>
     54 
     55 #if defined(HAVE_DIRENT_H)
     56 # include <dirent.h>
     57 # define NAMLEN(dirent) strlen((dirent)->d_name)
     58 #else
     59 # define dirent direct
     60 # define NAMLEN(dirent) (dirent)->d_namlen
     61 # if defined(HAVE_SYS_NDIR_H)
     62 #  include <sys/ndir.h>
     63 # endif
     64 # if defined(HAVE_SYS_DIR_H)
     65 #  include <sys/dir.h>
     66 # endif
     67 # if defined(HAVE_NDIR_H)
     68 #  include <ndir.h>
     69 # endif
     70 #endif
     71 
     72 #if defined(HAVE_STRING_H)
     73 #include <string.h>
     74 #else
     75 #if defined(HAVE_STRINGS_H)
     76 #include <strings.h>
     77 #endif
     78 #endif
     79 
     80 #ifdef ultrix
     81 extern char *strdup();
     82 #endif
     83 
     84 #ifdef __STDC__
     85 #define DECL(NAME,ARGS) NAME ARGS
     86 #define FDECL1(NAME,TYPE0, ARG0) \
     87 	NAME(TYPE0 ARG0)
     88 #define FDECL2(NAME,TYPE0, ARG0,TYPE1, ARG1) \
     89 	NAME(TYPE0 ARG0, TYPE1 ARG1)
     90 #define FDECL3(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2) \
     91 	NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2)
     92 #define FDECL4(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3) \
     93 	NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3)
     94 #define FDECL5(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4) \
     95 	NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3, TYPE4 ARG4)
     96 #define FDECL6(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4, TYPE5, ARG5) \
     97 	NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3, TYPE4 ARG4, TYPE5 ARG5)
     98 #else
     99 #define DECL(NAME,ARGS) NAME()
    100 #define FDECL1(NAME,TYPE0, ARG0) NAME(ARG0) TYPE0 ARG0;
    101 #define FDECL2(NAME,TYPE0, ARG0,TYPE1, ARG1) NAME(ARG0, ARG1) TYPE0 ARG0; TYPE1 ARG1;
    102 #define FDECL3(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2) \
    103 	NAME(ARG0, ARG1, ARG2) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2;
    104 #define FDECL4(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3) \
    105 	NAME(ARG0, ARG1, ARG2, ARG3, ARG4) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3;
    106 #define FDECL5(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4) \
    107 	NAME(ARG0, ARG1, ARG2, ARG3, ARG4) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3; TYPE4 ARG4;
    108 #define FDECL6(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4, TYPE5, ARG5) \
    109 	NAME(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3; TYPE4 ARG4; TYPE5 ARG5;
    110 #define const
    111 #endif
    112 
    113 
    114 #ifdef __SVR4
    115 #include <stdlib.h>
    116 #else
    117 extern int optind;
    118 extern char *optarg;
    119 /* extern int getopt (int __argc, char **__argv, char *__optstring); */
    120 #endif
    121 
    122 #include "iso9660.h"
    123 #include "defaults.h"
    124 #ifdef APPLE_HYB
    125 #include <mactypes.h>
    126 #include <hfs.h>
    127 struct hfs_info {
    128   hfsdirent	hfs_ent;
    129   char		*keyname;
    130   struct hfs_info *next;
    131 };
    132 #endif /* APPLE_HYB */
    133 
    134 struct directory_entry{
    135   struct directory_entry * next;
    136   struct directory_entry * jnext;
    137   struct iso_directory_record isorec;
    138   unsigned int starting_block;
    139   unsigned int size;
    140   unsigned short priority;
    141   unsigned char jreclen;	/* Joliet record len */
    142   char * name;
    143   char * table;
    144   char * whole_name;
    145   struct directory * filedir;
    146   struct directory_entry * parent_rec;
    147   unsigned int de_flags;
    148   ino_t inode;  /* Used in the hash table */
    149   dev_t dev;  /* Used in the hash table */
    150   unsigned char * rr_attributes;
    151   unsigned int rr_attr_size;
    152   unsigned int total_rr_attr_size;
    153   unsigned int got_rr_name;
    154 #ifdef APPLE_HYB
    155   struct directory_entry * assoc;	/* entry has a resource fork */
    156   hfsdirent *hfs_ent;			/* HFS parameters */
    157   unsigned int hfs_off;			/* offset to real start of fork */
    158   unsigned int hfs_type;		/* type of HFS Unix file */
    159 #endif /* APPLE_HYB */
    160 };
    161 
    162 struct file_hash{
    163   struct file_hash * next;
    164   ino_t inode;  /* Used in the hash table */
    165   dev_t dev;  /* Used in the hash table */
    166   unsigned int starting_block;
    167   unsigned int size;
    168 };
    169 
    170 
    171 /*
    172  * This structure is used to control the output of fragments to the cdrom
    173  * image.  Everything that will be written to the output image will eventually
    174  * go through this structure.   There are two pieces - first is the sizing where
    175  * we establish extent numbers for everything, and the second is when we actually
    176  * generate the contents and write it to the output image.
    177  *
    178  * This makes it trivial to extend mkisofs to write special things in the image.
    179  * All you need to do is hook an additional structure in the list, and the rest
    180  * works like magic.
    181  *
    182  * The three passes each do the following:
    183  *
    184  * The 'size' pass determines the size of each component and assigns the extent number
    185  * for that component.
    186  *
    187  * The 'generate' pass will adjust the contents and pointers as required now that extent
    188  * numbers are assigned.   In some cases, the contents of the record are also generated.
    189  *
    190  * The 'write' pass actually writes the data to the disc.
    191  */
    192 struct	output_fragment
    193 {
    194   struct output_fragment * of_next;
    195 #ifdef __STDC__
    196   int                      (*of_size)(int);
    197   int	                   (*of_generate)(void);
    198   int	                   (*of_write)(FILE *);
    199 #else
    200   int                      (*of_size)();
    201   int	                   (*of_generate)();
    202   int	                   (*of_write)();
    203 #endif
    204 };
    205 
    206 extern struct output_fragment * out_list;
    207 extern struct output_fragment * out_tail;
    208 
    209 extern struct output_fragment padblock_desc;
    210 extern struct output_fragment voldesc_desc;
    211 extern struct output_fragment joliet_desc;
    212 extern struct output_fragment torito_desc;
    213 extern struct output_fragment end_vol;
    214 extern struct output_fragment pathtable_desc;
    215 extern struct output_fragment jpathtable_desc;
    216 extern struct output_fragment dirtree_desc;
    217 extern struct output_fragment dirtree_clean;
    218 extern struct output_fragment jdirtree_desc;
    219 extern struct output_fragment extension_desc;
    220 extern struct output_fragment files_desc;
    221 
    222 /*
    223  * This structure describes one complete directory.  It has pointers
    224  * to other directories in the overall tree so that it is clear where
    225  * this directory lives in the tree, and it also must contain pointers
    226  * to the contents of the directory.  Note that subdirectories of this
    227  * directory exist twice in this stucture.  Once in the subdir chain,
    228  * and again in the contents chain.
    229  */
    230 struct directory{
    231   struct directory * next;  /* Next directory at same level as this one */
    232   struct directory * subdir; /* First subdirectory in this directory */
    233   struct directory * parent;
    234   struct directory_entry * contents;
    235   struct directory_entry * jcontents;
    236   struct directory_entry * self;
    237   char * whole_name;  /* Entire path */
    238   char * de_name;  /* Entire path */
    239   unsigned int ce_bytes;  /* Number of bytes of CE entries reqd for this dir */
    240   unsigned int depth;
    241   unsigned int size;
    242   unsigned int extent;
    243   unsigned int jsize;
    244   unsigned int jextent;
    245   unsigned short path_index;
    246   unsigned short jpath_index;
    247   unsigned short dir_flags;
    248   unsigned short dir_nlink;
    249 #ifdef APPLE_HYB
    250   hfsdirent *hfs_ent;		/* HFS parameters */
    251   struct hfs_info *hfs_info;	/* list of info for all entries in dir */
    252 #endif /* APPLE_HYB */
    253 };
    254 
    255 struct deferred{
    256   struct deferred * next;
    257   unsigned int starting_block;
    258   char * name;
    259   struct directory * filedir;
    260   unsigned int flags;
    261 };
    262 
    263 extern int goof;
    264 extern struct directory * root;
    265 extern struct directory * reloc_dir;
    266 extern unsigned int next_extent;
    267 extern unsigned int last_extent;
    268 extern unsigned int last_extent_written;
    269 extern unsigned int session_start;
    270 
    271 extern unsigned int path_table_size;
    272 extern unsigned int path_table[4];
    273 extern unsigned int path_blocks;
    274 extern char * path_table_l;
    275 extern char * path_table_m;
    276 
    277 extern unsigned int jpath_table_size;
    278 extern unsigned int jpath_table[4];
    279 extern unsigned int jpath_blocks;
    280 extern char * jpath_table_l;
    281 extern char * jpath_table_m;
    282 
    283 extern struct iso_directory_record root_record;
    284 extern struct iso_directory_record jroot_record;
    285 
    286 extern int use_eltorito;
    287 extern int use_RockRidge;
    288 extern int use_Joliet;
    289 extern int rationalize;
    290 extern int follow_links;
    291 extern int verbose;
    292 extern int all_files;
    293 extern int generate_tables;
    294 extern int print_size;
    295 extern int split_output;
    296 extern int jhide_trans_tbl;
    297 extern int hide_rr_moved;
    298 extern int omit_period;
    299 extern int omit_version_number;
    300 extern int transparent_compression;
    301 extern int RR_relocation_depth;
    302 extern int full_iso9660_filenames;
    303 extern int split_SL_component;
    304 extern int split_SL_field;
    305 #ifdef APPLE_HYB
    306 extern int apple_hyb;		/* create HFS hybrid */
    307 extern int apple_ext;		/* use Apple extensions */
    308 extern int apple_both;		/* common flag (for above) */
    309 extern int hfs_extra;		/* extra ISO extents (hfs_ce_size) */
    310 extern hce_mem *hce;		/* libhfs/mkisofs extras */
    311 extern int mac_name;		/* use Mac name for ISO9660/Joliet/RR */
    312 extern int create_dt;		/* create the Desktp files */
    313 extern char *hfs_boot_file;	/* name of HFS boot file */
    314 extern char *magic_file;	/* magic file for CREATOR/TYPE matching */
    315 extern int hfs_last;		/* order in which to process map/magic files */
    316 extern char *deftype;		/* default Apple TYPE */
    317 extern char *defcreator;	/* default Apple CREATOR */
    318 extern char *trans_tbl;		/* translation table name */
    319 extern int gen_pt;		/* generate HFS partition table */
    320 extern char *autoname;		/* Autostart filename */
    321 extern int afe_size;		/* Apple File Exchange block size */
    322 extern char *hfs_volume_id;	/* HFS volume ID */
    323 #define ASSOC_FLAG	4       /* ISO flag for "associated" file */
    324 #define MAP_LAST	1	/* process magic then map file */
    325 #define MAG_LAST	2	/* process map then magic file */
    326 extern char *hfs_bless;		/* name of folder to 'bless' (System Folder) */
    327 #endif /* APPLE_HYB */
    328 
    329 /* tree.c */
    330 extern int DECL(stat_filter, (char *, struct stat *));
    331 extern int DECL(lstat_filter, (char *, struct stat *));
    332 extern int DECL(sort_tree,(struct directory *));
    333 extern struct directory *
    334            DECL(find_or_create_directory,(struct directory *, const char *,
    335 					  struct directory_entry * self, int));
    336 extern void DECL (finish_cl_pl_entries, (void));
    337 extern int DECL(scan_directory_tree,(struct directory * this_dir,
    338 				     char * path,
    339 				     struct directory_entry * self));
    340 #ifdef APPLE_HYB
    341 extern int DECL(insert_file_entry,(struct directory *, char *,
    342 				   char *, int));
    343 #else
    344 extern int DECL(insert_file_entry,(struct directory *, char *,
    345 				   char *));
    346 #endif /* APPLE_HYB */
    347 extern void DECL(generate_iso9660_directories,(struct directory *, FILE*));
    348 extern void DECL(dump_tree,(struct directory * node));
    349 extern struct directory_entry * DECL(search_tree_file, (struct
    350 				directory * node,char * filename));
    351 extern void DECL(update_nlink_field,(struct directory * node));
    352 extern void DECL (init_fstatbuf, (void));
    353 extern struct stat root_statbuf;
    354 
    355 /* eltorito.c */
    356 extern void DECL(init_boot_catalog, (const char * path ));
    357 extern void DECL(get_torito_desc, (struct eltorito_boot_descriptor * path ));
    358 
    359 /* write.c */
    360 extern int DECL(get_733,(char *));
    361 extern int DECL(isonum_733,(unsigned char *));
    362 extern void DECL(set_723,(char *, unsigned int));
    363 extern void DECL(set_731,(char *, unsigned int));
    364 extern void DECL(set_721,(char *, unsigned int));
    365 extern void DECL(set_733,(char *, unsigned int));
    366 extern int  DECL(sort_directory,(struct directory_entry **));
    367 extern void DECL(generate_one_directory,(struct directory *, FILE*));
    368 extern void DECL(memcpy_max, (char *, char *, int));
    369 extern int DECL(oneblock_size, (int starting_extent));
    370 extern struct iso_primary_descriptor vol_desc;
    371 extern void DECL(xfwrite, (void * buffer, int count, int size, FILE * file));
    372 extern void DECL(set_732, (char * pnt, unsigned int i));
    373 extern void DECL(set_722, (char * pnt, unsigned int i));
    374 extern void DECL(outputlist_insert, (struct output_fragment * frag));
    375 
    376 /* multi.c */
    377 
    378 extern FILE * in_image;
    379 extern struct iso_directory_record *
    380 	DECL(merge_isofs,(char * path));
    381 
    382 extern int DECL(free_mdinfo, (struct directory_entry **, int len));
    383 
    384 extern struct directory_entry **
    385 	DECL(read_merging_directory,(struct iso_directory_record *, int*));
    386 extern void
    387 	DECL(merge_remaining_entries, (struct directory *,
    388 				       struct directory_entry **, int));
    389 extern int
    390 	DECL(merge_previous_session, (struct directory *,
    391 				      struct iso_directory_record *));
    392 
    393 extern int  DECL(get_session_start, (int *));
    394 
    395 /* joliet.c */
    396 int DECL(joliet_sort_tree, (struct directory * node));
    397 
    398 /* match.c */
    399 extern int DECL(matches, (char *));
    400 #ifdef APPLE_HYB
    401 extern int DECL(add_match, (char *));
    402 #else
    403 extern void DECL(add_match, (char *));
    404 #endif /* APPLE_HYB */
    405 
    406 /* files.c */
    407 struct dirent * DECL(readdir_add_files, (char **, char *, DIR *));
    408 
    409 /* */
    410 
    411 extern int DECL(iso9660_file_length,(const char* name,
    412 			       struct directory_entry * sresult, int flag));
    413 extern int DECL(iso9660_date,(char *, time_t));
    414 extern void DECL(add_hash,(struct directory_entry *));
    415 extern struct file_hash * DECL(find_hash,(dev_t, ino_t));
    416 #ifdef APPLE_HYB
    417 extern void flush_hash(void);
    418 #endif /* APPLE_HYB */
    419 extern void DECL(add_directory_hash,(dev_t, ino_t));
    420 extern struct file_hash * DECL(find_directory_hash,(dev_t, ino_t));
    421 extern void DECL (flush_file_hash, (void));
    422 extern int DECL(delete_file_hash,(struct directory_entry *));
    423 extern struct directory_entry * DECL(find_file_hash,(char *));
    424 extern void DECL(add_file_hash,(struct directory_entry *));
    425 extern int DECL(generate_rock_ridge_attributes,(char *, char *,
    426 					  struct directory_entry *,
    427 					  struct stat *, struct stat *,
    428 					  int  deep_flag));
    429 extern char * DECL(generate_rr_extension_record,(char * id,  char  * descriptor,
    430 				    char * source, int  * size));
    431 
    432 extern int    DECL(check_prev_session, (struct directory_entry **, int len,
    433 				     struct directory_entry *,
    434 				     struct stat *,
    435 				     struct stat *,
    436 				     struct directory_entry **));
    437 
    438 /* desktop.c */
    439 extern int make_desktop(hfsvol *, int);
    440 
    441 #ifdef	USE_SCG
    442 /* scsi.c */
    443 #ifdef __STDC__
    444 extern	int	readsecs(int startsecno, void *buffer, int sectorcount);
    445 extern	int	scsidev_open(char *path);
    446 #else
    447 extern	int	readsecs();
    448 extern	int	scsidev_open();
    449 #endif
    450 #endif
    451 
    452 extern char * extension_record;
    453 extern int extension_record_extent;
    454 extern int n_data_extents;
    455 
    456 /* These are a few goodies that can be specified on the command line, and  are
    457    filled into the root record */
    458 
    459 extern char * preparer;
    460 extern char * publisher;
    461 extern char * copyright;
    462 extern char * biblio;
    463 extern char * abstract;
    464 extern char * appid;
    465 extern char * volset_id;
    466 extern char * system_id;
    467 extern char * volume_id;
    468 extern char * boot_catalog;
    469 extern char * boot_image;
    470 extern int volume_set_size;
    471 extern int volume_sequence_number;
    472 
    473 extern void * DECL(e_malloc,(size_t));
    474 
    475 
    476 #define SECTOR_SIZE (2048)
    477 #define ROUND_UP(X)    ((X + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
    478 #ifdef APPLE_HYB
    479 #define V_ROUND_UP(X,Y) (((X + (Y - 1)) / Y) * Y)
    480 #define H_ROUND_UP(X)  ROUND_UP(((X)*HFS_BLOCKSZ))
    481 /* ISO blocks == 2048, HFS blocks == 512 */
    482 #define BLK_CONV (SECTOR_SIZE/HFS_BLOCKSZ)
    483 
    484 #define USE_MAC_NAME(N,E) ((N) && ((E)->hfs_ent != NULL) && (E)->hfs_type)
    485 #endif /* APPLE_HYB */
    486 
    487 #define NEED_RE 1
    488 #define NEED_PL  2
    489 #define NEED_CL 4
    490 #define NEED_CE 8
    491 #define NEED_SP 16
    492 
    493 #define PREV_SESS_DEV	(sizeof(dev_t) >= 4 ? 0x7ffffffd : 0x7ffd)
    494 #define TABLE_INODE	(sizeof(ino_t) >= 8 ? 0x7ffffffffffffffeLL : 0x7ffffffe)
    495 #define UNCACHED_INODE	(sizeof(ino_t) >= 8 ? 0x7fffffffffffffffLL : 0x7fffffff)
    496 #define UNCACHED_DEVICE	(sizeof(dev_t) >= 4 ? 0x7fffffff : 0x7fff)
    497 
    498 #ifdef VMS
    499 #define STAT_INODE(X) (X.st_ino[0])
    500 #define PATH_SEPARATOR ']'
    501 #define SPATH_SEPARATOR ""
    502 #else
    503 #define STAT_INODE(X) (X.st_ino)
    504 #define PATH_SEPARATOR '/'
    505 #define SPATH_SEPARATOR "/"
    506 #endif
    507 
    508 /*
    509  * When using multi-session, indicates that we can reuse the
    510  * TRANS.TBL information for this directory entry.  If this flag
    511  * is set for all entries in a directory, it means we can just
    512  * reuse the TRANS.TBL and not generate a new one.
    513  */
    514 #define SAFE_TO_REUSE_TABLE_ENTRY  0x01
    515 #define DIR_HAS_DOT		   0x02
    516 #define DIR_HAS_DOTDOT		   0x04
    517 #define INHIBIT_JOLIET_ENTRY	   0x08
    518 #define INHIBIT_RR_ENTRY	   0x10
    519 #define RELOCATED_DIRECTORY	   0x20
    520 #define INHIBIT_ISO9660_ENTRY	   0x40
    521 
    522 /*
    523  * Volume sequence number to use in all of the iso directory records.
    524  */
    525 #define DEF_VSN		1
    526 
    527 /*
    528  * Make sure we have a definition for this.  If not, take a very conservative
    529  * guess.  From what I can tell SunOS is the only one with this trouble.
    530  */
    531 #include <limits.h>
    532 #ifndef NAME_MAX
    533 #ifdef FILENAME_MAX
    534 #define NAME_MAX	FILENAME_MAX
    535 #else
    536 #define NAME_MAX	128
    537 #endif
    538 #endif
    539 
    540 #ifndef PATH_MAX
    541 #ifdef FILENAME_MAX
    542 #define PATH_MAX        FILENAME_MAX
    543 #else
    544 #define PATH_MAX        1024
    545 #endif
    546 #endif
    547