2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)isoinfo.c 1.50 05/05/15 joerg */
15 * File isodump.c - dump iso9660 directory information.
18 * Written by Eric Youngdale (1993).
20 * Copyright 1993 Yggdrasil Computing, Incorporated
21 * Copyright (c) 1999-2004 J. Schilling
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License version 2
25 * as published by the Free Software Foundation.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License along with
33 * this program; see the file COPYING. If not, write to the Free Software
34 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * Simple program to dump contents of iso9660 image in more usable format.
41 * To list contents of image (with or without RR):
42 * isoinfo -l [-R] -i imagefile
43 * To extract file from image:
44 * isoinfo -i imagefile -x xtractfile > outfile
45 * To generate a "find" like list of files:
46 * isoinfo -f -i imagefile
63 #include "../iso9660.h"
65 #include "../../wodim/defaults.h"
69 #if defined(__CYGWIN32__) || defined(__EMX__) || defined(__DJGPP__)
70 #include <io.h> /* for setmode() prototype */
74 * Make sure we have a definition for this. If not, take a very conservative
76 * POSIX requires the max pathname component lenght to be defined in limits.h
77 * If variable, it may be undefined. If undefined, there should be
78 * a definition for _POSIX_NAME_MAX in limits.h or in unistd.h
79 * As _POSIX_NAME_MAX is defined to 14, we cannot use it.
80 * XXX Eric's wrong comment:
81 * XXX From what I can tell SunOS is the only one with this trouble.
88 #define NAME_MAX FILENAME_MAX
96 #define PATH_MAX FILENAME_MAX
103 * XXX JS: Some structures have odd lengths!
104 * Some compilers (e.g. on Sun3/mc68020) padd the structures to even length.
105 * For this reason, we cannot use sizeof (struct iso_path_table) or
106 * sizeof (struct iso_directory_record) to compute on disk sizes.
107 * Instead, we use offsetof(..., name) and add the name size.
111 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
115 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
119 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
121 # define S_ISSOCK(m) (0)
126 * Note: always use these macros to avoid problems.
128 * ISO_ROUND_UP(X) may cause an integer overflow and thus give
129 * incorrect results. So avoid it if possible.
131 * ISO_BLOCKS(X) is overflow safe. Prefer this when ever it is possible.
133 #define SECTOR_SIZE (2048)
134 #define ISO_ROUND_UP(X) (((X) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1))
135 #define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
137 #define infile in_image
152 struct stat fstat_buf;
156 unsigned char date_buf[9];
158 * Use sector_offset != 0 (-N #) if we have an image file
159 * of a single session and we need to list the directory contents.
160 * This is the session block (sector) number of the start
161 * of the session when it would be on disk.
163 unsigned int sector_offset = 0;
165 unsigned char buffer[2048];
167 struct unls_table *unls;
169 #define PAGE sizeof (buffer)
171 #define ISODCL(from, to) (to - from + 1)
174 int isonum_721(char * p);
175 int isonum_723(char * p);
176 int isonum_731(char * p);
177 int isonum_732(char * p);
178 int isonum_733(unsigned char * p);
179 void printchars(char *s, int n);
180 char *sdate(char *dp);
181 void dump_pathtab(int block, int size);
182 int parse_rr(unsigned char * pnt, int len, int cont_flag);
183 void find_rr(struct iso_directory_record * idr, Uchar **pntp, int *lenp);
184 int dump_rr(struct iso_directory_record * idr);
185 void dump_stat(struct iso_directory_record * idr, int extent);
186 void extract_file(struct iso_directory_record * idr);
187 void parse_dir(char * rootname, int extent, int len);
188 void usage(int excode);
190 static void printf_bootinfo(FILE *f, int bootcat_offset);
191 static char *arch_name(int val);
192 static char *boot_name(int val);
193 static char *bootmedia_name(int val);
199 return ((p[0] & 0xff)
200 | ((p[1] & 0xff) << 8));
207 if (p[0] != p[3] || p[1] != p[2]) {
209 comerrno(EX_BAD, "invalid format 7.2.3 number\n");
211 fprintf(stderr, "invalid format 7.2.3 number\n");
216 return (isonum_721(p));
222 return ((p[0] & 0xff)
223 | ((p[1] & 0xff) << 8)
224 | ((p[2] & 0xff) << 16)
225 | ((p[3] & 0xff) << 24));
231 return ((p[3] & 0xff)
232 | ((p[2] & 0xff) << 8)
233 | ((p[1] & 0xff) << 16)
234 | ((p[0] & 0xff) << 24));
238 isonum_733(unsigned char *p)
240 return (isonum_731((char *)p));
244 printchars(char *s, int n)
249 for (; n > 0 && *s; n--) {
253 while (--i >= 0 && *p++ == ' ')
263 * Print date info from PVD
270 sprintf(d, "%4.4s %2.2s %2.2s %2.2s:%2.2s:%2.2s.%2.2s",
273 &dp[6], /* Monthday */
275 &dp[10], /* Minute */
276 &dp[12], /* Seconds */
277 &dp[14]); /* Hunreds of a Seconds */
280 * dp[16] contains minute offset from Greenwich
281 * Positive values are to the east of Greenwich.
287 dump_pathtab(int block, int size)
298 unsigned char uh, ul, uc, *up;
301 printf("Path table starts at block %d, size %d\n", block, size);
303 buf = (unsigned char *) malloc(ISO_ROUND_UP(size));
306 readsecs(block - sector_offset, buf, ISO_BLOCKS(size));
308 lseek(fileno(infile), ((off_t)(block - sector_offset)) << 11, SEEK_SET);
309 read(fileno(infile), buf, size);
314 while (offset < size) {
316 extent = isonum_731((char *)buf + offset + 2);
317 pindex = isonum_721((char *)buf + offset + 6);
324 for (j = 0; j < jlen; j++) {
325 uh = buf[offset + 8 + j*2];
326 ul = buf[offset + 8 + j*2+1];
328 up = unls->unls_uni2cs[uh];
335 namebuf[j] = uc ? uc : '_';
337 printf("%4d: %4d %x %.*s\n",
338 idx, pindex, extent, jlen, namebuf);
341 printf("%4d: %4d %x %.*s\n",
342 idx, pindex, extent, len, buf + offset + 8);
355 parse_rr(unsigned char *pnt, int len, int cont_flag)
361 int cont_extent, cont_offset, cont_size;
364 char symlinkname[1024];
369 cont_extent = cont_offset = cont_size = 0;
374 if (pnt[3] != 1 && pnt[3] != 2) {
375 printf("**BAD RRVERSION (%d)\n", pnt[3]);
376 return (0); /* JS ??? Is this right ??? */
379 if (pnt[0] == 'R' && pnt[1] == 'R') flag1 = pnt[4] & 0xff;
380 if (strncmp((char *)pnt, "PX", 2) == 0) flag2 |= 1; /* POSIX attributes */
381 if (strncmp((char *)pnt, "PN", 2) == 0) flag2 |= 2; /* POSIX device number */
382 if (strncmp((char *)pnt, "SL", 2) == 0) flag2 |= 4; /* Symlink */
383 if (strncmp((char *)pnt, "NM", 2) == 0) flag2 |= 8; /* Alternate Name */
384 if (strncmp((char *)pnt, "CL", 2) == 0) flag2 |= 16; /* Child link */
385 if (strncmp((char *)pnt, "PL", 2) == 0) flag2 |= 32; /* Parent link */
386 if (strncmp((char *)pnt, "RE", 2) == 0) flag2 |= 64; /* Relocated Direcotry */
387 if (strncmp((char *)pnt, "TF", 2) == 0) flag2 |= 128; /* Time stamp */
388 if (strncmp((char *)pnt, "SP", 2) == 0) {
389 flag2 |= 1024; /* SUSP record */
390 su_version = pnt[3] & 0xff;
392 if (strncmp((char *)pnt, "AA", 2) == 0) {
393 flag2 |= 2048; /* Apple Signature record */
394 aa_version = pnt[3] & 0xff;
397 if (strncmp((char *)pnt, "PX", 2) == 0) { /* POSIX attributes */
398 fstat_buf.st_mode = isonum_733(pnt+4);
399 fstat_buf.st_nlink = isonum_733(pnt+12);
400 fstat_buf.st_uid = isonum_733(pnt+20);
401 fstat_buf.st_gid = isonum_733(pnt+28);
404 if (strncmp((char *)pnt, "NM", 2) == 0) { /* Alternate Name */
405 int l = strlen(name_buf);
409 strncpy(&name_buf[l], (char *)(pnt+5), pnt[2] - 5);
410 name_buf[l + pnt[2] - 5] = 0;
414 if (strncmp((char *)pnt, "CE", 2) == 0) { /* Continuation Area */
415 cont_extent = isonum_733(pnt+4);
416 cont_offset = isonum_733(pnt+12);
417 cont_size = isonum_733(pnt+20);
420 if (strncmp((char *)pnt, "PL", 2) == 0 || strncmp((char *)pnt, "CL", 2) == 0) {
421 extent = isonum_733(pnt+4);
424 if (strncmp((char *)pnt, "SL", 2) == 0) { /* Symlink */
431 switch (pnts[0] & 0xfe) {
433 strncat(symlinkname, (char *)(pnts+2), pnts[1]);
434 symlinkname[pnts[1]] = 0;
437 strcat(symlinkname, ".");
440 strcat(symlinkname, "..");
443 strcat(symlinkname, "/");
446 strcat(symlinkname, "/mnt");
447 printf("Warning - mount point requested");
450 strcat(symlinkname, "kafka");
451 printf("Warning - host_name requested");
454 printf("Reserved bit setting in symlink");
458 if ((pnts[0] & 0xfe) && pnts[1] != 0) {
459 printf("Incorrect length in symlink component");
461 if (xname[0] == 0) strcpy(xname, "-> ");
462 strcat(xname, symlinkname);
464 xlen = strlen(xname);
465 if ((pnts[0] & 1) == 0 && xname[xlen-1] != '/') strcat(xname, "/");
467 slen -= (pnts[1] + 2);
468 pnts += (pnts[1] + 2);
475 if (len <= 3 && cont_extent) {
476 unsigned char sector[2048];
479 readsecs(cont_extent - sector_offset, sector, ISO_BLOCKS(sizeof (sector)));
481 lseek(fileno(infile), ((off_t)(cont_extent - sector_offset)) << 11, SEEK_SET);
482 read(fileno(infile), sector, sizeof (sector));
484 flag2 |= parse_rr(§or[cont_offset], cont_size, 1);
488 * for symbolic links, strip out the last '/'
490 if (xname[0] != 0 && xname[strlen(xname)-1] == '/') {
491 xname[strlen(xname)-1] = '\0';
497 find_rr(struct iso_directory_record *idr, Uchar **pntp, int *lenp)
499 struct iso_xa_dir_record *xadp;
503 len = idr->length[0] & 0xff;
504 len -= offsetof(struct iso_directory_record, name[0]);
505 len -= idr->name_len[0];
507 pnt = (unsigned char *) idr;
508 pnt += offsetof(struct iso_directory_record, name[0]);
509 pnt += idr->name_len[0];
510 if ((idr->name_len[0] & 1) == 0) {
515 xadp = (struct iso_xa_dir_record *)pnt;
517 if (xadp->signature[0] == 'X' && xadp->signature[1] == 'A' &&
518 xadp->reserved[0] == '\0') {
528 dump_rr(struct iso_directory_record *idr)
533 find_rr(idr, &pnt, &len);
534 return (parse_rr(pnt, len, 0));
545 struct todo *todo_idr = NULL;
547 char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
548 "Aug", "Sep", "Oct", "Nov", "Dec"};
551 dump_stat(struct iso_directory_record *idr, int extent)
556 memset(outline, ' ', sizeof (outline));
558 if (S_ISREG(fstat_buf.st_mode))
560 else if (S_ISDIR(fstat_buf.st_mode))
562 else if (S_ISLNK(fstat_buf.st_mode))
564 else if (S_ISCHR(fstat_buf.st_mode))
566 else if (S_ISBLK(fstat_buf.st_mode))
568 else if (S_ISFIFO(fstat_buf.st_mode))
570 else if (S_ISSOCK(fstat_buf.st_mode))
575 memset(outline+1, '-', 9);
576 if (fstat_buf.st_mode & S_IRUSR)
578 if (fstat_buf.st_mode & S_IWUSR)
580 if (fstat_buf.st_mode & S_IXUSR)
583 if (fstat_buf.st_mode & S_IRGRP)
585 if (fstat_buf.st_mode & S_IWGRP)
587 if (fstat_buf.st_mode & S_IXGRP)
590 if (fstat_buf.st_mode & S_IROTH)
592 if (fstat_buf.st_mode & S_IWOTH)
594 if (fstat_buf.st_mode & S_IXOTH)
598 * XXX This is totally ugly code from Eric.
599 * XXX If one field is wider than expected then it is truncated.
601 sprintf(outline+11, "%3ld", (long)fstat_buf.st_nlink);
602 sprintf(outline+15, "%4lo", (unsigned long)fstat_buf.st_uid);
603 sprintf(outline+20, "%4lo", (unsigned long)fstat_buf.st_gid);
604 sprintf(outline+30, "%10lld", (Llong)fstat_buf.st_size);
606 if (do_sectors == 0) {
607 sprintf(outline+30, "%10lld", (Llong)fstat_buf.st_size);
609 sprintf(outline+30, "%10lld", (Llong)((fstat_buf.st_size+PAGE-1)/PAGE));
612 if (date_buf[1] >= 1 && date_buf[1] <= 12) {
613 memcpy(outline+41, months[date_buf[1]-1], 3);
616 sprintf(outline+45, "%2d", date_buf[2]);
618 sprintf(outline+48, "%4d", date_buf[0]+1900);
620 sprintf(outline+53, "[%7d", extent); /* XXX up to 20 GB */
621 sprintf(outline+61, " %02X]", idr->flags[0]);
623 for (i = 0; i < 66; i++) {
624 if (outline[i] == 0) outline[i] = ' ';
627 printf("%s %s %s\n", outline, name_buf, xname);
631 extract_file(struct iso_directory_record *idr)
633 int extent, len, tlen;
634 unsigned char buff[2048];
636 #if defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(__EMX__) || defined(__DJGPP__)
637 setmode(fileno(stdout), O_BINARY);
640 extent = isonum_733((unsigned char *)idr->extent);
641 len = isonum_733((unsigned char *)idr->size);
645 readsecs(extent - sector_offset, buff, ISO_BLOCKS(sizeof (buff)));
646 tlen = (len > sizeof (buff) ? sizeof (buff) : len);
648 lseek(fileno(infile), ((off_t)(extent - sector_offset)) << 11, SEEK_SET);
649 tlen = (len > sizeof (buff) ? sizeof (buff) : len);
650 read(fileno(infile), buff, tlen);
654 write(STDOUT_FILENO, buff, tlen); /* FIXME: check return value */
659 parse_dir(char *rootname, int extent, int len)
661 char testname[PATH_MAX+1];
664 struct iso_directory_record * idr;
665 unsigned char uh, ul, uc, *up;
669 printf("\nDirectory listing of %s\n", rootname);
673 readsecs(extent - sector_offset, buffer, ISO_BLOCKS(sizeof (buffer)));
675 lseek(fileno(infile), ((off_t)(extent - sector_offset)) << 11, SEEK_SET);
676 read(fileno(infile), buffer, sizeof (buffer));
678 len -= sizeof (buffer);
682 idr = (struct iso_directory_record *) &buffer[i];
683 if (idr->length[0] == 0) break;
684 memset(&fstat_buf, 0, sizeof (fstat_buf));
686 name_buf[0] = xname[0] = 0;
687 fstat_buf.st_size = (off_t)(unsigned)isonum_733((unsigned char *)idr->size);
688 if (idr->flags[0] & 2)
689 fstat_buf.st_mode |= S_IFDIR;
691 fstat_buf.st_mode |= S_IFREG;
692 if (idr->name_len[0] == 1 && idr->name[0] == 0)
693 strcpy(name_buf, ".");
694 else if (idr->name_len[0] == 1 && idr->name[0] == 1)
695 strcpy(name_buf, "..");
702 * Unicode name. Convert as best we can.
708 for (j = 0; j < (int)idr->name_len[0] / 2; j++) {
710 ul = idr->name[j*2+1];
712 up = unls->unls_uni2cs[uh];
719 name_buf[j] = uc ? uc : '_';
721 name_buf[idr->name_len[0]/2] = '\0';
726 * Normal non-Unicode name.
728 strncpy(name_buf, idr->name, idr->name_len[0]);
729 name_buf[idr->name_len[0]] = 0;
733 * Don't know how to do these yet. Maybe they are the same
734 * as one of the above.
739 memcpy(date_buf, idr->date, 9);
742 if ((idr->flags[0] & 2) != 0 &&
743 (idr->name_len[0] != 1 ||
744 (idr->name[0] != 0 && idr->name[0] != 1))) {
746 * Add this directory to the todo list.
750 while (td->next != NULL)
752 td->next = (struct todo *) malloc(sizeof (*td));
755 todo_idr = td = (struct todo *) malloc(sizeof (*td));
758 td->extent = isonum_733((unsigned char *)idr->extent);
759 td->length = isonum_733((unsigned char *)idr->size);
760 td->name = (char *) malloc(strlen(rootname)
761 + strlen(name_buf) + 2);
762 strcpy(td->name, rootname);
763 strcat(td->name, name_buf);
764 strcat(td->name, "/");
766 strcpy(testname, rootname);
767 strcat(testname, name_buf);
768 if (xtract && strcmp(xtract, testname) == 0) {
773 (idr->name_len[0] != 1 ||
774 (idr->name[0] != 0 && idr->name[0] != 1))) {
775 strcpy(testname, rootname);
776 strcat(testname, name_buf);
777 printf("%s\n", testname);
780 dump_stat(idr, isonum_733((unsigned char *)idr->extent));
782 if (i > 2048 - offsetof(struct iso_directory_record, name[0])) break;
790 errmsgno(EX_BAD, "Usage: %s [options] -i filename\n", get_progname());
792 fprintf(stderr, "Options:\n");
793 fprintf(stderr, "\t-help,-h Print this help\n");
794 fprintf(stderr, "\t-version Print version info and exit\n");
795 fprintf(stderr, "\t-debug Print additional debug info\n");
796 fprintf(stderr, "\t-d Print information from the primary volume descriptor\n");
797 fprintf(stderr, "\t-f Generate output similar to 'find . -print'\n");
798 fprintf(stderr, "\t-J Print information from Joliet extensions\n");
799 fprintf(stderr, "\t-j charset Use charset to display Joliet file names\n");
800 fprintf(stderr, "\t-l Generate output similar to 'ls -lR'\n");
801 fprintf(stderr, "\t-p Print Path Table\n");
802 fprintf(stderr, "\t-R Print information from Rock Ridge extensions\n");
803 fprintf(stderr, "\t-s Print file size infos in multiples of sector size (%ld bytes).\n", (long)PAGE);
804 fprintf(stderr, "\t-N sector Sector number where ISO image should start on CD\n");
805 fprintf(stderr, "\t-T sector Sector number where actual session starts on CD\n");
806 fprintf(stderr, "\t-i filename Filename to read ISO-9660 image from\n");
807 fprintf(stderr, "\tdev=target SCSI target to use as CD/DVD-Recorder\n");
808 fprintf(stderr, "\t-x pathname Extract specified file to stdout\n");
813 main(int argc, char *argv[])
818 char * filename = NULL;
819 char * devname = NULL;
821 * Use toc_offset != 0 (-T #) if we have a complete multi-session
822 * disc that we want/need to play with.
823 * Here we specify the offset where we want to
824 * start searching for the TOC.
829 struct iso_primary_descriptor ipd;
830 struct iso_primary_descriptor jpd;
831 struct eltorito_boot_descriptor bpd;
832 struct iso_directory_record * idr;
833 char *charset = NULL;
834 char *opts = "help,h,version,debug,d,p,i*,dev*,J,R,l,x*,f,s,N#l,T#l,j*";
837 BOOL found_eltorito = FALSE;
838 int bootcat_offset = 0;
841 save_args(argc, argv);
845 if (getallargs(&cac, &cav, opts,
846 &help, &help, &prvers, &debug,
847 &do_pvd, &do_pathtab,
849 &use_joliet, &use_rock,
852 &do_find, &do_sectors,
853 §or_offset, &toc_offset,
855 errmsgno(EX_BAD, "Bad Option: '%s'\n", cav[0]);
861 printf("isoinfo %s (%s)\n", CDRKIT_VERSION, HOST_SYSTEM);
866 if (getfiles(&cac, &cav, opts) != 0) {
867 errmsgno(EX_BAD, "Bad Argument: '%s'\n", cav[0]);
871 init_unls(); /* Initialize UNICODE tables */
872 init_unls_file(charset);
873 if (charset == NULL) {
874 #if (defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(__DJGPP__)) && !defined(IS_CYGWIN_1)
875 unls = load_unls("cp437");
877 unls = load_unls("iso8859-1");
880 if (strcmp(charset, "default") == 0)
881 unls = load_unls_default();
883 unls = load_unls(charset);
885 if (unls == NULL) { /* Unknown charset specified */
886 fprintf(stderr, "Unknown charset: %s\nKnown charsets are:\n",
888 list_unls(); /* List all known charset names */
892 if (filename != NULL && devname != NULL) {
893 errmsgno(EX_BAD, "Only one of -i or dev= allowed\n");
897 if (filename == NULL && devname == NULL)
898 cdr_defaults(&devname, NULL, NULL, NULL);
900 if (filename == NULL && devname == NULL) {
902 errmsgno(EX_BAD, "ISO-9660 image not specified\n");
904 fprintf(stderr, "ISO-9660 image not specified\n");
909 if (filename != NULL)
910 infile = fopen(filename, "rb");
914 if (infile != NULL) {
917 } else if (scsidev_open(filename) < 0) {
922 comerr("Unable to open %s\n", filename);
924 fprintf(stderr, "Unable to open %s\n", filename);
930 * Absolute sector offset, so don't subtract sector_offset here.
933 readsecs(16 + toc_offset, &ipd, ISO_BLOCKS(sizeof (ipd)));
935 lseek(fileno(infile), ((off_t)(16 + toc_offset)) <<11, SEEK_SET);
936 read(fileno(infile), &ipd, sizeof (ipd));
938 idr = (struct iso_directory_record *)ipd.root_directory_record;
943 * DESC TYPE == 1 (VD_SFS) offset 8 len 1
944 * STR ID == "CDROM" offset 9 len 5
945 * STD_VER == 1 offset 14 len 1
947 if ((((char *)&ipd)[8] == 1) &&
948 (strncmp(&((char *)&ipd)[9], "CDROM", 5) == 0) &&
949 (((char *)&ipd)[14] == 1)) {
950 printf("CD-ROM is in High Sierra format\n");
956 * DESC TYPE == 1 (VD_PVD) offset 0 len 1
957 * STR ID == "CD001" offset 1 len 5
958 * STD_VER == 1 offset 6 len 1
960 if ((ipd.type[0] != ISO_VD_PRIMARY) ||
961 (strncmp(ipd.id, ISO_STANDARD_ID, sizeof (ipd.id)) != 0) ||
962 (ipd.version[0] != 1)) {
963 printf("CD-ROM is NOT in ISO 9660 format\n");
967 printf("CD-ROM is in ISO 9660 format\n");
968 printf("System id: ");
969 printchars(ipd.system_id, 32);
971 printf("Volume id: ");
972 printchars(ipd.volume_id, 32);
975 printf("Volume set id: ");
976 printchars(ipd.volume_set_id, 128);
978 printf("Publisher id: ");
979 printchars(ipd.publisher_id, 128);
981 printf("Data preparer id: ");
982 printchars(ipd.preparer_id, 128);
984 printf("Application id: ");
985 printchars(ipd.application_id, 128);
988 printf("Copyright File id: ");
989 printchars(ipd.copyright_file_id, 37);
991 printf("Abstract File id: ");
992 printchars(ipd.abstract_file_id, 37);
994 printf("Bibliographic File id: ");
995 printchars(ipd.bibliographic_file_id, 37);
998 printf("Volume set size is: %d\n", isonum_723(ipd.volume_set_size));
999 printf("Volume set sequence number is: %d\n", isonum_723(ipd.volume_sequence_number));
1000 printf("Logical block size is: %d\n", isonum_723(ipd.logical_block_size));
1001 printf("Volume size is: %d\n", isonum_733((unsigned char *)ipd.volume_space_size));
1006 dextent = isonum_733((unsigned char *)idr->extent);
1007 dlen = isonum_733((unsigned char *)idr->size);
1008 printf("Root directory extent: %d size: %d\n",
1010 printf("Path table size is: %d\n",
1011 isonum_733((unsigned char *)ipd.path_table_size));
1012 printf("L Path table start: %d\n",
1013 isonum_731(ipd.type_l_path_table));
1014 printf("L Path opt table start: %d\n",
1015 isonum_731(ipd.opt_type_l_path_table));
1016 printf("M Path table start: %d\n",
1017 isonum_732(ipd.type_m_path_table));
1018 printf("M Path opt table start: %d\n",
1019 isonum_732(ipd.opt_type_m_path_table));
1020 printf("Creation Date: %s\n",
1021 sdate(ipd.creation_date));
1022 printf("Modification Date: %s\n",
1023 sdate(ipd.modification_date));
1024 printf("Expiration Date: %s\n",
1025 sdate(ipd.expiration_date));
1026 printf("Effective Date: %s\n",
1027 sdate(ipd.effective_date));
1028 printf("File structure version: %d\n",
1029 ipd.file_structure_version[0]);
1033 movebytes(&ipd, &jpd, sizeof (ipd));
1034 while ((Uchar)jpd.type[0] != ISO_VD_END) {
1036 if (debug && (Uchar) jpd.type[0] == ISO_VD_SUPPLEMENTARY)
1037 fprintf(stderr, "Joliet escape sequence 0: '%c' 1: '%c' 2: '%c' 3: '%c'\n",
1038 jpd.escape_sequences[0],
1039 jpd.escape_sequences[1],
1040 jpd.escape_sequences[2],
1041 jpd.escape_sequences[3]);
1043 * If Joliet UCS escape sequence found, we may be wrong
1045 if (jpd.escape_sequences[0] == '%' &&
1046 jpd.escape_sequences[1] == '/' &&
1047 (jpd.escape_sequences[3] == '\0' ||
1048 jpd.escape_sequences[3] == ' ') &&
1049 (jpd.escape_sequences[2] == '@' ||
1050 jpd.escape_sequences[2] == 'C' ||
1051 jpd.escape_sequences[2] == 'E')) {
1053 if (jpd.version[0] == 1)
1056 if (jpd.type[0] == 0) {
1057 movebytes(&jpd, &bpd, sizeof (bpd));
1058 if (strncmp(bpd.system_id, EL_TORITO_ID, sizeof (EL_TORITO_ID)) == 0) {
1059 bootcat_offset = (Uchar)bpd.bootcat_ptr[0] +
1060 (Uchar)bpd.bootcat_ptr[1] * 256 +
1061 (Uchar)bpd.bootcat_ptr[2] * 65536 +
1062 (Uchar)bpd.bootcat_ptr[3] * 16777216;
1063 found_eltorito = TRUE;
1064 printf("El Torito VD version %d found, boot catalog is in sector %d\n",
1069 if (jpd.version[0] == 2) {
1070 printf("CD-ROM uses ISO 9660:1999 relaxed format\n");
1077 readsecs(block + toc_offset, &jpd, ISO_BLOCKS(sizeof (jpd)));
1079 lseek(fileno(infile), ((off_t)(block + toc_offset)) <<11, SEEK_SET);
1080 read(fileno(infile), &jpd, sizeof (jpd));
1088 * DESC TYPE == 1 (VD_PVD) offset 0 len 1
1089 * STR ID == "CD001" offset 1 len 5
1090 * STD_VER == 1 offset 6 len 1
1092 if ((ipd.type[0] != ISO_VD_PRIMARY) ||
1093 (strncmp(ipd.id, ISO_STANDARD_ID, sizeof (ipd.id)) != 0) ||
1094 (ipd.version[0] != 1)) {
1095 printf("CD-ROM is NOT in ISO 9660 format\n");
1099 if (use_joliet || do_pvd) {
1101 movebytes(&ipd, &jpd, sizeof (ipd));
1102 while ((unsigned char) jpd.type[0] != ISO_VD_END) {
1103 if (debug && (unsigned char) jpd.type[0] == ISO_VD_SUPPLEMENTARY)
1104 fprintf(stderr, "Joliet escape sequence 0: '%c' 1: '%c' 2: '%c' 3: '%c'\n",
1105 jpd.escape_sequences[0],
1106 jpd.escape_sequences[1],
1107 jpd.escape_sequences[2],
1108 jpd.escape_sequences[3]);
1110 * Find the UCS escape sequence.
1112 if (jpd.escape_sequences[0] == '%' &&
1113 jpd.escape_sequences[1] == '/' &&
1114 (jpd.escape_sequences[3] == '\0' ||
1115 jpd.escape_sequences[3] == ' ') &&
1116 (jpd.escape_sequences[2] == '@' ||
1117 jpd.escape_sequences[2] == 'C' ||
1118 jpd.escape_sequences[2] == 'E')) {
1124 readsecs(block + toc_offset, &jpd, ISO_BLOCKS(sizeof (jpd)));
1126 lseek(fileno(infile),
1127 ((off_t)(block + toc_offset)) <<11, SEEK_SET);
1128 read(fileno(infile), &jpd, sizeof (jpd));
1132 if (use_joliet && ((unsigned char) jpd.type[0] == ISO_VD_END)) {
1133 #ifdef USE_LIBSCHILY
1134 comerrno(EX_BAD, "Unable to find Joliet SVD\n");
1136 fprintf(stderr, "Unable to find Joliet SVD\n");
1141 switch (jpd.escape_sequences[2]) {
1153 if (ucs_level > 3) {
1154 #ifdef USE_LIBSCHILY
1156 "Don't know what ucs_level == %d means\n",
1160 "Don't know what ucs_level == %d means\n",
1165 if (jpd.escape_sequences[3] == ' ')
1167 "Warning: Joliet escape sequence uses illegal space at offset 3\n");
1172 printf("Joliet with UCS level %d found\n", ucs_level);
1174 printf("NO Joliet present\n");
1176 extent = isonum_733((unsigned char *)idr->extent);
1179 readsecs(extent - sector_offset, buffer, ISO_BLOCKS(sizeof (buffer)));
1181 lseek(fileno(infile),
1182 ((off_t)(extent - sector_offset)) <<11, SEEK_SET);
1183 read(fileno(infile), buffer, sizeof (buffer));
1185 idr = (struct iso_directory_record *) buffer;
1186 if ((c = dump_rr(idr)) != 0) {
1187 /* printf("RR %X %d\n", c, c);*/
1190 "Rock Ridge signatures version %d found\n",
1194 "Bad Rock Ridge signatures found (SU record missing)\n");
1197 * This is currently a no op!
1198 * We need to check the first plain file instead of
1199 * the '.' entry in the root directory.
1202 printf("Apple signatures version %d found\n",
1206 printf("NO Rock Ridge present\n");
1209 printf_bootinfo(infile, bootcat_offset);
1214 idr = (struct iso_directory_record *)jpd.root_directory_record;
1218 dump_pathtab(isonum_731(jpd.type_l_path_table),
1219 isonum_733((unsigned char *)jpd.path_table_size));
1221 dump_pathtab(isonum_731(ipd.type_l_path_table),
1222 isonum_733((unsigned char *)ipd.path_table_size));
1226 parse_dir("/", isonum_733((unsigned char *)idr->extent),
1227 isonum_733((unsigned char *)idr->size));
1230 parse_dir(td->name, td->extent, td->length);
1242 printf_bootinfo(FILE *f, int bootcat_offset)
1244 struct eltorito_validation_entry *evp;
1245 struct eltorito_defaultboot_entry *ebe;
1248 readsecs(bootcat_offset, buffer, ISO_BLOCKS(sizeof (buffer)));
1250 lseek(fileno(f), ((off_t)bootcat_offset) <<11, SEEK_SET);
1251 read(fileno(f), buffer, sizeof (buffer));
1254 evp = (struct eltorito_validation_entry *)buffer;
1255 ebe = (struct eltorito_defaultboot_entry *)&buffer[32];
1257 printf("Eltorito validation header:\n");
1258 printf(" Hid %d\n", (Uchar)evp->headerid[0]);
1259 printf(" Arch %d (%s)\n", (Uchar)evp->arch[0], arch_name((Uchar)evp->arch[0]));
1260 printf(" ID '%.23s'\n", evp->id);
1261 printf(" Key %X %X\n", (Uchar)evp->key1[0], (Uchar)evp->key2[0]);
1263 printf(" Eltorito defaultboot header:\n");
1264 printf(" Bootid %X (%s)\n", (Uchar)ebe->boot_id[0], boot_name((Uchar)ebe->boot_id[0]));
1265 printf(" Boot media %X (%s)\n", (Uchar)ebe->boot_media[0], bootmedia_name((Uchar)ebe->boot_media[0]));
1266 printf(" Load segment %X\n", la_to_2_byte(ebe->loadseg));
1267 printf(" Sys type %X\n", (Uchar)ebe->sys_type[0]);
1268 printf(" Nsect %X\n", la_to_2_byte(ebe->nsect));
1269 printf(" Bootoff %lX %ld\n", la_to_4_byte(ebe->bootoff), la_to_4_byte(ebe->bootoff));
1278 case EL_TORITO_ARCH_x86:
1280 case EL_TORITO_ARCH_PPC:
1282 case EL_TORITO_ARCH_MAC:
1285 return ("Unknown Arch");
1294 case EL_TORITO_BOOTABLE:
1295 return ("bootable");
1296 case EL_TORITO_NOT_BOOTABLE:
1297 return ("not bootable");
1304 bootmedia_name(int val)
1308 case EL_TORITO_MEDIA_NOEMUL:
1309 return ("No Emulation Boot");
1310 case EL_TORITO_MEDIA_12FLOP:
1311 return ("1200 Floppy");
1312 case EL_TORITO_MEDIA_144FLOP:
1313 return ("1.44MB Floppy");
1314 case EL_TORITO_MEDIA_288FLOP:
1315 return ("2.88MB Floppy");
1316 case EL_TORITO_MEDIA_HD:
1317 return ("Hard Disk Emulation");
1319 return ("Illegal Bootmedia");