Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / genisoimage / genisoimage.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
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).
6  *
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.
10  *
11  */
12
13 /* @(#)genisoimage.h    1.95 05/05/01 joerg */
14 /*
15  * Header file genisoimage.h - assorted structure definitions and typecasts.
16  *
17  * Written by Eric Youngdale (1993).
18  *
19  * Copyright 1993 Yggdrasil Computing, Incorporated
20  * Copyright (c) 1999,2000-2003 J. Schilling
21  *
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)
25  * any later version.
26  *
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.
31  *
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.
35  */
36
37 /* APPLE_HYB James Pearson j.pearson@ge.ucl.ac.uk 23/2/2000 */
38
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"
40
41
42 #include <mconfig.h>    /* Must be before stdio.h for LARGEFILE support */
43 #include <stdio.h>
44 #include <statdefs.h>
45 #include <stdxlib.h>
46 #include <unixstd.h>    /* Needed for for LARGEFILE support */
47 #include <strdefs.h>
48 #include <dirdefs.h>
49 #include <utypes.h>
50 #include <standard.h>
51 #include <libport.h>
52 #include "scsi.h"
53 #ifdef JIGDO_TEMPLATE
54 #include "jte.h"
55 #endif
56
57 #ifdef  DVD_VIDEO
58 #ifndef UDF
59 #define UDF
60 #endif
61 #endif
62
63 /*#if   _LFS_LARGEFILE*/
64 #ifdef  HAVE_LARGEFILES
65 /*
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
69  */
70 #       define  fseek   fseeko
71 #       define  ftell   ftello
72 #endif
73
74 #ifndef HAVE_LSTAT
75 #ifndef VMS
76 #define lstat   stat
77 #endif
78 #endif
79
80 #include "iso9660.h"
81 #include "defaults.h"
82 #include <unls.h>
83
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 */
88
89 #ifdef APPLE_HYB
90 #include "mactypes.h"
91 #include "hfs.h"
92
93 struct hfs_info {
94         unsigned char   finderinfo[32];
95         char            name[HFS_MAX_FLEN + 1];
96         /* should have fields for dates here as well */
97         char            *keyname;
98         struct hfs_info *next;
99 };
100
101 #endif  /* APPLE_HYB */
102
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;
108         off_t           size;
109         unsigned short  priority;
110         unsigned char   jreclen;        /* Joliet record len */
111         char            *name;
112         char            *table;
113         char            *whole_name;
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;
123 #ifdef APPLE_HYB
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 */
129 #ifdef SORTING
130         int             sort;           /* sort weight for entry */
131 #endif /* SORTING */
132 #ifdef UDF
133         int             udf_file_entry_sector;  /* also used as UDF unique ID */
134 #endif
135     uint64_t realsize;
136 };
137
138 struct file_hash {
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;
144         off_t           size;
145 #ifdef SORTING
146         struct directory_entry *de;
147 #endif /* SORTING */
148 };
149
150
151 /*
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.
157  *
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
160  * works like magic.
161  *
162  * The three passes each do the following:
163  *
164  * The 'size' pass determines the size of each component and assigns the extent number
165  * for that component.
166  *
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.
169  *
170  * The 'write' pass actually writes the data to the disc.
171  */
172 struct output_fragment {
173         struct output_fragment *of_next;
174         int             (*of_size)(int);
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 */
179 };
180
181 extern struct output_fragment *out_list;
182 extern struct output_fragment *out_tail;
183
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;
211
212 #ifdef APPLE_HYB
213 extern struct output_fragment hfs_desc;
214
215 #endif  /* APPLE_HYB */
216 #ifdef DVD_VIDEO
217 /*
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.
222  */
223 typedef struct {
224         int     realsize_ifo;
225         int     realsize_menu;
226         int     realsize_bup;
227         int     size_ifo;
228         int     size_menu;
229         int     size_title;
230         int     size_bup;
231         int     pad_ifo;
232         int     pad_menu;
233         int     pad_title;
234         int     pad_bup;
235         int     number_of_vob_files;
236         int     realsize_vob[10];
237 } title_set_t;
238
239 typedef struct {
240         int             num_titles;
241         title_set_t     *title_set;
242 } title_set_info_t;
243 #endif /* DVD_VIDEO */
244
245 /*
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.
252  */
253 struct directory {
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 */
263                                         /* for this dir */
264         unsigned int    depth;
265         unsigned int    size;
266         unsigned int    extent;
267         unsigned int    jsize;
268         unsigned int    jextent;
269         unsigned int    path_index;
270         unsigned int    jpath_index;
271         unsigned short  dir_flags;
272         unsigned short  dir_nlink;
273 #ifdef APPLE_HYB
274         hfsdirent       *hfs_ent;       /* HFS parameters */
275         struct hfs_info *hfs_info;      /* list of info for all entries in dir */
276 #endif  /* APPLE_HYB */
277 #ifdef SORTING
278         int             sort;           /* sort weight for child files */
279 #endif /* SORTING */
280 };
281
282 struct deferred_write {
283         struct deferred_write *next;
284         char            *table;
285         unsigned int    extent;
286         off_t           size;
287         char            *name;
288         struct directory_entry *s_entry;
289         unsigned int    pad;
290         off_t           off;
291 };
292
293 struct eltorito_boot_entry_info {
294         struct eltorito_boot_entry_info *next;
295         char            *boot_image;
296         int             not_bootable;
297         int             no_emul_boot;
298         int             hard_disk_boot;
299         int             boot_info_table;
300         int             load_size;
301         int             load_addr;
302 };
303
304 extern int      goof;
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;
311
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;
317
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;
323
324 extern struct iso_directory_record root_record;
325 extern struct iso_directory_record jroot_record;
326
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;
337 extern int      osecsize;
338 extern int      use_XA;
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;
352 extern int      verbose;
353 extern int      debug;
354 extern int      gui;
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;
364 extern int      no_rr;
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;
379 char            *outfile;
380
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 */
384
385 #ifdef DVD_VIDEO
386 extern int      dvd_video;
387 #endif /* DVD_VIDEO */
388
389
390 #ifdef APPLE_HYB
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 */
411
412 #define MAP_LAST        1       /* process magic then map file */
413 #define MAG_LAST        2       /* process map then magic file */
414
415 #ifndef PREP_BOOT
416 #define PREP_BOOT
417 #endif  /* PREP_BOOT */
418
419 #ifdef PREP_BOOT
420 extern char     *prep_boot_image[4];
421 extern int      use_prep_boot;
422 extern int      use_chrp_boot;
423
424 #endif  /* PREP_BOOT */
425 #endif  /* APPLE_HYB */
426
427 #ifdef SORTING
428 extern int      do_sort;
429 #endif /* SORTING */
430
431 /* tree.c */
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,
438                          int,
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);
443
444 #ifdef APPLE_HYB
445 extern int      insert_file_entry(struct directory *, char *, char *, int);
446 #else
447 extern int      insert_file_entry(struct directory *, char *, char *);
448 #endif  /* APPLE_HYB */
449
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;
458
459 /* eltorito.c */
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);
464
465 /* boot.c */
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);
472
473 /* boot-alpha.c */
474 extern int add_boot_alpha_filename(char *filename);
475
476 /* boot-hppa.c */
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);
482
483 /* boot-mips.c */
484 extern int add_boot_mips_filename(char *filename);
485
486 /* boot-mipsel.c */
487 extern int add_boot_mipsel_filename(char *filename);
488
489 /* rsync.c */
490 extern unsigned long long rsync64(unsigned char *mem, size_t size);
491
492 /* write.c */
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,
507                                                   BOOL islast);
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);
511
512 #ifdef APPLE_HYB
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 *);
518
519 #ifdef PREP_BOOT
520 extern void gen_prepboot_label(unsigned char *);
521
522 #endif  /* PREP_BOOT */
523 #endif  /* APPLE_HYB */
524
525 /* multi.c */
526
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 *, 
537                                                                                          char *, char *);
538 extern int get_session_start(int *);
539
540 /* joliet.c */
541 #ifdef  UDF
542 #   ifdef USE_ICONV
543 extern  size_t  convert_to_unicode      (unsigned char *buffer,
544                         int size, char *source, struct unls_table *inls);
545 #   else
546 extern  void    convert_to_unicode      (unsigned char *buffer,
547                         int size, char *source, struct unls_table *inls);
548 #   endif
549 extern  int     joliet_strlen   (const char *string, struct unls_table *inls);
550 #endif
551 extern unsigned char conv_charset(unsigned char, struct unls_table *,
552                                                                                          struct unls_table *);
553 extern int joliet_sort_tree(struct directory * node);
554
555 /* match.c */
556 extern int matches(char *);
557 extern int add_match(char *);
558
559 /* files.c */
560 struct dirent   *readdir_add_files(char **, char *, DIR *);
561
562 /* name.c */
563
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);
568
569 /* various */
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);
573
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 *);
581
582 extern int      generate_xa_rr_attributes(char *, char *, struct directory_entry *,
583                                                                                                   struct stat *, struct stat *, 
584                                                                                                   int deep_flag);
585 extern char     *generate_rr_extension_record(char *id, char *descriptor,
586                                                                                                                 char *source, int *size);
587
588 extern int      check_prev_session(struct directory_entry **, int len, 
589                                                                                  struct directory_entry *, struct stat *,
590                                                                                  struct stat *, struct directory_entry **);
591
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);
595
596 #ifdef APPLE_HYB
597 /* volume.c */
598 extern int make_mac_volume(struct directory * dpnt, int start_extent);
599 extern int write_fork(hfsfile * hfp, long tot);
600
601 /* apple.c */
602
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 *);
614
615 /* desktop.c */
616
617 extern int make_desktop(hfsvol *, int);
618
619 /* mac_label.c */
620
621 #ifdef  _MAC_LABEL_H
622 #ifdef PREP_BOOT
623 extern void     gen_prepboot_label(MacLabel * mac_label);
624 #endif
625 extern int      gen_mac_label(defer *);
626 #endif
627 extern int      autostart(void);
628
629 /* libfile */
630
631 extern char     *get_magic_match(const char *);
632 extern void     clean_magic(void);
633
634 #endif  /* APPLE_HYB */
635
636 extern char     *extension_record;
637 extern int      extension_record_extent;
638 extern int      n_data_extents;
639
640 /*
641  * These are a few goodies that can be specified on the command line, and are
642  * filled into the root record
643  */
644 extern char     *preparer;
645 extern char     *publisher;
646 extern char     *copyright;
647 extern char     *biblio;
648 extern char     *abstract;
649 extern char     *appid;
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;
659
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;
663
664 extern char     *findgequal(char *);
665 extern void     *e_malloc(size_t);
666
667 /*
668  * Note: always use these macros to avoid problems.
669  *
670  * ISO_ROUND_UP(X)      may cause an integer overflow and thus give
671  *                      incorrect results. So avoid it if possible.
672  *
673  * ISO_BLOCKS(X)        is overflow safe. Prefer this when ever it is possible.
674  */
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))
678
679 #define ROUND_UP(X, Y)  (((X + (Y - 1)) / Y) * Y)
680
681 #ifdef APPLE_HYB
682 /*
683  * ISO blocks == 2048, HFS blocks == 512
684  */
685 #define HFS_BLK_CONV    (SECTOR_SIZE/HFS_BLOCKSZ)
686
687 #define HFS_ROUND_UP(X) ISO_ROUND_UP(((X)*HFS_BLOCKSZ)) /* XXX ??? */
688 #define HFS_BLOCKS(X)   (ISO_BLOCKS(X) * HFS_BLK_CONV)
689
690 #define USE_MAC_NAME(E) (use_mac_name && ((E)->hfs_ent != NULL) && (E)->hfs_type)
691 #endif  /* APPLE_HYB */
692
693 /*
694  * Rock Ridge defines
695  */
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             */
701
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                   */
710
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          */
714
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  */
719
720
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)
725
726 #ifdef VMS
727 #define STAT_INODE(X)   (X.st_ino[0])
728 #define PATH_SEPARATOR  ']'
729 #define SPATH_SEPARATOR ""
730 #else
731 #define STAT_INODE(X)   (X.st_ino)
732 #define PATH_SEPARATOR  '/'
733 #define SPATH_SEPARATOR "/"
734 #endif
735
736 /*
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.
741  */
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 */
752
753 /*
754  * Volume sequence number to use in all of the iso directory records.
755  */
756 #define DEF_VSN         1
757
758 /*
759  * Make sure we have a definition for this.  If not, take a very conservative
760  * guess.
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.
767  */
768 #ifdef  HAVE_LIMITS_H
769 #include <limits.h>
770 #endif
771 #ifndef NAME_MAX
772 #ifdef FILENAME_MAX
773 #define NAME_MAX        FILENAME_MAX
774 #else
775 #define NAME_MAX        256
776 #endif
777 #endif
778
779 #ifndef PATH_MAX
780 #ifdef FILENAME_MAX
781 #define PATH_MAX        FILENAME_MAX
782 #else
783 #define PATH_MAX        1024
784 #endif
785 #endif
786
787 /*
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.
793  * See iso9660.h
794  */
795 #ifndef offsetof
796 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
797 #endif
798
799 /*
800  * EB: various shared stuff
801  */
802 extern char             *merge_warn_msg;