1 /* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
4 * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
5 * Perez-Rathke and Ram Vedam. All rights reserved.
7 * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
8 * Alan Perez-Rathke and Ram Vedam.
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
21 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
25 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
39 #include <sys/mount.h>
43 #include "iso9660_rrip.h"
45 static void debug_print_susp_attrs(cd9660node *, int);
46 static void debug_dump_to_xml_padded_hex_output(const char *, unsigned char *,
54 for (i = 1; i <= n; i ++)
60 debug_print_rrip_info(n)
63 struct ISO_SUSP_ATTRIBUTES *t;
64 TAILQ_FOREACH(t, &node->head, rr_ll) {
71 debug_print_susp_attrs(cd9660node *n, int indent)
73 struct ISO_SUSP_ATTRIBUTES *t;
75 TAILQ_FOREACH(t, &n->head, rr_ll) {
78 printf("%c%c: L:%i",t->attr.su_entry.SP.h.type[0],
79 t->attr.su_entry.SP.h.type[1],
80 (int)t->attr.su_entry.SP.h.length[0]);
86 debug_print_tree(cd9660node *node, int level)
88 #if !HAVE_NBTOOL_CONFIG_H
92 if (node->type & CD9660_TYPE_DOT) {
94 isonum_733(node->isoDirRecord->extent));
95 } else if (node->type & CD9660_TYPE_DOTDOT) {
97 isonum_733(node->isoDirRecord->extent));
98 } else if (node->isoDirRecord->name[0]=='\0') {
99 printf("(ROOT) (%" PRIu32 " to %" PRId64 ")\n",
100 node->fileDataSector,
101 node->fileDataSector +
102 node->fileSectorsUsed - 1);
104 printf("%s (%s) (%" PRIu32 " to %" PRId64 ")\n",
105 node->isoDirRecord->name,
106 (node->isoDirRecord->flags[0]
107 & ISO_FLAG_DIRECTORY) ? "DIR" : "FILE",
108 node->fileDataSector,
109 (node->fileSectorsUsed == 0) ?
110 node->fileDataSector :
112 + node->fileSectorsUsed - 1);
114 if (diskStructure.rock_ridge_enabled)
115 debug_print_susp_attrs(node, level + 1);
116 TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
117 debug_print_tree(cn, level + 1);
119 printf("Sorry, debugging is not supported in host-tools mode.\n");
124 debug_print_path_tree(cd9660node *n)
126 cd9660node *iterator = n;
128 /* Only display this message when called with the root node */
129 if (n->parent == NULL)
130 printf("debug_print_path_table: Dumping path table contents\n");
132 while (iterator != NULL) {
133 if (iterator->isoDirRecord->name[0] == '\0')
134 printf("0) (ROOT)\n");
136 printf("%i) %s\n", iterator->level,
137 iterator->isoDirRecord->name);
139 iterator = iterator->ptnext;
144 debug_print_volume_descriptor_information(void)
146 volume_descriptor *tmp = diskStructure.firstVolumeDescriptor;
147 char temp[CD9660_SECTOR_SIZE];
149 printf("==Listing Volume Descriptors==\n");
151 while (tmp != NULL) {
152 memset(temp, 0, CD9660_SECTOR_SIZE);
153 memcpy(temp, tmp->volumeDescriptorData + 1, 5);
154 printf("Volume descriptor in sector %" PRId64
155 ": type %i, ID %s\n",
156 tmp->sector, tmp->volumeDescriptorData[0], temp);
157 switch(tmp->volumeDescriptorData[0]) {
158 case 0:/*boot record*/
167 case 3: /* Volume Partition Descriptor */
170 case 255: /* terminator */
176 printf("==Done Listing Volume Descriptors==\n");
180 debug_dump_to_xml_ptentry(path_table_entry *pttemp, int num, int mode)
182 printf("<ptentry num=\"%i\">\n" ,num);
183 printf("<length>%i</length>\n", pttemp->length[0]);
184 printf("<extended_attribute_length>%i</extended_attribute_length>\n",
185 pttemp->extended_attribute_length[0]);
186 printf("<parent_number>%i</parent_number>\n",
187 debug_get_encoded_number(pttemp->parent_number,mode));
188 debug_dump_to_xml_padded_hex_output("name",
189 pttemp->name, pttemp->length[0]);
190 printf("</ptentry>\n");
194 debug_dump_to_xml_path_table(FILE *fd, off_t sector, int size, int mode)
196 path_table_entry pttemp;
200 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
204 /* Read fixed data first */
205 fread(&pttemp, 1, 8, fd);
208 fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0], fd);
209 t += pttemp.length[0];
210 debug_dump_to_xml_ptentry(&pttemp, n, mode);
217 * XML Debug output functions
218 * Dump hierarchy of CD, as well as volume info, to XML
219 * Can be used later to diff against a standard,
220 * or just provide easy to read detailed debug output
223 debug_dump_to_xml(FILE *fd)
225 unsigned char buf[CD9660_SECTOR_SIZE];
228 struct iso_primary_descriptor primaryVD;
229 struct _boot_volume_descriptor bootVD;
231 printf("<cd9660dump>\n");
233 /* Display Volume Descriptors */
236 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
238 fread(buf, 1, CD9660_SECTOR_SIZE, fd);
239 t = (int)((unsigned char)buf[0]);
242 memcpy(&bootVD, buf, CD9660_SECTOR_SIZE);
245 memcpy(&primaryVD, buf, CD9660_SECTOR_SIZE);
248 debug_dump_to_xml_volume_descriptor(buf, sector);
252 t = debug_get_encoded_number((u_char *)primaryVD.type_l_path_table,
254 t2 = debug_get_encoded_number((u_char *)primaryVD.path_table_size, 733);
255 printf("Path table 1 located at sector %i and is %i bytes long\n",
257 debug_dump_to_xml_path_table(fd, t, t2, 721);
259 t = debug_get_encoded_number((u_char *)primaryVD.type_m_path_table,
261 debug_dump_to_xml_path_table(fd, t, t2, 722);
263 printf("</cd9660dump>\n");
267 debug_dump_to_xml_padded_hex_output(const char *element, unsigned char *buf,
273 printf("<%s>",element);
274 for (i = 0; i < len; i++) {
275 t = (unsigned char)buf[i];
276 if (t >= 32 && t < 127)
279 printf("</%s>\n",element);
281 printf("<%s:hex>",element);
282 for (i = 0; i < len; i++) {
283 t = (unsigned char)buf[i];
286 printf("</%s:hex>\n",element);
290 debug_get_encoded_number(unsigned char* buf, int mode)
292 #if !HAVE_NBTOOL_CONFIG_H
294 /* 711: Single bite */
296 return isonum_711(buf);
298 /* 712: Single signed byte */
300 return isonum_712((signed char *)buf);
304 return isonum_721(buf);
308 return isonum_731(buf);
312 return isonum_722(buf);
316 return isonum_732(buf);
318 /* 723: 16 bit bothE */
320 return isonum_723(buf);
322 /* 733: 32 bit bothE */
324 return isonum_733(buf);
331 debug_dump_integer(const char *element, char* buf, int mode)
333 printf("<%s>%i</%s>\n", element,
334 debug_get_encoded_number((unsigned char *)buf, mode), element);
338 debug_dump_string(const char *element __unused, unsigned char *buf __unused, int len __unused)
344 debug_dump_directory_record_9_1(unsigned char* buf)
346 printf("<directoryrecord>\n");
347 debug_dump_integer("length",
348 ((struct iso_directory_record*) buf)->length, 711);
349 debug_dump_integer("ext_attr_length",
350 ((struct iso_directory_record*) buf)->ext_attr_length,711);
351 debug_dump_integer("extent",
352 (char *)((struct iso_directory_record*) buf)->extent, 733);
353 debug_dump_integer("size",
354 (char *)((struct iso_directory_record*) buf)->size, 733);
355 debug_dump_integer("flags",
356 ((struct iso_directory_record*) buf)->flags, 711);
357 debug_dump_integer("file_unit_size",
358 ((struct iso_directory_record*) buf)->file_unit_size,711);
359 debug_dump_integer("interleave",
360 ((struct iso_directory_record*) buf)->interleave, 711);
361 debug_dump_integer("volume_sequence_number",
362 ((struct iso_directory_record*) buf)->volume_sequence_number,
364 debug_dump_integer("name_len",
365 ((struct iso_directory_record*) buf)->name_len, 711);
366 debug_dump_to_xml_padded_hex_output("name",
367 (u_char *)((struct iso_directory_record*) buf)->name,
368 debug_get_encoded_number((u_char *)
369 ((struct iso_directory_record*) buf)->length, 711));
370 printf("</directoryrecord>\n");
375 debug_dump_to_xml_volume_descriptor(unsigned char* buf, int sector)
377 printf("<volumedescriptor sector=\"%i\">\n", sector);
389 printf("supplementary");
393 printf("volume partition descriptor");
397 printf("terminator");
401 printf("</vdtype>\n");
404 debug_dump_integer("type",
405 ((struct iso_primary_descriptor*)buf)->type, 711);
406 debug_dump_to_xml_padded_hex_output("id",
407 (u_char *)((struct iso_primary_descriptor*) buf)->id,
409 debug_dump_integer("version",
410 ((struct iso_primary_descriptor*)buf)->version,
412 debug_dump_to_xml_padded_hex_output("system_id",
413 (u_char *)((struct iso_primary_descriptor*)buf)->system_id,
415 debug_dump_to_xml_padded_hex_output("volume_id",
416 (u_char *)((struct iso_primary_descriptor*)buf)->volume_id,
418 debug_dump_integer("volume_space_size",
419 ((struct iso_primary_descriptor*)buf)->volume_space_size,
421 debug_dump_integer("volume_set_size",
422 ((struct iso_primary_descriptor*)buf)->volume_set_size,
424 debug_dump_integer("volume_sequence_number",
425 ((struct iso_primary_descriptor*)buf)->volume_sequence_number,
427 debug_dump_integer("logical_block_size",
428 ((struct iso_primary_descriptor*)buf)->logical_block_size,
430 debug_dump_integer("path_table_size",
431 ((struct iso_primary_descriptor*)buf)->path_table_size,
433 debug_dump_integer("type_l_path_table",
434 ((struct iso_primary_descriptor*)buf)->type_l_path_table,
436 debug_dump_integer("opt_type_l_path_table",
437 ((struct iso_primary_descriptor*)buf)->opt_type_l_path_table,
439 debug_dump_integer("type_m_path_table",
440 ((struct iso_primary_descriptor*)buf)->type_m_path_table,
442 debug_dump_integer("opt_type_m_path_table",
443 ((struct iso_primary_descriptor*)buf)->opt_type_m_path_table,732);
444 debug_dump_directory_record_9_1(
445 (u_char *)((struct iso_primary_descriptor*)buf)->root_directory_record);
446 debug_dump_to_xml_padded_hex_output("volume_set_id",
447 (u_char *)((struct iso_primary_descriptor*) buf)->volume_set_id,
449 debug_dump_to_xml_padded_hex_output("publisher_id",
450 (u_char *)((struct iso_primary_descriptor*) buf)->publisher_id,
452 debug_dump_to_xml_padded_hex_output("preparer_id",
453 (u_char *)((struct iso_primary_descriptor*) buf)->preparer_id,
455 debug_dump_to_xml_padded_hex_output("application_id",
456 (u_char *)((struct iso_primary_descriptor*) buf)->application_id,
458 debug_dump_to_xml_padded_hex_output("copyright_file_id",
459 (u_char *)((struct iso_primary_descriptor*) buf)->copyright_file_id,
461 debug_dump_to_xml_padded_hex_output("abstract_file_id",
462 (u_char *)((struct iso_primary_descriptor*) buf)->abstract_file_id,
464 debug_dump_to_xml_padded_hex_output("bibliographic_file_id",
465 (u_char *)((struct iso_primary_descriptor*) buf)->bibliographic_file_id,
468 debug_dump_to_xml_padded_hex_output("creation_date",
469 (u_char *)((struct iso_primary_descriptor*) buf)->creation_date,
471 debug_dump_to_xml_padded_hex_output("modification_date",
472 (u_char *)((struct iso_primary_descriptor*) buf)->modification_date,
474 debug_dump_to_xml_padded_hex_output("expiration_date",
475 (u_char *)((struct iso_primary_descriptor*) buf)->expiration_date,
477 debug_dump_to_xml_padded_hex_output("effective_date",
478 (u_char *)((struct iso_primary_descriptor*) buf)->effective_date,
481 debug_dump_to_xml_padded_hex_output("file_structure_version",
482 (u_char *)((struct iso_primary_descriptor*) buf)->file_structure_version,
486 printf("</volumedescriptor>\n");