1 /* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
6 * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
7 * Perez-Rathke and Ram Vedam. All rights reserved.
9 * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
10 * Alan Perez-Rathke and Ram Vedam.
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
23 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
27 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
41 #include <sys/mount.h>
45 #include "iso9660_rrip.h"
47 static void debug_print_susp_attrs(cd9660node *, int);
48 static void debug_dump_to_xml_padded_hex_output(const char *, unsigned char *,
56 for (i = 1; i <= n; i ++)
62 debug_print_rrip_info(cd9660node *n)
64 struct ISO_SUSP_ATTRIBUTES *t;
65 TAILQ_FOREACH(t, &node->head, rr_ll) {
72 debug_print_susp_attrs(cd9660node *n, int indent)
74 struct ISO_SUSP_ATTRIBUTES *t;
76 TAILQ_FOREACH(t, &n->head, rr_ll) {
79 printf("%c%c: L:%i",t->attr.su_entry.SP.h.type[0],
80 t->attr.su_entry.SP.h.type[1],
81 (int)t->attr.su_entry.SP.h.length[0]);
87 debug_print_tree(iso9660_disk *diskStructure, cd9660node *node, int level)
89 #if !HAVE_NBTOOL_CONFIG_H
93 if (node->type & CD9660_TYPE_DOT) {
95 isonum_733(node->isoDirRecord->extent));
96 } else if (node->type & CD9660_TYPE_DOTDOT) {
98 isonum_733(node->isoDirRecord->extent));
99 } else if (node->isoDirRecord->name[0]=='\0') {
100 printf("(ROOT) (%" PRIu32 " to %" PRId64 ")\n",
101 node->fileDataSector,
102 node->fileDataSector +
103 node->fileSectorsUsed - 1);
105 printf("%s (%s) (%" PRIu32 " to %" PRId64 ")\n",
106 node->isoDirRecord->name,
107 (node->isoDirRecord->flags[0]
108 & ISO_FLAG_DIRECTORY) ? "DIR" : "FILE",
109 node->fileDataSector,
110 (node->fileSectorsUsed == 0) ?
111 node->fileDataSector :
113 + node->fileSectorsUsed - 1);
115 if (diskStructure->rock_ridge_enabled)
116 debug_print_susp_attrs(node, level + 1);
117 TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
118 debug_print_tree(diskStructure, cn, level + 1);
120 printf("Sorry, debugging is not supported in host-tools mode.\n");
125 debug_print_path_tree(cd9660node *n)
127 cd9660node *iterator = n;
129 /* Only display this message when called with the root node */
130 if (n->parent == NULL)
131 printf("debug_print_path_table: Dumping path table contents\n");
133 while (iterator != NULL) {
134 if (iterator->isoDirRecord->name[0] == '\0')
135 printf("0) (ROOT)\n");
137 printf("%i) %s\n", iterator->level,
138 iterator->isoDirRecord->name);
140 iterator = iterator->ptnext;
145 debug_print_volume_descriptor_information(iso9660_disk *diskStructure)
147 volume_descriptor *tmp = diskStructure->firstVolumeDescriptor;
148 char temp[CD9660_SECTOR_SIZE];
150 printf("==Listing Volume Descriptors==\n");
152 while (tmp != NULL) {
153 memset(temp, 0, CD9660_SECTOR_SIZE);
154 memcpy(temp, tmp->volumeDescriptorData + 1, 5);
155 printf("Volume descriptor in sector %" PRId64
156 ": type %i, ID %s\n",
157 tmp->sector, tmp->volumeDescriptorData[0], temp);
158 switch(tmp->volumeDescriptorData[0]) {
159 case 0:/*boot record*/
168 case 3: /* Volume Partition Descriptor */
171 case 255: /* terminator */
177 printf("==Done Listing Volume Descriptors==\n");
181 debug_dump_to_xml_ptentry(path_table_entry *pttemp, int num, int mode)
183 printf("<ptentry num=\"%i\">\n" ,num);
184 printf("<length>%i</length>\n", pttemp->length[0]);
185 printf("<extended_attribute_length>%i</extended_attribute_length>\n",
186 pttemp->extended_attribute_length[0]);
187 printf("<parent_number>%i</parent_number>\n",
188 debug_get_encoded_number(pttemp->parent_number,mode));
189 debug_dump_to_xml_padded_hex_output("name",
190 pttemp->name, pttemp->length[0]);
191 printf("</ptentry>\n");
195 debug_dump_to_xml_path_table(FILE *fd, off_t sector, int size, int mode)
197 path_table_entry pttemp;
201 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
205 /* Read fixed data first */
206 fread(&pttemp, 1, 8, fd);
209 fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0], fd);
210 t += pttemp.length[0];
211 debug_dump_to_xml_ptentry(&pttemp, n, mode);
218 * XML Debug output functions
219 * Dump hierarchy of CD, as well as volume info, to XML
220 * Can be used later to diff against a standard,
221 * or just provide easy to read detailed debug output
224 debug_dump_to_xml(FILE *fd)
226 unsigned char buf[CD9660_SECTOR_SIZE];
229 struct iso_primary_descriptor primaryVD;
230 struct _boot_volume_descriptor bootVD;
232 printf("<cd9660dump>\n");
234 /* Display Volume Descriptors */
237 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
239 fread(buf, 1, CD9660_SECTOR_SIZE, fd);
240 t = (int)((unsigned char)buf[0]);
243 memcpy(&bootVD, buf, CD9660_SECTOR_SIZE);
246 memcpy(&primaryVD, buf, CD9660_SECTOR_SIZE);
249 debug_dump_to_xml_volume_descriptor(buf, sector);
253 t = debug_get_encoded_number((u_char *)primaryVD.type_l_path_table,
255 t2 = debug_get_encoded_number((u_char *)primaryVD.path_table_size, 733);
256 printf("Path table 1 located at sector %i and is %i bytes long\n",
258 debug_dump_to_xml_path_table(fd, t, t2, 721);
260 t = debug_get_encoded_number((u_char *)primaryVD.type_m_path_table,
262 debug_dump_to_xml_path_table(fd, t, t2, 722);
264 printf("</cd9660dump>\n");
268 debug_dump_to_xml_padded_hex_output(const char *element, unsigned char *buf,
274 printf("<%s>",element);
275 for (i = 0; i < len; i++) {
276 t = (unsigned char)buf[i];
277 if (t >= 32 && t < 127)
280 printf("</%s>\n",element);
282 printf("<%s:hex>",element);
283 for (i = 0; i < len; i++) {
284 t = (unsigned char)buf[i];
287 printf("</%s:hex>\n",element);
291 debug_get_encoded_number(unsigned char* buf, int mode)
293 #if !HAVE_NBTOOL_CONFIG_H
295 /* 711: Single bite */
297 return isonum_711(buf);
299 /* 712: Single signed byte */
301 return isonum_712((signed char *)buf);
305 return isonum_721(buf);
309 return isonum_731(buf);
313 return isonum_722(buf);
317 return isonum_732(buf);
319 /* 723: 16 bit bothE */
321 return isonum_723(buf);
323 /* 733: 32 bit bothE */
325 return isonum_733(buf);
332 debug_dump_integer(const char *element, char* buf, int mode)
334 printf("<%s>%i</%s>\n", element,
335 debug_get_encoded_number((unsigned char *)buf, mode), element);
339 debug_dump_string(const char *element __unused, unsigned char *buf __unused, int len __unused)
345 debug_dump_directory_record_9_1(unsigned char* buf)
347 printf("<directoryrecord>\n");
348 debug_dump_integer("length",
349 ((struct iso_directory_record*) buf)->length, 711);
350 debug_dump_integer("ext_attr_length",
351 ((struct iso_directory_record*) buf)->ext_attr_length,711);
352 debug_dump_integer("extent",
353 (char *)((struct iso_directory_record*) buf)->extent, 733);
354 debug_dump_integer("size",
355 (char *)((struct iso_directory_record*) buf)->size, 733);
356 debug_dump_integer("flags",
357 ((struct iso_directory_record*) buf)->flags, 711);
358 debug_dump_integer("file_unit_size",
359 ((struct iso_directory_record*) buf)->file_unit_size,711);
360 debug_dump_integer("interleave",
361 ((struct iso_directory_record*) buf)->interleave, 711);
362 debug_dump_integer("volume_sequence_number",
363 ((struct iso_directory_record*) buf)->volume_sequence_number,
365 debug_dump_integer("name_len",
366 ((struct iso_directory_record*) buf)->name_len, 711);
367 debug_dump_to_xml_padded_hex_output("name",
368 (u_char *)((struct iso_directory_record*) buf)->name,
369 debug_get_encoded_number((u_char *)
370 ((struct iso_directory_record*) buf)->length, 711));
371 printf("</directoryrecord>\n");
376 debug_dump_to_xml_volume_descriptor(unsigned char* buf, int sector)
378 printf("<volumedescriptor sector=\"%i\">\n", sector);
390 printf("supplementary");
394 printf("volume partition descriptor");
398 printf("terminator");
402 printf("</vdtype>\n");
405 debug_dump_integer("type",
406 ((struct iso_primary_descriptor*)buf)->type, 711);
407 debug_dump_to_xml_padded_hex_output("id",
408 (u_char *)((struct iso_primary_descriptor*) buf)->id,
410 debug_dump_integer("version",
411 ((struct iso_primary_descriptor*)buf)->version,
413 debug_dump_to_xml_padded_hex_output("system_id",
414 (u_char *)((struct iso_primary_descriptor*)buf)->system_id,
416 debug_dump_to_xml_padded_hex_output("volume_id",
417 (u_char *)((struct iso_primary_descriptor*)buf)->volume_id,
419 debug_dump_integer("volume_space_size",
420 ((struct iso_primary_descriptor*)buf)->volume_space_size,
422 debug_dump_integer("volume_set_size",
423 ((struct iso_primary_descriptor*)buf)->volume_set_size,
425 debug_dump_integer("volume_sequence_number",
426 ((struct iso_primary_descriptor*)buf)->volume_sequence_number,
428 debug_dump_integer("logical_block_size",
429 ((struct iso_primary_descriptor*)buf)->logical_block_size,
431 debug_dump_integer("path_table_size",
432 ((struct iso_primary_descriptor*)buf)->path_table_size,
434 debug_dump_integer("type_l_path_table",
435 ((struct iso_primary_descriptor*)buf)->type_l_path_table,
437 debug_dump_integer("opt_type_l_path_table",
438 ((struct iso_primary_descriptor*)buf)->opt_type_l_path_table,
440 debug_dump_integer("type_m_path_table",
441 ((struct iso_primary_descriptor*)buf)->type_m_path_table,
443 debug_dump_integer("opt_type_m_path_table",
444 ((struct iso_primary_descriptor*)buf)->opt_type_m_path_table,732);
445 debug_dump_directory_record_9_1(
446 (u_char *)((struct iso_primary_descriptor*)buf)->root_directory_record);
447 debug_dump_to_xml_padded_hex_output("volume_set_id",
448 (u_char *)((struct iso_primary_descriptor*) buf)->volume_set_id,
450 debug_dump_to_xml_padded_hex_output("publisher_id",
451 (u_char *)((struct iso_primary_descriptor*) buf)->publisher_id,
453 debug_dump_to_xml_padded_hex_output("preparer_id",
454 (u_char *)((struct iso_primary_descriptor*) buf)->preparer_id,
456 debug_dump_to_xml_padded_hex_output("application_id",
457 (u_char *)((struct iso_primary_descriptor*) buf)->application_id,
459 debug_dump_to_xml_padded_hex_output("copyright_file_id",
460 (u_char *)((struct iso_primary_descriptor*) buf)->copyright_file_id,
462 debug_dump_to_xml_padded_hex_output("abstract_file_id",
463 (u_char *)((struct iso_primary_descriptor*) buf)->abstract_file_id,
465 debug_dump_to_xml_padded_hex_output("bibliographic_file_id",
466 (u_char *)((struct iso_primary_descriptor*) buf)->bibliographic_file_id,
469 debug_dump_to_xml_padded_hex_output("creation_date",
470 (u_char *)((struct iso_primary_descriptor*) buf)->creation_date,
472 debug_dump_to_xml_padded_hex_output("modification_date",
473 (u_char *)((struct iso_primary_descriptor*) buf)->modification_date,
475 debug_dump_to_xml_padded_hex_output("expiration_date",
476 (u_char *)((struct iso_primary_descriptor*) buf)->expiration_date,
478 debug_dump_to_xml_padded_hex_output("effective_date",
479 (u_char *)((struct iso_primary_descriptor*) buf)->effective_date,
482 debug_dump_to_xml_padded_hex_output("file_structure_version",
483 (u_char *)((struct iso_primary_descriptor*) buf)->file_structure_version,
487 printf("</volumedescriptor>\n");