1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc * isoread.c
3433d6423SLionel Sambuc *
4433d6423SLionel Sambuc * isoread reads a file system in ISO9660 or HIGH SIERRA format from
5433d6423SLionel Sambuc * a given device.
6433d6423SLionel Sambuc *
7433d6423SLionel Sambuc * Apr 5 1995 Michel R. Prevenier
8433d6423SLionel Sambuc * Nov 16 1996 Kees J. Bot -- bug fix: isoread filename matching
9433d6423SLionel Sambuc * Dec 7 1997 Albert S. Woodhull -- bug fix: return values
10433d6423SLionel Sambuc * " " : isodir filename handling
11433d6423SLionel Sambuc * -- added : isoread -a option
12433d6423SLionel Sambuc * Mar 21 2000 Michael A. Temari -- bug fix: look_up only searched first
13433d6423SLionel Sambuc * : block of directory
14433d6423SLionel Sambuc * : stack overflow in recurse_dir
15433d6423SLionel Sambuc * : and various other bugs
16433d6423SLionel Sambuc * Apr 14 2002 Michael A. Temari -- bug fix: fixed recursing directories
17433d6423SLionel Sambuc * : and printing dates 2000 and
18433d6423SLionel Sambuc * : later
19433d6423SLionel Sambuc * May 14 2002 Kees J. Bot -- bug fix: fixed error messages
20433d6423SLionel Sambuc * Mar 14 2003 Kees J. Bot -- added : iso{dir,read} -B option
21433d6423SLionel Sambuc * Jul 24 2003 Michael A. Temari -- bug fix: bytes to blocks roundup fix
22433d6423SLionel Sambuc */
23433d6423SLionel Sambuc
24433d6423SLionel Sambuc #include <ctype.h>
25433d6423SLionel Sambuc #include <errno.h>
26433d6423SLionel Sambuc #include <limits.h>
27433d6423SLionel Sambuc #include <sys/types.h>
28433d6423SLionel Sambuc #include <sys/stat.h>
29433d6423SLionel Sambuc #include <fcntl.h>
30433d6423SLionel Sambuc #include <stdlib.h>
31433d6423SLionel Sambuc #include <stdio.h>
32433d6423SLionel Sambuc #include <string.h>
33433d6423SLionel Sambuc #include <time.h>
34433d6423SLionel Sambuc #include <sys/times.h>
35433d6423SLionel Sambuc #include <unistd.h>
36433d6423SLionel Sambuc
37433d6423SLionel Sambuc /*
38433d6423SLionel Sambuc * definitions used by the ISO9660 and HIGH SIERRA file system
39433d6423SLionel Sambuc */
40433d6423SLionel Sambuc
41433d6423SLionel Sambuc #define ISO9660_ID "CD001"
42433d6423SLionel Sambuc #define HIGH_SIERRA_ID "CDROM"
43433d6423SLionel Sambuc #define BLOCK_SIZE 2048
44433d6423SLionel Sambuc #define BLOCK_SHIFT 11
45433d6423SLionel Sambuc
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc /* Fields in a ISO9660 volume descriptor */
48433d6423SLionel Sambuc struct iso9660_descriptor
49433d6423SLionel Sambuc {
50433d6423SLionel Sambuc char type[1];
51433d6423SLionel Sambuc char id[5];
52433d6423SLionel Sambuc char version[1];
53433d6423SLionel Sambuc char reserved1[1];
54433d6423SLionel Sambuc char system_id[32];
55433d6423SLionel Sambuc char volume_id[32];
56433d6423SLionel Sambuc char reserved2[8];
57433d6423SLionel Sambuc char volume_size[8];
58433d6423SLionel Sambuc char reserved3[32];
59433d6423SLionel Sambuc char volume_set_size[4];
60433d6423SLionel Sambuc char volume_seq_nr[4];
61433d6423SLionel Sambuc char block_size[4];
62433d6423SLionel Sambuc char path_table_size[8];
63433d6423SLionel Sambuc char type_l_path_table[4];
64433d6423SLionel Sambuc char opt_type_l_path_table[4];
65433d6423SLionel Sambuc char type_m_path_table[4];
66433d6423SLionel Sambuc char opt_type_m_path_table[4];
67433d6423SLionel Sambuc char root_dir_entry[34];
68433d6423SLionel Sambuc char vol_set_id[128];
69433d6423SLionel Sambuc char publ_id[128];
70433d6423SLionel Sambuc char prep_id[128];
71433d6423SLionel Sambuc char appl_id[128];
72433d6423SLionel Sambuc char copyright_file_id[37];
73433d6423SLionel Sambuc char abstract_file_id[37];
74433d6423SLionel Sambuc char bibl_file_id[37];
75433d6423SLionel Sambuc char creation_date[17];
76433d6423SLionel Sambuc char mod_date[17];
77433d6423SLionel Sambuc char exp_date[17];
78433d6423SLionel Sambuc char eff_date[17];
79433d6423SLionel Sambuc char file_struc_version[1];
80433d6423SLionel Sambuc char reserved4[1];
81433d6423SLionel Sambuc char appl_data[512];
82433d6423SLionel Sambuc char reserved5[653];
83433d6423SLionel Sambuc };
84433d6423SLionel Sambuc
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc /* Fields in a High Sierra volume descriptor */
87433d6423SLionel Sambuc struct high_sierra_descriptor
88433d6423SLionel Sambuc {
89433d6423SLionel Sambuc char reserved1[8];
90433d6423SLionel Sambuc char type[1];
91433d6423SLionel Sambuc char id[5];
92433d6423SLionel Sambuc char version[1];
93433d6423SLionel Sambuc char reserved2[1];
94433d6423SLionel Sambuc char system_id[32];
95433d6423SLionel Sambuc char volume_id[32];
96433d6423SLionel Sambuc char reserved3[8];
97433d6423SLionel Sambuc char volume_size[8];
98433d6423SLionel Sambuc char reserved4[32];
99433d6423SLionel Sambuc char vol_set_size[4];
100433d6423SLionel Sambuc char volume_seq_nr[4];
101433d6423SLionel Sambuc char block_size[4];
102433d6423SLionel Sambuc char path_table_size[8];
103433d6423SLionel Sambuc char type_l_path_table[4];
104433d6423SLionel Sambuc char reserved5[28];
105433d6423SLionel Sambuc char root_dir_entry[34];
106433d6423SLionel Sambuc };
107433d6423SLionel Sambuc
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc /* Fields in a directory entry */
110433d6423SLionel Sambuc struct dir_entry
111433d6423SLionel Sambuc {
112433d6423SLionel Sambuc char length[1];
113433d6423SLionel Sambuc char ext_attr_length[1];
114433d6423SLionel Sambuc char first_block[8];
115433d6423SLionel Sambuc char size[8];
116433d6423SLionel Sambuc char date[7];
117433d6423SLionel Sambuc char flags[1];
118433d6423SLionel Sambuc char file_unit_size[1];
119433d6423SLionel Sambuc char interleave[1];
120433d6423SLionel Sambuc char volume_seq_nr[4];
121433d6423SLionel Sambuc char name_length[1];
122433d6423SLionel Sambuc char name[1];
123433d6423SLionel Sambuc };
124433d6423SLionel Sambuc
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc #define STDOUT stdout
127433d6423SLionel Sambuc #define STDERR stderr
128433d6423SLionel Sambuc #define NULL_DIR (struct dir_entry *) 0
129433d6423SLionel Sambuc #define MAX_NAME_LENGTH 255
130433d6423SLionel Sambuc #define MAX_PATH_LENGTH 1024
131433d6423SLionel Sambuc
132433d6423SLionel Sambuc #define NR_OF_CHARS 13
133433d6423SLionel Sambuc #define NR_OF_BLANKS 2
134433d6423SLionel Sambuc #define NR_OF_COLS (80 / (NR_OF_CHARS + NR_OF_BLANKS))
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc /* This macro always returns a lower case character */
137433d6423SLionel Sambuc #define LOWER_CASE(CHR) (CHR >= 'A' && CHR <= 'Z' ? CHR | 0x20 : CHR)
138433d6423SLionel Sambuc
139433d6423SLionel Sambuc /* Macro's for determining . , .. and normal directory entries */
140433d6423SLionel Sambuc #define IS_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 0 ? 1 : 0)
141433d6423SLionel Sambuc #define IS_DOT_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 1 ? 1 : 0)
142433d6423SLionel Sambuc #define IS_DIR(PTR) (PTR->flags[-High_Sierra] & 2 ? 1 : 0)
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc
145433d6423SLionel Sambuc int main(int argc, char **argv);
146433d6423SLionel Sambuc int iso_cmp(char *name, struct dir_entry *dir_ptr, int dir_flag);
147433d6423SLionel Sambuc void list_dir(struct dir_entry *dir_ptr);
148433d6423SLionel Sambuc void list_file(struct dir_entry *dir_ptr);
149433d6423SLionel Sambuc struct dir_entry *look_up(char *name);
150433d6423SLionel Sambuc void recurse_dir(char *path, struct dir_entry *dir_ptr);
151433d6423SLionel Sambuc void read_device(long offset, int nr_of_bytes, char *buffer);
152433d6423SLionel Sambuc int valid_fs(void);
153433d6423SLionel Sambuc void usage(void);
154433d6423SLionel Sambuc void print_date(char *date);
155433d6423SLionel Sambuc void print_dir_date(char *date);
156433d6423SLionel Sambuc void iso_info(struct iso9660_descriptor *vol_desc);
157433d6423SLionel Sambuc void hs_info(struct high_sierra_descriptor *vol_desc);
158433d6423SLionel Sambuc int iso_711(char *c);
159433d6423SLionel Sambuc int iso_712(char *c);
160433d6423SLionel Sambuc int iso_721(char *c);
161433d6423SLionel Sambuc int iso_722(char *c);
162433d6423SLionel Sambuc int iso_723(char *c);
163433d6423SLionel Sambuc long iso_731(char *c);
164433d6423SLionel Sambuc long iso_732(char *c);
165433d6423SLionel Sambuc long iso_733(char *c);
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc
168433d6423SLionel Sambuc char Buffer[BLOCK_SIZE]; /* buffer to hold read data */
169433d6423SLionel Sambuc int Device; /* global file descriptor */
170433d6423SLionel Sambuc struct iso9660_descriptor *Iso_Vol_Desc; /* iso9660 volume descriptor */
171433d6423SLionel Sambuc struct high_sierra_descriptor *Hs_Vol_Desc; /* high sierra volume descriptor */
172433d6423SLionel Sambuc int High_Sierra = 0; /* 1 = high sierra format */
173433d6423SLionel Sambuc int Iso9660 = 0; /* 1 = iso9660 format */
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc /* This comes in handy when printing the date */
176433d6423SLionel Sambuc char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
177433d6423SLionel Sambuc
178433d6423SLionel Sambuc /* Flags displaying what to do */
179433d6423SLionel Sambuc int Read_File = 0; /* 1 = Read file */
180433d6423SLionel Sambuc int Read_Dir = 0; /* 1 = Read directory entry */
181433d6423SLionel Sambuc int Read_Info = 0; /* 1 = Read volume descriptor */
182433d6423SLionel Sambuc int Recurse = 0; /* 1 = Recursively descend directories */
183433d6423SLionel Sambuc int Verbose = 0; /* 1 = Print all info on directories */
184433d6423SLionel Sambuc int ByteOffset = 0; /* 1 = Print byte offset and length of files */
185433d6423SLionel Sambuc int Aflag = 0; /* 1 = Suppress output of \r */
186433d6423SLionel Sambuc
iso_cmp(name,dir_ptr,dir_flag)187433d6423SLionel Sambuc int iso_cmp(name, dir_ptr, dir_flag)
188433d6423SLionel Sambuc char *name;
189433d6423SLionel Sambuc struct dir_entry *dir_ptr;
190433d6423SLionel Sambuc int dir_flag;
191433d6423SLionel Sambuc {
192433d6423SLionel Sambuc /* Compare name with directory entries, looking for match with a dirname.
193433d6423SLionel Sambuc * An iso9660 filename is terminated by ";n", where n will probably
194433d6423SLionel Sambuc * be 1. A directory name is not terminated by anything special, it may be
195433d6423SLionel Sambuc * followed by a \0 if padding is needed to put the following directory
196433d6423SLionel Sambuc * entry on an even address.
197433d6423SLionel Sambuc */
198433d6423SLionel Sambuc int i;
199433d6423SLionel Sambuc int len;
200433d6423SLionel Sambuc
201433d6423SLionel Sambuc /* First match the filename */
202433d6423SLionel Sambuc len = strlen(name);
203433d6423SLionel Sambuc if (len > iso_711(dir_ptr->name_length)) return 1;
204433d6423SLionel Sambuc for (i = 0; i < len; i++)
205433d6423SLionel Sambuc {
206433d6423SLionel Sambuc if (dir_ptr->name[i] == ';') return 1; /* found end of a filename */
207433d6423SLionel Sambuc if (name[i] != LOWER_CASE(dir_ptr->name[i])) return 1; /* match failed */
208433d6423SLionel Sambuc }
209433d6423SLionel Sambuc if (dir_ptr->name[i] != ';' && i != len) return 1; /* incomplete match */
210433d6423SLionel Sambuc
211433d6423SLionel Sambuc /* The filename is ok, now look at the file type */
212433d6423SLionel Sambuc if (dir_flag && !IS_DIR(dir_ptr)) return 1; /* File type not correct */
213433d6423SLionel Sambuc
214433d6423SLionel Sambuc return 0;
215433d6423SLionel Sambuc }
216433d6423SLionel Sambuc
217433d6423SLionel Sambuc
usage()218433d6423SLionel Sambuc void usage()
219433d6423SLionel Sambuc {
220433d6423SLionel Sambuc if (Read_Dir)
221433d6423SLionel Sambuc fprintf (STDERR, "Usage: isodir [-lrB] inputfile [dir]\n");
222433d6423SLionel Sambuc else if (Read_Info)
223433d6423SLionel Sambuc fprintf (STDERR, "Usage: isoinfo inputfile\n");
224433d6423SLionel Sambuc else
225433d6423SLionel Sambuc fprintf (STDERR, "Usage: isoread [-a] inputfile file\n");
226433d6423SLionel Sambuc exit(1);
227433d6423SLionel Sambuc }
228433d6423SLionel Sambuc
229433d6423SLionel Sambuc
main(argc,argv)230433d6423SLionel Sambuc int main(argc, argv)
231433d6423SLionel Sambuc int argc;
232433d6423SLionel Sambuc char **argv;
233433d6423SLionel Sambuc {
234433d6423SLionel Sambuc struct dir_entry *entry;
235433d6423SLionel Sambuc char path[MAX_PATH_LENGTH];
236433d6423SLionel Sambuc char *input_file;
237433d6423SLionel Sambuc char *basename;
238433d6423SLionel Sambuc char *file_name;
239433d6423SLionel Sambuc int i,j;
240433d6423SLionel Sambuc
241433d6423SLionel Sambuc /* Read arguments */
242433d6423SLionel Sambuc basename = argv[0];
243433d6423SLionel Sambuc while (*argv[0] != '\0')
244433d6423SLionel Sambuc if (*argv[0]++ == '/') basename = argv[0];
245433d6423SLionel Sambuc
246433d6423SLionel Sambuc if (strcmp(basename,"isodir") == 0) Read_Dir = 1;
247433d6423SLionel Sambuc else if (strcmp(basename,"isoinfo") == 0) Read_Info = 1;
248433d6423SLionel Sambuc else Read_File = 1;
249433d6423SLionel Sambuc
250433d6423SLionel Sambuc if ((argc > 5 && Read_Dir) || (argc != 2 && Read_Info) ||
251433d6423SLionel Sambuc (argc > 4 && Read_File)) usage();
252433d6423SLionel Sambuc
253433d6423SLionel Sambuc i = 1;
254433d6423SLionel Sambuc
255433d6423SLionel Sambuc while (i < argc && argv[i][0] == '-')
256433d6423SLionel Sambuc {
257433d6423SLionel Sambuc char *opt = argv[i++] + 1;
258433d6423SLionel Sambuc
259433d6423SLionel Sambuc if (opt[0] == '-' && opt[1] == '\0') break;
260433d6423SLionel Sambuc
261433d6423SLionel Sambuc while (*opt != '\0')
262433d6423SLionel Sambuc {
263433d6423SLionel Sambuc if (Read_Info) usage();
264433d6423SLionel Sambuc if (Read_Dir)
265433d6423SLionel Sambuc switch (*opt++)
266433d6423SLionel Sambuc {
267433d6423SLionel Sambuc case 'r': Recurse = 1; break;
268433d6423SLionel Sambuc case 'l': Verbose = 1; break;
269433d6423SLionel Sambuc case 'B': ByteOffset = 1; break;
270433d6423SLionel Sambuc default: usage();
271433d6423SLionel Sambuc }
272433d6423SLionel Sambuc if (Read_File)
273433d6423SLionel Sambuc switch (*opt++)
274433d6423SLionel Sambuc {
275433d6423SLionel Sambuc case 'a': Aflag = 1; break;
276433d6423SLionel Sambuc case 'B': ByteOffset = 1; break;
277433d6423SLionel Sambuc default: usage();
278433d6423SLionel Sambuc }
279433d6423SLionel Sambuc }
280433d6423SLionel Sambuc }
281433d6423SLionel Sambuc
282433d6423SLionel Sambuc if (i >= argc) usage();
283433d6423SLionel Sambuc input_file = argv[i++];
284433d6423SLionel Sambuc
285433d6423SLionel Sambuc if (Read_File)
286433d6423SLionel Sambuc {
287433d6423SLionel Sambuc if (i >= argc) usage();
288433d6423SLionel Sambuc file_name = argv[i++];
289433d6423SLionel Sambuc }
290433d6423SLionel Sambuc
291433d6423SLionel Sambuc if (Read_Dir)
292433d6423SLionel Sambuc {
293433d6423SLionel Sambuc file_name = "/";
294433d6423SLionel Sambuc if (i < argc)
295433d6423SLionel Sambuc {
296433d6423SLionel Sambuc file_name = argv[i++];
297433d6423SLionel Sambuc }
298433d6423SLionel Sambuc }
299433d6423SLionel Sambuc
300433d6423SLionel Sambuc if (i < argc) usage();
301433d6423SLionel Sambuc
302433d6423SLionel Sambuc if (Read_File || Read_Dir)
303433d6423SLionel Sambuc {
304433d6423SLionel Sambuc for (i=0; file_name[i] != '\0'; i++)
305433d6423SLionel Sambuc path[i] = LOWER_CASE(file_name[i]);
306433d6423SLionel Sambuc path[i] = '\0';
307433d6423SLionel Sambuc }
308433d6423SLionel Sambuc
309433d6423SLionel Sambuc /* Open file system (file or device) */
310433d6423SLionel Sambuc if ((Device = open(input_file, O_RDONLY)) < 0)
311433d6423SLionel Sambuc {
312433d6423SLionel Sambuc fprintf (STDERR, "cannot open %s: %s\n", input_file, strerror(errno));
313433d6423SLionel Sambuc exit(-1);
314433d6423SLionel Sambuc }
315433d6423SLionel Sambuc
316433d6423SLionel Sambuc
317433d6423SLionel Sambuc if (!valid_fs())
318433d6423SLionel Sambuc {
319433d6423SLionel Sambuc fprintf (STDERR, "File system not in ISO9660 or HIGH SIERRA format \n");
320433d6423SLionel Sambuc exit(-1);
321433d6423SLionel Sambuc }
322433d6423SLionel Sambuc
323433d6423SLionel Sambuc
324433d6423SLionel Sambuc if (Read_Info)
325433d6423SLionel Sambuc {
326433d6423SLionel Sambuc if (Iso9660)
327433d6423SLionel Sambuc iso_info(Iso_Vol_Desc);
328433d6423SLionel Sambuc else
329433d6423SLionel Sambuc hs_info(Hs_Vol_Desc);
330433d6423SLionel Sambuc exit(0);
331433d6423SLionel Sambuc }
332433d6423SLionel Sambuc
333433d6423SLionel Sambuc /* Lookup file */
334433d6423SLionel Sambuc if ((entry = look_up(path)) != NULL_DIR)
335433d6423SLionel Sambuc {
336433d6423SLionel Sambuc if (Read_Dir)
337433d6423SLionel Sambuc if (Recurse) recurse_dir(path,entry);
338433d6423SLionel Sambuc else list_dir(entry);
339433d6423SLionel Sambuc else
340433d6423SLionel Sambuc list_file(entry);
341433d6423SLionel Sambuc }
342433d6423SLionel Sambuc else
343433d6423SLionel Sambuc {
344433d6423SLionel Sambuc if (Read_Dir)
345433d6423SLionel Sambuc fprintf (STDERR, "Directory");
346433d6423SLionel Sambuc else
347433d6423SLionel Sambuc fprintf (STDERR, "File");
348433d6423SLionel Sambuc fprintf (STDERR, " %s not found\n", path);
349433d6423SLionel Sambuc exit(-1);
350433d6423SLionel Sambuc }
351433d6423SLionel Sambuc return 0;
352433d6423SLionel Sambuc }
353433d6423SLionel Sambuc
354433d6423SLionel Sambuc
look_up(path)355433d6423SLionel Sambuc struct dir_entry *look_up(path)
356433d6423SLionel Sambuc char *path;
357433d6423SLionel Sambuc {
358433d6423SLionel Sambuc /* Lookup a file name */
359433d6423SLionel Sambuc
360433d6423SLionel Sambuc struct dir_entry *dir_ptr;
361433d6423SLionel Sambuc long block;
362433d6423SLionel Sambuc int nr_of_blocks;
363433d6423SLionel Sambuc int offset;
364433d6423SLionel Sambuc char name[MAX_NAME_LENGTH + 1];
365433d6423SLionel Sambuc int name_index = 0;
366433d6423SLionel Sambuc int last_in_path = 0;
367433d6423SLionel Sambuc int found;
368433d6423SLionel Sambuc int i,j;
369433d6423SLionel Sambuc
370433d6423SLionel Sambuc /* Get the right dir entry structure */
371433d6423SLionel Sambuc if (Iso9660)
372433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) Iso_Vol_Desc->root_dir_entry;
373433d6423SLionel Sambuc else
374433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) Hs_Vol_Desc->root_dir_entry;
375433d6423SLionel Sambuc
376433d6423SLionel Sambuc /* If we look for the root we already have the right entry */
377*d0055759SDavid van Moolenbroek if (path[0] == '/') {
378433d6423SLionel Sambuc if (strlen(path) == 1) return dir_ptr;
379433d6423SLionel Sambuc else name_index = 1; /* first name in path */
380*d0055759SDavid van Moolenbroek }
381433d6423SLionel Sambuc
382433d6423SLionel Sambuc /* Keep searching for the path elements until all are found */
383433d6423SLionel Sambuc while (!last_in_path)
384433d6423SLionel Sambuc {
385433d6423SLionel Sambuc /* Get next name in path */
386433d6423SLionel Sambuc for (i = name_index; i < strlen(path); i++)
387433d6423SLionel Sambuc {
388433d6423SLionel Sambuc if (path[i] == '/') break;
389433d6423SLionel Sambuc name[i - name_index] = path[i];
390433d6423SLionel Sambuc }
391433d6423SLionel Sambuc last_in_path =
392433d6423SLionel Sambuc (i == strlen(path) || (i == strlen(path) - 1 && path[i] == '/'));
393433d6423SLionel Sambuc name[i-name_index] = '\0';
394433d6423SLionel Sambuc name_index = i + 1;
395433d6423SLionel Sambuc
396433d6423SLionel Sambuc /* Get block of next directory */
397433d6423SLionel Sambuc block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
398433d6423SLionel Sambuc nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
399433d6423SLionel Sambuc
400433d6423SLionel Sambuc /* Search for file in dir entry */
401433d6423SLionel Sambuc found = 0;
402433d6423SLionel Sambuc for (j=0; j < nr_of_blocks && !found; j++)
403433d6423SLionel Sambuc {
404433d6423SLionel Sambuc /* Read a directory block */
405433d6423SLionel Sambuc read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
406433d6423SLionel Sambuc block++;
407433d6423SLionel Sambuc
408433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) Buffer;
409433d6423SLionel Sambuc
410433d6423SLionel Sambuc offset = 0;
411433d6423SLionel Sambuc /* Compare with all entries in this block */
412433d6423SLionel Sambuc while (iso_711(dir_ptr->length) > 0 && offset < BLOCK_SIZE)
413433d6423SLionel Sambuc {
414433d6423SLionel Sambuc if (iso_cmp(name, dir_ptr,
415e01448ddSJacob Adams (Read_Dir || !last_in_path)) == 0)
416433d6423SLionel Sambuc {
417433d6423SLionel Sambuc found = 1;
418433d6423SLionel Sambuc break;
419433d6423SLionel Sambuc }
420433d6423SLionel Sambuc /* Next entry */
421433d6423SLionel Sambuc offset += iso_711(dir_ptr->length);
422433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) (Buffer + offset);
423433d6423SLionel Sambuc }
424433d6423SLionel Sambuc }
425433d6423SLionel Sambuc if (!found) return NULL_DIR; /* path element not found */
426433d6423SLionel Sambuc }
427433d6423SLionel Sambuc return dir_ptr;
428433d6423SLionel Sambuc }
429433d6423SLionel Sambuc
430433d6423SLionel Sambuc
recurse_dir(path,dir_ptr)431433d6423SLionel Sambuc void recurse_dir(path, dir_ptr)
432433d6423SLionel Sambuc char *path;
433433d6423SLionel Sambuc struct dir_entry *dir_ptr;
434433d6423SLionel Sambuc {
435433d6423SLionel Sambuc /* Recursively descend all directories starting with dir_ptr */
436433d6423SLionel Sambuc
437433d6423SLionel Sambuc char tmp_path[MAX_PATH_LENGTH];
438433d6423SLionel Sambuc int i,j, path_length;
439433d6423SLionel Sambuc long block, saveblock, dblock;
440433d6423SLionel Sambuc int nr_of_blocks;
441433d6423SLionel Sambuc int offset = 0;
442433d6423SLionel Sambuc
443433d6423SLionel Sambuc
444433d6423SLionel Sambuc /* Save block number and nr of blocks of current dir entry because
445433d6423SLionel Sambuc * list_dir changes dir_ptr
446433d6423SLionel Sambuc */
447433d6423SLionel Sambuc block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
448433d6423SLionel Sambuc nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
449433d6423SLionel Sambuc
450433d6423SLionel Sambuc /* Add a trailing / to path if necessary */
451433d6423SLionel Sambuc path_length = strlen(path);
452433d6423SLionel Sambuc if (path[path_length-1] != '/')
453433d6423SLionel Sambuc {
454433d6423SLionel Sambuc path[path_length++] = '/';
455433d6423SLionel Sambuc path[path_length] = '\0';
456433d6423SLionel Sambuc }
457433d6423SLionel Sambuc
458433d6423SLionel Sambuc /* Print current path of directory, and list contents of directory */
459433d6423SLionel Sambuc fprintf(STDOUT,"directory %s:\n\n", path);
460433d6423SLionel Sambuc list_dir(dir_ptr);
461433d6423SLionel Sambuc fprintf(STDOUT,"\n\n");
462433d6423SLionel Sambuc
463433d6423SLionel Sambuc for (j=0; j < nr_of_blocks; j++)
464433d6423SLionel Sambuc {
465433d6423SLionel Sambuc read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
466433d6423SLionel Sambuc saveblock = block++;
467433d6423SLionel Sambuc
468433d6423SLionel Sambuc /* Save buffer, because the next recursive call destroys
469433d6423SLionel Sambuc * the global Buffer
470433d6423SLionel Sambuc */
471433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) Buffer;
472433d6423SLionel Sambuc
473433d6423SLionel Sambuc /* Search this dir entry for directories */
474433d6423SLionel Sambuc offset = 0;
475433d6423SLionel Sambuc while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
476433d6423SLionel Sambuc {
477433d6423SLionel Sambuc /* Is current file a directory and not the . or .. entries */
478433d6423SLionel Sambuc if (IS_DIR(dir_ptr) && !IS_DOT(dir_ptr) && !IS_DOT_DOT(dir_ptr))
479433d6423SLionel Sambuc {
480433d6423SLionel Sambuc /* setup path for next recursive call */
481433d6423SLionel Sambuc for (i=0; i<path_length; i++) tmp_path[i] = path[i];
482433d6423SLionel Sambuc for (i=0;i<iso_711(dir_ptr->name_length) && dir_ptr->name[i] != ';';i++)
483433d6423SLionel Sambuc tmp_path[i+path_length] = LOWER_CASE(dir_ptr->name[i]);
484433d6423SLionel Sambuc tmp_path[i+path_length] = '/';
485433d6423SLionel Sambuc tmp_path[i+1+path_length] = '\0';
486433d6423SLionel Sambuc
487433d6423SLionel Sambuc /* Read block of directory we found */
488433d6423SLionel Sambuc dblock = iso_733(dir_ptr->first_block);
489433d6423SLionel Sambuc read_device(dblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
490433d6423SLionel Sambuc
491433d6423SLionel Sambuc /* And start all over again with this entry */
492433d6423SLionel Sambuc recurse_dir(tmp_path, (struct dir_entry *) Buffer);
493433d6423SLionel Sambuc
494433d6423SLionel Sambuc /* get the block we were looking at */
495433d6423SLionel Sambuc read_device(saveblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
496433d6423SLionel Sambuc }
497433d6423SLionel Sambuc
498433d6423SLionel Sambuc /* Go to the next file in this directory */
499433d6423SLionel Sambuc offset += iso_711(dir_ptr->length);
500433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) (Buffer + offset);
501433d6423SLionel Sambuc }
502433d6423SLionel Sambuc }
503433d6423SLionel Sambuc }
504433d6423SLionel Sambuc
505433d6423SLionel Sambuc
list_dir(dir_ptr)506433d6423SLionel Sambuc void list_dir(dir_ptr)
507433d6423SLionel Sambuc struct dir_entry *dir_ptr;
508433d6423SLionel Sambuc {
509433d6423SLionel Sambuc /* List all entries in a directory */
510433d6423SLionel Sambuc int tty;
511433d6423SLionel Sambuc long block;
512433d6423SLionel Sambuc int nr_of_blocks;
513433d6423SLionel Sambuc int i,j;
514433d6423SLionel Sambuc int offset = 0;
515433d6423SLionel Sambuc char name[NR_OF_CHARS+NR_OF_BLANKS+1];
516433d6423SLionel Sambuc int name_len;
517433d6423SLionel Sambuc int column = 0;
518433d6423SLionel Sambuc int skip = 0;
519433d6423SLionel Sambuc
520433d6423SLionel Sambuc tty = isatty(STDOUT_FILENO);
521433d6423SLionel Sambuc /* Get first block of directory */
522433d6423SLionel Sambuc block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
523433d6423SLionel Sambuc nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
524433d6423SLionel Sambuc
525433d6423SLionel Sambuc /* Read all directory blocks and display their contents */
526433d6423SLionel Sambuc for (j=0; j < nr_of_blocks; j++)
527433d6423SLionel Sambuc {
528433d6423SLionel Sambuc read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
529433d6423SLionel Sambuc block++;
530433d6423SLionel Sambuc
531433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) (Buffer);
532433d6423SLionel Sambuc offset = 0;
533433d6423SLionel Sambuc while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
534433d6423SLionel Sambuc {
535433d6423SLionel Sambuc name_len = 0;
536433d6423SLionel Sambuc if (IS_DOT(dir_ptr))
537433d6423SLionel Sambuc {
538433d6423SLionel Sambuc name[name_len++] = '.';
539433d6423SLionel Sambuc if (!Verbose) skip = 1;
540433d6423SLionel Sambuc }
541433d6423SLionel Sambuc else
542433d6423SLionel Sambuc {
543433d6423SLionel Sambuc if (IS_DOT_DOT(dir_ptr))
544433d6423SLionel Sambuc {
545433d6423SLionel Sambuc name[name_len++] = '.';
546433d6423SLionel Sambuc name[name_len++] = '.';
547433d6423SLionel Sambuc if (!Verbose) skip = 1;
548433d6423SLionel Sambuc }
549433d6423SLionel Sambuc else
550433d6423SLionel Sambuc {
551433d6423SLionel Sambuc for (i=0; i<iso_711(dir_ptr->name_length) &&
552433d6423SLionel Sambuc i<NR_OF_CHARS; i++)
553433d6423SLionel Sambuc {
554433d6423SLionel Sambuc if (dir_ptr->name[i] == ';') break;
555433d6423SLionel Sambuc name[name_len++] = LOWER_CASE(dir_ptr->name[i]);
556433d6423SLionel Sambuc }
557433d6423SLionel Sambuc if (IS_DIR(dir_ptr) && tty) name[name_len++] = '/';
558433d6423SLionel Sambuc }
559433d6423SLionel Sambuc }
560433d6423SLionel Sambuc if (!skip)
561433d6423SLionel Sambuc {
562433d6423SLionel Sambuc if (ByteOffset)
563433d6423SLionel Sambuc {
564433d6423SLionel Sambuc fprintf (STDOUT, "%10ld ",
565433d6423SLionel Sambuc (iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length))
566433d6423SLionel Sambuc * BLOCK_SIZE);
567433d6423SLionel Sambuc }
568433d6423SLionel Sambuc if (Verbose || ByteOffset)
569433d6423SLionel Sambuc {
570433d6423SLionel Sambuc fprintf (STDOUT, "%10ld ", iso_733(dir_ptr->size));
571433d6423SLionel Sambuc }
572433d6423SLionel Sambuc if (Verbose)
573433d6423SLionel Sambuc {
574433d6423SLionel Sambuc print_dir_date(dir_ptr->date);
575433d6423SLionel Sambuc fprintf (STDOUT, " ");
576433d6423SLionel Sambuc }
577433d6423SLionel Sambuc if(!tty)
578433d6423SLionel Sambuc name[name_len] = '\0';
579433d6423SLionel Sambuc else {
580433d6423SLionel Sambuc for(i=name_len; i<(NR_OF_CHARS+NR_OF_BLANKS); i++) name[i] = ' ';
581433d6423SLionel Sambuc name[NR_OF_CHARS+NR_OF_BLANKS] = '\0';
582433d6423SLionel Sambuc }
583433d6423SLionel Sambuc fprintf(STDOUT, "%s", name);
584433d6423SLionel Sambuc if (!(Verbose || ByteOffset))
585433d6423SLionel Sambuc {
586433d6423SLionel Sambuc column++;
587433d6423SLionel Sambuc if (column >= NR_OF_COLS || !tty)
588433d6423SLionel Sambuc {
589433d6423SLionel Sambuc column = 0;
590433d6423SLionel Sambuc fprintf(STDOUT,"\n");
591433d6423SLionel Sambuc }
592433d6423SLionel Sambuc }
593433d6423SLionel Sambuc else fprintf(STDOUT,"\n");
594433d6423SLionel Sambuc }
595433d6423SLionel Sambuc skip = 0;
596433d6423SLionel Sambuc offset += iso_711(dir_ptr->length);
597433d6423SLionel Sambuc dir_ptr = (struct dir_entry *) (Buffer+offset);
598433d6423SLionel Sambuc }
599433d6423SLionel Sambuc }
600433d6423SLionel Sambuc if (!Verbose && column) fprintf(STDOUT,"\n");
601433d6423SLionel Sambuc }
602433d6423SLionel Sambuc
603433d6423SLionel Sambuc
print_dir_date(date)604433d6423SLionel Sambuc void print_dir_date(date)
605433d6423SLionel Sambuc char *date;
606433d6423SLionel Sambuc {
607433d6423SLionel Sambuc /* Print date in a directory entry */
608433d6423SLionel Sambuc
609433d6423SLionel Sambuc int m;
610433d6423SLionel Sambuc
611433d6423SLionel Sambuc m = iso_711(&date[1]) - 1;
612433d6423SLionel Sambuc if(m < 0 || m > 11)
613433d6423SLionel Sambuc fprintf(STDOUT, " ");
614433d6423SLionel Sambuc else
615433d6423SLionel Sambuc fprintf(STDOUT,"%.3s",&months[m*3]);
616433d6423SLionel Sambuc
617433d6423SLionel Sambuc fprintf (STDOUT, " %02d %04d %02d:%02d:%02d",
618433d6423SLionel Sambuc date[2],
619433d6423SLionel Sambuc 1900+date[0],
620433d6423SLionel Sambuc date[3],
621433d6423SLionel Sambuc date[4],
622433d6423SLionel Sambuc date[5]);
623433d6423SLionel Sambuc }
624433d6423SLionel Sambuc
625433d6423SLionel Sambuc
list_file(dir_ptr)626433d6423SLionel Sambuc void list_file(dir_ptr)
627433d6423SLionel Sambuc struct dir_entry *dir_ptr;
628433d6423SLionel Sambuc {
629433d6423SLionel Sambuc /* List contents of a file */
630433d6423SLionel Sambuc
631433d6423SLionel Sambuc int i;
632433d6423SLionel Sambuc long block;
633433d6423SLionel Sambuc long size;
634433d6423SLionel Sambuc char c;
635433d6423SLionel Sambuc
636433d6423SLionel Sambuc block = iso_733(dir_ptr->first_block);
637433d6423SLionel Sambuc size = iso_733(dir_ptr->size);
638433d6423SLionel Sambuc
639433d6423SLionel Sambuc if (ByteOffset) {
640433d6423SLionel Sambuc fprintf(STDOUT, "%ld %ld\n", block*BLOCK_SIZE, size);
641433d6423SLionel Sambuc return;
642433d6423SLionel Sambuc }
643433d6423SLionel Sambuc
644433d6423SLionel Sambuc while (size > 0)
645433d6423SLionel Sambuc if (Aflag == 1) {
646433d6423SLionel Sambuc read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
647433d6423SLionel Sambuc for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
648433d6423SLionel Sambuc if (Buffer[i] != '\r') fprintf(STDOUT, "%c", Buffer[i]);
649433d6423SLionel Sambuc size-= BLOCK_SIZE;
650433d6423SLionel Sambuc block++;
651433d6423SLionel Sambuc } else {
652433d6423SLionel Sambuc read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
653433d6423SLionel Sambuc for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
654433d6423SLionel Sambuc fprintf(STDOUT, "%c", Buffer[i]);
655433d6423SLionel Sambuc size-= BLOCK_SIZE;
656433d6423SLionel Sambuc block++;
657433d6423SLionel Sambuc }
658433d6423SLionel Sambuc }
659433d6423SLionel Sambuc
660433d6423SLionel Sambuc
print_date(date)661433d6423SLionel Sambuc void print_date(date)
662433d6423SLionel Sambuc char *date;
663433d6423SLionel Sambuc {
664433d6423SLionel Sambuc /* Print the date in a volume descriptor */
665433d6423SLionel Sambuc
666433d6423SLionel Sambuc fprintf (STDOUT, "%c%c-%c%c-%c%c%c%c %c%c:%c%c:%c%c",
667433d6423SLionel Sambuc date[4],
668433d6423SLionel Sambuc date[5],
669433d6423SLionel Sambuc date[6],
670433d6423SLionel Sambuc date[7],
671433d6423SLionel Sambuc date[0],
672433d6423SLionel Sambuc date[1],
673433d6423SLionel Sambuc date[2],
674433d6423SLionel Sambuc date[3],
675433d6423SLionel Sambuc date[8],
676433d6423SLionel Sambuc date[9],
677433d6423SLionel Sambuc date[10],
678433d6423SLionel Sambuc date[11],
679433d6423SLionel Sambuc date[12],
680433d6423SLionel Sambuc date[13]);
681433d6423SLionel Sambuc }
682433d6423SLionel Sambuc
iso_info(vol_desc)683433d6423SLionel Sambuc void iso_info(vol_desc)
684433d6423SLionel Sambuc struct iso9660_descriptor *vol_desc;
685433d6423SLionel Sambuc {
686433d6423SLionel Sambuc int i;
687433d6423SLionel Sambuc
688433d6423SLionel Sambuc fprintf (STDOUT, "Format: ISO9660 \n");
689433d6423SLionel Sambuc fprintf (STDOUT, "System id: ");
690433d6423SLionel Sambuc for (i=0; i< sizeof(vol_desc->system_id); i++)
691433d6423SLionel Sambuc fprintf(STDOUT, "%c", vol_desc->system_id[i]);
692433d6423SLionel Sambuc fprintf (STDOUT, "\n");
693433d6423SLionel Sambuc fprintf (STDOUT, "Volume id: ");
694433d6423SLionel Sambuc for (i=0; i< sizeof(vol_desc->volume_id); i++)
695433d6423SLionel Sambuc fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
696433d6423SLionel Sambuc fprintf (STDOUT, "\n");
697433d6423SLionel Sambuc fprintf (STDOUT, "Volume size: %ld Kb\n", iso_733(vol_desc->volume_size)*2);
698433d6423SLionel Sambuc fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
699433d6423SLionel Sambuc fprintf (STDOUT, "Creation date: ");
700433d6423SLionel Sambuc print_date(vol_desc->creation_date);
701433d6423SLionel Sambuc fprintf(STDOUT, "\n");
702433d6423SLionel Sambuc fprintf (STDOUT, "Modification date: ");
703433d6423SLionel Sambuc print_date(vol_desc->mod_date);
704433d6423SLionel Sambuc fprintf (STDOUT, "\n");
705433d6423SLionel Sambuc fprintf (STDOUT, "Expiration date: ");
706433d6423SLionel Sambuc print_date(vol_desc->exp_date);
707433d6423SLionel Sambuc fprintf (STDOUT, "\n");
708433d6423SLionel Sambuc fprintf (STDOUT, "Effective date: ");
709433d6423SLionel Sambuc print_date(vol_desc->eff_date);
710433d6423SLionel Sambuc fprintf (STDOUT, "\n");
711433d6423SLionel Sambuc }
712433d6423SLionel Sambuc
713433d6423SLionel Sambuc
hs_info(vol_desc)714433d6423SLionel Sambuc void hs_info(vol_desc)
715433d6423SLionel Sambuc struct high_sierra_descriptor *vol_desc;
716433d6423SLionel Sambuc {
717433d6423SLionel Sambuc int i;
718433d6423SLionel Sambuc
719433d6423SLionel Sambuc fprintf (STDOUT, "Format: HIGH SIERRA \n");
720433d6423SLionel Sambuc fprintf (STDOUT, "System id: ");
721433d6423SLionel Sambuc for (i=0; i< sizeof(vol_desc->system_id); i++)
722433d6423SLionel Sambuc fprintf(STDOUT, "%c", vol_desc->system_id[i]);
723433d6423SLionel Sambuc fprintf (STDOUT, "\n");
724433d6423SLionel Sambuc fprintf (STDOUT, "Volume id: ");
725433d6423SLionel Sambuc for (i=0; i< sizeof(vol_desc->volume_id); i++)
726433d6423SLionel Sambuc fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
727433d6423SLionel Sambuc fprintf (STDOUT, "\n");
728433d6423SLionel Sambuc fprintf (STDOUT, "Volume size: %ld Kb\n", (iso_733(vol_desc->volume_size)*2));
729433d6423SLionel Sambuc fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
730433d6423SLionel Sambuc }
731433d6423SLionel Sambuc
732433d6423SLionel Sambuc
valid_fs()733433d6423SLionel Sambuc int valid_fs()
734433d6423SLionel Sambuc {
735433d6423SLionel Sambuc
736433d6423SLionel Sambuc int i;
737433d6423SLionel Sambuc
738433d6423SLionel Sambuc /* search for a volume descriptor */
739433d6423SLionel Sambuc for (i=16; i<100; i++)
740433d6423SLionel Sambuc {
741433d6423SLionel Sambuc
742433d6423SLionel Sambuc read_device((long)(i)*BLOCK_SIZE, BLOCK_SIZE, Buffer);
743433d6423SLionel Sambuc
744433d6423SLionel Sambuc Iso_Vol_Desc = (struct iso9660_descriptor *) Buffer;
745433d6423SLionel Sambuc Hs_Vol_Desc = (struct high_sierra_descriptor *) Buffer;
746433d6423SLionel Sambuc
747433d6423SLionel Sambuc if (strncmp(Iso_Vol_Desc->id, ISO9660_ID, sizeof Iso_Vol_Desc->id) == 0)
748433d6423SLionel Sambuc {
749433d6423SLionel Sambuc /* iso_info(Iso_Vol_Desc); */
750433d6423SLionel Sambuc Iso9660 = 1;
751433d6423SLionel Sambuc break;
752433d6423SLionel Sambuc }
753433d6423SLionel Sambuc
754433d6423SLionel Sambuc if (strncmp(Hs_Vol_Desc->id, HIGH_SIERRA_ID, sizeof Hs_Vol_Desc->id) == 0)
755433d6423SLionel Sambuc {
756433d6423SLionel Sambuc /* hs_info(Hs_Vol_Desc); */
757433d6423SLionel Sambuc High_Sierra = 1;
758433d6423SLionel Sambuc break;
759433d6423SLionel Sambuc }
760433d6423SLionel Sambuc }
761433d6423SLionel Sambuc
762433d6423SLionel Sambuc if (i >= 100) return 0;
763433d6423SLionel Sambuc return 1;
764433d6423SLionel Sambuc }
765433d6423SLionel Sambuc
766433d6423SLionel Sambuc
read_device(offset,nr_of_bytes,buffer)767433d6423SLionel Sambuc void read_device(offset, nr_of_bytes, buffer)
768433d6423SLionel Sambuc long offset;
769433d6423SLionel Sambuc int nr_of_bytes;
770433d6423SLionel Sambuc char *buffer;
771433d6423SLionel Sambuc {
772433d6423SLionel Sambuc int bytes_read;
773433d6423SLionel Sambuc
774433d6423SLionel Sambuc if (lseek(Device, offset, SEEK_SET) == -1)
775433d6423SLionel Sambuc {
776433d6423SLionel Sambuc fflush (stdout);
777433d6423SLionel Sambuc fprintf (STDERR, "seek error: %s\n", strerror(errno));
778433d6423SLionel Sambuc exit(1);
779433d6423SLionel Sambuc }
780433d6423SLionel Sambuc
781433d6423SLionel Sambuc bytes_read = read(Device, buffer, nr_of_bytes);
782433d6423SLionel Sambuc if (bytes_read != nr_of_bytes)
783433d6423SLionel Sambuc {
784433d6423SLionel Sambuc fprintf (STDERR, "read error: %s\n",
785433d6423SLionel Sambuc bytes_read >= 0 ? "Short read" : strerror(errno));
786433d6423SLionel Sambuc exit (1);
787433d6423SLionel Sambuc }
788433d6423SLionel Sambuc }
789433d6423SLionel Sambuc
790433d6423SLionel Sambuc
791433d6423SLionel Sambuc /* The ISO9660 functions */
792433d6423SLionel Sambuc
iso_711(c)793433d6423SLionel Sambuc int iso_711 (c)
794433d6423SLionel Sambuc char *c;
795433d6423SLionel Sambuc {
796433d6423SLionel Sambuc return (*c & 0xff);
797433d6423SLionel Sambuc }
798433d6423SLionel Sambuc
799433d6423SLionel Sambuc
iso_712(c)800433d6423SLionel Sambuc int iso_712 (c)
801433d6423SLionel Sambuc char *c;
802433d6423SLionel Sambuc {
803433d6423SLionel Sambuc int n;
804433d6423SLionel Sambuc
805433d6423SLionel Sambuc n = *c;
806433d6423SLionel Sambuc if (n & 0x80) n |= 0xffffff00;
807433d6423SLionel Sambuc return n;
808433d6423SLionel Sambuc }
809433d6423SLionel Sambuc
iso_721(c)810433d6423SLionel Sambuc int iso_721 (c)
811433d6423SLionel Sambuc char *c;
812433d6423SLionel Sambuc {
813433d6423SLionel Sambuc return ((c[0] & 0xff) | ((c[1] & 0xff) << 8));
814433d6423SLionel Sambuc }
815433d6423SLionel Sambuc
iso_722(c)816433d6423SLionel Sambuc int iso_722 (c)
817433d6423SLionel Sambuc char *c;
818433d6423SLionel Sambuc {
819433d6423SLionel Sambuc return (((c[0] & 0xff) << 8) | (c[1] & 0xff));
820433d6423SLionel Sambuc }
821433d6423SLionel Sambuc
iso_723(c)822433d6423SLionel Sambuc int iso_723 (c)
823433d6423SLionel Sambuc char *c;
824433d6423SLionel Sambuc {
825433d6423SLionel Sambuc if (c[0] != c[3] || c[1] != c[2])
826433d6423SLionel Sambuc {
827433d6423SLionel Sambuc fprintf (STDERR, "Invalid ISO 7.2.3 number\n");
828433d6423SLionel Sambuc exit (1);
829433d6423SLionel Sambuc }
830433d6423SLionel Sambuc return (iso_721 (c));
831433d6423SLionel Sambuc }
832433d6423SLionel Sambuc
iso_731(c)833433d6423SLionel Sambuc long iso_731 (c)
834433d6423SLionel Sambuc char *c;
835433d6423SLionel Sambuc {
836433d6423SLionel Sambuc return ((long)(c[0] & 0xff)
837433d6423SLionel Sambuc | ((long)(c[1] & 0xff) << 8)
838433d6423SLionel Sambuc | ((long)(c[2] & 0xff) << 16)
839433d6423SLionel Sambuc | ((long)(c[3] & 0xff) << 24));
840433d6423SLionel Sambuc }
841433d6423SLionel Sambuc
842433d6423SLionel Sambuc
iso_732(c)843433d6423SLionel Sambuc long iso_732 (c)
844433d6423SLionel Sambuc char *c;
845433d6423SLionel Sambuc {
846433d6423SLionel Sambuc return (((long)(c[0] & 0xff) << 24)
847433d6423SLionel Sambuc | (((long)c[1] & 0xff) << 16)
848433d6423SLionel Sambuc | (((long)c[2] & 0xff) << 8)
849433d6423SLionel Sambuc | ((long)c[3] & 0xff));
850433d6423SLionel Sambuc }
851433d6423SLionel Sambuc
iso_733(c)852433d6423SLionel Sambuc long iso_733 (c)
853433d6423SLionel Sambuc char *c;
854433d6423SLionel Sambuc {
855433d6423SLionel Sambuc int i;
856433d6423SLionel Sambuc
857433d6423SLionel Sambuc for (i = 0; i < 4; i++)
858433d6423SLionel Sambuc {
859433d6423SLionel Sambuc if (c[i] != c[7-i])
860433d6423SLionel Sambuc {
861433d6423SLionel Sambuc fprintf (STDERR, "Invalid ISO 7.3.3 number\n");
862433d6423SLionel Sambuc exit (1);
863433d6423SLionel Sambuc }
864433d6423SLionel Sambuc }
865433d6423SLionel Sambuc return (iso_731(c));
866433d6423SLionel Sambuc }
867