xref: /minix3/usr.sbin/makefs/cd9660/cd9660_debug.c (revision 9f988b79349f9b89ecc822458c30ec8897558560)
1*9f988b79SJean-Baptiste Boric /*	$NetBSD: cd9660_debug.c,v 1.13 2013/10/19 17:16:37 christos Exp $	*/
2*9f988b79SJean-Baptiste Boric 
3*9f988b79SJean-Baptiste Boric /*
4*9f988b79SJean-Baptiste Boric  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
5*9f988b79SJean-Baptiste Boric  * Perez-Rathke and Ram Vedam.  All rights reserved.
6*9f988b79SJean-Baptiste Boric  *
7*9f988b79SJean-Baptiste Boric  * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
8*9f988b79SJean-Baptiste Boric  * Alan Perez-Rathke and Ram Vedam.
9*9f988b79SJean-Baptiste Boric  *
10*9f988b79SJean-Baptiste Boric  * Redistribution and use in source and binary forms, with or
11*9f988b79SJean-Baptiste Boric  * without modification, are permitted provided that the following
12*9f988b79SJean-Baptiste Boric  * conditions are met:
13*9f988b79SJean-Baptiste Boric  * 1. Redistributions of source code must retain the above copyright
14*9f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer.
15*9f988b79SJean-Baptiste Boric  * 2. Redistributions in binary form must reproduce the above
16*9f988b79SJean-Baptiste Boric  *    copyright notice, this list of conditions and the following
17*9f988b79SJean-Baptiste Boric  *    disclaimer in the documentation and/or other materials provided
18*9f988b79SJean-Baptiste Boric  *    with the distribution.
19*9f988b79SJean-Baptiste Boric  *
20*9f988b79SJean-Baptiste Boric  * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
21*9f988b79SJean-Baptiste Boric  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
22*9f988b79SJean-Baptiste Boric  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23*9f988b79SJean-Baptiste Boric  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24*9f988b79SJean-Baptiste Boric  * DISCLAIMED.  IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
25*9f988b79SJean-Baptiste Boric  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
26*9f988b79SJean-Baptiste Boric  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27*9f988b79SJean-Baptiste Boric  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28*9f988b79SJean-Baptiste Boric  * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*9f988b79SJean-Baptiste Boric  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30*9f988b79SJean-Baptiste Boric  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*9f988b79SJean-Baptiste Boric  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32*9f988b79SJean-Baptiste Boric  * OF SUCH DAMAGE.
33*9f988b79SJean-Baptiste Boric  */
34*9f988b79SJean-Baptiste Boric 
35*9f988b79SJean-Baptiste Boric #if HAVE_NBTOOL_CONFIG_H
36*9f988b79SJean-Baptiste Boric #include "nbtool_config.h"
37*9f988b79SJean-Baptiste Boric #endif
38*9f988b79SJean-Baptiste Boric 
39*9f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
40*9f988b79SJean-Baptiste Boric #include <sys/param.h>
41*9f988b79SJean-Baptiste Boric 
42*9f988b79SJean-Baptiste Boric #if defined(__RCSID) && !defined(__lint)
43*9f988b79SJean-Baptiste Boric __RCSID("$NetBSD: cd9660_debug.c,v 1.13 2013/10/19 17:16:37 christos Exp $");
44*9f988b79SJean-Baptiste Boric #endif  /* !__lint */
45*9f988b79SJean-Baptiste Boric 
46*9f988b79SJean-Baptiste Boric #if !HAVE_NBTOOL_CONFIG_H
47*9f988b79SJean-Baptiste Boric #include <sys/mount.h>
48*9f988b79SJean-Baptiste Boric #endif
49*9f988b79SJean-Baptiste Boric 
50*9f988b79SJean-Baptiste Boric #include "makefs.h"
51*9f988b79SJean-Baptiste Boric #include "cd9660.h"
52*9f988b79SJean-Baptiste Boric #include "iso9660_rrip.h"
53*9f988b79SJean-Baptiste Boric 
54*9f988b79SJean-Baptiste Boric static void debug_print_susp_attrs(cd9660node *, int);
55*9f988b79SJean-Baptiste Boric static void debug_dump_to_xml_padded_hex_output(const char *, unsigned char *,
56*9f988b79SJean-Baptiste Boric 						int);
57*9f988b79SJean-Baptiste Boric 
58*9f988b79SJean-Baptiste Boric static inline void
print_n_tabs(int n)59*9f988b79SJean-Baptiste Boric print_n_tabs(int n)
60*9f988b79SJean-Baptiste Boric {
61*9f988b79SJean-Baptiste Boric 	int i;
62*9f988b79SJean-Baptiste Boric 
63*9f988b79SJean-Baptiste Boric 	for (i = 1; i <= n; i ++)
64*9f988b79SJean-Baptiste Boric 		printf("\t");
65*9f988b79SJean-Baptiste Boric }
66*9f988b79SJean-Baptiste Boric 
67*9f988b79SJean-Baptiste Boric #if 0
68*9f988b79SJean-Baptiste Boric void
69*9f988b79SJean-Baptiste Boric debug_print_rrip_info(n)
70*9f988b79SJean-Baptiste Boric cd9660node *n;
71*9f988b79SJean-Baptiste Boric {
72*9f988b79SJean-Baptiste Boric 	struct ISO_SUSP_ATTRIBUTES *t;
73*9f988b79SJean-Baptiste Boric 	TAILQ_FOREACH(t, &node->head, rr_ll) {
74*9f988b79SJean-Baptiste Boric 
75*9f988b79SJean-Baptiste Boric 	}
76*9f988b79SJean-Baptiste Boric }
77*9f988b79SJean-Baptiste Boric #endif
78*9f988b79SJean-Baptiste Boric 
79*9f988b79SJean-Baptiste Boric static void
debug_print_susp_attrs(cd9660node * n,int indent)80*9f988b79SJean-Baptiste Boric debug_print_susp_attrs(cd9660node *n, int indent)
81*9f988b79SJean-Baptiste Boric {
82*9f988b79SJean-Baptiste Boric 	struct ISO_SUSP_ATTRIBUTES *t;
83*9f988b79SJean-Baptiste Boric 
84*9f988b79SJean-Baptiste Boric 	TAILQ_FOREACH(t, &n->head, rr_ll) {
85*9f988b79SJean-Baptiste Boric 		print_n_tabs(indent);
86*9f988b79SJean-Baptiste Boric 		printf("-");
87*9f988b79SJean-Baptiste Boric 		printf("%c%c: L:%i",t->attr.su_entry.SP.h.type[0],
88*9f988b79SJean-Baptiste Boric 		    t->attr.su_entry.SP.h.type[1],
89*9f988b79SJean-Baptiste Boric 		    (int)t->attr.su_entry.SP.h.length[0]);
90*9f988b79SJean-Baptiste Boric 		printf("\n");
91*9f988b79SJean-Baptiste Boric 	}
92*9f988b79SJean-Baptiste Boric }
93*9f988b79SJean-Baptiste Boric 
94*9f988b79SJean-Baptiste Boric void
debug_print_tree(iso9660_disk * diskStructure,cd9660node * node,int level)95*9f988b79SJean-Baptiste Boric debug_print_tree(iso9660_disk *diskStructure, cd9660node *node, int level)
96*9f988b79SJean-Baptiste Boric {
97*9f988b79SJean-Baptiste Boric #if !HAVE_NBTOOL_CONFIG_H
98*9f988b79SJean-Baptiste Boric 	cd9660node *cn;
99*9f988b79SJean-Baptiste Boric 
100*9f988b79SJean-Baptiste Boric 	print_n_tabs(level);
101*9f988b79SJean-Baptiste Boric 	if (node->type & CD9660_TYPE_DOT) {
102*9f988b79SJean-Baptiste Boric 		printf(". (%i)\n",
103*9f988b79SJean-Baptiste Boric 		    isonum_733(node->isoDirRecord->extent));
104*9f988b79SJean-Baptiste Boric 	} else if (node->type & CD9660_TYPE_DOTDOT) {
105*9f988b79SJean-Baptiste Boric 		printf("..(%i)\n",
106*9f988b79SJean-Baptiste Boric 		    isonum_733(node->isoDirRecord->extent));
107*9f988b79SJean-Baptiste Boric 	} else if (node->isoDirRecord->name[0]=='\0') {
108*9f988b79SJean-Baptiste Boric 		printf("(ROOT) (%" PRIu32 " to %" PRId64 ")\n",
109*9f988b79SJean-Baptiste Boric 		    node->fileDataSector,
110*9f988b79SJean-Baptiste Boric 		    node->fileDataSector +
111*9f988b79SJean-Baptiste Boric 			node->fileSectorsUsed - 1);
112*9f988b79SJean-Baptiste Boric 	} else {
113*9f988b79SJean-Baptiste Boric 		printf("%s (%s) (%" PRIu32 " to %" PRId64 ")\n",
114*9f988b79SJean-Baptiste Boric 		    node->isoDirRecord->name,
115*9f988b79SJean-Baptiste Boric 		    (node->isoDirRecord->flags[0]
116*9f988b79SJean-Baptiste Boric 			& ISO_FLAG_DIRECTORY) ?  "DIR" : "FILE",
117*9f988b79SJean-Baptiste Boric 		    node->fileDataSector,
118*9f988b79SJean-Baptiste Boric 		    (node->fileSectorsUsed == 0) ?
119*9f988b79SJean-Baptiste Boric 			node->fileDataSector :
120*9f988b79SJean-Baptiste Boric 			node->fileDataSector
121*9f988b79SJean-Baptiste Boric 			    + node->fileSectorsUsed - 1);
122*9f988b79SJean-Baptiste Boric 	}
123*9f988b79SJean-Baptiste Boric 	if (diskStructure->rock_ridge_enabled)
124*9f988b79SJean-Baptiste Boric 		debug_print_susp_attrs(node, level + 1);
125*9f988b79SJean-Baptiste Boric 	TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
126*9f988b79SJean-Baptiste Boric 		debug_print_tree(diskStructure, cn, level + 1);
127*9f988b79SJean-Baptiste Boric #else
128*9f988b79SJean-Baptiste Boric 	printf("Sorry, debugging is not supported in host-tools mode.\n");
129*9f988b79SJean-Baptiste Boric #endif
130*9f988b79SJean-Baptiste Boric }
131*9f988b79SJean-Baptiste Boric 
132*9f988b79SJean-Baptiste Boric void
debug_print_path_tree(cd9660node * n)133*9f988b79SJean-Baptiste Boric debug_print_path_tree(cd9660node *n)
134*9f988b79SJean-Baptiste Boric {
135*9f988b79SJean-Baptiste Boric 	cd9660node *iterator = n;
136*9f988b79SJean-Baptiste Boric 
137*9f988b79SJean-Baptiste Boric 	/* Only display this message when called with the root node */
138*9f988b79SJean-Baptiste Boric 	if (n->parent == NULL)
139*9f988b79SJean-Baptiste Boric 		printf("debug_print_path_table: Dumping path table contents\n");
140*9f988b79SJean-Baptiste Boric 
141*9f988b79SJean-Baptiste Boric 	while (iterator != NULL) {
142*9f988b79SJean-Baptiste Boric 		if (iterator->isoDirRecord->name[0] == '\0')
143*9f988b79SJean-Baptiste Boric 			printf("0) (ROOT)\n");
144*9f988b79SJean-Baptiste Boric 		else
145*9f988b79SJean-Baptiste Boric 			printf("%i) %s\n", iterator->level,
146*9f988b79SJean-Baptiste Boric 			    iterator->isoDirRecord->name);
147*9f988b79SJean-Baptiste Boric 
148*9f988b79SJean-Baptiste Boric 		iterator = iterator->ptnext;
149*9f988b79SJean-Baptiste Boric 	}
150*9f988b79SJean-Baptiste Boric }
151*9f988b79SJean-Baptiste Boric 
152*9f988b79SJean-Baptiste Boric void
debug_print_volume_descriptor_information(iso9660_disk * diskStructure)153*9f988b79SJean-Baptiste Boric debug_print_volume_descriptor_information(iso9660_disk *diskStructure)
154*9f988b79SJean-Baptiste Boric {
155*9f988b79SJean-Baptiste Boric 	volume_descriptor *tmp = diskStructure->firstVolumeDescriptor;
156*9f988b79SJean-Baptiste Boric 	char temp[CD9660_SECTOR_SIZE];
157*9f988b79SJean-Baptiste Boric 
158*9f988b79SJean-Baptiste Boric 	printf("==Listing Volume Descriptors==\n");
159*9f988b79SJean-Baptiste Boric 
160*9f988b79SJean-Baptiste Boric 	while (tmp != NULL) {
161*9f988b79SJean-Baptiste Boric 		memset(temp, 0, CD9660_SECTOR_SIZE);
162*9f988b79SJean-Baptiste Boric 		memcpy(temp, tmp->volumeDescriptorData + 1, 5);
163*9f988b79SJean-Baptiste Boric 		printf("Volume descriptor in sector %" PRId64
164*9f988b79SJean-Baptiste Boric 		    ": type %i, ID %s\n",
165*9f988b79SJean-Baptiste Boric 		    tmp->sector, tmp->volumeDescriptorData[0], temp);
166*9f988b79SJean-Baptiste Boric 		switch(tmp->volumeDescriptorData[0]) {
167*9f988b79SJean-Baptiste Boric 		case 0:/*boot record*/
168*9f988b79SJean-Baptiste Boric 			break;
169*9f988b79SJean-Baptiste Boric 
170*9f988b79SJean-Baptiste Boric 		case 1:		/* PVD */
171*9f988b79SJean-Baptiste Boric 			break;
172*9f988b79SJean-Baptiste Boric 
173*9f988b79SJean-Baptiste Boric 		case 2:		/* SVD */
174*9f988b79SJean-Baptiste Boric 			break;
175*9f988b79SJean-Baptiste Boric 
176*9f988b79SJean-Baptiste Boric 		case 3:		/* Volume Partition Descriptor */
177*9f988b79SJean-Baptiste Boric 			break;
178*9f988b79SJean-Baptiste Boric 
179*9f988b79SJean-Baptiste Boric 		case 255:	/* terminator */
180*9f988b79SJean-Baptiste Boric 			break;
181*9f988b79SJean-Baptiste Boric 		}
182*9f988b79SJean-Baptiste Boric 		tmp = tmp->next;
183*9f988b79SJean-Baptiste Boric 	}
184*9f988b79SJean-Baptiste Boric 
185*9f988b79SJean-Baptiste Boric 	printf("==Done Listing Volume Descriptors==\n");
186*9f988b79SJean-Baptiste Boric }
187*9f988b79SJean-Baptiste Boric 
188*9f988b79SJean-Baptiste Boric void
debug_dump_to_xml_ptentry(path_table_entry * pttemp,int num,int mode)189*9f988b79SJean-Baptiste Boric debug_dump_to_xml_ptentry(path_table_entry *pttemp, int num, int mode)
190*9f988b79SJean-Baptiste Boric {
191*9f988b79SJean-Baptiste Boric 	printf("<ptentry num=\"%i\">\n" ,num);
192*9f988b79SJean-Baptiste Boric 	printf("<length>%i</length>\n", pttemp->length[0]);
193*9f988b79SJean-Baptiste Boric 	printf("<extended_attribute_length>%i</extended_attribute_length>\n",
194*9f988b79SJean-Baptiste Boric 	    pttemp->extended_attribute_length[0]);
195*9f988b79SJean-Baptiste Boric 	printf("<parent_number>%i</parent_number>\n",
196*9f988b79SJean-Baptiste Boric 	    debug_get_encoded_number(pttemp->parent_number,mode));
197*9f988b79SJean-Baptiste Boric 	debug_dump_to_xml_padded_hex_output("name",
198*9f988b79SJean-Baptiste Boric 	    pttemp->name, pttemp->length[0]);
199*9f988b79SJean-Baptiste Boric 	printf("</ptentry>\n");
200*9f988b79SJean-Baptiste Boric }
201*9f988b79SJean-Baptiste Boric 
202*9f988b79SJean-Baptiste Boric void
debug_dump_to_xml_path_table(FILE * fd,off_t sector,int size,int mode)203*9f988b79SJean-Baptiste Boric debug_dump_to_xml_path_table(FILE *fd, off_t sector, int size, int mode)
204*9f988b79SJean-Baptiste Boric {
205*9f988b79SJean-Baptiste Boric 	path_table_entry pttemp;
206*9f988b79SJean-Baptiste Boric 	int t = 0;
207*9f988b79SJean-Baptiste Boric 	int n = 0;
208*9f988b79SJean-Baptiste Boric 
209*9f988b79SJean-Baptiste Boric 	if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
210*9f988b79SJean-Baptiste Boric 		err(1, "fseeko");
211*9f988b79SJean-Baptiste Boric 
212*9f988b79SJean-Baptiste Boric 	while (t < size) {
213*9f988b79SJean-Baptiste Boric 		/* Read fixed data first */
214*9f988b79SJean-Baptiste Boric 		fread(&pttemp, 1, 8, fd);
215*9f988b79SJean-Baptiste Boric 		t += 8;
216*9f988b79SJean-Baptiste Boric 		/* Read variable */
217*9f988b79SJean-Baptiste Boric 		fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0], fd);
218*9f988b79SJean-Baptiste Boric 		t += pttemp.length[0];
219*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_ptentry(&pttemp, n, mode);
220*9f988b79SJean-Baptiste Boric 		n++;
221*9f988b79SJean-Baptiste Boric 	}
222*9f988b79SJean-Baptiste Boric 
223*9f988b79SJean-Baptiste Boric }
224*9f988b79SJean-Baptiste Boric 
225*9f988b79SJean-Baptiste Boric /*
226*9f988b79SJean-Baptiste Boric  * XML Debug output functions
227*9f988b79SJean-Baptiste Boric  * Dump hierarchy of CD, as well as volume info, to XML
228*9f988b79SJean-Baptiste Boric  * Can be used later to diff against a standard,
229*9f988b79SJean-Baptiste Boric  * or just provide easy to read detailed debug output
230*9f988b79SJean-Baptiste Boric  */
231*9f988b79SJean-Baptiste Boric void
debug_dump_to_xml(FILE * fd)232*9f988b79SJean-Baptiste Boric debug_dump_to_xml(FILE *fd)
233*9f988b79SJean-Baptiste Boric {
234*9f988b79SJean-Baptiste Boric 	unsigned char buf[CD9660_SECTOR_SIZE];
235*9f988b79SJean-Baptiste Boric 	off_t sector;
236*9f988b79SJean-Baptiste Boric 	int t, t2;
237*9f988b79SJean-Baptiste Boric 	struct iso_primary_descriptor primaryVD;
238*9f988b79SJean-Baptiste Boric 	struct _boot_volume_descriptor bootVD;
239*9f988b79SJean-Baptiste Boric 
240*9f988b79SJean-Baptiste Boric 	memset(&primaryVD, 0, sizeof(primaryVD));
241*9f988b79SJean-Baptiste Boric 	printf("<cd9660dump>\n");
242*9f988b79SJean-Baptiste Boric 
243*9f988b79SJean-Baptiste Boric 	/* Display Volume Descriptors */
244*9f988b79SJean-Baptiste Boric 	sector = 16;
245*9f988b79SJean-Baptiste Boric 	do {
246*9f988b79SJean-Baptiste Boric 		if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
247*9f988b79SJean-Baptiste Boric 			err(1, "fseeko");
248*9f988b79SJean-Baptiste Boric 		fread(buf, 1, CD9660_SECTOR_SIZE, fd);
249*9f988b79SJean-Baptiste Boric 		t = (int)((unsigned char)buf[0]);
250*9f988b79SJean-Baptiste Boric 		switch (t) {
251*9f988b79SJean-Baptiste Boric 		case 0:
252*9f988b79SJean-Baptiste Boric 			memcpy(&bootVD, buf, CD9660_SECTOR_SIZE);
253*9f988b79SJean-Baptiste Boric 			break;
254*9f988b79SJean-Baptiste Boric 		case 1:
255*9f988b79SJean-Baptiste Boric 			memcpy(&primaryVD, buf, CD9660_SECTOR_SIZE);
256*9f988b79SJean-Baptiste Boric 			break;
257*9f988b79SJean-Baptiste Boric 		}
258*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_volume_descriptor(buf, sector);
259*9f988b79SJean-Baptiste Boric 		sector++;
260*9f988b79SJean-Baptiste Boric 	} while (t != 255);
261*9f988b79SJean-Baptiste Boric 
262*9f988b79SJean-Baptiste Boric 	t = debug_get_encoded_number((u_char *)primaryVD.type_l_path_table,
263*9f988b79SJean-Baptiste Boric 	    731);
264*9f988b79SJean-Baptiste Boric 	t2 = debug_get_encoded_number((u_char *)primaryVD.path_table_size, 733);
265*9f988b79SJean-Baptiste Boric 	printf("Path table 1 located at sector %i and is %i bytes long\n",
266*9f988b79SJean-Baptiste Boric 	    t,t2);
267*9f988b79SJean-Baptiste Boric 	debug_dump_to_xml_path_table(fd, t, t2, 721);
268*9f988b79SJean-Baptiste Boric 
269*9f988b79SJean-Baptiste Boric 	t = debug_get_encoded_number((u_char *)primaryVD.type_m_path_table,
270*9f988b79SJean-Baptiste Boric 	    731);
271*9f988b79SJean-Baptiste Boric 	debug_dump_to_xml_path_table(fd, t, t2, 722);
272*9f988b79SJean-Baptiste Boric 
273*9f988b79SJean-Baptiste Boric 	printf("</cd9660dump>\n");
274*9f988b79SJean-Baptiste Boric }
275*9f988b79SJean-Baptiste Boric 
276*9f988b79SJean-Baptiste Boric static void
debug_dump_to_xml_padded_hex_output(const char * element,unsigned char * buf,int len)277*9f988b79SJean-Baptiste Boric debug_dump_to_xml_padded_hex_output(const char *element, unsigned char *buf,
278*9f988b79SJean-Baptiste Boric 				    int len)
279*9f988b79SJean-Baptiste Boric {
280*9f988b79SJean-Baptiste Boric 	int i;
281*9f988b79SJean-Baptiste Boric 	int t;
282*9f988b79SJean-Baptiste Boric 
283*9f988b79SJean-Baptiste Boric 	printf("<%s>",element);
284*9f988b79SJean-Baptiste Boric 	for (i = 0; i < len; i++) {
285*9f988b79SJean-Baptiste Boric 		t = (unsigned char)buf[i];
286*9f988b79SJean-Baptiste Boric 		if (t >= 32 && t < 127)
287*9f988b79SJean-Baptiste Boric 			printf("%c",t);
288*9f988b79SJean-Baptiste Boric 	}
289*9f988b79SJean-Baptiste Boric 	printf("</%s>\n",element);
290*9f988b79SJean-Baptiste Boric 
291*9f988b79SJean-Baptiste Boric 	printf("<%s:hex>",element);
292*9f988b79SJean-Baptiste Boric 	for (i = 0; i < len; i++) {
293*9f988b79SJean-Baptiste Boric 		t = (unsigned char)buf[i];
294*9f988b79SJean-Baptiste Boric 		printf(" %x",t);
295*9f988b79SJean-Baptiste Boric 	}
296*9f988b79SJean-Baptiste Boric 	printf("</%s:hex>\n",element);
297*9f988b79SJean-Baptiste Boric }
298*9f988b79SJean-Baptiste Boric 
299*9f988b79SJean-Baptiste Boric int
debug_get_encoded_number(unsigned char * buf,int mode)300*9f988b79SJean-Baptiste Boric debug_get_encoded_number(unsigned char* buf, int mode)
301*9f988b79SJean-Baptiste Boric {
302*9f988b79SJean-Baptiste Boric #if !HAVE_NBTOOL_CONFIG_H
303*9f988b79SJean-Baptiste Boric 	switch (mode) {
304*9f988b79SJean-Baptiste Boric 	/* 711: Single bite */
305*9f988b79SJean-Baptiste Boric 	case 711:
306*9f988b79SJean-Baptiste Boric 		return isonum_711(buf);
307*9f988b79SJean-Baptiste Boric 
308*9f988b79SJean-Baptiste Boric 	/* 712: Single signed byte */
309*9f988b79SJean-Baptiste Boric 	case 712:
310*9f988b79SJean-Baptiste Boric 		return isonum_712((signed char *)buf);
311*9f988b79SJean-Baptiste Boric 
312*9f988b79SJean-Baptiste Boric 	/* 721: 16 bit LE */
313*9f988b79SJean-Baptiste Boric 	case 721:
314*9f988b79SJean-Baptiste Boric 		return isonum_721(buf);
315*9f988b79SJean-Baptiste Boric 
316*9f988b79SJean-Baptiste Boric 	/* 731: 32 bit LE */
317*9f988b79SJean-Baptiste Boric 	case 731:
318*9f988b79SJean-Baptiste Boric 		return isonum_731(buf);
319*9f988b79SJean-Baptiste Boric 
320*9f988b79SJean-Baptiste Boric 	/* 722: 16 bit BE */
321*9f988b79SJean-Baptiste Boric 	case 722:
322*9f988b79SJean-Baptiste Boric 		return isonum_722(buf);
323*9f988b79SJean-Baptiste Boric 
324*9f988b79SJean-Baptiste Boric 	/* 732: 32 bit BE */
325*9f988b79SJean-Baptiste Boric 	case 732:
326*9f988b79SJean-Baptiste Boric 		return isonum_732(buf);
327*9f988b79SJean-Baptiste Boric 
328*9f988b79SJean-Baptiste Boric 	/* 723: 16 bit bothE */
329*9f988b79SJean-Baptiste Boric 	case 723:
330*9f988b79SJean-Baptiste Boric 		return isonum_723(buf);
331*9f988b79SJean-Baptiste Boric 
332*9f988b79SJean-Baptiste Boric 	/* 733: 32 bit bothE */
333*9f988b79SJean-Baptiste Boric 	case 733:
334*9f988b79SJean-Baptiste Boric 		return isonum_733(buf);
335*9f988b79SJean-Baptiste Boric 	}
336*9f988b79SJean-Baptiste Boric #endif
337*9f988b79SJean-Baptiste Boric 	return 0;
338*9f988b79SJean-Baptiste Boric }
339*9f988b79SJean-Baptiste Boric 
340*9f988b79SJean-Baptiste Boric void
debug_dump_integer(const char * element,char * buf,int mode)341*9f988b79SJean-Baptiste Boric debug_dump_integer(const char *element, char* buf, int mode)
342*9f988b79SJean-Baptiste Boric {
343*9f988b79SJean-Baptiste Boric 	printf("<%s>%i</%s>\n", element,
344*9f988b79SJean-Baptiste Boric 	    debug_get_encoded_number((unsigned char *)buf, mode), element);
345*9f988b79SJean-Baptiste Boric }
346*9f988b79SJean-Baptiste Boric 
347*9f988b79SJean-Baptiste Boric void
debug_dump_string(const char * element __unused,unsigned char * buf __unused,int len __unused)348*9f988b79SJean-Baptiste Boric debug_dump_string(const char *element __unused, unsigned char *buf __unused, int len __unused)
349*9f988b79SJean-Baptiste Boric {
350*9f988b79SJean-Baptiste Boric 
351*9f988b79SJean-Baptiste Boric }
352*9f988b79SJean-Baptiste Boric 
353*9f988b79SJean-Baptiste Boric void
debug_dump_directory_record_9_1(unsigned char * buf)354*9f988b79SJean-Baptiste Boric debug_dump_directory_record_9_1(unsigned char* buf)
355*9f988b79SJean-Baptiste Boric {
356*9f988b79SJean-Baptiste Boric 	printf("<directoryrecord>\n");
357*9f988b79SJean-Baptiste Boric 	debug_dump_integer("length",
358*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->length, 711);
359*9f988b79SJean-Baptiste Boric 	debug_dump_integer("ext_attr_length",
360*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->ext_attr_length,711);
361*9f988b79SJean-Baptiste Boric 	debug_dump_integer("extent",
362*9f988b79SJean-Baptiste Boric 	    (char *)((struct iso_directory_record*) buf)->extent, 733);
363*9f988b79SJean-Baptiste Boric 	debug_dump_integer("size",
364*9f988b79SJean-Baptiste Boric 	    (char *)((struct iso_directory_record*) buf)->size, 733);
365*9f988b79SJean-Baptiste Boric 	debug_dump_integer("flags",
366*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->flags, 711);
367*9f988b79SJean-Baptiste Boric 	debug_dump_integer("file_unit_size",
368*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->file_unit_size,711);
369*9f988b79SJean-Baptiste Boric 	debug_dump_integer("interleave",
370*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->interleave, 711);
371*9f988b79SJean-Baptiste Boric 	debug_dump_integer("volume_sequence_number",
372*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->volume_sequence_number,
373*9f988b79SJean-Baptiste Boric 	    723);
374*9f988b79SJean-Baptiste Boric 	debug_dump_integer("name_len",
375*9f988b79SJean-Baptiste Boric 	    ((struct iso_directory_record*) buf)->name_len, 711);
376*9f988b79SJean-Baptiste Boric 	debug_dump_to_xml_padded_hex_output("name",
377*9f988b79SJean-Baptiste Boric 	    (u_char *)((struct iso_directory_record*) buf)->name,
378*9f988b79SJean-Baptiste Boric 		debug_get_encoded_number((u_char *)
379*9f988b79SJean-Baptiste Boric 		    ((struct iso_directory_record*) buf)->length, 711));
380*9f988b79SJean-Baptiste Boric 	printf("</directoryrecord>\n");
381*9f988b79SJean-Baptiste Boric }
382*9f988b79SJean-Baptiste Boric 
383*9f988b79SJean-Baptiste Boric 
384*9f988b79SJean-Baptiste Boric void
debug_dump_to_xml_volume_descriptor(unsigned char * buf,int sector)385*9f988b79SJean-Baptiste Boric debug_dump_to_xml_volume_descriptor(unsigned char* buf, int sector)
386*9f988b79SJean-Baptiste Boric {
387*9f988b79SJean-Baptiste Boric 	printf("<volumedescriptor sector=\"%i\">\n", sector);
388*9f988b79SJean-Baptiste Boric 	printf("<vdtype>");
389*9f988b79SJean-Baptiste Boric 	switch(buf[0]) {
390*9f988b79SJean-Baptiste Boric 	case 0:
391*9f988b79SJean-Baptiste Boric 		printf("boot");
392*9f988b79SJean-Baptiste Boric 		break;
393*9f988b79SJean-Baptiste Boric 
394*9f988b79SJean-Baptiste Boric 	case 1:
395*9f988b79SJean-Baptiste Boric 		printf("primary");
396*9f988b79SJean-Baptiste Boric 		break;
397*9f988b79SJean-Baptiste Boric 
398*9f988b79SJean-Baptiste Boric 	case 2:
399*9f988b79SJean-Baptiste Boric 		printf("supplementary");
400*9f988b79SJean-Baptiste Boric 		break;
401*9f988b79SJean-Baptiste Boric 
402*9f988b79SJean-Baptiste Boric 	case 3:
403*9f988b79SJean-Baptiste Boric 		printf("volume partition descriptor");
404*9f988b79SJean-Baptiste Boric 		break;
405*9f988b79SJean-Baptiste Boric 
406*9f988b79SJean-Baptiste Boric 	case 255:
407*9f988b79SJean-Baptiste Boric 		printf("terminator");
408*9f988b79SJean-Baptiste Boric 		break;
409*9f988b79SJean-Baptiste Boric 	}
410*9f988b79SJean-Baptiste Boric 
411*9f988b79SJean-Baptiste Boric 	printf("</vdtype>\n");
412*9f988b79SJean-Baptiste Boric 	switch(buf[0]) {
413*9f988b79SJean-Baptiste Boric 	case 1:
414*9f988b79SJean-Baptiste Boric 		debug_dump_integer("type",
415*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->type, 711);
416*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("id",
417*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->id,
418*9f988b79SJean-Baptiste Boric 		    ISODCL (  2,   6));
419*9f988b79SJean-Baptiste Boric 		debug_dump_integer("version",
420*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->version,
421*9f988b79SJean-Baptiste Boric 		     711);
422*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("system_id",
423*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*)buf)->system_id,
424*9f988b79SJean-Baptiste Boric 		    ISODCL(9,40));
425*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("volume_id",
426*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*)buf)->volume_id,
427*9f988b79SJean-Baptiste Boric 		    ISODCL(41,72));
428*9f988b79SJean-Baptiste Boric 		debug_dump_integer("volume_space_size",
429*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->volume_space_size,
430*9f988b79SJean-Baptiste Boric 		    733);
431*9f988b79SJean-Baptiste Boric 		debug_dump_integer("volume_set_size",
432*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->volume_set_size,
433*9f988b79SJean-Baptiste Boric 			    733);
434*9f988b79SJean-Baptiste Boric 		debug_dump_integer("volume_sequence_number",
435*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->volume_sequence_number,
436*9f988b79SJean-Baptiste Boric 		    723);
437*9f988b79SJean-Baptiste Boric 		debug_dump_integer("logical_block_size",
438*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->logical_block_size,
439*9f988b79SJean-Baptiste Boric 			    723);
440*9f988b79SJean-Baptiste Boric 		debug_dump_integer("path_table_size",
441*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->path_table_size,
442*9f988b79SJean-Baptiste Boric 			    733);
443*9f988b79SJean-Baptiste Boric 		debug_dump_integer("type_l_path_table",
444*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->type_l_path_table,
445*9f988b79SJean-Baptiste Boric 		    731);
446*9f988b79SJean-Baptiste Boric 		debug_dump_integer("opt_type_l_path_table",
447*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->opt_type_l_path_table,
448*9f988b79SJean-Baptiste Boric 		    731);
449*9f988b79SJean-Baptiste Boric 		debug_dump_integer("type_m_path_table",
450*9f988b79SJean-Baptiste Boric 		    ((struct iso_primary_descriptor*)buf)->type_m_path_table,
451*9f988b79SJean-Baptiste Boric 		    732);
452*9f988b79SJean-Baptiste Boric 		debug_dump_integer("opt_type_m_path_table",
453*9f988b79SJean-Baptiste Boric 			((struct iso_primary_descriptor*)buf)->opt_type_m_path_table,732);
454*9f988b79SJean-Baptiste Boric 		debug_dump_directory_record_9_1(
455*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*)buf)->root_directory_record);
456*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("volume_set_id",
457*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->volume_set_id,
458*9f988b79SJean-Baptiste Boric 		    ISODCL (191, 318));
459*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("publisher_id",
460*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->publisher_id,
461*9f988b79SJean-Baptiste Boric 		    ISODCL (319, 446));
462*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("preparer_id",
463*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->preparer_id,
464*9f988b79SJean-Baptiste Boric 		    ISODCL (447, 574));
465*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("application_id",
466*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->application_id,
467*9f988b79SJean-Baptiste Boric 		    ISODCL (575, 702));
468*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("copyright_file_id",
469*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->copyright_file_id,
470*9f988b79SJean-Baptiste Boric 		    ISODCL (703, 739));
471*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("abstract_file_id",
472*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->abstract_file_id,
473*9f988b79SJean-Baptiste Boric 		    ISODCL (740, 776));
474*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("bibliographic_file_id",
475*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->bibliographic_file_id,
476*9f988b79SJean-Baptiste Boric 		    ISODCL (777, 813));
477*9f988b79SJean-Baptiste Boric 
478*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("creation_date",
479*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->creation_date,
480*9f988b79SJean-Baptiste Boric 		    ISODCL (814, 830));
481*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("modification_date",
482*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->modification_date,
483*9f988b79SJean-Baptiste Boric 		    ISODCL (831, 847));
484*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("expiration_date",
485*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->expiration_date,
486*9f988b79SJean-Baptiste Boric 		    ISODCL (848, 864));
487*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("effective_date",
488*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->effective_date,
489*9f988b79SJean-Baptiste Boric 		    ISODCL (865, 881));
490*9f988b79SJean-Baptiste Boric 
491*9f988b79SJean-Baptiste Boric 		debug_dump_to_xml_padded_hex_output("file_structure_version",
492*9f988b79SJean-Baptiste Boric 		    (u_char *)((struct iso_primary_descriptor*) buf)->file_structure_version,
493*9f988b79SJean-Baptiste Boric 		    ISODCL(882,882));
494*9f988b79SJean-Baptiste Boric 		break;
495*9f988b79SJean-Baptiste Boric 	}
496*9f988b79SJean-Baptiste Boric 	printf("</volumedescriptor>\n");
497*9f988b79SJean-Baptiste Boric }
498*9f988b79SJean-Baptiste Boric 
499