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 /* @(#)isodebug.c 1.10 05/05/01 Copyright 1996-2004 J. Schilling */
15 * Copyright (c) 1996-2004 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <sys/types.h>
46 #include "../../wodim/defaults.h"
48 #define _delta(from, to) ((to) - (from) + 1)
52 #define VD_SUPPLEMENT 2
53 #define VD_PARTITION 3
58 struct iso9660_voldesc {
59 char vd_type [_delta(1, 1)];
60 char vd_id [_delta(2, 6)];
61 char vd_version [_delta(7, 7)];
62 char vd_fill [_delta(8, 2048)];
65 struct iso9660_boot_voldesc {
66 char vd_type [_delta(1, 1)];
67 char vd_id [_delta(2, 6)];
68 char vd_version [_delta(7, 7)];
69 char vd_bootsys [_delta(8, 39)];
70 char vd_bootid [_delta(40, 71)];
71 char vd_bootcode [_delta(72, 2048)];
74 struct iso9660_pr_voldesc {
75 char vd_type [_delta(1, 1)];
76 char vd_id [_delta(2, 6)];
77 char vd_version [_delta(7, 7)];
78 char vd_unused1 [_delta(8, 8)];
79 char vd_system_id [_delta(9, 40)];
80 char vd_volume_id [_delta(41, 72)];
81 char vd_unused2 [_delta(73, 80)];
82 char vd_volume_space_size [_delta(81, 88)];
83 char vd_unused3 [_delta(89, 120)];
84 char vd_volume_set_size [_delta(121, 124)];
85 char vd_volume_seq_number [_delta(125, 128)];
86 char vd_lbsize [_delta(129, 132)];
87 char vd_path_table_size [_delta(133, 140)];
88 char vd_pos_path_table_l [_delta(141, 144)];
89 char vd_opt_pos_path_table_l [_delta(145, 148)];
90 char vd_pos_path_table_m [_delta(149, 152)];
91 char vd_opt_pos_path_table_m [_delta(153, 156)];
92 char vd_root_dir [_delta(157, 190)];
93 char vd_volume_set_id [_delta(191, 318)];
94 char vd_publisher_id [_delta(319, 446)];
95 char vd_data_preparer_id [_delta(447, 574)];
96 char vd_application_id [_delta(575, 702)];
97 char vd_copyr_file_id [_delta(703, 739)];
98 char vd_abstr_file_id [_delta(740, 776)];
99 char vd_bibl_file_id [_delta(777, 813)];
100 char vd_create_time [_delta(814, 830)];
101 char vd_mod_time [_delta(831, 847)];
102 char vd_expiry_time [_delta(848, 864)];
103 char vd_effective_time [_delta(865, 881)];
104 char vd_file_struct_vers [_delta(882, 882)];
105 char vd_reserved1 [_delta(883, 883)];
106 char vd_application_use [_delta(884, 1395)];
107 char vd_fill [_delta(1396, 2048)];
110 #define GET_UBYTE(a) a_to_u_byte(a)
111 #define GET_SBYTE(a) a_to_byte(a)
112 #define GET_SHORT(a) a_to_u_2_byte(&((unsigned char *) (a))[0])
113 #define GET_BSHORT(a) a_to_u_2_byte(&((unsigned char *) (a))[2])
114 #define GET_INT(a) a_to_4_byte(&((unsigned char *) (a))[0])
115 #define GET_LINT(a) la_to_4_byte(&((unsigned char *) (a))[0])
116 #define GET_BINT(a) a_to_4_byte(&((unsigned char *) (a))[4])
118 #define infile in_image
121 static void usage(int excode);
122 static char *isodinfo(FILE *f);
127 errmsgno(EX_BAD, "Usage: %s [options] image\n",
130 fprintf(stderr, "Options:\n");
131 fprintf(stderr, "\t-help,-h Print this help\n");
132 fprintf(stderr, "\t-version Print version info and exit\n");
133 fprintf(stderr, "\t-i filename Filename to read ISO-9660 image from\n");
134 fprintf(stderr, "\tdev=target SCSI target to use as CD/DVD-Recorder\n");
135 fprintf(stderr, "\nIf neither -i nor dev= are speficied, <image> is needed.\n");
142 static struct iso9660_voldesc vd;
143 struct iso9660_pr_voldesc *vp;
153 * First check if a bad guy tries to call isosize()
154 * with an unappropriate file descriptor.
155 * return -1 in this case.
157 if (isatty(fileno(f)))
159 if (fstat(fileno(f), &sb) < 0)
161 mode = sb.st_mode & S_IFMT;
162 if (!S_ISREG(mode) && !S_ISBLK(mode) && !S_ISCHR(mode))
166 vp = (struct iso9660_pr_voldesc *) &vd;
170 readsecs(sec_off, &vd, 1);
172 if (lseek(fileno(f), (off_t)(sec_off * 2048L), SEEK_SET) == -1)
174 read(fileno(f), &vd, sizeof (vd));
178 if (GET_UBYTE(vd.vd_type) == VD_PRIMARY) {
183 } while (GET_UBYTE(vd.vd_type) != VD_TERM);
185 if (GET_UBYTE(vd.vd_type) != VD_TERM)
189 readsecs(sec_off, &vd, 1);
191 if (lseek(fileno(f), (off_t)(sec_off * 2048L), SEEK_SET) == -1)
193 read(fileno(f), &vd, sizeof (vd));
197 return ((char *)&vd);
201 main(int argc, char *argv[])
205 char *opts = "help,h,version,i*,dev*";
208 char *filename = NULL;
209 char *devname = NULL;
213 save_args(argc, argv);
217 if (getallargs(&cac, &cav, opts, &help, &help, &prvers,
218 &filename, &devname) < 0) {
219 errmsgno(EX_BAD, "Bad Option: '%s'\n", cav[0]);
225 printf("isodebug %s (%s)\n", CDRKIT_VERSION, HOST_SYSTEM);
230 if (filename == NULL && devname == NULL) {
231 if (getfiles(&cac, &cav, opts) != 0) {
236 if (getfiles(&cac, &cav, opts) != 0) {
237 errmsgno(EX_BAD, "Bad Argument: '%s'\n", cav[0]);
240 if (filename != NULL && devname != NULL) {
241 errmsgno(EX_BAD, "Only one of -i or dev= allowed\n");
245 if (filename == NULL && devname == NULL)
246 cdr_defaults(&devname, NULL, NULL, NULL);
248 if (filename == NULL && devname == NULL) {
249 errmsgno(EX_BAD, "ISO-9660 image not specified\n");
253 if (filename != NULL)
254 infile = fopen(filename, "rb");
258 if (infile != NULL) {
261 } else if (scsidev_open(filename) < 0) {
265 comerr("Cannot open '%s'\n", filename);
268 p = isodinfo(infile);
270 printf("No ISO-9660 image debug info.\n");
271 } else if (strncmp(p, "MKI ", 4) == 0) {
272 eol = strchr(p, '\n');
275 printf("ISO-9660 image created at %s\n", &p[4]);
277 printf("\nCmdline: '%s'\n", &eol[1]);