2 * dump a 9660 cd image for a little while.
12 #pragma varargck type "s" uchar*
13 #pragma varargck type "L" uchar*
14 #pragma varargck type "B" uchar*
15 #pragma varargck type "N" uchar*
16 #pragma varargck type "T" uchar*
17 #pragma varargck type "D" uchar*
19 typedef struct Voldesc Voldesc;
21 uchar magic[8]; /* 0x01, "CD001", 0x01, 0x00 */
22 uchar systemid[32]; /* system identifier */
23 uchar volumeid[32]; /* volume identifier */
24 uchar unused[8]; /* character set in secondary desc */
25 uchar volsize[8]; /* volume size */
27 uchar volsetsize[4]; /* volume set size = 1 */
28 uchar volseqnum[4]; /* volume sequence number = 1 */
29 uchar blocksize[4]; /* logical block size */
30 uchar pathsize[8]; /* path table size */
31 uchar lpathloc[4]; /* Lpath */
32 uchar olpathloc[4]; /* optional Lpath */
33 uchar mpathloc[4]; /* Mpath */
34 uchar ompathloc[4]; /* optional Mpath */
35 uchar rootdir[34]; /* root directory */
36 uchar volsetid[128]; /* volume set identifier */
38 uchar prepid[128]; /* data preparer identifier */
39 uchar applid[128]; /* application identifier */
40 uchar notice[37]; /* copyright notice file */
41 uchar abstract[37]; /* abstract file */
42 uchar biblio[37]; /* bibliographic file */
43 uchar cdate[17]; /* creation date */
44 uchar mdate[17]; /* modification date */
45 uchar xdate[17]; /* expiration date */
46 uchar edate[17]; /* effective date */
47 uchar fsvers; /* file system version = 1 */
56 print("magic %.2ux %.5s %.2ux %2ux\n",
57 v->magic[0], v->magic+1, v->magic[6], v->magic[7]);
58 if(v->magic[0] == 0xFF)
61 print("system %.32T\n", v->systemid);
62 print("volume %.32T\n", v->volumeid);
63 print("volume size %.4N\n", v->volsize);
64 print("charset %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n",
65 v->charset[0], v->charset[1], v->charset[2], v->charset[3],
66 v->charset[4], v->charset[5], v->charset[6], v->charset[7]);
67 print("volume set size %.2N\n", v->volsetsize);
68 print("volume sequence number %.2N\n", v->volseqnum);
69 print("logical block size %.2N\n", v->blocksize);
70 print("path size %.4L\n", v->pathsize);
71 print("lpath loc %.4L\n", v->lpathloc);
72 print("opt lpath loc %.4L\n", v->olpathloc);
73 print("mpath loc %.4B\n", v->mpathloc);
74 print("opt mpath loc %.4B\n", v->ompathloc);
75 print("rootdir %D\n", v->rootdir);
76 print("volume set identifier %.128T\n", v->volsetid);
77 print("publisher %.128T\n", v->publisher);
78 print("preparer %.128T\n", v->prepid);
79 print("application %.128T\n", v->applid);
80 print("notice %.37T\n", v->notice);
81 print("abstract %.37T\n", v->abstract);
82 print("biblio %.37T\n", v->biblio);
83 print("creation date %.17s\n", v->cdate);
84 print("modification date %.17s\n", v->mdate);
85 print("expiration date %.17s\n", v->xdate);
86 print("effective date %.17s\n", v->edate);
87 print("fs version %d\n", v->fsvers);
90 typedef struct Cdir Cdir;
102 uchar name[1]; /* chumminess */
104 #pragma varargck type "D" Cdir*
112 c = va_arg(fmt->args, Cdir*);
113 if(c->namelen == 1 && c->name[0] == '\0' || c->name[0] == '\001') {
114 snprint(buf, sizeof buf, ".%s dloc %.4N dlen %.4N",
115 c->name[0] ? "." : "", c->dloc, c->dlen);
117 snprint(buf, sizeof buf, "%.*T dloc %.4N dlen %.4N", c->namelen, c->name,
124 typedef struct Path Path;
130 uchar name[1]; /* chumminess */
132 #pragma varargck type "P" Path*
150 char xfmt[128], buf[128];
153 p = va_arg(fmt->args, Path*);
154 sprint(xfmt, "data=%%.4%c up=%%.2%c name=%%.*T (%%d)", longc, longc);
155 snprint(buf, sizeof buf, xfmt, p->dloc, p->parent, p->namelen, p->name, p->namelen);
175 little(void *a, int n)
188 /* numbers in big or little endian. */
196 p = va_arg(fmt->args, uchar*);
198 if(!(fmt->flags&FmtPrec)) {
199 fmtstrcpy(fmt, "*BL*");
204 v = big(p, fmt->prec);
206 v = little(p, fmt->prec);
208 sprint(buf, "0x%.*lux", fmt->prec*2, v);
209 fmt->flags &= ~FmtPrec;
214 /* numbers in both little and big endian */
221 p = va_arg(fmt->args, uchar*);
223 sprint(buf, "%.*L %.*B", fmt->prec, p, fmt->prec, p+fmt->prec);
224 fmt->flags &= ~FmtPrec;
235 p = va_arg(fmt->args, char*);
236 for(i=0; i<fmt->prec; i++)
239 for(p=buf+strlen(buf); p>buf && p[-1]==' '; p--)
242 fmt->flags &= ~FmtPrec;
254 p = va_arg(fmt->args, uchar*);
255 for(i=0; i*2+2<=fmt->prec; i++, p+=2)
256 buf[i] = (p[0]<<8)|p[1];
258 for(r=buf+i; r>buf && r[-1]==L' '; r--)
261 fmt->flags &= ~FmtPrec;
262 return fmtprint(fmt, "%S", buf);
268 fmtinstall('T', asciiTfmt);
274 fmtinstall('T', runeTfmt);
278 getsect(uchar *buf, int n)
280 if(Bseek(b, n*2048, 0) != n*2048 || Bread(b, buf, 2048) != 2048)
281 sysfatal("reading block %ux", n);
285 pathtable(Voldesc *v, int islittle)
287 int i, j, n, sz, addr;
288 ulong (*word)(void*, int);
289 uchar x[2048], *p, *ep;
292 print(">>> entire %s path table\n", islittle ? "little" : "big");
301 sz = little(v->pathsize, 4); /* little, not word */
302 addr = word(islittle ? v->lpathloc : v->mpathloc, 4);
311 for(i=0; p<ep; i++) {
315 print("0x%.4x %4d+%-4ld %P\n", n, j, p-x, pt);
317 p += 8+pt->namelen+(pt->namelen&1);
337 c = (Cdir*)v->rootdir;
338 rootdirloc = little(c->dloc, 4);
339 print(">>> sed 5q root directory\n");
340 getsect(x, rootdirloc);
342 for(i=0; i<5 && (p-x)<little(c->dlen, 4); i++) {
344 p += ((Cdir*)p)->len;
352 main(int argc, char **argv)
354 uchar root[2048], jroot[2048];
357 sysfatal("usage: %s file", argv[0]);
359 b = Bopen(argv[1], OREAD);
361 sysfatal("bopen %r");
363 fmtinstall('L', BLfmt);
364 fmtinstall('B', BLfmt);
365 fmtinstall('N', Nfmt);
366 fmtinstall('D', Dfmt);
367 fmtinstall('P', Pfmt);