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)
90 uvlong start, end, rdoff;
94 Creadblock(cd, buf, vdblock, Blocksize);
95 c = (Cdir*)(buf + offsetof(Cvoldesc, rootdir[0]));
100 start = (vlong)cd->nextblock * Blocksize;
103 writepath(cd, c, 1, size);
104 len = addlength(len, little(c->dlen, 4), wp);
109 n = (len[rp]+Blocksize-1)/Blocksize;
111 bk = (size==Big ? big : little)(p.dloc, 4);
112 rdoff = Croffset(cd);
114 Creadblock(cd, buf, bk+i, Blocksize);
116 if(i != 0 && c->namelen == 1 && c->name[0] == '\0')
117 break; /* hit another directory; stop */
118 while(c->len && c->namelen &&
119 (uchar*)c + c->len < buf + Blocksize) {
120 if(c->flags & 0x02 &&
121 (c->namelen > 1 || c->name[0] > '\001')) {
123 writepath(cd, c, rp, size);
124 len = addlength(len, little(c->dlen, 4), wp);
127 c = (Cdir*)((uchar*)c+c->len);
139 writepathtablepair(Cdimg *cd, ulong vdblock)
141 ulong bloc, lloc, sz, sz2;
143 lloc = cd->nextblock;
144 sz = writepathtable(cd, vdblock, Little);
145 bloc = cd->nextblock;
146 sz2 = writepathtable(cd, vdblock, Big);
148 setpathtable(cd, vdblock, sz, lloc, bloc);
152 writepathtables(Cdimg *cd)
154 cd->pathblock = cd->nextblock;
156 writepathtablepair(cd, cd->iso9660pvd);
157 if(cd->flags & CDjoliet)
158 writepathtablepair(cd, cd->jolietsvd);