iso9660.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. CDbootnoemu = 1<<7,
  119. };
  120. typedef struct Tx Tx;
  121. struct Tx {
  122. char *bad; /* atoms */
  123. char *good;
  124. };
  125. struct Conform {
  126. Tx *t;
  127. int nt; /* delta = 32 */
  128. };
  129. struct Cdinfo {
  130. int flags;
  131. char *volumename;
  132. char *volumeset;
  133. char *publisher;
  134. char *preparer;
  135. char *application;
  136. char *bootimage;
  137. };
  138. //enum {
  139. // Blocklen = 2048, /* unused */
  140. //};
  141. /*
  142. * This is a doubly binary tree.
  143. * We have a tree keyed on the MD5 values
  144. * as well as a tree keyed on the block numbers.
  145. */
  146. typedef struct Dump Dump;
  147. typedef struct Dumpdir Dumpdir;
  148. struct Dump {
  149. Cdimg *cd;
  150. Dumpdir *md5root;
  151. Dumpdir *blockroot;
  152. };
  153. struct Dumpdir {
  154. char *name;
  155. uchar md5[MD5dlen];
  156. ulong block;
  157. ulong length;
  158. Dumpdir *md5left;
  159. Dumpdir *md5right;
  160. Dumpdir *blockleft;
  161. Dumpdir *blockright;
  162. };
  163. struct Dumproot {
  164. char *name;
  165. int nkid;
  166. Dumproot *kid;
  167. Direc root;
  168. Direc jroot;
  169. };
  170. /*
  171. * ISO9660 on-CD structures.
  172. */
  173. typedef struct Cdir Cdir;
  174. typedef struct Cpath Cpath;
  175. typedef struct Cvoldesc Cvoldesc;
  176. /* a volume descriptor block */
  177. struct Cvoldesc {
  178. uchar magic[8]; /* 0x01, "CD001", 0x01, 0x00 */
  179. uchar systemid[32]; /* system identifier */
  180. uchar volumeid[32]; /* volume identifier */
  181. uchar unused[8]; /* character set in secondary desc */
  182. uchar volsize[8]; /* volume size */
  183. uchar charset[32];
  184. uchar volsetsize[4]; /* volume set size = 1 */
  185. uchar volseqnum[4]; /* volume sequence number = 1 */
  186. uchar blocksize[4]; /* logical block size */
  187. uchar pathsize[8]; /* path table size */
  188. uchar lpathloc[4]; /* Lpath */
  189. uchar olpathloc[4]; /* optional Lpath */
  190. uchar mpathloc[4]; /* Mpath */
  191. uchar ompathloc[4]; /* optional Mpath */
  192. uchar rootdir[34]; /* directory entry for root */
  193. uchar volumeset[128]; /* volume set identifier */
  194. uchar publisher[128];
  195. uchar preparer[128]; /* data preparer identifier */
  196. uchar application[128]; /* application identifier */
  197. uchar notice[37]; /* copyright notice file */
  198. uchar abstract[37]; /* abstract file */
  199. uchar biblio[37]; /* bibliographic file */
  200. uchar cdate[17]; /* creation date */
  201. uchar mdate[17]; /* modification date */
  202. uchar xdate[17]; /* expiration date */
  203. uchar edate[17]; /* effective date */
  204. uchar fsvers; /* file system version = 1 */
  205. };
  206. /* a directory entry */
  207. struct Cdir {
  208. uchar len;
  209. uchar xlen;
  210. uchar dloc[8];
  211. uchar dlen[8];
  212. uchar date[7];
  213. uchar flags;
  214. uchar unitsize;
  215. uchar gapsize;
  216. uchar volseqnum[4];
  217. uchar namelen;
  218. uchar name[1]; /* chumminess */
  219. };
  220. /* a path table entry */
  221. struct Cpath {
  222. uchar namelen;
  223. uchar xlen;
  224. uchar dloc[4];
  225. uchar parent[2];
  226. uchar name[1]; /* chumminess */
  227. };
  228. enum { /* Rockridge flags */
  229. RR_PX = 1<<0,
  230. RR_PN = 1<<1,
  231. RR_SL = 1<<2,
  232. RR_NM = 1<<3,
  233. RR_CL = 1<<4,
  234. RR_PL = 1<<5,
  235. RR_RE = 1<<6,
  236. RR_TF = 1<<7,
  237. };
  238. enum { /* CputrripTF type argument */
  239. TFcreation = 1<<0,
  240. TFmodify = 1<<1,
  241. TFaccess = 1<<2,
  242. TFattributes = 1<<3,
  243. TFbackup = 1<<4,
  244. TFexpiration = 1<<5,
  245. TFeffective = 1<<6,
  246. TFlongform = 1<<7,
  247. };
  248. enum { /* CputrripNM flag types */
  249. NMcontinue = 1<<0,
  250. NMcurrent = 1<<1,
  251. NMparent = 1<<2,
  252. NMroot = 1<<3,
  253. NMvolroot = 1<<4,
  254. NMhost = 1<<5,
  255. };
  256. /* boot.c */
  257. void Cputbootvol(Cdimg*);
  258. void Cputbootcat(Cdimg*);
  259. void Cupdatebootvol(Cdimg*);
  260. void Cupdatebootcat(Cdimg*);
  261. void findbootimage(Cdimg*, Direc*);
  262. /* cdrdwr.c */
  263. Cdimg *createcd(char*, Cdinfo);
  264. Cdimg *opencd(char*, Cdinfo);
  265. void Creadblock(Cdimg*, void*, ulong, ulong);
  266. ulong big(void*, int);
  267. ulong little(void*, int);
  268. int parsedir(Cdimg*, Direc*, uchar*, int, char *(*)(uchar*, int));
  269. void setroot(Cdimg*, ulong, ulong, ulong);
  270. void setvolsize(Cdimg*, ulong, ulong);
  271. void setpathtable(Cdimg*, ulong, ulong, ulong, ulong);
  272. void Cputc(Cdimg*, int);
  273. void Cputnl(Cdimg*, ulong, int);
  274. void Cputnm(Cdimg*, ulong, int);
  275. void Cputn(Cdimg*, long, int);
  276. void Crepeat(Cdimg*, int, int);
  277. void Cputs(Cdimg*, char*, int);
  278. void Cwrite(Cdimg*, void*, int);
  279. void Cputr(Cdimg*, Rune);
  280. void Crepeatr(Cdimg*, Rune, int);
  281. void Cputrs(Cdimg*, Rune*, int);
  282. void Cputrscvt(Cdimg*, char*, int);
  283. void Cpadblock(Cdimg*);
  284. void Cputdate(Cdimg*, ulong);
  285. void Cputdate1(Cdimg*, ulong);
  286. void Cread(Cdimg*, void*, int);
  287. void Cwflush(Cdimg*);
  288. void Cwseek(Cdimg*, vlong);
  289. uvlong Cwoffset(Cdimg*);
  290. uvlong Croffset(Cdimg*);
  291. int Cgetc(Cdimg*);
  292. void Crseek(Cdimg*, vlong);
  293. char *Crdline(Cdimg*, int);
  294. int Clinelen(Cdimg*);
  295. /* conform.c */
  296. void rdconform(Cdimg*);
  297. char *conform(char*, int);
  298. void wrconform(Cdimg*, int, ulong*, uvlong*);
  299. /* direc.c */
  300. void mkdirec(Direc*, XDir*);
  301. Direc *walkdirec(Direc*, char*);
  302. Direc *adddirec(Direc*, char*, XDir*);
  303. void copydirec(Direc*, Direc*);
  304. void checknames(Direc*, int (*)(char*));
  305. void convertnames(Direc*, char* (*)(char*, char*));
  306. void dsort(Direc*, int (*)(const void*, const void*));
  307. void setparents(Direc*);
  308. /* dump.c */
  309. ulong Cputdumpblock(Cdimg*);
  310. int hasdump(Cdimg*);
  311. Dump *dumpcd(Cdimg*, Direc*);
  312. Dumpdir *lookupmd5(Dump*, uchar*);
  313. void insertmd5(Dump*, char*, uchar*, ulong, ulong);
  314. Direc readdumpdirs(Cdimg*, XDir*, char*(*)(uchar*,int));
  315. char *adddumpdir(Direc*, ulong, XDir*);
  316. void copybutname(Direc*, Direc*);
  317. void readkids(Cdimg*, Direc*, char*(*)(uchar*,int));
  318. void freekids(Direc*);
  319. void readdumpconform(Cdimg*);
  320. void rmdumpdir(Direc*, char*);
  321. /* ichar.c */
  322. char *isostring(uchar*, int);
  323. int isbadiso9660(char*);
  324. int isocmp(const void*, const void*);
  325. int isisofrog(char);
  326. void Cputisopvd(Cdimg*, Cdinfo);
  327. /* jchar.c */
  328. char *jolietstring(uchar*, int);
  329. int isbadjoliet(char*);
  330. int jolietcmp(const void*, const void*);
  331. int isjolietfrog(Rune);
  332. void Cputjolietsvd(Cdimg*, Cdinfo);
  333. /* path.c */
  334. void writepathtables(Cdimg*);
  335. /* util.c */
  336. void *emalloc(ulong);
  337. void *erealloc(void*, ulong);
  338. char *atom(char*);
  339. char *struprcpy(char*, char*);
  340. int chat(char*, ...);
  341. /* unix.c, plan9.c */
  342. void dirtoxdir(XDir*, Dir*);
  343. void fdtruncate(int, ulong);
  344. long uidno(char*);
  345. long gidno(char*);
  346. /* rune.c */
  347. Rune *strtorune(Rune*, char*);
  348. Rune *runechr(Rune*, Rune);
  349. int runecmp(Rune*, Rune*);
  350. /* sysuse.c */
  351. int Cputsysuse(Cdimg*, Direc*, int, int, int);
  352. /* write.c */
  353. void writefiles(Dump*, Cdimg*, Direc*);
  354. void writedirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
  355. void writedumpdirs(Cdimg*, Direc*, int(*)(Cdimg*, Direc*, int, int, int));
  356. int Cputisodir(Cdimg*, Direc*, int, int, int);
  357. int Cputjolietdir(Cdimg*, Direc*, int, int, int);
  358. void Cputendvd(Cdimg*);
  359. enum {
  360. Blocksize = 2048,
  361. Ndirblock = 16, /* directory blocks allocated at once */
  362. DTdot = 0,
  363. DTdotdot,
  364. DTiden,
  365. DTroot,
  366. DTrootdot,
  367. };
  368. extern ulong now;
  369. extern Conform *map;
  370. extern int chatty;
  371. extern int docolon;
  372. extern int mk9660;
  373. extern int blocksize;