iso9660.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * iso9660.h
  3. *
  4. * Routines and data structures to support reading and writing ISO 9660 CD images.
  5. * See the ISO 9660 or ECMA 119 standards.
  6. *
  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.
  10. */
  11. typedef struct Cdimg Cdimg;
  12. typedef struct Cdinfo Cdinfo;
  13. typedef struct Conform Conform;
  14. typedef struct Direc Direc;
  15. typedef struct Dumproot Dumproot;
  16. typedef struct Voldesc Voldesc;
  17. typedef struct XDir XDir;
  18. #ifndef CHLINK
  19. #define CHLINK 0
  20. #endif
  21. struct XDir {
  22. char *name;
  23. char *uid;
  24. char *gid;
  25. char *symlink;
  26. ulong uidno; /* Numeric uid */
  27. ulong gidno; /* Numeric gid */
  28. ulong mode;
  29. ulong atime;
  30. ulong mtime;
  31. ulong ctime;
  32. vlong length;
  33. };
  34. /*
  35. * A directory entry in a ISO9660 tree.
  36. * The extra data (uid, etc.) here is put into the system use areas.
  37. */
  38. struct Direc {
  39. char *name; /* real name */
  40. char *confname; /* conformant name */
  41. char *srcfile; /* file to copy onto the image */
  42. ulong block;
  43. ulong length;
  44. int flags;
  45. char *uid;
  46. char *gid;
  47. char *symlink;
  48. ulong mode;
  49. long atime;
  50. long ctime;
  51. long mtime;
  52. ulong uidno;
  53. ulong gidno;
  54. Direc *child;
  55. int nchild;
  56. };
  57. enum { /* Direc flags */
  58. Dbadname = 1<<0, /* Non-conformant name */
  59. };
  60. /*
  61. * Data found in a volume descriptor.
  62. */
  63. struct Voldesc {
  64. char *systemid;
  65. char *volumeset;
  66. char *publisher;
  67. char *preparer;
  68. char *application;
  69. /* file names for various parameters */
  70. char *abstract;
  71. char *biblio;
  72. char *notice;
  73. /* path table */
  74. ulong pathsize;
  75. ulong lpathloc;
  76. ulong mpathloc;
  77. /* root of file tree */
  78. Direc root;
  79. };
  80. /*
  81. * An ISO9660 CD image. Various parameters are kept in memory but the
  82. * real image file is opened for reading and writing on fd.
  83. *
  84. * The bio buffers brd and bwr moderate reading and writing to the image.
  85. * The routines we use are careful to flush one before or after using the other,
  86. * as necessary.
  87. */
  88. struct Cdimg {
  89. char *file;
  90. int fd;
  91. ulong dumpblock;
  92. ulong nextblock;
  93. ulong iso9660pvd;
  94. ulong jolietsvd;
  95. ulong pathblock;
  96. uvlong rrcontin; /* rock ridge continuation offset */
  97. ulong nulldump; /* next dump block */
  98. ulong nconform; /* number of conform entries written already */
  99. uvlong bootcatptr;
  100. ulong bootcatblock;
  101. uvlong bootimageptr;
  102. Direc *bootdirec;
  103. char *bootimage;
  104. Biobuf brd;
  105. Biobuf bwr;
  106. int flags;
  107. Voldesc iso;
  108. Voldesc joliet;
  109. };
  110. enum { /* Cdimg->flags, Cdinfo->flags */
  111. CDjoliet = 1<<0,
  112. CDplan9 = 1<<1,
  113. CDconform = 1<<2,
  114. CDrockridge = 1<<3,
  115. CDnew = 1<<4,
  116. CDdump = 1<<5,
  117. CDbootable = 1<<6,
  118. };
  119. typedef struct Tx Tx;
  120. struct Tx {
  121. char *bad; /* atoms */
  122. char *good;
  123. };
  124. struct Conform {
  125. Tx *t;
  126. int nt; /* delta = 32 */
  127. };
  128. struct Cdinfo {
  129. int flags;
  130. char *volumename;
  131. char *volumeset;
  132. char *publisher;
  133. char *preparer;
  134. char *application;
  135. char *bootimage;
  136. };
  137. //enum {
  138. // Blocklen = 2048, /* unused */
  139. //};
  140. /*
  141. * This is a doubly binary tree.
  142. * We have a tree keyed on the MD5 values
  143. * as well as a tree keyed on the block numbers.
  144. */
  145. typedef struct Dump Dump;
  146. typedef struct Dumpdir Dumpdir;
  147. struct Dump {
  148. Cdimg *cd;
  149. Dumpdir *md5root;
  150. Dumpdir *blockroot;
  151. };
  152. struct Dumpdir {
  153. char *name;
  154. uchar md5[MD5dlen];
  155. ulong block;
  156. ulong length;
  157. Dumpdir *md5left;
  158. Dumpdir *md5right;
  159. Dumpdir *blockleft;
  160. Dumpdir *blockright;
  161. };
  162. struct Dumproot {
  163. char *name;
  164. int nkid;
  165. Dumproot *kid;
  166. Direc root;
  167. Direc jroot;
  168. };
  169. /*
  170. * ISO9660 on-CD structures.
  171. */
  172. typedef struct Cdir Cdir;
  173. typedef struct Cpath Cpath;
  174. typedef struct Cvoldesc Cvoldesc;
  175. /* a volume descriptor block */
  176. struct Cvoldesc {
  177. uchar magic[8]; /* 0x01, "CD001", 0x01, 0x00 */
  178. uchar systemid[32]; /* system identifier */
  179. uchar volumeid[32]; /* volume identifier */
  180. uchar unused[8]; /* character set in secondary desc */
  181. uchar volsize[8]; /* volume size */
  182. uchar charset[32];
  183. uchar volsetsize[4]; /* volume set size = 1 */
  184. uchar volseqnum[4]; /* volume sequence number = 1 */
  185. uchar blocksize[4]; /* logical block size */
  186. uchar pathsize[8]; /* path table size */
  187. uchar lpathloc[4]; /* Lpath */
  188. uchar olpathloc[4]; /* optional Lpath */
  189. uchar mpathloc[4]; /* Mpath */
  190. uchar ompathloc[4]; /* optional Mpath */
  191. uchar rootdir[34]; /* directory entry for root */
  192. uchar volumeset[128]; /* volume set identifier */
  193. uchar publisher[128];
  194. uchar preparer[128]; /* data preparer identifier */
  195. uchar application[128]; /* application identifier */
  196. uchar notice[37]; /* copyright notice file */
  197. uchar abstract[37]; /* abstract file */
  198. uchar biblio[37]; /* bibliographic file */
  199. uchar cdate[17]; /* creation date */
  200. uchar mdate[17]; /* modification date */
  201. uchar xdate[17]; /* expiration date */
  202. uchar edate[17]; /* effective date */
  203. uchar fsvers; /* file system version = 1 */
  204. };
  205. /* a directory entry */
  206. struct Cdir {
  207. uchar len;
  208. uchar xlen;
  209. uchar dloc[8];
  210. uchar dlen[8];
  211. uchar date[7];
  212. uchar flags;
  213. uchar unitsize;
  214. uchar gapsize;
  215. uchar volseqnum[4];
  216. uchar namelen;
  217. uchar name[1]; /* chumminess */
  218. };
  219. /* a path table entry */
  220. struct Cpath {
  221. uchar namelen;
  222. uchar xlen;
  223. uchar dloc[4];
  224. uchar parent[2];
  225. uchar name[1]; /* chumminess */
  226. };
  227. enum { /* Rockridge flags */
  228. RR_PX = 1<<0,
  229. RR_PN = 1<<1,
  230. RR_SL = 1<<2,
  231. RR_NM = 1<<3,
  232. RR_CL = 1<<4,
  233. RR_PL = 1<<5,
  234. RR_RE = 1<<6,
  235. RR_TF = 1<<7,
  236. };
  237. enum { /* CputrripTF type argument */
  238. TFcreation = 1<<0,
  239. TFmodify = 1<<1,
  240. TFaccess = 1<<2,
  241. TFattributes = 1<<3,
  242. TFbackup = 1<<4,
  243. TFexpiration = 1<<5,
  244. TFeffective = 1<<6,
  245. TFlongform = 1<<7,
  246. };
  247. enum { /* CputrripNM flag types */
  248. NMcontinue = 1<<0,
  249. NMcurrent = 1<<1,
  250. NMparent = 1<<2,
  251. NMroot = 1<<3,
  252. NMvolroot = 1<<4,
  253. NMhost = 1<<5,
  254. };
  255. /* boot.c */
  256. void Cputbootvol(Cdimg*);
  257. void Cputbootcat(Cdimg*);
  258. void Cupdatebootvol(Cdimg*);
  259. void Cupdatebootcat(Cdimg*);
  260. void findbootimage(Cdimg*, Direc*);
  261. /* cdrdwr.c */
  262. Cdimg *createcd(char*, Cdinfo);
  263. Cdimg *opencd(char*, Cdinfo);
  264. void Creadblock(Cdimg*, void*, ulong, ulong);
  265. ulong big(void*, int);
  266. ulong little(void*, int);
  267. int parsedir(Cdimg*, Direc*, uchar*, int, char *(*)(uchar*, int));
  268. void setroot(Cdimg*, ulong, ulong, ulong);
  269. void setvolsize(Cdimg*, ulong, ulong);
  270. void setpathtable(Cdimg*, ulong, ulong, ulong, ulong);
  271. void Cputc(Cdimg*, int);
  272. void Cputnl(Cdimg*, ulong, int);
  273. void Cputnm(Cdimg*, ulong, int);
  274. void Cputn(Cdimg*, long, int);
  275. void Crepeat(Cdimg*, int, int);
  276. void Cputs(Cdimg*, char*, int);
  277. void Cwrite(Cdimg*, void*, int);
  278. void Cputr(Cdimg*, Rune);
  279. void Crepeatr(Cdimg*, Rune, int);
  280. void Cputrs(Cdimg*, Rune*, int);
  281. void Cputrscvt(Cdimg*, char*, int);
  282. void Cpadblock(Cdimg*);
  283. void Cputdate(Cdimg*, ulong);
  284. void Cputdate1(Cdimg*, ulong);
  285. void Cread(Cdimg*, void*, int);
  286. void Cwflush(Cdimg*);
  287. void Cwseek(Cdimg*, vlong);
  288. uvlong Cwoffset(Cdimg*);
  289. uvlong Croffset(Cdimg*);
  290. int Cgetc(Cdimg*);
  291. void Crseek(Cdimg*, vlong);
  292. char *Crdline(Cdimg*, int);
  293. int Clinelen(Cdimg*);
  294. /* conform.c */
  295. void rdconform(Cdimg*);
  296. char *conform(char*, int);
  297. void wrconform(Cdimg*, int, ulong*, uvlong*);
  298. /* direc.c */
  299. void mkdirec(Direc*, XDir*);
  300. Direc *walkdirec(Direc*, char*);
  301. Direc *adddirec(Direc*, char*, XDir*);
  302. void copydirec(Direc*, Direc*);
  303. void checknames(Direc*, int (*)(char*));
  304. void convertnames(Direc*, char* (*)(char*, char*));
  305. void dsort(Direc*, int (*)(const void*, const void*));
  306. void setparents(Direc*);
  307. /* dump.c */
  308. ulong Cputdumpblock(Cdimg*);
  309. int hasdump(Cdimg*);
  310. Dump *dumpcd(Cdimg*, Direc*);
  311. Dumpdir *lookupmd5(Dump*, uchar*);
  312. void insertmd5(Dump*, char*, uchar*, ulong, ulong);
  313. Direc readdumpdirs(Cdimg*, XDir*, char*(*)(uchar*,int));
  314. char *adddumpdir(Direc*, ulong, XDir*);
  315. void copybutname(Direc*, Direc*);
  316. void readkids(Cdimg*, Direc*, char*(*)(uchar*,int));
  317. void freekids(Direc*);
  318. void readdumpconform(Cdimg*);
  319. void rmdumpdir(Direc*, char*);
  320. /* ichar.c */
  321. char *isostring(uchar*, int);
  322. int isbadiso9660(char*);
  323. int isocmp(const void*, const void*);
  324. int isisofrog(char);
  325. void Cputisopvd(Cdimg*, Cdinfo);
  326. /* jchar.c */
  327. char *jolietstring(uchar*, int);
  328. int isbadjoliet(char*);
  329. int jolietcmp(const void*, const void*);
  330. int isjolietfrog(Rune);
  331. void Cputjolietsvd(Cdimg*, Cdinfo);
  332. /* path.c */
  333. void writepathtables(Cdimg*);
  334. /* util.c */
  335. void *emalloc(ulong);
  336. void *erealloc(void*, ulong);
  337. char *atom(char*);
  338. char *struprcpy(char*, char*);
  339. int chat(char*, ...);
  340. /* unix.c, plan9.c */
  341. void dirtoxdir(XDir*, Dir*);
  342. void fdtruncate(int, ulong);
  343. long uidno(char*);
  344. long gidno(char*);
  345. /* rune.c */
  346. Rune *strtorune(Rune*, char*);
  347. Rune *runechr(Rune*, Rune);
  348. int runecmp(Rune*, Rune*);
  349. /* sysuse.c */
  350. int Cputsysuse(Cdimg*, Direc*, int, int, int);
  351. /* write.c */
  352. void writefiles(Dump*, Cdimg*, Direc*);
  353. void writedirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
  354. void writedumpdirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
  355. int Cputisodir(Cdimg*, Direc*, int, int, int);
  356. int Cputjolietdir(Cdimg*, Direc*, int, int, int);
  357. void Cputendvd(Cdimg*);
  358. enum {
  359. Blocksize = 2048,
  360. Ndirblock = 16, /* directory blocks allocated at once */
  361. DTdot = 0,
  362. DTdotdot,
  363. DTiden,
  364. DTroot,
  365. DTrootdot,
  366. };
  367. extern ulong now;
  368. extern Conform *map;
  369. extern int chatty;
  370. extern int docolon;
  371. extern int mk9660;
  372. extern int blocksize;