]> git.proxmox.com Git - grub2.git/blob - util/mkisofs/mkisofs.h
2009-11-11 Robert Millan <rmh.grub@aybabtu.com>
[grub2.git] / util / mkisofs / mkisofs.h
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 Copyright (C) 2009 Free Software Foundation, Inc.
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 3, 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, see <http://www.gnu.org/licenses/>.
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24 /*
25 * $Id: mkisofs.h,v 1.20 1999/03/02 04:16:41 eric Exp $
26 */
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <prototyp.h>
31 #include <sys/stat.h>
32
33 /* This symbol is used to indicate that we do not have things like
34 symlinks, devices, and so forth available. Just files and dirs */
35
36 #ifdef VMS
37 #define NON_UNIXFS
38 #endif
39
40 #ifdef DJGPP
41 #define NON_UNIXFS
42 #endif
43
44 #ifdef VMS
45 #include <sys/dir.h>
46 #define dirent direct
47 #endif
48
49 #ifdef _WIN32
50 #define NON_UNIXFS
51 #endif /* _WIN32 */
52
53 #ifndef S_IROTH
54 #define S_IROTH 0
55 #endif
56
57 #ifndef S_IRGRP
58 #define S_IRGRP 0
59 #endif
60
61 #ifndef HAVE_GETUID
62 static inline int
63 getuid ()
64 {
65 return 0;
66 }
67 #endif
68
69 #ifndef HAVE_GETGID
70 static inline int
71 getgid ()
72 {
73 return 0;
74 }
75 #endif
76
77 #ifndef HAVE_LSTAT
78 static inline int
79 lstat (const char *filename, struct stat *buf)
80 {
81 return stat (filename, buf);
82 }
83 #endif
84
85 #include <string.h>
86 #include <sys/types.h>
87 #include <sys/stat.h>
88
89 #if defined(HAVE_DIRENT_H)
90 # include <dirent.h>
91 # define NAMLEN(dirent) strlen((dirent)->d_name)
92 #else
93 # define dirent direct
94 # define NAMLEN(dirent) (dirent)->d_namlen
95 # if defined(HAVE_SYS_NDIR_H)
96 # include <sys/ndir.h>
97 # endif
98 # if defined(HAVE_SYS_DIR_H)
99 # include <sys/dir.h>
100 # endif
101 # if defined(HAVE_NDIR_H)
102 # include <ndir.h>
103 # endif
104 #endif
105
106 #if defined(HAVE_STRING_H)
107 #include <string.h>
108 #else
109 #if defined(HAVE_STRINGS_H)
110 #include <strings.h>
111 #endif
112 #endif
113
114 #ifdef ultrix
115 extern char *strdup();
116 #endif
117
118 #ifdef __STDC__
119 #define DECL(NAME,ARGS) NAME ARGS
120 #define FDECL1(NAME,TYPE0, ARG0) \
121 NAME(TYPE0 ARG0)
122 #define FDECL2(NAME,TYPE0, ARG0,TYPE1, ARG1) \
123 NAME(TYPE0 ARG0, TYPE1 ARG1)
124 #define FDECL3(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2) \
125 NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2)
126 #define FDECL4(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3) \
127 NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3)
128 #define FDECL5(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4) \
129 NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3, TYPE4 ARG4)
130 #define FDECL6(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4, TYPE5, ARG5) \
131 NAME(TYPE0 ARG0, TYPE1 ARG1, TYPE2 ARG2, TYPE3 ARG3, TYPE4 ARG4, TYPE5 ARG5)
132 #else
133 #define DECL(NAME,ARGS) NAME()
134 #define FDECL1(NAME,TYPE0, ARG0) NAME(ARG0) TYPE0 ARG0;
135 #define FDECL2(NAME,TYPE0, ARG0,TYPE1, ARG1) NAME(ARG0, ARG1) TYPE0 ARG0; TYPE1 ARG1;
136 #define FDECL3(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2) \
137 NAME(ARG0, ARG1, ARG2) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2;
138 #define FDECL4(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3) \
139 NAME(ARG0, ARG1, ARG2, ARG3, ARG4) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3;
140 #define FDECL5(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4) \
141 NAME(ARG0, ARG1, ARG2, ARG3, ARG4) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3; TYPE4 ARG4;
142 #define FDECL6(NAME,TYPE0, ARG0,TYPE1, ARG1, TYPE2, ARG2, TYPE3, ARG3, TYPE4, ARG4, TYPE5, ARG5) \
143 NAME(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) TYPE0 ARG0; TYPE1 ARG1; TYPE2 ARG2; TYPE3 ARG3; TYPE4 ARG4; TYPE5 ARG5;
144 #define const
145 #endif
146
147
148 #ifdef __SVR4
149 #include <stdlib.h>
150 #else
151 extern int optind;
152 extern char *optarg;
153 /* extern int getopt (int __argc, char **__argv, char *__optstring); */
154 #endif
155
156 #include "iso9660.h"
157 #include "defaults.h"
158
159 struct directory_entry{
160 struct directory_entry * next;
161 struct directory_entry * jnext;
162 struct iso_directory_record isorec;
163 uint64_t starting_block;
164 uint64_t size;
165 unsigned short priority;
166 unsigned char jreclen; /* Joliet record len */
167 char * name;
168 char * table;
169 char * whole_name;
170 struct directory * filedir;
171 struct directory_entry * parent_rec;
172 unsigned int de_flags;
173 ino_t inode; /* Used in the hash table */
174 dev_t dev; /* Used in the hash table */
175 unsigned char * rr_attributes;
176 unsigned int rr_attr_size;
177 unsigned int total_rr_attr_size;
178 unsigned int got_rr_name;
179 };
180
181 struct file_hash{
182 struct file_hash * next;
183 ino_t inode; /* Used in the hash table */
184 dev_t dev; /* Used in the hash table */
185 unsigned int starting_block;
186 unsigned int size;
187 };
188
189
190 /*
191 * This structure is used to control the output of fragments to the cdrom
192 * image. Everything that will be written to the output image will eventually
193 * go through this structure. There are two pieces - first is the sizing where
194 * we establish extent numbers for everything, and the second is when we actually
195 * generate the contents and write it to the output image.
196 *
197 * This makes it trivial to extend mkisofs to write special things in the image.
198 * All you need to do is hook an additional structure in the list, and the rest
199 * works like magic.
200 *
201 * The three passes each do the following:
202 *
203 * The 'size' pass determines the size of each component and assigns the extent number
204 * for that component.
205 *
206 * The 'generate' pass will adjust the contents and pointers as required now that extent
207 * numbers are assigned. In some cases, the contents of the record are also generated.
208 *
209 * The 'write' pass actually writes the data to the disc.
210 */
211 struct output_fragment
212 {
213 struct output_fragment * of_next;
214 #ifdef __STDC__
215 int (*of_size)(int);
216 int (*of_generate)(void);
217 int (*of_write)(FILE *);
218 #else
219 int (*of_size)();
220 int (*of_generate)();
221 int (*of_write)();
222 #endif
223 };
224
225 extern struct output_fragment * out_list;
226 extern struct output_fragment * out_tail;
227
228 extern struct output_fragment padblock_desc;
229 extern struct output_fragment voldesc_desc;
230 extern struct output_fragment joliet_desc;
231 extern struct output_fragment torito_desc;
232 extern struct output_fragment end_vol;
233 extern struct output_fragment pathtable_desc;
234 extern struct output_fragment jpathtable_desc;
235 extern struct output_fragment dirtree_desc;
236 extern struct output_fragment dirtree_clean;
237 extern struct output_fragment jdirtree_desc;
238 extern struct output_fragment extension_desc;
239 extern struct output_fragment files_desc;
240
241 /*
242 * This structure describes one complete directory. It has pointers
243 * to other directories in the overall tree so that it is clear where
244 * this directory lives in the tree, and it also must contain pointers
245 * to the contents of the directory. Note that subdirectories of this
246 * directory exist twice in this stucture. Once in the subdir chain,
247 * and again in the contents chain.
248 */
249 struct directory{
250 struct directory * next; /* Next directory at same level as this one */
251 struct directory * subdir; /* First subdirectory in this directory */
252 struct directory * parent;
253 struct directory_entry * contents;
254 struct directory_entry * jcontents;
255 struct directory_entry * self;
256 char * whole_name; /* Entire path */
257 char * de_name; /* Entire path */
258 unsigned int ce_bytes; /* Number of bytes of CE entries reqd for this dir */
259 unsigned int depth;
260 unsigned int size;
261 unsigned int extent;
262 unsigned int jsize;
263 unsigned int jextent;
264 unsigned short path_index;
265 unsigned short jpath_index;
266 unsigned short dir_flags;
267 unsigned short dir_nlink;
268 };
269
270 extern int goof;
271 extern struct directory * root;
272 extern struct directory * reloc_dir;
273 extern uint64_t next_extent;
274 extern uint64_t last_extent;
275 extern uint64_t last_extent_written;
276 extern uint64_t session_start;
277
278 extern unsigned int path_table_size;
279 extern unsigned int path_table[4];
280 extern unsigned int path_blocks;
281 extern char * path_table_l;
282 extern char * path_table_m;
283
284 extern unsigned int jpath_table_size;
285 extern unsigned int jpath_table[4];
286 extern unsigned int jpath_blocks;
287 extern char * jpath_table_l;
288 extern char * jpath_table_m;
289
290 extern struct iso_directory_record root_record;
291 extern struct iso_directory_record jroot_record;
292
293 extern int use_eltorito;
294 extern int use_eltorito_emul_floppy;
295 extern int use_boot_info_table;
296 extern int use_RockRidge;
297 extern int use_Joliet;
298 extern int rationalize;
299 extern int follow_links;
300 extern int verbose;
301 extern int all_files;
302 extern int generate_tables;
303 extern int print_size;
304 extern int split_output;
305 extern int omit_period;
306 extern int omit_version_number;
307 extern int transparent_compression;
308 extern unsigned int RR_relocation_depth;
309 extern int full_iso9660_filenames;
310 extern int split_SL_component;
311 extern int split_SL_field;
312
313 /* tree.c */
314 extern int DECL(stat_filter, (char *, struct stat *));
315 extern int DECL(lstat_filter, (char *, struct stat *));
316 extern int DECL(sort_tree,(struct directory *));
317 extern struct directory *
318 DECL(find_or_create_directory,(struct directory *, const char *,
319 struct directory_entry * self, int));
320 extern void DECL (finish_cl_pl_entries, (void));
321 extern int DECL(scan_directory_tree,(struct directory * this_dir,
322 char * path,
323 struct directory_entry * self));
324 extern int DECL(insert_file_entry,(struct directory *, char *,
325 char *));
326
327 extern void DECL(generate_iso9660_directories,(struct directory *, FILE*));
328 extern void DECL(dump_tree,(struct directory * node));
329 extern struct directory_entry * DECL(search_tree_file, (struct
330 directory * node,char * filename));
331 extern void DECL(update_nlink_field,(struct directory * node));
332 extern void DECL (init_fstatbuf, (void));
333 extern struct stat root_statbuf;
334
335 /* eltorito.c */
336 extern void DECL(init_boot_catalog, (const char * path ));
337 extern void DECL(get_torito_desc, (struct eltorito_boot_descriptor * path ));
338
339 /* write.c */
340 extern int DECL(get_731,(char *));
341 extern int DECL(get_733,(char *));
342 extern int DECL(isonum_733,(unsigned char *));
343 extern void DECL(set_723,(char *, unsigned int));
344 extern void DECL(set_731,(char *, unsigned int));
345 extern void DECL(set_721,(char *, unsigned int));
346 extern void DECL(set_733,(char *, unsigned int));
347 extern int DECL(sort_directory,(struct directory_entry **));
348 extern void DECL(generate_one_directory,(struct directory *, FILE*));
349 extern void DECL(memcpy_max, (char *, char *, int));
350 extern int DECL(oneblock_size, (int starting_extent));
351 extern struct iso_primary_descriptor vol_desc;
352 extern void DECL(xfwrite, (void * buffer, uint64_t count, uint64_t size, FILE * file));
353 extern void DECL(set_732, (char * pnt, unsigned int i));
354 extern void DECL(set_722, (char * pnt, unsigned int i));
355 extern void DECL(outputlist_insert, (struct output_fragment * frag));
356
357 /*
358 * Set by user command-line to override default date values
359 */
360
361 extern char *creation_date;
362 extern char *modification_date;
363 extern char *expiration_date;
364 extern char *effective_date;
365
366 /* multi.c */
367
368 extern FILE * in_image;
369 extern struct iso_directory_record *
370 DECL(merge_isofs,(char * path));
371
372 extern int DECL(free_mdinfo, (struct directory_entry **, int len));
373
374 extern struct directory_entry **
375 DECL(read_merging_directory,(struct iso_directory_record *, int*));
376 extern void
377 DECL(merge_remaining_entries, (struct directory *,
378 struct directory_entry **, int));
379 extern int
380 DECL(merge_previous_session, (struct directory *,
381 struct iso_directory_record *));
382
383 extern int DECL(get_session_start, (int *));
384
385 /* joliet.c */
386 int DECL(joliet_sort_tree, (struct directory * node));
387
388 /* match.c */
389 extern int DECL(matches, (char *));
390 extern void DECL(add_match, (char *));
391
392 /* files.c */
393 struct dirent * DECL(readdir_add_files, (char **, char *, DIR *));
394
395 /* */
396
397 extern int DECL(iso9660_file_length,(const char* name,
398 struct directory_entry * sresult, int flag));
399 extern int DECL(iso9660_date,(char *, time_t));
400 extern void DECL(add_hash,(struct directory_entry *));
401 extern struct file_hash * DECL(find_hash,(dev_t, ino_t));
402 extern void DECL(add_directory_hash,(dev_t, ino_t));
403 extern struct file_hash * DECL(find_directory_hash,(dev_t, ino_t));
404 extern void DECL (flush_file_hash, (void));
405 extern int DECL(delete_file_hash,(struct directory_entry *));
406 extern struct directory_entry * DECL(find_file_hash,(char *));
407 extern void DECL(add_file_hash,(struct directory_entry *));
408 extern int DECL(generate_rock_ridge_attributes,(char *, char *,
409 struct directory_entry *,
410 struct stat *, struct stat *,
411 int deep_flag));
412 extern char * DECL(generate_rr_extension_record,(char * id, char * descriptor,
413 char * source, int * size));
414
415 extern int DECL(check_prev_session, (struct directory_entry **, int len,
416 struct directory_entry *,
417 struct stat *,
418 struct stat *,
419 struct directory_entry **));
420
421 #ifdef USE_SCG
422 /* scsi.c */
423 #ifdef __STDC__
424 extern int readsecs(int startsecno, void *buffer, int sectorcount);
425 extern int scsidev_open(char *path);
426 #else
427 extern int readsecs();
428 extern int scsidev_open();
429 #endif
430 #endif
431
432 extern char * extension_record;
433 extern int extension_record_extent;
434 extern int n_data_extents;
435
436 /* These are a few goodies that can be specified on the command line, and are
437 filled into the root record */
438
439 extern char * preparer;
440 extern char * publisher;
441 extern char * copyright;
442 extern char * biblio;
443 extern char * abstract;
444 extern char * appid;
445 extern char * volset_id;
446 extern char * system_id;
447 extern char * volume_id;
448 extern char * boot_catalog;
449 extern char * boot_image;
450 extern int volume_set_size;
451 extern int volume_sequence_number;
452
453 extern void * DECL(e_malloc,(size_t));
454
455
456 #define SECTOR_SIZE (2048)
457 #define ROUND_UP(X) ((X + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
458
459 #define NEED_RE 1
460 #define NEED_PL 2
461 #define NEED_CL 4
462 #define NEED_CE 8
463 #define NEED_SP 16
464
465 #define PREV_SESS_DEV (sizeof(dev_t) >= 4 ? 0x7ffffffd : 0x7ffd)
466 #define TABLE_INODE (sizeof(ino_t) >= 4 ? 0x7ffffffe : 0x7ffe)
467 #define UNCACHED_INODE (sizeof(ino_t) >= 4 ? 0x7fffffff : 0x7fff)
468 #define UNCACHED_DEVICE (sizeof(dev_t) >= 4 ? 0x7fffffff : 0x7fff)
469
470 #ifdef VMS
471 #define STAT_INODE(X) (X.st_ino[0])
472 #define PATH_SEPARATOR ']'
473 #define SPATH_SEPARATOR ""
474 #else
475 #define STAT_INODE(X) (X.st_ino)
476 #define PATH_SEPARATOR '/'
477 #define SPATH_SEPARATOR "/"
478 #endif
479
480 /*
481 * When using multi-session, indicates that we can reuse the
482 * TRANS.TBL information for this directory entry. If this flag
483 * is set for all entries in a directory, it means we can just
484 * reuse the TRANS.TBL and not generate a new one.
485 */
486 #define SAFE_TO_REUSE_TABLE_ENTRY 0x01
487 #define DIR_HAS_DOT 0x02
488 #define DIR_HAS_DOTDOT 0x04
489 #define INHIBIT_JOLIET_ENTRY 0x08
490 #define INHIBIT_RR_ENTRY 0x10
491 #define RELOCATED_DIRECTORY 0x20
492 #define INHIBIT_ISO9660_ENTRY 0x40
493
494 /*
495 * Volume sequence number to use in all of the iso directory records.
496 */
497 #define DEF_VSN 1
498
499 /*
500 * Make sure we have a definition for this. If not, take a very conservative
501 * guess. From what I can tell SunOS is the only one with this trouble.
502 */
503 #ifndef NAME_MAX
504 #ifdef FILENAME_MAX
505 #define NAME_MAX FILENAME_MAX
506 #else
507 #define NAME_MAX 128
508 #endif
509 #endif