4 * Routines and data structures to support reading and writing
5 * ISO 9660 CD images. See the ISO 9660 or ECMA 119 standards.
7 * Also supports Rock Ridge extensions for long file names and Unix stuff.
8 * Also supports Microsoft's Joliet extensions for Unicode and long file names.
9 * Also supports El Torito bootable CD spec.
12 typedef struct Cdimg Cdimg;
13 typedef struct Cdinfo Cdinfo;
14 typedef struct Conform Conform;
15 typedef struct Direc Direc;
16 typedef struct Dumproot Dumproot;
17 typedef struct Voldesc Voldesc;
18 typedef struct XDir XDir;
29 ulong uidno; /* Numeric uid */
30 ulong gidno; /* Numeric gid */
41 * A directory entry in a ISO9660 tree.
42 * The extra data (uid, etc.) here is put into the system use areas.
45 char *name; /* real name */
46 char *confname; /* conformant name */
47 char *srcfile; /* file to copy onto the image */
67 enum { /* Direc flags */
68 Dbadname = 1<<0 /* Non-conformant name */
72 * Data found in a volume descriptor.
81 /* file names for various parameters */
91 /* root of file tree */
96 * An ISO9660 CD image. Various parameters are kept in memory but the
97 * real image file is opened for reading and writing on fd.
99 * The bio buffers brd and bwr moderate reading and writing to the image.
100 * The routines we use are careful to flush one before or after using the other,
111 ulong rrcontin; /* rock ridge continuation offset */
112 ulong nulldump; /* next dump block */
113 ulong nconform; /* number of conform entries written already */
128 enum { /* Cdimg->flags, Cdinfo->flags */
138 typedef struct Tx Tx;
140 char *bad; /* atoms */
146 int nt; /* delta = 32 */
166 * This is a doubly binary tree.
167 * We have a tree keyed on the MD5 values
168 * as well as a tree keyed on the block numbers.
170 typedef struct Dump Dump;
171 typedef struct Dumpdir Dumpdir;
199 * ISO9660 on-CD structures.
201 typedef struct Cdir Cdir;
202 typedef struct Cpath Cpath;
203 typedef struct Cvoldesc Cvoldesc;
205 /* a volume descriptor block */
207 uchar magic[8]; /* 0x01, "CD001", 0x01, 0x00 */
208 uchar systemid[32]; /* system identifier */
209 uchar volumeid[32]; /* volume identifier */
210 uchar unused[8]; /* character set in secondary desc */
211 uchar volsize[8]; /* volume size */
213 uchar volsetsize[4]; /* volume set size = 1 */
214 uchar volseqnum[4]; /* volume sequence number = 1 */
215 uchar blocksize[4]; /* logical block size */
216 uchar pathsize[8]; /* path table size */
217 uchar lpathloc[4]; /* Lpath */
218 uchar olpathloc[4]; /* optional Lpath */
219 uchar mpathloc[4]; /* Mpath */
220 uchar ompathloc[4]; /* optional Mpath */
221 uchar rootdir[34]; /* directory entry for root */
222 uchar volumeset[128]; /* volume set identifier */
223 uchar publisher[128];
224 uchar preparer[128]; /* data preparer identifier */
225 uchar application[128]; /* application identifier */
226 uchar notice[37]; /* copyright notice file */
227 uchar abstract[37]; /* abstract file */
228 uchar biblio[37]; /* bibliographic file */
229 uchar cdate[17]; /* creation date */
230 uchar mdate[17]; /* modification date */
231 uchar xdate[17]; /* expiration date */
232 uchar edate[17]; /* effective date */
233 uchar fsvers; /* file system version = 1 */
236 /* a directory entry */
248 uchar name[1]; /* chumminess */
251 /* a path table entry */
257 uchar name[1]; /* chumminess */
260 enum { /* Rockridge flags */
271 enum { /* CputrripTF type argument */
282 enum { /* CputrripNM flag types */
292 void Cputbootvol(Cdimg*);
293 void Cputbootcat(Cdimg*);
294 void Cupdatebootvol(Cdimg*);
295 void Cupdatebootcat(Cdimg*);
296 void findbootimage(Cdimg*, Direc*);
299 Cdimg *createcd(char*, Cdinfo);
300 Cdimg *opencd(char*, Cdinfo);
301 void Creadblock(Cdimg*, void*, ulong, ulong);
302 ulong big(void*, int);
303 ulong little(void*, int);
304 int parsedir(Cdimg*, Direc*, uchar*, int, char *(*)(uchar*, int));
305 void setroot(Cdimg*, ulong, ulong, ulong);
306 void setvolsize(Cdimg*, ulong, ulong);
307 void setpathtable(Cdimg*, ulong, ulong, ulong, ulong);
308 void Cputc(Cdimg*, int);
309 void Cputnl(Cdimg*, ulong, int);
310 void Cputnm(Cdimg*, ulong, int);
311 void Cputn(Cdimg*, long, int);
312 void Crepeat(Cdimg*, int, int);
313 void Cputs(Cdimg*, char*, int);
314 void Cwrite(Cdimg*, void*, int);
315 void Cputr(Cdimg*, Rune);
316 void Crepeatr(Cdimg*, Rune, int);
317 void Cputrs(Cdimg*, Rune*, int);
318 void Cputrscvt(Cdimg*, char*, int);
319 void Cpadblock(Cdimg*);
320 void Cputdate(Cdimg*, ulong);
321 void Cputdate1(Cdimg*, ulong);
322 void Cread(Cdimg*, void*, int);
323 void Cwflush(Cdimg*);
324 void Cwseek(Cdimg*, ulong);
325 ulong Cwoffset(Cdimg*);
326 ulong Croffset(Cdimg*);
328 void Crseek(Cdimg*, ulong);
329 char *Crdline(Cdimg*, int);
330 int Clinelen(Cdimg*);
333 void rdconform(Cdimg*);
334 char *conform(char*, int);
335 void wrconform(Cdimg*, int, ulong*, ulong*);
338 void mkdirec(Direc*, XDir*);
339 Direc *walkdirec(Direc*, char*);
340 Direc *adddirec(Direc*, char*, XDir*);
341 void copydirec(Direc*, Direc*);
342 void checknames(Direc*, int (*)(char*));
343 void convertnames(Direc*, char* (*)(char*, char*));
344 void dsort(Direc*, int (*)(const void*, const void*));
345 void setparents(Direc*);
348 ulong Cputdumpblock(Cdimg*);
350 Dump *dumpcd(Cdimg*, Direc*);
351 Dumpdir *lookupmd5(Dump*, uchar*);
352 void insertmd5(Dump*, char*, uchar*, ulong, ulong);
354 Direc readdumpdirs(Cdimg*, XDir*, char*(*)(uchar*,int));
355 char *adddumpdir(Direc*, ulong, XDir*);
356 void copybutname(Direc*, Direc*);
358 void readkids(Cdimg*, Direc*, char*(*)(uchar*,int));
359 void freekids(Direc*);
360 void readdumpconform(Cdimg*);
361 void rmdumpdir(Direc*, char*);
364 char *isostring(uchar*, int);
365 int isbadiso9660(char*);
366 int isocmp(const void*, const void*);
368 void Cputisopvd(Cdimg*, Cdinfo);
371 char *jolietstring(uchar*, int);
372 int isbadjoliet(char*);
373 int jolietcmp(const void*, const void*);
374 int isjolietfrog(Rune);
375 void Cputjolietsvd(Cdimg*, Cdinfo);
378 void writepathtables(Cdimg*);
381 void *emalloc(ulong);
382 void *erealloc(void*, ulong);
384 char *struprcpy(char*, char*);
385 int chat(char*, ...);
387 /* unix.c, plan9.c */
388 void dirtoxdir(XDir*, Dir*);
389 void fdtruncate(int, ulong);
394 Rune *strtorune(Rune*, char*);
395 Rune *runechr(Rune*, Rune);
396 int runecmp(Rune*, Rune*);
399 int Cputsysuse(Cdimg*, Direc*, int, int, int);
402 void writefiles(Dump*, Cdimg*, Direc*);
403 void writedirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
404 void writedumpdirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
405 int Cputisodir(Cdimg*, Direc*, int, int, int);
406 int Cputjolietdir(Cdimg*, Direc*, int, int, int);
407 void Cputendvd(Cdimg*);
411 Ndirblock = 16, /* directory blocks allocated at once */