1 /* @(#)mkisofs.h	1.153 20/03/24 joerg */
2 /*
3  * Header file mkisofs.h - assorted structure definitions and typecasts.
4  *
5  * Written by Eric Youngdale (1993).
6  *
7  * Copyright 1993 Yggdrasil Computing, Incorporated
8  * Copyright (c) 1999,2000-2020 J. Schilling
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 /* APPLE_HYB James Pearson j.pearson@ge.ucl.ac.uk 23/2/2000 */
26 
27 /* DUPLICATES_ONCE Alex Kopylov cdrtools@bootcd.ru 19.06.2004 */
28 
29 #include <schily/mconfig.h>	/* Must be before stdio.h for LARGEFILE support */
30 #include <schily/stdio.h>
31 #include <schily/types.h>
32 #include <schily/time.h>
33 #include <schily/stat.h>
34 #include <schily/stdlib.h>
35 #include <schily/unistd.h>	/* Needed for for LARGEFILE support */
36 #include <schily/string.h>
37 #include <schily/dirent.h>
38 #include <schily/utypes.h>
39 #include <schily/standard.h>
40 #include <schily/nlsdefs.h>
41 #include <schily/ctype.h>
42 #include <schily/libport.h>	/* Define missing prototypes */
43 #include "scsi.h"
44 
45 #ifdef	DVD_AUD_VID
46 #ifndef	UDF
47 #define	UDF
48 #endif
49 #endif
50 
51 #ifdef	USE_LARGEFILES
52 /*
53  * XXX Hack until fseeko()/ftello() are available everywhere or until
54  * XXX we know a secure way to let autoconf ckeck for fseeko()/ftello()
55  * XXX without defining FILE_OFFSETBITS to 64 in confdefs.h
56  */
57 #	define	fseek	fseeko
58 #	define	ftell	ftello
59 #endif
60 
61 #ifndef	HAVE_LSTAT
62 #ifndef	VMS
63 #define	lstat	stat
64 #endif
65 #endif
66 
67 #include "iso9660.h"
68 #include "defaults.h"
69 #include <schily/siconv.h>
70 
71 extern siconvt_t	*in_nls;	/* input UNICODE conversion table */
72 extern siconvt_t	*out_nls;	/* output UNICODE conversion table */
73 extern siconvt_t	*hfs_inls;	/* input HFS UNICODE conversion table */
74 extern siconvt_t	*hfs_onls;	/* output HFS UNICODE conversion table */
75 
76 /*
77  * Structure used to pass arguments via trewalk() to walkfun().
78  */
79 struct wargs {
80 	void	*dir;			/* Pointer to struct directory *root */
81 	char	*name;			/* NULL or alternative short name    */
82 };
83 
84 #ifdef APPLE_HYB
85 #include "mactypes.h"
86 #include "hfs.h"
87 
88 struct hfs_info {
89 	unsigned char	finderinfo[32];
90 	char		name[HFS_MAX_FLEN + 1];
91 	/* should have fields for dates here as well */
92 	char		*keyname;
93 	struct hfs_info *next;
94 };
95 
96 #endif	/* APPLE_HYB */
97 
98 /*
99  * Our version of "struct timespec".
100  * Currently only used with UDF.
101  */
102 typedef struct timesp {
103 	time_t	tv_sec;
104 	Int32_t	tv_nsec;
105 } timesp;
106 
107 struct directory_entry {
108 	struct directory_entry *next;
109 	struct directory_entry *jnext;
110 	struct iso_directory_record isorec;
111 	unsigned int	starting_block;
112 	off_t		size;
113 	int		mxpart;		/* Extent number	  */
114 	unsigned short	priority;
115 	unsigned char	jreclen;	/* Joliet record len */
116 	char		*name;
117 	char		*table;
118 	char		*whole_name;
119 	struct directory *filedir;
120 	struct directory_entry *parent_rec;
121 	struct directory_entry *mxroot;	/* Pointer to orig entry */
122 	unsigned int	de_flags;
123 #ifdef UDF
124 	mode_t	mode;	/* used for udf */
125 	dev_t	rdev;	/* used for udf devices */
126 	uid_t	uid;	/* used for udf */
127 	gid_t	gid;	/* used for udf */
128 	timesp	atime;	/* timespec for atime */
129 	timesp	mtime;	/* timespec for mtime */
130 	timesp	ctime;	/* timespec for ctime */
131 #endif
132 	ino_t		inode;		/* Used in the hash table */
133 	dev_t		dev;		/* Used in the hash table */
134 	unsigned char	*rr_attributes;
135 	unsigned int	rr_attr_size;
136 	unsigned int	total_rr_attr_size;
137 	unsigned int	got_rr_name;
138 #ifdef APPLE_HYB
139 	struct directory_entry *assoc;	/* entry has a resource fork */
140 	hfsdirent	*hfs_ent;	/* HFS parameters */
141 	off_t		hfs_off;	/* offset to real start of fork */
142 	int		hfs_type;	/* type of HFS Unix file */
143 #endif	/* APPLE_HYB */
144 #ifdef SORTING
145 	int		sort;		/* sort weight for entry */
146 #endif /* SORTING */
147 #ifdef UDF
148 	int		udf_file_entry_sector;	/* also used as UDF unique ID */
149 #endif
150 #ifdef	DUPLICATES_ONCE
151 	unsigned char	*digest_fast;
152 	unsigned char	*digest_full;
153 #endif
154 };
155 
156 struct file_hash {
157 	struct file_hash *next;
158 	ino_t		inode;		/* Used in the hash table */
159 	dev_t		dev;		/* Used in the hash table */
160 	nlink_t		nlink;		/* Used to compute new link count */
161 	unsigned int	starting_block;
162 	off_t		size;
163 #if	defined(SORTING) || defined(DUPLICATES_ONCE)
164 	struct directory_entry *de;
165 #endif /* SORTING */
166 };
167 
168 
169 /*
170  * This structure is used to control the output of fragments to the cdrom
171  * image.  Everything that will be written to the output image will eventually
172  * go through this structure.   There are two pieces - first is the sizing where
173  * we establish extent numbers for everything, and the second is when we actually
174  * generate the contents and write it to the output image.
175  *
176  * This makes it trivial to extend mkisofs to write special things in the image.
177  * All you need to do is hook an additional structure in the list, and the rest
178  * works like magic.
179  *
180  * The three passes each do the following:
181  *
182  * The 'size' pass determines the size of each component and assigns the extent number
183  * for that component.
184  *
185  * The 'generate' pass will adjust the contents and pointers as required now that extent
186  * numbers are assigned.  In some cases, the contents of the record are also generated.
187  *
188  * The 'write' pass actually writes the data to the disc.
189  */
190 struct output_fragment {
191 	struct output_fragment *of_next;
192 	int		(*of_size)	__PR((UInt32_t));
193 	int		(*of_generate)	__PR((void));
194 	int		(*of_write)	__PR((FILE *));
195 	char		*of_name;			/* Textual description */
196 	unsigned int	of_start_extent;		/* For consist check */
197 };
198 
199 extern struct output_fragment *out_list;
200 extern struct output_fragment *out_tail;
201 
202 extern struct output_fragment startpad_desc;
203 extern struct output_fragment voldesc_desc;
204 extern struct output_fragment xvoldesc_desc;
205 extern struct output_fragment joliet_desc;
206 extern struct output_fragment torito_desc;
207 extern struct output_fragment end_vol;
208 extern struct output_fragment version_desc;
209 extern struct output_fragment pathtable_desc;
210 extern struct output_fragment jpathtable_desc;
211 extern struct output_fragment dirtree_desc;
212 extern struct output_fragment dirtree_clean;
213 extern struct output_fragment jdirtree_desc;
214 extern struct output_fragment extension_desc;
215 extern struct output_fragment files_desc;
216 extern struct output_fragment interpad_desc;
217 extern struct output_fragment endpad_desc;
218 extern struct output_fragment sunboot_desc;
219 extern struct output_fragment sunlabel_desc;
220 extern struct output_fragment genboot_desc;
221 extern struct output_fragment strfile_desc;
222 extern struct output_fragment strdir_desc;
223 extern struct output_fragment strpath_desc;
224 
225 #ifdef APPLE_HYB
226 extern struct output_fragment hfs_desc;
227 
228 #endif	/* APPLE_HYB */
229 #ifdef DVD_AUD_VID
230 /*
231  * This structure holds the information necessary to create a valid
232  * DVD-Video image. Basically it's how much to pad the files so the
233  * file offsets described in the video_ts.ifo and vts_xx_0.ifo are
234  * the correct one in the image that we create.
235  */
236 typedef struct {
237 	int	realsize_ifo;
238 	int	realsize_menu;
239 	int	realsize_bup;
240 	int	size_ifo;
241 	int	size_menu;
242 	int	size_title;
243 	int	size_bup;
244 	int	pad_ifo;
245 	int	pad_menu;
246 	int	pad_title;
247 	int	pad_bup;
248 	int	number_of_vob_files;
249 	int	realsize_vob[10];
250 } title_set_t;
251 
252 typedef struct {
253 	int		num_titles;
254 	title_set_t	*title_set;
255 } title_set_info_t;
256 #endif /* DVD_AUD_VID */
257 
258 /*
259  * This structure describes one complete directory.  It has pointers
260  * to other directories in the overall tree so that it is clear where
261  * this directory lives in the tree, and it also must contain pointers
262  * to the contents of the directory.  Note that subdirectories of this
263  * directory exist twice in this stucture.  Once in the subdir chain,
264  * and again in the contents chain.
265  */
266 struct directory {
267 	struct directory *next;		/* Next directory at same level as this one */
268 	struct directory *subdir;	/* First subdirectory in this directory */
269 	struct directory *parent;
270 	struct directory_entry *contents;
271 	struct directory_entry *jcontents;
272 	struct directory_entry *self;
273 	char		*whole_name;	/* Entire source path */
274 	char		*de_path;	/* Entire path iside ISO-9660 */
275 	char		*de_name;	/* Last path name component */
276 	unsigned int	ce_bytes;	/* Number of bytes of CE entries read */
277 					/* for this dir */
278 	unsigned int	depth;
279 	unsigned int	size;
280 	unsigned int	extent;
281 	unsigned int	jsize;
282 	unsigned int	jextent;
283 	unsigned int	path_index;
284 	unsigned int	jpath_index;
285 	unsigned short	dir_flags;
286 	unsigned short	dir_nlink;
287 #ifdef APPLE_HYB
288 	hfsdirent	*hfs_ent;	/* HFS parameters */
289 	struct hfs_info	*hfs_info;	/* list of info for all entries in dir */
290 #endif	/* APPLE_HYB */
291 #ifdef SORTING
292 	int		sort;		/* sort weight for child files */
293 #endif /* SORTING */
294 };
295 
296 struct deferred_write {
297 	struct deferred_write *next;
298 	char		*table;
299 	unsigned int	extent;
300 	off_t		size;
301 	char		*name;
302 	struct directory_entry *s_entry;
303 	unsigned int	pad;
304 	off_t		off;
305 	unsigned int	dw_flags;
306 #ifdef APPLE_HYB
307 	int		hfstype;
308 #endif
309 };
310 
311 struct eltorito_boot_entry_info {
312 	struct eltorito_boot_entry_info *next;
313 	char		*boot_image;
314 	int		not_bootable;
315 	int		no_emul_boot;
316 	int		hard_disk_boot;
317 	int		boot_info_table;
318 	int		load_size;
319 	int		load_addr;
320 
321 #define	ELTORITO_BOOT_ID	1
322 #define	ELTORITO_SECTION_HEADER 2
323 	int		type;
324 	/*
325 	 * Valid if (type & ELTORITO_BOOT_ID) != 0
326 	 */
327 	int		boot_platform;
328 
329 };
330 
331 typedef struct ldate {
332 	time_t	l_sec;
333 	int	l_usec;
334 	int	l_gmtoff;
335 } ldate;
336 
337 extern int	goof;
338 extern struct directory *root;
339 extern struct directory *reloc_dir;
340 extern UInt32_t next_extent;
341 extern UInt32_t last_extent;
342 extern UInt32_t last_extent_written;
343 extern UInt32_t session_start;
344 
345 extern unsigned int path_table_size;
346 extern unsigned int path_table[4];
347 extern unsigned int path_blocks;
348 extern char	*path_table_l;
349 extern char	*path_table_m;
350 
351 extern unsigned int jpath_table_size;
352 extern unsigned int jpath_table[4];
353 extern unsigned int jpath_blocks;
354 extern char	*jpath_table_l;
355 extern char	*jpath_table_m;
356 
357 extern struct iso_directory_record root_record;
358 extern struct iso_directory_record jroot_record;
359 
360 extern int	check_oldnames;
361 extern int	check_session;
362 extern int	use_eltorito;
363 extern int	hard_disk_boot;
364 extern int	not_bootable;
365 extern int	no_emul_boot;
366 extern int	load_addr;
367 extern int	load_size;
368 extern int	boot_info_table;
369 extern int	use_RockRidge;
370 extern int	osecsize;
371 extern int	use_XA;
372 extern int	use_Joliet;
373 extern int	rationalize;
374 extern int	rationalize_uid;
375 extern int	rationalize_gid;
376 extern int	rationalize_filemode;
377 extern int	rationalize_dirmode;
378 extern uid_t	uid_to_use;
379 extern gid_t	gid_to_use;
380 extern int	filemode_to_use;
381 extern int	dirmode_to_use;
382 extern int	new_dir_mode;
383 extern int	follow_links;
384 extern int	cache_inodes;
385 #ifdef	DUPLICATES_ONCE
386 extern int	duplicates_once;
387 #endif
388 extern int	verbose;
389 extern int	debug;
390 extern int	gui;
391 extern int	all_files;
392 extern int	generate_tables;
393 extern int	print_size;
394 extern int	split_output;
395 extern int	use_graft_ptrs;
396 extern int	jhide_trans_tbl;
397 extern int	hide_rr_moved;
398 extern int	omit_period;
399 extern int	omit_version_number;
400 extern int	no_rr;
401 extern int	transparent_compression;
402 extern Uint	RR_relocation_depth;
403 extern int	do_largefiles;
404 extern off_t	maxnonlarge;
405 extern int	iso9660_level;
406 extern int	iso9660_namelen;
407 extern int	full_iso9660_filenames;
408 extern int	nolimitpathtables;
409 extern int	relaxed_filenames;
410 extern int	allow_lowercase;
411 extern int	allow_multidot;
412 extern int	iso_translate;
413 extern int	allow_leading_dots;
414 extern int	use_fileversion;
415 extern int	split_SL_component;
416 extern int	split_SL_field;
417 extern char	*trans_tbl;
418 
419 #define	JMAX		64	/* maximum Joliet file name length (spec) */
420 #define	JLONGMAX	103	/* out of spec Joliet file name length */
421 extern int	jlen;		/* selected maximum Joliet file name length */
422 
423 #ifdef DVD_AUD_VID
424 
425 #define	DVD_SPEC_NONE	0x0
426 #define	DVD_SPEC_VIDEO	0x1
427 #define	DVD_SPEC_AUDIO	0x2
428 #define	DVD_SPEC_HYBRD	(DVD_SPEC_VIDEO | DVD_SPEC_AUDIO)
429 extern int	dvd_audio;
430 extern int	dvd_hybrid;
431 extern int	dvd_video;
432 extern int	dvd_aud_vid_flag;
433 #endif /* DVD_AUD_VID */
434 
435 
436 extern int	donotwrite_macpart;
437 
438 #ifdef APPLE_HYB
439 extern int	apple_hyb;	/* create HFS hybrid */
440 extern int	apple_ext;	/* use Apple extensions */
441 extern int	apple_both;	/* common flag (for above) */
442 extern int	hfs_extra;	/* extra ISO extents (hfs_ce_size) */
443 extern hce_mem	*hce;		/* libhfs/mkisofs extras */
444 extern int	use_mac_name;	/* use Mac name for ISO9660/Joliet/RR */
445 extern int	create_dt;	/* create the Desktp files */
446 extern char	*hfs_boot_file;	/* name of HFS boot file */
447 extern char	*magic_file;	/* magic file for CREATOR/TYPE matching */
448 extern int	hfs_last;	/* order in which to process map/magic files */
449 extern char	*deftype;	/* default Apple TYPE */
450 extern char	*defcreator;	/* default Apple CREATOR */
451 extern int	gen_pt;		/* generate HFS partition table */
452 extern char	*autoname;	/* Autostart filename */
453 extern int	afe_size;	/* Apple File Exchange block size */
454 extern char	*hfs_volume_id;	/* HFS volume ID */
455 extern int	icon_pos;	/* Keep Icon position */
456 extern int	hfs_lock;	/* lock HFS volume (read-only) */
457 extern char	*hfs_bless;	/* name of folder to 'bless' (System Folder) */
458 extern char	*hfs_parms;	/* low level HFS parameters */
459 
460 #define	MAP_LAST	1	/* process magic then map file */
461 #define	MAG_LAST	2	/* process map then magic file */
462 
463 #ifndef PREP_BOOT
464 #define	PREP_BOOT
465 #endif	/* PREP_BOOT */
466 
467 #ifdef PREP_BOOT
468 extern char	*prep_boot_image[4];
469 extern int	use_prep_boot;
470 extern int	use_chrp_boot;
471 
472 #endif	/* PREP_BOOT */
473 #endif	/* APPLE_HYB */
474 
475 #ifdef SORTING
476 extern int	do_sort;
477 #endif /* SORTING */
478 
479 /* tree.c */
480 extern int stat_filter __PR((char *, struct stat *));
481 extern int lstat_filter __PR((char *, struct stat *));
482 extern int sort_tree __PR((struct directory *));
483 extern void attach_dot_entries __PR((struct directory * dirnode,
484 					struct stat * this_stat,
485 					struct stat * parent_stat));
486 extern struct directory *
487 		find_or_create_directory __PR((struct directory *,
488 				char *,
489 				struct directory_entry * self, int));
490 extern void	finish_cl_pl_entries __PR((void));
491 extern int	scan_directory_tree __PR((struct directory * this_dir,
492 				char *path,
493 				struct directory_entry * self));
494 
495 extern int	insert_file_entry __PR((struct directory *, char *,
496 				char *, struct stat *, int));
497 
498 extern	struct directory_entry *
499 		dup_directory_entry	__PR((struct directory_entry *s_entry));
500 extern void generate_iso9660_directories __PR((struct directory *, FILE *));
501 extern void dump_tree __PR((struct directory * node));
502 extern struct directory_entry *search_tree_file __PR((struct
503 				directory * node, char *filename));
504 extern void init_fstatbuf __PR((void));
505 extern struct stat root_statbuf;
506 extern struct stat fstatbuf;
507 
508 /* eltorito.c */
509 extern void init_boot_catalog __PR((const char *path));
510 extern void insert_boot_cat __PR((void));
511 extern void get_boot_entry	__PR((void));
512 extern int  new_boot_entry	__PR((void));
513 extern void ex_boot_enoent	__PR((char *msg, char *pname));
514 
515 /* boot.c */
516 extern int sparc_boot_label __PR((char *label));
517 extern int sunx86_boot_label __PR((char *label));
518 extern int scan_sparc_boot __PR((char *files));
519 extern int scan_sunx86_boot __PR((char *files));
520 extern int make_sun_label __PR((void));
521 extern int make_sunx86_label __PR((void));
522 
523 /* isonum.c */
524 extern void set_721 __PR((void *, UInt32_t));
525 extern void set_722 __PR((void *, UInt32_t));
526 extern void set_723 __PR((void *, UInt32_t));
527 extern void set_731 __PR((void *, UInt32_t));
528 extern void set_732 __PR((void *, UInt32_t));
529 extern void set_733 __PR((void *, UInt32_t));
530 
531 extern UInt32_t get_711 __PR((void *));
532 extern UInt32_t get_721 __PR((void *));
533 extern UInt32_t get_723 __PR((void *));
534 extern UInt32_t get_731 __PR((void *));
535 extern UInt32_t get_732 __PR((void *));
536 extern UInt32_t get_733 __PR((void *));
537 
538 /* write.c */
539 extern int sort_directory __PR((struct directory_entry **, int));
540 extern void generate_one_directory __PR((struct directory *, FILE *));
541 extern void memcpy_max __PR((char *, char *, int));
542 extern int oneblock_size __PR((UInt32_t starting_extent));
543 extern struct iso_primary_descriptor vol_desc;
544 extern void xfwrite __PR((void *buffer, int size, int count, FILE * file, int submode, BOOL islast));
545 extern void outputlist_insert __PR((struct output_fragment * frag));
546 
547 #ifdef APPLE_HYB
548 extern Ulong get_adj_size __PR((int Csize));
549 extern int adj_size __PR((int Csize, UInt32_t start_extent, int extra));
550 extern void adj_size_other __PR((struct directory * dpnt));
551 extern int insert_padding_file __PR((int size));
552 extern int gen_mac_label __PR((struct deferred_write *));
553 
554 #ifdef PREP_BOOT
555 extern void gen_prepboot_label __PR((unsigned char *));
556 
557 #endif	/* PREP_BOOT */
558 #endif	/* APPLE_HYB */
559 
560 /* multi.c */
561 
562 extern FILE	*in_image;
563 extern BOOL	ignerr;
564 extern int open_merge_image __PR((char *path));
565 extern int close_merge_image __PR((void));
566 extern struct iso_directory_record *
567 			merge_isofs __PR((char *path));
568 extern unsigned char	*parse_xa __PR((unsigned char *pnt, int *lenp,
569 				struct directory_entry * dpnt));
570 extern int	rr_flags	__PR((struct iso_directory_record *idr));
571 extern int merge_previous_session __PR((struct directory *,
572 				struct iso_directory_record *, char *, char *));
573 extern int get_session_start __PR((int *));
574 
575 /* joliet.c */
576 #ifdef	UDF
577 extern	void	convert_to_unicode	__PR((unsigned char *buffer,
578 			int size, char *source, siconvt_t *inls));
579 extern	int	joliet_strlen		__PR((const char *string, size_t maxlen,
580 						siconvt_t *inls));
581 #endif
582 extern void conv_charset __PR((unsigned char *to, size_t *tosizep,
583 				unsigned char *from, size_t *fromsizep,
584 				siconvt_t *,
585 				siconvt_t *));
586 extern int joliet_sort_tree __PR((struct directory * node));
587 
588 /* match.c */
589 extern int matches __PR((char *));
590 extern int add_match __PR((char *));
591 
592 /* files.c */
593 struct dirent	*readdir_add_files __PR((char **, char *, DIR *));
594 
595 /* name.c */
596 
597 extern void iso9660_check	__PR((struct iso_directory_record *idr, struct directory_entry *ndr));
598 extern int iso9660_file_length __PR((const char *name,
599 				struct directory_entry * sresult, int flag));
600 
601 /* various */
602 extern int iso9660_date __PR((char *, time_t));
603 extern int iso9660_ldate __PR((char *, time_t, int, int));
604 extern void add_hash __PR((struct directory_entry *));
605 extern struct file_hash *find_hash __PR((struct directory_entry *spnt));
606 
607 extern void flush_hash __PR((void));
608 extern void add_directory_hash __PR((dev_t, ino_t));
609 extern struct file_hash *find_directory_hash __PR((dev_t, ino_t));
610 extern void flush_file_hash __PR((void));
611 extern int delete_file_hash __PR((struct directory_entry *));
612 extern struct directory_entry *find_file_hash __PR((char *));
613 extern void add_file_hash __PR((struct directory_entry *));
614 
615 extern int	generate_xa_rr_attributes __PR((char *, char *,
616 				struct directory_entry *,
617 				struct stat *, struct stat *,
618 				int deep_flag));
619 extern char	*generate_rr_extension_record __PR((char *id,
620 				char *descriptor,
621 				char *source, int *size));
622 
623 extern int	check_prev_session __PR((struct directory_entry **, int len,
624 				struct directory_entry *,
625 				struct stat *,
626 				struct stat *,
627 				struct directory_entry **));
628 
629 extern void	match_cl_re_entries __PR((void));
630 extern void	finish_cl_pl_for_prev_session __PR((void));
631 extern char	*find_rr_attribute __PR((unsigned char *pnt, int len, char *attr_type));
632 
633 extern void	udf_set_extattr_macresfork __PR((unsigned char *buf, off_t size, unsigned rba));
634 extern void	udf_set_extattr_freespace __PR((unsigned char *buf, off_t size, unsigned rba));
635 extern int	udf_get_symlinkcontents __PR((char *, char *, off_t *));
636 
637 /* inode.c */
638 extern	void	do_inode		__PR((struct directory *dpnt));
639 extern	void	do_dir_nlink		__PR((struct directory *dpnt));
640 
641 #ifdef APPLE_HYB
642 /* volume.c */
643 extern int make_mac_volume __PR((struct directory * dpnt, UInt32_t start_extent));
644 extern int write_fork __PR((hfsfile * hfp, long tot));
645 
646 /* apple.c */
647 
648 extern void del_hfs_info __PR((struct hfs_info *));
649 extern int get_hfs_dir __PR((char *, char *, struct directory_entry *));
650 extern int get_hfs_info __PR((char *, char *, struct directory_entry *));
651 extern int get_hfs_rname __PR((char *, char *, char *));
652 extern int hfs_exclude __PR((char *));
653 extern void print_hfs_info __PR((struct directory_entry *));
654 extern void hfs_init __PR((char *, unsigned short, unsigned int));
655 extern void delete_rsrc_ent __PR((struct directory_entry *));
656 extern void clean_hfs __PR((void));
657 extern void perr __PR((char *));
658 extern void set_root_info __PR((char *));
659 extern int file_is_resource __PR((char *fname, int hfstype));
660 extern int hfs_excludepath __PR((char *));
661 
662 /* desktop.c */
663 
664 extern int make_desktop __PR((hfsvol *, int));
665 
666 /* mac_label.c */
667 
668 #ifdef	_MAC_LABEL_H
669 #ifdef PREP_BOOT
670 extern void	gen_prepboot_label __PR((MacLabel * mac_label));
671 #endif
672 extern int	gen_mac_label __PR((defer *));
673 #endif
674 extern int	autostart __PR((void));
675 
676 /* libfile */
677 
678 extern char	*get_magic_match __PR((const char *));
679 extern void	clean_magic __PR((void));
680 
681 #endif	/* APPLE_HYB */
682 
683 #ifdef	USE_FIND
684 /*
685  * The callback function for treewalk() from walk.c
686  */
687 #ifdef	_SCHILY_WALK_H
688 EXPORT	int	walkfunc	__PR((char *nm, struct stat *fs, int type,
689 					struct WALK *state));
690 #endif
691 #endif
692 
693 extern char	*extension_record;
694 extern UInt32_t	extension_record_extent;
695 /*extern int	n_data_extents;*/
696 extern	BOOL	archive_isreg;
697 extern	dev_t	archive_dev;
698 extern	ino_t	archive_ino;
699 
700 /*
701  * These are a few goodies that can be specified on the command line, and are
702  * filled into the root record
703  */
704 extern char	*preparer;
705 extern char	*publisher;
706 extern char	*copyright;
707 extern char	*biblio;
708 extern char	*abstract;
709 extern char	*appid;
710 extern char	*volset_id;
711 extern char	*system_id;
712 extern char	*volume_id;
713 extern char	*boot_catalog;
714 extern char	*boot_image;
715 extern char	*genboot_image;
716 extern int	ucs_level;
717 extern int	volume_set_size;
718 extern int	volume_sequence_number;
719 
720 extern struct eltorito_boot_entry_info *first_boot_entry;
721 extern struct eltorito_boot_entry_info *last_boot_entry;
722 extern struct eltorito_boot_entry_info *current_boot_entry;
723 
724 extern	UInt32_t null_inodes;
725 extern	BOOL	correct_inodes;
726 extern	BOOL	rrip112;
727 extern	BOOL	long_rr_time;	/* TRUE: use long (17 Byte) time format	    */
728 extern	BOOL	noatime;	/* Whether not to include file access time  */
729 
730 extern char	*findgequal	__PR((char *));
731 extern void	*e_malloc	__PR((size_t));
732 extern char	*e_strdup	__PR((const char *));
733 
734 /*
735  * Note: always use these macros to avoid problems.
736  *
737  * ISO_ROUND_UP(X)	may cause an integer overflow and thus give
738  *			incorrect results. So avoid it if possible.
739  *
740  * ISO_BLOCKS(X)	is overflow safe. Prefer this when ever it is possible.
741  */
742 #define	SECTOR_SIZE	(2048)
743 #define	ISO_ROUND_UP(X)	(((X) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
744 #define	ISO_BLOCKS(X)	(((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
745 
746 #define	ROUND_UP(X, Y)	(((X + (Y - 1)) / Y) * Y)
747 
748 #ifdef APPLE_HYB
749 /*
750  * ISO blocks == 2048, HFS blocks == 512
751  */
752 #define	HFS_BLK_CONV	(SECTOR_SIZE/HFS_BLOCKSZ)
753 
754 #define	HFS_ROUND_UP(X)	ISO_ROUND_UP(((X)*HFS_BLOCKSZ))	/* XXX ??? */
755 #define	HFS_BLOCKS(X)	(ISO_BLOCKS(X) * HFS_BLK_CONV)
756 
757 #define	USE_MAC_NAME(E)	(use_mac_name && ((E)->hfs_ent != NULL) && (E)->hfs_type)
758 #endif	/* APPLE_HYB */
759 
760 /*
761  * Inode and device values for special purposes.
762  */
763 #define	PREV_SESS_DEV	((dev_t)-2)
764 #define	TABLE_INODE	((ino_t)-2)
765 #define	UNCACHED_INODE	((ino_t)-1)
766 #define	UNCACHED_DEVICE	((dev_t)-1)
767 
768 /*
769  * The highest value used for the inodes we assign to files that do not have
770  * a starting block address (zero length files, symlinks, dev nodes, pipes,
771  * socket).
772  * We need to make sure that these numbers are valid ISO-9660 block addresses,
773  * this is why we use unsigned 32-bit integer values.
774  * We need to make sure that the inode numbers assigned for zero sized files
775  * is in a proper range, this is why we use numbers above the range of block
776  * addresses we use in the image. We start counting backwards from 0xFFFFFFF0
777  * to leave enough space for special numbers from the range listed above.
778  */
779 #define	NULL_INO_MAX	((UInt32_t)0xFFFFFFF0)
780 
781 #ifdef VMS
782 #define	STAT_INODE(X)	(X.st_ino[0])
783 #define	PATH_SEPARATOR	']'
784 #define	SPATH_SEPARATOR	""
785 #else
786 #define	STAT_INODE(X)	(X.st_ino)
787 #define	PATH_SEPARATOR	'/'
788 #define	SPATH_SEPARATOR	"/"
789 #endif
790 
791 /*
792  * When using multi-session, indicates that we can reuse the
793  * TRANS.TBL information for this directory entry. If this flag
794  * is set for all entries in a directory, it means we can just
795  * reuse the TRANS.TBL and not generate a new one.
796  */
797 #define	SAFE_TO_REUSE_TABLE_ENTRY  0x01		/* de_flags only  */
798 #define	DIR_HAS_DOT		   0x02		/* dir_flags only */
799 #define	DIR_HAS_DOTDOT		   0x04		/* dir_flags only */
800 #define	INHIBIT_JOLIET_ENTRY	   0x08
801 #define	INHIBIT_RR_ENTRY	   0x10		/* not used	  */
802 #define	RELOCATED_DIRECTORY	   0x20		/* de_flags only  */
803 #define	INHIBIT_ISO9660_ENTRY	   0x40
804 #define	MEMORY_FILE		   0x80		/* de_flags only  */
805 #define	HIDDEN_FILE		   0x100	/* de_flags only  */
806 #define	DIR_WAS_SCANNED		   0x200	/* dir_flags only */
807 #define	RESOURCE_FORK		   0x400	/* de_flags only  */
808 #define	IS_SYMLINK		   0x800	/* de_flags only  */
809 #define	MULTI_EXTENT		   0x1000	/* de_flags only  */
810 #define	INHIBIT_UDF_ENTRY	   0x2000
811 
812 /*
813  * Volume sequence number to use in all of the iso directory records.
814  */
815 #define	DEF_VSN		1
816 
817 /*
818  * Make sure we have a definition for this.  If not, take a very conservative
819  * guess.
820  * POSIX requires the max pathname component lenght to be defined in limits.h
821  * If variable, it may be undefined. If undefined, there should be
822  * a definition for _POSIX_NAME_MAX in limits.h or in unistd.h
823  * As _POSIX_NAME_MAX is defined to 14, we cannot use it.
824  * XXX Eric's wrong comment:
825  * XXX From what I can tell SunOS is the only one with this trouble.
826  */
827 #include <schily/limits.h>
828 
829 #ifndef NAME_MAX
830 #ifdef FILENAME_MAX
831 #define	NAME_MAX	FILENAME_MAX
832 #else
833 #define	NAME_MAX	256
834 #endif
835 #endif
836 
837 #ifndef PATH_MAX
838 #ifdef FILENAME_MAX
839 #define	PATH_MAX	FILENAME_MAX
840 #else
841 #define	PATH_MAX	1024
842 #endif
843 #endif
844 
845 /*
846  * Cygwin seems to have PATH_MAX == 260 which is less than the usable
847  * path length. We raise PATH_MAX to at least 1024 for now for all platforms
848  * unless someone reports problems with mkisofs memory size.
849  */
850 #if	PATH_MAX < 1024
851 #undef	PATH_MAX
852 #define	PATH_MAX	1024
853 #endif
854 
855 /*
856  * XXX JS: Some structures have odd lengths!
857  * Some compilers (e.g. on Sun3/mc68020) padd the structures to even length.
858  * For this reason, we cannot use sizeof (struct iso_path_table) or
859  * sizeof (struct iso_directory_record) to compute on disk sizes.
860  * Instead, we use offsetof(..., name) and add the name size.
861  * See iso9660.h
862  */
863 #ifndef	offsetof
864 #define	offsetof(TYPE, MEMBER)	((size_t) &((TYPE *)0)->MEMBER)
865 #endif
866 
867 #ifdef UDF
868 extern int	use_udf;
869 #endif
870 extern int	create_udfsymlinks;
871 
872 #if !defined(HAVE_MEMSET) && !defined(memset)
873 #define	memset(s, c, n)		fillbytes(s, n, c)
874 #endif
875 #if !defined(HAVE_MEMCHR) && !defined(memchr)
876 #define	memchr(s, c, n)		findbytes(s, n, c)
877 #endif
878 #if !defined(HAVE_MEMCPY) && !defined(memcpy)
879 #define	memcpy(s1, s2, n)	movebytes(s2, s1, n)
880 #endif
881 #if !defined(HAVE_MEMMOVE) && !defined(memmove)
882 #define	memmove(s1, s2, n)	movebytes(s2, s1, n)
883 #endif
884