9 * Add the requisite path tables to the CD image.
10 * They get put on the end once everything else is done.
11 * We use the path table itself as a queue in the breadth-first
12 * traversal of the tree.
14 * The only problem with this is that the path table does not
15 * store the lengths of the directories. So we keep an explicit
16 * map in an array in memory.
25 Crdpath(Cdimg *cd, Cpath *p)
27 p->namelen = Cgetc(cd);
29 Crseek(cd, (Croffset(cd)+Blocksize-1)/Blocksize * Blocksize);
30 p->namelen = Cgetc(cd);
31 assert(p->namelen != 0);
35 assert(p->xlen == 0); /* sanity, might not be true if we start using the extended fields */
37 Cread(cd, p->dloc, 4);
38 Cread(cd, p->parent, 2);
40 Crseek(cd, Croffset(cd)+p->namelen+p->xlen+(p->namelen&1)); /* skip name, ext data */
44 writepath(Cdimg *cd, Cdir *c, int parent, int size)
47 DO NOT UNCOMMENT THIS CODE.
48 This commented-out code is here only so that no one comes
49 along and adds it later.
51 The ISO 9660 spec is silent about whether path table entries
52 need to be padded so that they never cross block boundaries.
53 It would be reasonable to assume that they are like every other
54 data structure in the bloody spec; this code pads them out.
56 Empirically, though, they're NOT padded. Windows NT and
57 derivatives are the only known current operating systems
58 that actually read these things.
62 l = 1+1+4+2+c->namelen;
63 if(Cwoffset(cd)/Blocksize != (Cwoffset(cd)+l)/Blocksize)
66 Cputc(cd, c->namelen);
68 Cwrite(cd, c->dloc + (size==Little ? 0 : 4), 4);
69 (size==Little ? Cputnl : Cputnm)(cd, parent, 2);
70 Cwrite(cd, c->name, c->namelen);
76 addlength(ulong *a, ulong x, int n)
79 a = erealloc(a, (n+128)*sizeof a[0]);
85 writepathtable(Cdimg *cd, ulong vdblock, int size)
89 ulong bk, end, i, *len, n, rdoff, start;
93 Creadblock(cd, buf, vdblock, Blocksize);
94 c = (Cdir*)(buf+offsetof(Cvoldesc, rootdir[0]));
99 start = cd->nextblock*Blocksize;
102 writepath(cd, c, 1, size);
103 len = addlength(len, little(c->dlen, 4), wp);
108 n = (len[rp]+Blocksize-1)/Blocksize;
110 bk = (size==Big ? big : little)(p.dloc, 4);
111 rdoff = Croffset(cd);
113 Creadblock(cd, buf, bk+i, Blocksize);
115 if(i != 0 && c->namelen == 1 && c->name[0] == '\0') /* hit another directory; stop */
117 while(c->len && c->namelen && (uchar*)c+c->len < buf+Blocksize) {
118 if((c->flags & 0x02) && (c->namelen > 1 || c->name[0] > '\001')) { /* directory */
119 writepath(cd, c, rp, size);
120 len = addlength(len, little(c->dlen, 4), wp);
123 c = (Cdir*)((uchar*)c+c->len);
135 writepathtablepair(Cdimg *cd, ulong vdblock)
137 ulong bloc, lloc, sz, sz2;
139 lloc = cd->nextblock;
140 sz = writepathtable(cd, vdblock, Little);
141 bloc = cd->nextblock;
142 sz2 = writepathtable(cd, vdblock, Big);
144 setpathtable(cd, vdblock, sz, lloc, bloc);
148 writepathtables(Cdimg *cd)
150 cd->pathblock = cd->nextblock;
152 writepathtablepair(cd, cd->iso9660pvd);
153 if(cd->flags & CDjoliet)
154 writepathtablepair(cd, cd->jolietsvd);