2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)genisoimage.h 1.95 05/05/01 joerg */
15 * Header file genisoimage.h - assorted structure definitions and typecasts.
17 * Written by Eric Youngdale (1993).
19 * Copyright 1993 Yggdrasil Computing, Incorporated
20 * Copyright (c) 1999,2000-2003 J. Schilling
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2, or (at your option)
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 /* APPLE_HYB James Pearson j.pearson@ge.ucl.ac.uk 23/2/2000 */
39 #define APPID_DEFAULT "GENISOIMAGE ISO 9660/HFS FILESYSTEM CREATOR (C) 1993 E.YOUNGDALE (C) 1997-2006 J.PEARSON/J.SCHILLING (C) 2006-2007 CDRKIT TEAM"
42 #include <mconfig.h> /* Must be before stdio.h for LARGEFILE support */
46 #include <unixstd.h> /* Needed for for LARGEFILE support */
63 /*#if _LFS_LARGEFILE*/
64 #ifdef HAVE_LARGEFILES
66 * XXX Hack until fseeko()/ftello() are available everywhere or until
67 * XXX we know a secure way to let autoconf ckeck for fseeko()/ftello()
68 * XXX without defining FILE_OFFSETBITS to 64 in confdefs.h
84 extern struct unls_table *in_nls; /* input UNICODE conversion table */
85 extern struct unls_table *out_nls; /* output UNICODE conversion table */
86 extern struct unls_table *hfs_inls; /* input HFS UNICODE conversion table */
87 extern struct unls_table *hfs_onls; /* output HFS UNICODE conversion table */
94 unsigned char finderinfo[32];
95 char name[HFS_MAX_FLEN + 1];
96 /* should have fields for dates here as well */
98 struct hfs_info *next;
101 #endif /* APPLE_HYB */
103 struct directory_entry {
104 struct directory_entry *next;
105 struct directory_entry *jnext;
106 struct iso_directory_record isorec;
107 unsigned int starting_block;
109 unsigned short priority;
110 unsigned char jreclen; /* Joliet record len */
114 struct directory *filedir;
115 struct directory_entry *parent_rec;
116 unsigned int de_flags;
117 ino_t inode; /* Used in the hash table */
118 dev_t dev; /* Used in the hash table */
119 unsigned char *rr_attributes;
120 unsigned int rr_attr_size;
121 unsigned int total_rr_attr_size;
122 unsigned int got_rr_name;
124 struct directory_entry *assoc; /* entry has a resource fork */
125 hfsdirent *hfs_ent; /* HFS parameters */
126 off_t hfs_off; /* offset to real start of fork */
127 int hfs_type; /* type of HFS Unix file */
128 #endif /* APPLE_HYB */
130 int sort; /* sort weight for entry */
133 int udf_file_entry_sector; /* also used as UDF unique ID */
139 struct file_hash *next;
140 ino_t inode; /* Used in the hash table */
141 dev_t dev; /* Used in the hash table */
142 nlink_t nlink; /* Used to compute new link count */
143 unsigned int starting_block;
146 struct directory_entry *de;
152 * This structure is used to control the output of fragments to the cdrom
153 * image. Everything that will be written to the output image will eventually
154 * go through this structure. There are two pieces - first is the sizing where
155 * we establish extent numbers for everything, and the second is when we actually
156 * generate the contents and write it to the output image.
158 * This makes it trivial to extend genisoimage to write special things in the image.
159 * All you need to do is hook an additional structure in the list, and the rest
162 * The three passes each do the following:
164 * The 'size' pass determines the size of each component and assigns the extent number
165 * for that component.
167 * The 'generate' pass will adjust the contents and pointers as required now that extent
168 * numbers are assigned. In some cases, the contents of the record are also generated.
170 * The 'write' pass actually writes the data to the disc.
172 struct output_fragment {
173 struct output_fragment *of_next;
175 int (*of_generate)(void);
176 int (*of_write)(FILE *);
177 char *of_name; /* Textual description */
178 unsigned int of_start_extent; /* For consist check */
181 extern struct output_fragment *out_list;
182 extern struct output_fragment *out_tail;
184 extern struct output_fragment startpad_desc;
185 extern struct output_fragment voldesc_desc;
186 extern struct output_fragment xvoldesc_desc;
187 extern struct output_fragment joliet_desc;
188 extern struct output_fragment torito_desc;
189 extern struct output_fragment end_vol;
190 extern struct output_fragment version_desc;
191 extern struct output_fragment pathtable_desc;
192 extern struct output_fragment jpathtable_desc;
193 extern struct output_fragment dirtree_desc;
194 extern struct output_fragment dirtree_clean;
195 extern struct output_fragment jdirtree_desc;
196 extern struct output_fragment extension_desc;
197 extern struct output_fragment files_desc;
198 extern struct output_fragment interpad_desc;
199 extern struct output_fragment endpad_desc;
200 extern struct output_fragment sunboot_desc;
201 extern struct output_fragment sunlabel_desc;
202 extern struct output_fragment genboot_desc;
203 extern struct output_fragment strfile_desc;
204 extern struct output_fragment strdir_desc;
205 extern struct output_fragment strpath_desc;
206 extern struct output_fragment alphaboot_desc;
207 extern struct output_fragment hppaboot_desc;
208 extern struct output_fragment alpha_hppa_boot_desc;
209 extern struct output_fragment mipsboot_desc;
210 extern struct output_fragment mipselboot_desc;
213 extern struct output_fragment hfs_desc;
215 #endif /* APPLE_HYB */
218 * This structure holds the information necessary to create a valid
219 * DVD-Video image. Basically it's how much to pad the files so the
220 * file offsets described in the video_ts.ifo and vts_xx_0.ifo are
221 * the correct one in the image that we create.
235 int number_of_vob_files;
236 int realsize_vob[10];
241 title_set_t *title_set;
243 #endif /* DVD_VIDEO */
246 * This structure describes one complete directory. It has pointers
247 * to other directories in the overall tree so that it is clear where
248 * this directory lives in the tree, and it also must contain pointers
249 * to the contents of the directory. Note that subdirectories of this
250 * directory exist twice in this stucture. Once in the subdir chain,
251 * and again in the contents chain.
254 struct directory *next; /* Next directory at same level as this one */
255 struct directory *subdir; /* First subdirectory in this directory */
256 struct directory *parent;
257 struct directory_entry *contents;
258 struct directory_entry *jcontents;
259 struct directory_entry *self;
260 char *whole_name; /* Entire path */
261 char *de_name; /* Entire path */
262 unsigned int ce_bytes; /* Number of bytes of CE entries read */
268 unsigned int jextent;
269 unsigned int path_index;
270 unsigned int jpath_index;
271 unsigned short dir_flags;
272 unsigned short dir_nlink;
274 hfsdirent *hfs_ent; /* HFS parameters */
275 struct hfs_info *hfs_info; /* list of info for all entries in dir */
276 #endif /* APPLE_HYB */
278 int sort; /* sort weight for child files */
282 struct deferred_write {
283 struct deferred_write *next;
288 struct directory_entry *s_entry;
293 struct eltorito_boot_entry_info {
294 struct eltorito_boot_entry_info *next;
305 extern struct directory *root;
306 extern struct directory *reloc_dir;
307 extern unsigned int next_extent;
308 extern unsigned int last_extent;
309 extern unsigned int last_extent_written;
310 extern unsigned int session_start;
312 extern unsigned int path_table_size;
313 extern unsigned int path_table[4];
314 extern unsigned int path_blocks;
315 extern char *path_table_l;
316 extern char *path_table_m;
318 extern unsigned int jpath_table_size;
319 extern unsigned int jpath_table[4];
320 extern unsigned int jpath_blocks;
321 extern char *jpath_table_l;
322 extern char *jpath_table_m;
324 extern struct iso_directory_record root_record;
325 extern struct iso_directory_record jroot_record;
327 extern int check_oldnames;
328 extern int check_session;
329 extern int use_eltorito;
330 extern int hard_disk_boot;
331 extern int not_bootable;
332 extern int no_emul_boot;
333 extern int load_addr;
334 extern int load_size;
335 extern int boot_info_table;
336 extern int use_RockRidge;
339 extern int use_Joliet;
340 extern int rationalize;
341 extern int rationalize_uid;
342 extern int rationalize_gid;
343 extern int rationalize_filemode;
344 extern int rationalize_dirmode;
345 extern uid_t uid_to_use;
346 extern gid_t gid_to_use;
347 extern int filemode_to_use;
348 extern int dirmode_to_use;
349 extern int new_dir_mode;
350 extern int follow_links;
351 extern int cache_inodes;
355 extern int all_files;
356 extern int generate_tables;
357 extern int print_size;
358 extern int split_output;
359 extern int use_graft_ptrs;
360 extern int jhide_trans_tbl;
361 extern int hide_rr_moved;
362 extern int omit_period;
363 extern int omit_version_number;
365 extern int transparent_compression;
366 extern Uint RR_relocation_depth;
367 extern int iso9660_level;
368 extern int iso9660_namelen;
369 extern int full_iso9660_filenames;
370 extern int relaxed_filenames;
371 extern int allow_lowercase;
372 extern int allow_multidot;
373 extern int iso_translate;
374 extern int allow_leading_dots;
375 extern int use_fileversion;
376 extern int split_SL_component;
377 extern int split_SL_field;
378 extern char *trans_tbl;
381 #define JMAX 64 /* maximum Joliet file name length (spec) */
382 #define JLONGMAX 103 /* out of spec Joliet file name length */
383 extern int jlen; /* selected maximum Joliet file name length */
386 extern int dvd_video;
387 #endif /* DVD_VIDEO */
391 extern int apple_hyb; /* create HFS hybrid */
392 extern int apple_ext; /* use Apple extensions */
393 extern int apple_both; /* common flag (for above) */
394 extern int hfs_extra; /* extra ISO extents (hfs_ce_size) */
395 extern hce_mem *hce; /* libhfs/genisoimage extras */
396 extern int use_mac_name; /* use Mac name for ISO9660/Joliet/RR */
397 extern int create_dt; /* create the Desktp files */
398 extern char *hfs_boot_file; /* name of HFS boot file */
399 extern char *magic_filename; /* magic file for CREATOR/TYPE matching */
400 extern int hfs_last; /* order in which to process map/magic files */
401 extern char *deftype; /* default Apple TYPE */
402 extern char *defcreator; /* default Apple CREATOR */
403 extern int gen_pt; /* generate HFS partition table */
404 extern char *autoname; /* Autostart filename */
405 extern int afe_size; /* Apple File Exchange block size */
406 extern char *hfs_volume_id; /* HFS volume ID */
407 extern int icon_pos; /* Keep Icon position */
408 extern int hfs_lock; /* lock HFS volume (read-only) */
409 extern char *hfs_bless; /* name of folder to 'bless' (System Folder) */
410 extern char *hfs_parms; /* low level HFS parameters */
412 #define MAP_LAST 1 /* process magic then map file */
413 #define MAG_LAST 2 /* process map then magic file */
417 #endif /* PREP_BOOT */
420 extern char *prep_boot_image[4];
421 extern int use_prep_boot;
422 extern int use_chrp_boot;
424 #endif /* PREP_BOOT */
425 #endif /* APPLE_HYB */
432 extern int stat_filter(char *, struct stat *);
433 extern int lstat_filter(char *, struct stat *);
434 extern int sort_tree(struct directory *);
435 extern struct directory *
436 find_or_create_directory(struct directory *, const char *,
437 struct directory_entry *self,
439 struct stat *stat_template);
440 extern void finish_cl_pl_entries(void);
441 extern int scan_directory_tree(struct directory *this_dir, char *path,
442 struct directory_entry *self);
445 extern int insert_file_entry(struct directory *, char *, char *, int);
447 extern int insert_file_entry(struct directory *, char *, char *);
448 #endif /* APPLE_HYB */
450 extern void generate_iso9660_directories(struct directory *, FILE *);
451 extern void dump_tree(struct directory * node);
452 extern struct directory_entry *
453 search_tree_file(struct directory * node, char *filename);
454 extern void update_nlink_field(struct directory * node);
455 extern void init_fstatbuf(void);
456 extern struct stat root_statbuf;
457 extern struct stat fstatbuf;
460 extern void init_boot_catalog(const char *path);
461 extern void insert_boot_cat(void);
462 extern void get_boot_entry(void);
463 extern void new_boot_entry(void);
466 extern void sparc_boot_label(char *label);
467 extern void sunx86_boot_label(char *label);
468 extern void scan_sparc_boot(char *files);
469 extern void scan_sunx86_boot(char *files);
470 extern int make_sun_label(void);
471 extern int make_sunx86_label(void);
474 extern int add_boot_alpha_filename(char *filename);
477 extern int add_boot_hppa_cmdline(char *cmdline);
478 extern int add_boot_hppa_kernel_32(char *filename);
479 extern int add_boot_hppa_kernel_64(char *filename);
480 extern int add_boot_hppa_bootloader(char *filename);
481 extern int add_boot_hppa_ramdisk(char *filename);
484 extern int add_boot_mips_filename(char *filename);
487 extern int add_boot_mipsel_filename(char *filename);
490 extern unsigned long long rsync64(unsigned char *mem, size_t size);
493 extern int get_731(char *);
494 extern int get_732(char *);
495 extern int get_733(char *);
496 extern int isonum_733(unsigned char *);
497 extern void set_723(char *, unsigned int);
498 extern void set_731(char *, unsigned int);
499 extern void set_721(char *, unsigned int);
500 extern void set_733(char *, unsigned int);
501 extern int sort_directory(struct directory_entry **, int);
502 extern void generate_one_directory(struct directory *, FILE *);
503 extern void memcpy_max(char *, char *, int);
504 extern int oneblock_size(int starting_extent);
505 extern struct iso_primary_descriptor vol_desc;
506 extern void xfwrite(void *buffer, int size, int count, FILE *file, int submode,
508 extern void set_732(char *pnt, unsigned int i);
509 extern void set_722(char *pnt, unsigned int i);
510 extern void outputlist_insert(struct output_fragment * frag);
513 extern Ulong get_adj_size(int Csize);
514 extern int adj_size(int Csize, int start_extent, int extra);
515 extern void adj_size_other(struct directory * dpnt);
516 extern int insert_padding_file(int size);
517 extern int gen_mac_label(struct deferred_write *);
520 extern void gen_prepboot_label(unsigned char *);
522 #endif /* PREP_BOOT */
523 #endif /* APPLE_HYB */
527 extern FILE *in_image;
528 extern int open_merge_image(char *path);
529 extern int close_merge_image(void);
530 extern struct iso_directory_record *
531 merge_isofs(char *path);
532 extern unsigned char *parse_xa(unsigned char *pnt, int *lenp,
533 struct directory_entry *dpnt);
534 extern int rr_flags(struct iso_directory_record *idr);
535 extern int merge_previous_session(struct directory *,
536 struct iso_directory_record *,
538 extern int get_session_start(int *);
543 extern size_t convert_to_unicode (unsigned char *buffer,
544 int size, char *source, struct unls_table *inls);
546 extern void convert_to_unicode (unsigned char *buffer,
547 int size, char *source, struct unls_table *inls);
549 extern int joliet_strlen (const char *string, struct unls_table *inls);
551 extern unsigned char conv_charset(unsigned char, struct unls_table *,
552 struct unls_table *);
553 extern int joliet_sort_tree(struct directory * node);
556 extern int matches(char *);
557 extern int add_match(char *);
560 struct dirent *readdir_add_files(char **, char *, DIR *);
564 extern void iso9660_check(struct iso_directory_record *idr,
565 struct directory_entry *ndr);
566 extern int iso9660_file_length(const char *name,
567 struct directory_entry *sresult, int flag);
570 extern int iso9660_date(char *, time_t);
571 extern void add_hash(struct directory_entry *);
572 extern struct file_hash *find_hash(dev_t, ino_t);
574 extern void flush_hash(void);
575 extern void add_directory_hash(dev_t, ino_t);
576 extern struct file_hash *find_directory_hash(dev_t, ino_t);
577 extern void flush_file_hash(void);
578 extern int delete_file_hash(struct directory_entry *);
579 extern struct directory_entry *find_file_hash(char *);
580 extern void add_file_hash(struct directory_entry *);
582 extern int generate_xa_rr_attributes(char *, char *, struct directory_entry *,
583 struct stat *, struct stat *,
585 extern char *generate_rr_extension_record(char *id, char *descriptor,
586 char *source, int *size);
588 extern int check_prev_session(struct directory_entry **, int len,
589 struct directory_entry *, struct stat *,
590 struct stat *, struct directory_entry **);
592 extern void match_cl_re_entries(void);
593 extern void finish_cl_pl_for_prev_session(void);
594 extern char *find_rr_attribute(unsigned char *pnt, int len, char *attr_type);
598 extern int make_mac_volume(struct directory * dpnt, int start_extent);
599 extern int write_fork(hfsfile * hfp, long tot);
603 extern void del_hfs_info(struct hfs_info *);
604 extern int get_hfs_dir(char *, char *, struct directory_entry *);
605 extern int get_hfs_info(char *, char *, struct directory_entry *);
606 extern int get_hfs_rname(char *, char *, char *);
607 extern int hfs_exclude(char *);
608 extern void print_hfs_info(struct directory_entry *);
609 extern void hfs_init(char *, unsigned short, unsigned int);
610 extern void delete_rsrc_ent(struct directory_entry *);
611 extern void clean_hfs(void);
612 extern void perr(char *);
613 extern void set_root_info(char *);
617 extern int make_desktop(hfsvol *, int);
623 extern void gen_prepboot_label(MacLabel * mac_label);
625 extern int gen_mac_label(defer *);
627 extern int autostart(void);
631 extern char *get_magic_match(const char *);
632 extern void clean_magic(void);
634 #endif /* APPLE_HYB */
636 extern char *extension_record;
637 extern int extension_record_extent;
638 extern int n_data_extents;
641 * These are a few goodies that can be specified on the command line, and are
642 * filled into the root record
644 extern char *preparer;
645 extern char *publisher;
646 extern char *copyright;
648 extern char *abstract;
650 extern char *volset_id;
651 extern char *system_id;
652 extern char *volume_id;
653 extern char *boot_catalog;
654 extern char *boot_image;
655 extern char *genboot_image;
656 extern int ucs_level;
657 extern int volume_set_size;
658 extern int volume_sequence_number;
660 extern struct eltorito_boot_entry_info *first_boot_entry;
661 extern struct eltorito_boot_entry_info *last_boot_entry;
662 extern struct eltorito_boot_entry_info *current_boot_entry;
664 extern char *findgequal(char *);
665 extern void *e_malloc(size_t);
668 * Note: always use these macros to avoid problems.
670 * ISO_ROUND_UP(X) may cause an integer overflow and thus give
671 * incorrect results. So avoid it if possible.
673 * ISO_BLOCKS(X) is overflow safe. Prefer this when ever it is possible.
675 #define SECTOR_SIZE (2048)
676 #define ISO_ROUND_UP(X) (((X) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
677 #define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
679 #define ROUND_UP(X, Y) (((X + (Y - 1)) / Y) * Y)
683 * ISO blocks == 2048, HFS blocks == 512
685 #define HFS_BLK_CONV (SECTOR_SIZE/HFS_BLOCKSZ)
687 #define HFS_ROUND_UP(X) ISO_ROUND_UP(((X)*HFS_BLOCKSZ)) /* XXX ??? */
688 #define HFS_BLOCKS(X) (ISO_BLOCKS(X) * HFS_BLK_CONV)
690 #define USE_MAC_NAME(E) (use_mac_name && ((E)->hfs_ent != NULL) && (E)->hfs_type)
691 #endif /* APPLE_HYB */
696 #define NEED_RE 1 /* Need Relocated Direcotry */
697 #define NEED_PL 2 /* Need Parent link */
698 #define NEED_CL 4 /* Need Child link */
699 #define NEED_CE 8 /* Need Continuation Area */
700 #define NEED_SP 16 /* Need SUSP record */
702 #define RR_FLAG_PX 1 /* POSIX attributes */
703 #define RR_FLAG_PN 2 /* POSIX device number */
704 #define RR_FLAG_SL 4 /* Symlink */
705 #define RR_FLAG_NM 8 /* Alternate Name */
706 #define RR_FLAG_CL 16 /* Child link */
707 #define RR_FLAG_PL 32 /* Parent link */
708 #define RR_FLAG_RE 64 /* Relocated Direcotry */
709 #define RR_FLAG_TF 128 /* Time stamp */
711 #define RR_FLAG_SP 1024 /* SUSP record */
712 #define RR_FLAG_AA 2048 /* Apple Signature record */
713 #define RR_FLAG_XA 4096 /* XA signature record */
715 #define RR_FLAG_CE 8192 /* SUSP Continuation aerea */
716 #define RR_FLAG_ER 16384 /* Extension record for RR signature */
717 #define RR_FLAG_RR 32768 /* RR Signature in every file */
718 #define RR_FLAG_ZF 65535 /* Linux compression extension */
721 #define PREV_SESS_DEV (sizeof (dev_t) >= 4 ? 0x7ffffffd : 0x7ffd)
722 #define TABLE_INODE (sizeof (ino_t) >= 4 ? 0x7ffffffe : 0x7ffe)
723 #define UNCACHED_INODE (sizeof (ino_t) >= 4 ? 0x7fffffff : 0x7fff)
724 #define UNCACHED_DEVICE (sizeof (dev_t) >= 4 ? 0x7fffffff : 0x7fff)
727 #define STAT_INODE(X) (X.st_ino[0])
728 #define PATH_SEPARATOR ']'
729 #define SPATH_SEPARATOR ""
731 #define STAT_INODE(X) (X.st_ino)
732 #define PATH_SEPARATOR '/'
733 #define SPATH_SEPARATOR "/"
737 * When using multi-session, indicates that we can reuse the
738 * TRANS.TBL information for this directory entry. If this flag
739 * is set for all entries in a directory, it means we can just
740 * reuse the TRANS.TBL and not generate a new one.
742 #define SAFE_TO_REUSE_TABLE_ENTRY 0x01 /* de_flags only */
743 #define DIR_HAS_DOT 0x02 /* dir_flags only */
744 #define DIR_HAS_DOTDOT 0x04 /* dir_flags only */
745 #define INHIBIT_JOLIET_ENTRY 0x08
746 #define INHIBIT_RR_ENTRY 0x10 /* not used */
747 #define RELOCATED_DIRECTORY 0x20 /* de_flags only */
748 #define INHIBIT_ISO9660_ENTRY 0x40
749 #define MEMORY_FILE 0x80 /* de_flags only */
750 #define HIDDEN_FILE 0x100 /* de_flags only */
751 #define DIR_WAS_SCANNED 0x200 /* dir_flags only */
754 * Volume sequence number to use in all of the iso directory records.
759 * Make sure we have a definition for this. If not, take a very conservative
761 * POSIX requires the max pathname component lenght to be defined in limits.h
762 * If variable, it may be undefined. If undefined, there should be
763 * a definition for _POSIX_NAME_MAX in limits.h or in unistd.h
764 * As _POSIX_NAME_MAX is defined to 14, we cannot use it.
765 * XXX Eric's wrong comment:
766 * XXX From what I can tell SunOS is the only one with this trouble.
773 #define NAME_MAX FILENAME_MAX
781 #define PATH_MAX FILENAME_MAX
783 #define PATH_MAX 1024
788 * XXX JS: Some structures have odd lengths!
789 * Some compilers (e.g. on Sun3/mc68020) padd the structures to even length.
790 * For this reason, we cannot use sizeof (struct iso_path_table) or
791 * sizeof (struct iso_directory_record) to compute on disk sizes.
792 * Instead, we use offsetof(..., name) and add the name size.
796 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
800 * EB: various shared stuff
802 extern char *merge_warn_msg;