xref: /openbsd/gnu/usr.sbin/mkhybrid/src/mkisofs.h (revision 510d2225)
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.5 2023/11/21 08:46:06 jmatthew Exp $
24  */
25 
26 /* APPLE_HYB James Pearson j.pearson@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 omit_period;
297 extern int omit_version_number;
298 extern int transparent_compression;
299 extern int RR_relocation_depth;
300 extern int full_iso9660_filenames;
301 extern int split_SL_component;
302 extern int split_SL_field;
303 #ifdef APPLE_HYB
304 extern int apple_hyb;		/* create HFS hybrid */
305 extern int apple_ext;		/* use Apple extensions */
306 extern int apple_both;		/* common flag (for above) */
307 extern int hfs_extra;		/* extra ISO extents (hfs_ce_size) */
308 extern hce_mem *hce;		/* libhfs/mkisofs extras */
309 extern int mac_name;		/* use Mac name for ISO9660/Joliet/RR */
310 extern int create_dt;		/* create the Desktp files */
311 extern char *hfs_boot_file;	/* name of HFS boot file */
312 extern char *magic_file;	/* magic file for CREATOR/TYPE matching */
313 extern int hfs_last;		/* order in which to process map/magic files */
314 extern char *deftype;		/* default Apple TYPE */
315 extern char *defcreator;	/* default Apple CREATOR */
316 extern char *trans_tbl;		/* translation table name */
317 extern int gen_pt;		/* generate HFS partition table */
318 extern char *autoname;		/* Autostart filename */
319 extern int bsize;		/* Apple File Exchange block size */
320 extern char *hfs_volume_id;	/* HFS volume ID */
321 #define ASSOC_FLAG	4       /* ISO flag for "associated" file */
322 #define MAP_LAST	1	/* process magic then map file */
323 #define MAG_LAST	2	/* process map then magic file */
324 extern char *hfs_bless;		/* name of folder to 'bless' (System Folder) */
325 #endif /* APPLE_HYB */
326 
327 /* tree.c */
328 extern int DECL(stat_filter, (char *, struct stat *));
329 extern int DECL(lstat_filter, (char *, struct stat *));
330 extern int DECL(sort_tree,(struct directory *));
331 extern struct directory *
332            DECL(find_or_create_directory,(struct directory *, const char *,
333 					  struct directory_entry * self, int));
334 extern void DECL (finish_cl_pl_entries, (void));
335 extern int DECL(scan_directory_tree,(struct directory * this_dir,
336 				     char * path,
337 				     struct directory_entry * self));
338 #ifdef APPLE_HYB
339 extern int DECL(insert_file_entry,(struct directory *, char *,
340 				   char *, int));
341 #else
342 extern int DECL(insert_file_entry,(struct directory *, char *,
343 				   char *));
344 #endif /* APPLE_HYB */
345 extern void DECL(generate_iso9660_directories,(struct directory *, FILE*));
346 extern void DECL(dump_tree,(struct directory * node));
347 extern struct directory_entry * DECL(search_tree_file, (struct
348 				directory * node,char * filename));
349 extern void DECL(update_nlink_field,(struct directory * node));
350 extern void DECL (init_fstatbuf, (void));
351 extern struct stat root_statbuf;
352 
353 /* eltorito.c */
354 extern void DECL(init_boot_catalog, (const char * path ));
355 extern void DECL(get_torito_desc, (struct eltorito_boot_descriptor * path ));
356 
357 /* write.c */
358 extern int DECL(get_733,(char *));
359 extern int DECL(isonum_733,(unsigned char *));
360 extern void DECL(set_723,(char *, unsigned int));
361 extern void DECL(set_731,(char *, unsigned int));
362 extern void DECL(set_721,(char *, unsigned int));
363 extern void DECL(set_733,(char *, unsigned int));
364 extern int  DECL(sort_directory,(struct directory_entry **));
365 extern void DECL(generate_one_directory,(struct directory *, FILE*));
366 extern void DECL(memcpy_max, (char *, char *, int));
367 extern int DECL(oneblock_size, (int starting_extent));
368 extern struct iso_primary_descriptor vol_desc;
369 extern void DECL(xfwrite, (void * buffer, int count, int size, FILE * file));
370 extern void DECL(set_732, (char * pnt, unsigned int i));
371 extern void DECL(set_722, (char * pnt, unsigned int i));
372 extern void DECL(outputlist_insert, (struct output_fragment * frag));
373 
374 /* multi.c */
375 
376 extern FILE * in_image;
377 extern struct iso_directory_record *
378 	DECL(merge_isofs,(char * path));
379 
380 extern int DECL(free_mdinfo, (struct directory_entry **, int len));
381 
382 extern struct directory_entry **
383 	DECL(read_merging_directory,(struct iso_directory_record *, int*));
384 extern void
385 	DECL(merge_remaining_entries, (struct directory *,
386 				       struct directory_entry **, int));
387 extern int
388 	DECL(merge_previous_session, (struct directory *,
389 				      struct iso_directory_record *));
390 
391 extern int  DECL(get_session_start, (int *));
392 
393 /* joliet.c */
394 int DECL(joliet_sort_tree, (struct directory * node));
395 
396 /* match.c */
397 extern int DECL(matches, (char *));
398 #ifdef APPLE_HYB
399 extern int DECL(add_match, (char *));
400 #else
401 extern void DECL(add_match, (char *));
402 #endif /* APPLE_HYB */
403 
404 /* files.c */
405 struct dirent * DECL(readdir_add_files, (char **, char *, DIR *));
406 
407 /* */
408 
409 extern int DECL(iso9660_file_length,(const char* name,
410 			       struct directory_entry * sresult, int flag));
411 extern int DECL(iso9660_date,(char *, time_t));
412 extern void DECL(add_hash,(struct directory_entry *));
413 extern struct file_hash * DECL(find_hash,(dev_t, ino_t));
414 #ifdef APPLE_HYB
415 extern void flush_hash();
416 #endif /* APPLE_HYB */
417 extern void DECL(add_directory_hash,(dev_t, ino_t));
418 extern struct file_hash * DECL(find_directory_hash,(dev_t, ino_t));
419 extern void DECL (flush_file_hash, (void));
420 extern int DECL(delete_file_hash,(struct directory_entry *));
421 extern struct directory_entry * DECL(find_file_hash,(char *));
422 extern void DECL(add_file_hash,(struct directory_entry *));
423 extern int DECL(generate_rock_ridge_attributes,(char *, char *,
424 					  struct directory_entry *,
425 					  struct stat *, struct stat *,
426 					  int  deep_flag));
427 extern char * DECL(generate_rr_extension_record,(char * id,  char  * descriptor,
428 				    char * source, int  * size));
429 
430 extern int    DECL(check_prev_session, (struct directory_entry **, int len,
431 				     struct directory_entry *,
432 				     struct stat *,
433 				     struct stat *,
434 				     struct directory_entry **));
435 
436 #ifdef	USE_SCG
437 /* scsi.c */
438 #ifdef __STDC__
439 extern	int	readsecs(int startsecno, void *buffer, int sectorcount);
440 extern	int	scsidev_open(char *path);
441 #else
442 extern	int	readsecs();
443 extern	int	scsidev_open();
444 #endif
445 #endif
446 
447 extern char * extension_record;
448 extern int extension_record_extent;
449 extern int n_data_extents;
450 
451 /* These are a few goodies that can be specified on the command line, and  are
452    filled into the root record */
453 
454 extern char * preparer;
455 extern char * publisher;
456 extern char * copyright;
457 extern char * biblio;
458 extern char * abstract;
459 extern char * appid;
460 extern char * volset_id;
461 extern char * system_id;
462 extern char * volume_id;
463 extern char * boot_catalog;
464 extern char * boot_image;
465 extern char * efi_boot_image;
466 extern int volume_set_size;
467 extern int volume_sequence_number;
468 
469 extern void * DECL(e_malloc,(size_t));
470 
471 
472 #define SECTOR_SIZE (2048)
473 #define ROUND_UP(X)    ((X + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
474 #ifdef APPLE_HYB
475 #define V_ROUND_UP(X,Y) (((X + (Y - 1)) / Y) * Y)
476 #define H_ROUND_UP(X)  ROUND_UP(((X)*HFS_BLOCKSZ))
477 /* ISO blocks == 2048, HFS blocks == 512 */
478 #define BLK_CONV (SECTOR_SIZE/HFS_BLOCKSZ)
479 
480 #define USE_MAC_NAME(N,E) ((N) && ((E)->hfs_ent != NULL) && (E)->hfs_type)
481 #endif /* APPLE_HYB */
482 
483 #define NEED_RE 1
484 #define NEED_PL  2
485 #define NEED_CL 4
486 #define NEED_CE 8
487 #define NEED_SP 16
488 
489 #define PREV_SESS_DEV	(sizeof(dev_t) >= 4 ? 0x7ffffffd : 0x7ffd)
490 #define TABLE_INODE	(sizeof(ino_t) >= 8 ? 0x7ffffffffffffffeLL : 0x7ffffffe)
491 #define UNCACHED_INODE	(sizeof(ino_t) >= 8 ? 0x7fffffffffffffffLL : 0x7fffffff)
492 #define UNCACHED_DEVICE	(sizeof(dev_t) >= 4 ? 0x7fffffff : 0x7fff)
493 
494 #ifdef VMS
495 #define STAT_INODE(X) (X.st_ino[0])
496 #define PATH_SEPARATOR ']'
497 #define SPATH_SEPARATOR ""
498 #else
499 #define STAT_INODE(X) (X.st_ino)
500 #define PATH_SEPARATOR '/'
501 #define SPATH_SEPARATOR "/"
502 #endif
503 
504 /*
505  * When using multi-session, indicates that we can reuse the
506  * TRANS.TBL information for this directory entry.  If this flag
507  * is set for all entries in a directory, it means we can just
508  * reuse the TRANS.TBL and not generate a new one.
509  */
510 #define SAFE_TO_REUSE_TABLE_ENTRY  0x01
511 #define DIR_HAS_DOT		   0x02
512 #define DIR_HAS_DOTDOT		   0x04
513 #define INHIBIT_JOLIET_ENTRY	   0x08
514 #define INHIBIT_RR_ENTRY	   0x10
515 #define RELOCATED_DIRECTORY	   0x20
516 #define INHIBIT_ISO9660_ENTRY	   0x40
517 
518 /*
519  * Volume sequence number to use in all of the iso directory records.
520  */
521 #define DEF_VSN		1
522 
523 /*
524  * Make sure we have a definition for this.  If not, take a very conservative
525  * guess.  From what I can tell SunOS is the only one with this trouble.
526  */
527 #ifndef NAME_MAX
528 #ifdef FILENAME_MAX
529 #define NAME_MAX	FILENAME_MAX
530 #else
531 #define NAME_MAX	128
532 #endif
533 #endif
534