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
81extern 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
117extern int optind;
118extern 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>
127struct hfs_info {
128  hfsdirent	hfs_ent;
129  char		*keyname;
130  struct hfs_info *next;
131};
132#endif /* APPLE_HYB */
133
134struct 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
162struct 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 */
192struct	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
206extern struct output_fragment * out_list;
207extern struct output_fragment * out_tail;
208
209extern struct output_fragment padblock_desc;
210extern struct output_fragment voldesc_desc;
211extern struct output_fragment joliet_desc;
212extern struct output_fragment torito_desc;
213extern struct output_fragment end_vol;
214extern struct output_fragment pathtable_desc;
215extern struct output_fragment jpathtable_desc;
216extern struct output_fragment dirtree_desc;
217extern struct output_fragment dirtree_clean;
218extern struct output_fragment jdirtree_desc;
219extern struct output_fragment extension_desc;
220extern 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 */
230struct 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
255struct deferred{
256  struct deferred * next;
257  unsigned int starting_block;
258  char * name;
259  struct directory * filedir;
260  unsigned int flags;
261};
262
263extern int goof;
264extern struct directory * root;
265extern struct directory * reloc_dir;
266extern unsigned int next_extent;
267extern unsigned int last_extent;
268extern unsigned int last_extent_written;
269extern unsigned int session_start;
270
271extern unsigned int path_table_size;
272extern unsigned int path_table[4];
273extern unsigned int path_blocks;
274extern char * path_table_l;
275extern char * path_table_m;
276
277extern unsigned int jpath_table_size;
278extern unsigned int jpath_table[4];
279extern unsigned int jpath_blocks;
280extern char * jpath_table_l;
281extern char * jpath_table_m;
282
283extern struct iso_directory_record root_record;
284extern struct iso_directory_record jroot_record;
285
286extern int use_eltorito;
287extern int use_RockRidge;
288extern int use_Joliet;
289extern int rationalize;
290extern int follow_links;
291extern int verbose;
292extern int all_files;
293extern int generate_tables;
294extern int print_size;
295extern int split_output;
296extern int omit_period;
297extern int omit_version_number;
298extern int transparent_compression;
299extern int RR_relocation_depth;
300extern int full_iso9660_filenames;
301extern int split_SL_component;
302extern int split_SL_field;
303#ifdef APPLE_HYB
304extern int apple_hyb;		/* create HFS hybrid */
305extern int apple_ext;		/* use Apple extensions */
306extern int apple_both;		/* common flag (for above) */
307extern int hfs_extra;		/* extra ISO extents (hfs_ce_size) */
308extern hce_mem *hce;		/* libhfs/mkisofs extras */
309extern int mac_name;		/* use Mac name for ISO9660/Joliet/RR */
310extern int create_dt;		/* create the Desktp files */
311extern char *hfs_boot_file;	/* name of HFS boot file */
312extern char *magic_file;	/* magic file for CREATOR/TYPE matching */
313extern int hfs_last;		/* order in which to process map/magic files */
314extern char *deftype;		/* default Apple TYPE */
315extern char *defcreator;	/* default Apple CREATOR */
316extern char *trans_tbl;		/* translation table name */
317extern int gen_pt;		/* generate HFS partition table */
318extern char *autoname;		/* Autostart filename */
319extern int bsize;		/* Apple File Exchange block size */
320extern 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 */
324extern char *hfs_bless;		/* name of folder to 'bless' (System Folder) */
325#endif /* APPLE_HYB */
326
327/* tree.c */
328extern int DECL(stat_filter, (char *, struct stat *));
329extern int DECL(lstat_filter, (char *, struct stat *));
330extern int DECL(sort_tree,(struct directory *));
331extern struct directory *
332           DECL(find_or_create_directory,(struct directory *, const char *,
333					  struct directory_entry * self, int));
334extern void DECL (finish_cl_pl_entries, (void));
335extern int DECL(scan_directory_tree,(struct directory * this_dir,
336				     char * path,
337				     struct directory_entry * self));
338#ifdef APPLE_HYB
339extern int DECL(insert_file_entry,(struct directory *, char *,
340				   char *, int));
341#else
342extern int DECL(insert_file_entry,(struct directory *, char *,
343				   char *));
344#endif /* APPLE_HYB */
345extern void DECL(generate_iso9660_directories,(struct directory *, FILE*));
346extern void DECL(dump_tree,(struct directory * node));
347extern struct directory_entry * DECL(search_tree_file, (struct
348				directory * node,char * filename));
349extern void DECL(update_nlink_field,(struct directory * node));
350extern void DECL (init_fstatbuf, (void));
351extern struct stat root_statbuf;
352
353/* eltorito.c */
354extern void DECL(init_boot_catalog, (const char * path ));
355extern void DECL(get_torito_desc, (struct eltorito_boot_descriptor * path ));
356
357/* write.c */
358extern int DECL(get_733,(char *));
359extern int DECL(isonum_733,(unsigned char *));
360extern void DECL(set_723,(char *, unsigned int));
361extern void DECL(set_731,(char *, unsigned int));
362extern void DECL(set_721,(char *, unsigned int));
363extern void DECL(set_733,(char *, unsigned int));
364extern int  DECL(sort_directory,(struct directory_entry **));
365extern void DECL(generate_one_directory,(struct directory *, FILE*));
366extern void DECL(memcpy_max, (char *, char *, int));
367extern int DECL(oneblock_size, (int starting_extent));
368extern struct iso_primary_descriptor vol_desc;
369extern void DECL(xfwrite, (void * buffer, int count, int size, FILE * file));
370extern void DECL(set_732, (char * pnt, unsigned int i));
371extern void DECL(set_722, (char * pnt, unsigned int i));
372extern void DECL(outputlist_insert, (struct output_fragment * frag));
373
374/* multi.c */
375
376extern FILE * in_image;
377extern struct iso_directory_record *
378	DECL(merge_isofs,(char * path));
379
380extern int DECL(free_mdinfo, (struct directory_entry **, int len));
381
382extern struct directory_entry **
383	DECL(read_merging_directory,(struct iso_directory_record *, int*));
384extern void
385	DECL(merge_remaining_entries, (struct directory *,
386				       struct directory_entry **, int));
387extern int
388	DECL(merge_previous_session, (struct directory *,
389				      struct iso_directory_record *));
390
391extern int  DECL(get_session_start, (int *));
392
393/* joliet.c */
394int DECL(joliet_sort_tree, (struct directory * node));
395
396/* match.c */
397extern int DECL(matches, (char *));
398#ifdef APPLE_HYB
399extern int DECL(add_match, (char *));
400#else
401extern void DECL(add_match, (char *));
402#endif /* APPLE_HYB */
403
404/* files.c */
405struct dirent * DECL(readdir_add_files, (char **, char *, DIR *));
406
407/* */
408
409extern int DECL(iso9660_file_length,(const char* name,
410			       struct directory_entry * sresult, int flag));
411extern int DECL(iso9660_date,(char *, time_t));
412extern void DECL(add_hash,(struct directory_entry *));
413extern struct file_hash * DECL(find_hash,(dev_t, ino_t));
414#ifdef APPLE_HYB
415extern void flush_hash();
416#endif /* APPLE_HYB */
417extern void DECL(add_directory_hash,(dev_t, ino_t));
418extern struct file_hash * DECL(find_directory_hash,(dev_t, ino_t));
419extern void DECL (flush_file_hash, (void));
420extern int DECL(delete_file_hash,(struct directory_entry *));
421extern struct directory_entry * DECL(find_file_hash,(char *));
422extern void DECL(add_file_hash,(struct directory_entry *));
423extern int DECL(generate_rock_ridge_attributes,(char *, char *,
424					  struct directory_entry *,
425					  struct stat *, struct stat *,
426					  int  deep_flag));
427extern char * DECL(generate_rr_extension_record,(char * id,  char  * descriptor,
428				    char * source, int  * size));
429
430extern 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__
439extern	int	readsecs(int startsecno, void *buffer, int sectorcount);
440extern	int	scsidev_open(char *path);
441#else
442extern	int	readsecs();
443extern	int	scsidev_open();
444#endif
445#endif
446
447extern char * extension_record;
448extern int extension_record_extent;
449extern 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
454extern char * preparer;
455extern char * publisher;
456extern char * copyright;
457extern char * biblio;
458extern char * abstract;
459extern char * appid;
460extern char * volset_id;
461extern char * system_id;
462extern char * volume_id;
463extern char * boot_catalog;
464extern char * boot_image;
465extern char * efi_boot_image;
466extern int volume_set_size;
467extern int volume_sequence_number;
468
469extern 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