cd9660_rrip.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /* $OpenBSD: cd9660_rrip.c,v 1.13 2015/03/14 03:38:50 jsg Exp $ */
  2. /* $NetBSD: cd9660_rrip.c,v 1.17 1997/01/24 00:27:32 cgd Exp $ */
  3. /*-
  4. * Copyright (c) 1993, 1994
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley
  8. * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
  9. * Support code is derived from software contributed to Berkeley
  10. * by Atsushi Murai (amurai@spec.co.jp).
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the University nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * @(#)cd9660_rrip.c 8.6 (Berkeley) 12/5/94
  37. */
  38. #include <sys/param.h>
  39. #include <sys/systm.h>
  40. #include <sys/namei.h>
  41. #include <sys/buf.h>
  42. #include <sys/vnode.h>
  43. #include <sys/lock.h>
  44. #include <sys/mount.h>
  45. #include <sys/kernel.h>
  46. #include <sys/stat.h>
  47. #include <sys/types.h>
  48. #include <sys/time.h>
  49. #include <isofs/cd9660/iso.h>
  50. #include <isofs/cd9660/cd9660_extern.h>
  51. #include <isofs/cd9660/cd9660_node.h>
  52. #include <isofs/cd9660/cd9660_rrip.h>
  53. #include <isofs/cd9660/iso_rrip.h>
  54. typedef struct {
  55. char type[2];
  56. int (*func)(void *, ISO_RRIP_ANALYZE *);
  57. void (*func2)(void *, ISO_RRIP_ANALYZE *);
  58. int result;
  59. } RRIP_TABLE;
  60. static int cd9660_rrip_attr(void *, ISO_RRIP_ANALYZE *);
  61. static void cd9660_rrip_defattr(void *, ISO_RRIP_ANALYZE *);
  62. static int cd9660_rrip_slink(void *, ISO_RRIP_ANALYZE *);
  63. static int cd9660_rrip_altname(void *, ISO_RRIP_ANALYZE *);
  64. static void cd9660_rrip_defname(void *, ISO_RRIP_ANALYZE *);
  65. static int cd9660_rrip_pclink(void *, ISO_RRIP_ANALYZE *);
  66. static int cd9660_rrip_reldir(void *, ISO_RRIP_ANALYZE *);
  67. static int cd9660_rrip_tstamp(void *, ISO_RRIP_ANALYZE *);
  68. static void cd9660_rrip_deftstamp(void *, ISO_RRIP_ANALYZE *);
  69. static int cd9660_rrip_device(void *, ISO_RRIP_ANALYZE *);
  70. static int cd9660_rrip_idflag(void *, ISO_RRIP_ANALYZE *);
  71. static int cd9660_rrip_cont(void *, ISO_RRIP_ANALYZE *);
  72. static int cd9660_rrip_stop(void *, ISO_RRIP_ANALYZE *);
  73. static int cd9660_rrip_extref(void *, ISO_RRIP_ANALYZE *);
  74. static int cd9660_rrip_loop(struct iso_directory_record *,
  75. ISO_RRIP_ANALYZE *, RRIP_TABLE *);
  76. /*
  77. * POSIX file attribute
  78. */
  79. static int
  80. cd9660_rrip_attr(v, ana)
  81. void *v;
  82. ISO_RRIP_ANALYZE *ana;
  83. {
  84. ISO_RRIP_ATTR *p = v;
  85. ana->inop->inode.iso_mode = isonum_733(p->mode);
  86. ana->inop->inode.iso_uid = isonum_733(p->uid);
  87. ana->inop->inode.iso_gid = isonum_733(p->gid);
  88. ana->inop->inode.iso_links = isonum_733(p->links);
  89. ana->fields &= ~ISO_SUSP_ATTR;
  90. return (ISO_SUSP_ATTR);
  91. }
  92. static void
  93. cd9660_rrip_defattr(v, ana)
  94. void *v;
  95. ISO_RRIP_ANALYZE *ana;
  96. {
  97. struct iso_directory_record *isodir = v;
  98. /* But this is a required field! */
  99. printf("RRIP without PX field?\n");
  100. cd9660_defattr(isodir, ana->inop, NULL);
  101. }
  102. /*
  103. * Symbolic Links
  104. */
  105. static int
  106. cd9660_rrip_slink(v, ana)
  107. void *v;
  108. ISO_RRIP_ANALYZE *ana;
  109. {
  110. ISO_RRIP_SLINK *p = v;
  111. register ISO_RRIP_SLINK_COMPONENT *pcomp;
  112. register ISO_RRIP_SLINK_COMPONENT *pcompe;
  113. int len, wlen, cont;
  114. char *outbuf, *inbuf;
  115. pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component;
  116. pcompe =
  117. (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length));
  118. len = *ana->outlen;
  119. outbuf = ana->outbuf;
  120. cont = ana->cont;
  121. /*
  122. * Gathering a Symbolic name from each component with path
  123. */
  124. for (; pcomp < pcompe;
  125. pcomp = (ISO_RRIP_SLINK_COMPONENT *)
  126. ((char *)pcomp + ISO_RRIP_SLSIZ + isonum_711(pcomp->clen))) {
  127. if (!cont) {
  128. if (len < ana->maxlen) {
  129. len++;
  130. *outbuf++ = '/';
  131. }
  132. }
  133. cont = 0;
  134. inbuf = "..";
  135. wlen = 0;
  136. switch (*pcomp->cflag) {
  137. case ISO_SUSP_CFLAG_CURRENT:
  138. /* Inserting Current */
  139. wlen = 1;
  140. break;
  141. case ISO_SUSP_CFLAG_PARENT:
  142. /* Inserting Parent */
  143. wlen = 2;
  144. break;
  145. case ISO_SUSP_CFLAG_ROOT:
  146. /* Inserting slash for ROOT */
  147. /* start over from beginning(?) */
  148. outbuf -= len;
  149. len = 0;
  150. break;
  151. case ISO_SUSP_CFLAG_VOLROOT:
  152. /* Inserting a mount point i.e. "/cdrom" */
  153. /* same as above */
  154. outbuf -= len;
  155. len = 0;
  156. inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname;
  157. wlen = strlen(inbuf);
  158. break;
  159. case ISO_SUSP_CFLAG_HOST:
  160. /* Inserting hostname i.e. "kurt.tools.de" */
  161. inbuf = hostname;
  162. wlen = hostnamelen;
  163. break;
  164. case ISO_SUSP_CFLAG_CONTINUE:
  165. cont = 1;
  166. /* FALLTHROUGH */
  167. case 0:
  168. /* Inserting component */
  169. wlen = isonum_711(pcomp->clen);
  170. inbuf = pcomp->name;
  171. break;
  172. default:
  173. printf("RRIP with incorrect flags?");
  174. wlen = ana->maxlen + 1;
  175. break;
  176. }
  177. if (len + wlen > ana->maxlen) {
  178. /* indicate error to caller */
  179. ana->cont = 1;
  180. ana->fields = 0;
  181. ana->outbuf -= *ana->outlen;
  182. *ana->outlen = 0;
  183. return (0);
  184. }
  185. bcopy(inbuf, outbuf, wlen);
  186. outbuf += wlen;
  187. len += wlen;
  188. }
  189. ana->outbuf = outbuf;
  190. *ana->outlen = len;
  191. ana->cont = cont;
  192. if (!isonum_711(p->flags)) {
  193. ana->fields &= ~ISO_SUSP_SLINK;
  194. return (ISO_SUSP_SLINK);
  195. }
  196. return (0);
  197. }
  198. /*
  199. * Alternate name
  200. */
  201. static int
  202. cd9660_rrip_altname(v, ana)
  203. void *v;
  204. ISO_RRIP_ANALYZE *ana;
  205. {
  206. ISO_RRIP_ALTNAME *p = v;
  207. char *inbuf;
  208. int wlen;
  209. int cont;
  210. inbuf = "..";
  211. wlen = 0;
  212. cont = 0;
  213. switch (*p->flags) {
  214. case ISO_SUSP_CFLAG_CURRENT:
  215. /* Inserting Current */
  216. wlen = 1;
  217. break;
  218. case ISO_SUSP_CFLAG_PARENT:
  219. /* Inserting Parent */
  220. wlen = 2;
  221. break;
  222. case ISO_SUSP_CFLAG_HOST:
  223. /* Inserting hostname i.e. "kurt.tools.de" */
  224. inbuf = hostname;
  225. wlen = hostnamelen;
  226. break;
  227. case ISO_SUSP_CFLAG_CONTINUE:
  228. cont = 1;
  229. /* FALLTHROUGH */
  230. case 0:
  231. /* Inserting component */
  232. wlen = isonum_711(p->h.length) - 5;
  233. inbuf = (char *)p + 5;
  234. break;
  235. default:
  236. printf("RRIP with incorrect NM flags?\n");
  237. wlen = ana->maxlen + 1;
  238. break;
  239. }
  240. if ((*ana->outlen += wlen) > ana->maxlen) {
  241. /* treat as no name field */
  242. ana->fields &= ~ISO_SUSP_ALTNAME;
  243. ana->outbuf -= *ana->outlen - wlen;
  244. *ana->outlen = 0;
  245. return (0);
  246. }
  247. bcopy(inbuf, ana->outbuf, wlen);
  248. ana->outbuf += wlen;
  249. if (!cont) {
  250. ana->fields &= ~ISO_SUSP_ALTNAME;
  251. return (ISO_SUSP_ALTNAME);
  252. }
  253. return (0);
  254. }
  255. static void
  256. cd9660_rrip_defname(v, ana)
  257. void *v;
  258. ISO_RRIP_ANALYZE *ana;
  259. {
  260. struct iso_directory_record *isodir = v;
  261. strlcpy(ana->outbuf, "..", ana->maxlen - *ana->outlen);
  262. switch (*isodir->name) {
  263. default:
  264. isofntrans(isodir->name, isonum_711(isodir->name_len),
  265. ana->outbuf, ana->outlen, 1,
  266. isonum_711(isodir->flags) & 4, ana->imp->joliet_level);
  267. break;
  268. case 0:
  269. *ana->outlen = 1;
  270. break;
  271. case 1:
  272. *ana->outlen = 2;
  273. break;
  274. }
  275. }
  276. /*
  277. * Parent or Child Link
  278. */
  279. static int
  280. cd9660_rrip_pclink(v, ana)
  281. void *v;
  282. ISO_RRIP_ANALYZE *ana;
  283. {
  284. ISO_RRIP_CLINK *p = v;
  285. *ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift;
  286. ana->fields &= ~(ISO_SUSP_CLINK | ISO_SUSP_PLINK);
  287. return (*p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK);
  288. }
  289. /*
  290. * Relocated directory
  291. */
  292. /*ARGSUSED*/
  293. static int
  294. cd9660_rrip_reldir(v, ana)
  295. void *v;
  296. ISO_RRIP_ANALYZE *ana;
  297. {
  298. /* special hack to make caller aware of RE field */
  299. *ana->outlen = 0;
  300. ana->fields = 0;
  301. return (ISO_SUSP_RELDIR | ISO_SUSP_ALTNAME | ISO_SUSP_CLINK |
  302. ISO_SUSP_PLINK);
  303. }
  304. static int
  305. cd9660_rrip_tstamp(v, ana)
  306. void *v;
  307. ISO_RRIP_ANALYZE *ana;
  308. {
  309. ISO_RRIP_TSTAMP *p = v;
  310. u_char *ptime;
  311. ptime = p->time;
  312. /* Check a format of time stamp (7bytes/17bytes) */
  313. if (!(*p->flags & ISO_SUSP_TSTAMP_FORM17)) {
  314. if (*p->flags & ISO_SUSP_TSTAMP_CREAT)
  315. ptime += 7;
  316. if (*p->flags & ISO_SUSP_TSTAMP_MODIFY) {
  317. cd9660_tstamp_conv7(ptime,
  318. &ana->inop->inode.iso_mtime);
  319. ptime += 7;
  320. } else
  321. bzero(&ana->inop->inode.iso_mtime,
  322. sizeof(struct timespec));
  323. if (*p->flags & ISO_SUSP_TSTAMP_ACCESS) {
  324. cd9660_tstamp_conv7(ptime,
  325. &ana->inop->inode.iso_atime);
  326. ptime += 7;
  327. } else
  328. ana->inop->inode.iso_atime =
  329. ana->inop->inode.iso_mtime;
  330. if (*p->flags & ISO_SUSP_TSTAMP_ATTR)
  331. cd9660_tstamp_conv7(ptime,
  332. &ana->inop->inode.iso_ctime);
  333. else
  334. ana->inop->inode.iso_ctime =
  335. ana->inop->inode.iso_mtime;
  336. } else {
  337. if (*p->flags & ISO_SUSP_TSTAMP_CREAT)
  338. ptime += 17;
  339. if (*p->flags & ISO_SUSP_TSTAMP_MODIFY) {
  340. cd9660_tstamp_conv17(ptime,
  341. &ana->inop->inode.iso_mtime);
  342. ptime += 17;
  343. } else
  344. bzero(&ana->inop->inode.iso_mtime,
  345. sizeof(struct timespec));
  346. if (*p->flags & ISO_SUSP_TSTAMP_ACCESS) {
  347. cd9660_tstamp_conv17(ptime,
  348. &ana->inop->inode.iso_atime);
  349. ptime += 17;
  350. } else
  351. ana->inop->inode.iso_atime =
  352. ana->inop->inode.iso_mtime;
  353. if (*p->flags & ISO_SUSP_TSTAMP_ATTR)
  354. cd9660_tstamp_conv17(ptime,
  355. &ana->inop->inode.iso_ctime);
  356. else
  357. ana->inop->inode.iso_ctime =
  358. ana->inop->inode.iso_mtime;
  359. }
  360. ana->fields &= ~ISO_SUSP_TSTAMP;
  361. return (ISO_SUSP_TSTAMP);
  362. }
  363. static void
  364. cd9660_rrip_deftstamp(v, ana)
  365. void *v;
  366. ISO_RRIP_ANALYZE *ana;
  367. {
  368. struct iso_directory_record *isodir = v;
  369. cd9660_deftstamp(isodir, ana->inop, NULL);
  370. }
  371. /*
  372. * POSIX device modes
  373. */
  374. static int
  375. cd9660_rrip_device(v, ana)
  376. void *v;
  377. ISO_RRIP_ANALYZE *ana;
  378. {
  379. ISO_RRIP_DEVICE *p = v;
  380. u_int high, low;
  381. high = isonum_733(p->dev_t_high);
  382. low = isonum_733(p->dev_t_low);
  383. if (high == 0)
  384. ana->inop->inode.iso_rdev = makedev(major(low), minor(low));
  385. else
  386. ana->inop->inode.iso_rdev = makedev(high, minor(low));
  387. ana->fields &= ~ISO_SUSP_DEVICE;
  388. return (ISO_SUSP_DEVICE);
  389. }
  390. /*
  391. * Flag indicating
  392. */
  393. static int
  394. cd9660_rrip_idflag(v, ana)
  395. void *v;
  396. ISO_RRIP_ANALYZE *ana;
  397. {
  398. ISO_RRIP_IDFLAG *p = v;
  399. /* don't touch high bits */
  400. ana->fields &= isonum_711(p->flags) | ~0xff;
  401. /* special handling of RE field */
  402. if (ana->fields & ISO_SUSP_RELDIR)
  403. return (cd9660_rrip_reldir(p, ana));
  404. return (ISO_SUSP_IDFLAG);
  405. }
  406. /*
  407. * Continuation pointer
  408. */
  409. static int
  410. cd9660_rrip_cont(v, ana)
  411. void *v;
  412. ISO_RRIP_ANALYZE *ana;
  413. {
  414. ISO_RRIP_CONT *p = v;
  415. ana->iso_ce_blk = isonum_733(p->location);
  416. ana->iso_ce_off = isonum_733(p->offset);
  417. ana->iso_ce_len = isonum_733(p->length);
  418. return (ISO_SUSP_CONT);
  419. }
  420. /*
  421. * System Use end
  422. */
  423. static int
  424. cd9660_rrip_stop(v, ana)
  425. void *v;
  426. ISO_RRIP_ANALYZE *ana;
  427. {
  428. return (ISO_SUSP_STOP);
  429. }
  430. /*
  431. * Extension reference
  432. */
  433. static int
  434. cd9660_rrip_extref(v, ana)
  435. void *v;
  436. ISO_RRIP_ANALYZE *ana;
  437. {
  438. ISO_RRIP_EXTREF *p = v;
  439. if (isonum_711(p->version) != 1)
  440. return (0);
  441. if (isonum_711(p->len_id) != 9 &&
  442. isonum_711(p->len_id) != 10)
  443. return (0);
  444. if (isonum_711(p->len_id) == 9 &&
  445. bcmp((char *)p + 8, "IEEE_1282", 9))
  446. return (0);
  447. if (isonum_711(p->len_id) == 10 &&
  448. bcmp((char *)p + 8, "IEEE_P1282", 10) &&
  449. bcmp((char *)p + 8, "RRIP_1991A", 10))
  450. return (0);
  451. ana->fields &= ~ISO_SUSP_EXTREF;
  452. return (ISO_SUSP_EXTREF);
  453. }
  454. static int
  455. cd9660_rrip_loop(isodir, ana, table)
  456. struct iso_directory_record *isodir;
  457. ISO_RRIP_ANALYZE *ana;
  458. RRIP_TABLE *table;
  459. {
  460. register RRIP_TABLE *ptable;
  461. register ISO_SUSP_HEADER *phead;
  462. register ISO_SUSP_HEADER *pend;
  463. struct buf *bp = NULL;
  464. char *pwhead;
  465. u_char c;
  466. int result;
  467. /*
  468. * Note: If name length is odd,
  469. * it will be padded by 1 byte after the name
  470. */
  471. pwhead = isodir->name + isonum_711(isodir->name_len);
  472. if (!(isonum_711(isodir->name_len) & 1))
  473. pwhead++;
  474. isochar(isodir->name, pwhead, ana->imp->joliet_level, &c);
  475. /* If it's not the '.' entry of the root dir obey SP field */
  476. if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
  477. pwhead += ana->imp->rr_skip;
  478. else
  479. pwhead += ana->imp->rr_skip0;
  480. phead = (ISO_SUSP_HEADER *)pwhead;
  481. pend =
  482. (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
  483. result = 0;
  484. while (1) {
  485. ana->iso_ce_len = 0;
  486. /*
  487. * Note: "pend" should be more than one SUSP header
  488. */
  489. while (pend >= phead + 1) {
  490. if (isonum_711(phead->version) == 1) {
  491. for (ptable = table; ptable->func; ptable++) {
  492. if (*phead->type == *ptable->type &&
  493. phead->type[1] == ptable->type[1])
  494. {
  495. result |=
  496. ptable->func(phead, ana);
  497. break;
  498. }
  499. }
  500. if (!ana->fields)
  501. break;
  502. }
  503. if (result & ISO_SUSP_STOP) {
  504. result &= ~ISO_SUSP_STOP;
  505. break;
  506. }
  507. /* plausibility check */
  508. if (isonum_711(phead->length) < sizeof(*phead))
  509. break;
  510. /*
  511. * move to next SUSP
  512. * Hopefully this works with newer versions, too
  513. */
  514. phead = (ISO_SUSP_HEADER *)
  515. ((char *)phead + isonum_711(phead->length));
  516. }
  517. if (ana->fields && ana->iso_ce_len) {
  518. if (ana->iso_ce_blk >= ana->imp->volume_space_size ||
  519. ana->iso_ce_off + ana->iso_ce_len >
  520. ana->imp->logical_block_size ||
  521. bread(ana->imp->im_devvp, ana->iso_ce_blk <<
  522. (ana->imp->im_bshift - DEV_BSHIFT),
  523. ana->imp->logical_block_size, &bp))
  524. /* what to do now? */
  525. break;
  526. phead =
  527. (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
  528. pend = (ISO_SUSP_HEADER *)
  529. ((char *)phead + ana->iso_ce_len);
  530. } else
  531. break;
  532. }
  533. if (bp)
  534. brelse(bp);
  535. /*
  536. * If we don't find the Basic SUSP stuffs, just set default value
  537. * (attribute/time stamp)
  538. */
  539. for (ptable = table; ptable->func2; ptable++)
  540. if (!(ptable->result & result))
  541. ptable->func2(isodir, ana);
  542. return (result);
  543. }
  544. /*
  545. * Get Attributes.
  546. */
  547. static RRIP_TABLE rrip_table_analyze[] = {
  548. { "PX", cd9660_rrip_attr, cd9660_rrip_defattr,
  549. ISO_SUSP_ATTR },
  550. { "TF", cd9660_rrip_tstamp, cd9660_rrip_deftstamp,
  551. ISO_SUSP_TSTAMP },
  552. { "PN", cd9660_rrip_device, 0,
  553. ISO_SUSP_DEVICE },
  554. { "RR", cd9660_rrip_idflag, 0,
  555. ISO_SUSP_IDFLAG },
  556. { "CE", cd9660_rrip_cont, 0,
  557. ISO_SUSP_CONT },
  558. { "ST", cd9660_rrip_stop, 0,
  559. ISO_SUSP_STOP },
  560. { "", 0, 0,
  561. 0 }
  562. };
  563. int
  564. cd9660_rrip_analyze(isodir, inop, imp)
  565. struct iso_directory_record *isodir;
  566. struct iso_node *inop;
  567. struct iso_mnt *imp;
  568. {
  569. ISO_RRIP_ANALYZE analyze;
  570. analyze.inop = inop;
  571. analyze.imp = imp;
  572. analyze.fields = ISO_SUSP_ATTR | ISO_SUSP_TSTAMP | ISO_SUSP_DEVICE;
  573. return (cd9660_rrip_loop(isodir, &analyze, rrip_table_analyze));
  574. }
  575. /*
  576. * Get Alternate Name.
  577. */
  578. static RRIP_TABLE rrip_table_getname[] = {
  579. { "NM", cd9660_rrip_altname, cd9660_rrip_defname,
  580. ISO_SUSP_ALTNAME },
  581. { "CL", cd9660_rrip_pclink, 0,
  582. ISO_SUSP_CLINK|ISO_SUSP_PLINK },
  583. { "PL", cd9660_rrip_pclink, 0,
  584. ISO_SUSP_CLINK|ISO_SUSP_PLINK },
  585. { "RE", cd9660_rrip_reldir, 0,
  586. ISO_SUSP_RELDIR },
  587. { "RR", cd9660_rrip_idflag, 0,
  588. ISO_SUSP_IDFLAG },
  589. { "CE", cd9660_rrip_cont, 0,
  590. ISO_SUSP_CONT },
  591. { "ST", cd9660_rrip_stop, 0,
  592. ISO_SUSP_STOP },
  593. { "", 0, 0,
  594. 0 }
  595. };
  596. int
  597. cd9660_rrip_getname(isodir, outbuf, outlen, inump, imp)
  598. struct iso_directory_record *isodir;
  599. char *outbuf;
  600. u_short *outlen;
  601. cdino_t *inump;
  602. struct iso_mnt *imp;
  603. {
  604. ISO_RRIP_ANALYZE analyze;
  605. RRIP_TABLE *tab;
  606. u_char c;
  607. analyze.outbuf = outbuf;
  608. analyze.outlen = outlen;
  609. analyze.maxlen = NAME_MAX;
  610. analyze.inump = inump;
  611. analyze.imp = imp;
  612. analyze.fields = ISO_SUSP_ALTNAME | ISO_SUSP_RELDIR | ISO_SUSP_CLINK |
  613. ISO_SUSP_PLINK;
  614. *outlen = 0;
  615. isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
  616. imp->joliet_level, &c);
  617. tab = rrip_table_getname;
  618. if (c == 0 || c == 1) {
  619. cd9660_rrip_defname(isodir, &analyze);
  620. analyze.fields &= ~ISO_SUSP_ALTNAME;
  621. tab++;
  622. }
  623. return (cd9660_rrip_loop(isodir, &analyze, tab));
  624. }
  625. /*
  626. * Get Symbolic Link.
  627. */
  628. static RRIP_TABLE rrip_table_getsymname[] = {
  629. { "SL", cd9660_rrip_slink, 0, ISO_SUSP_SLINK },
  630. { "RR", cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
  631. { "CE", cd9660_rrip_cont, 0, ISO_SUSP_CONT },
  632. { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP },
  633. { "", 0, 0, 0 }
  634. };
  635. int
  636. cd9660_rrip_getsymname(isodir, outbuf, outlen, imp)
  637. struct iso_directory_record *isodir;
  638. char *outbuf;
  639. u_short *outlen;
  640. struct iso_mnt *imp;
  641. {
  642. ISO_RRIP_ANALYZE analyze;
  643. analyze.outbuf = outbuf;
  644. analyze.outlen = outlen;
  645. *outlen = 0;
  646. analyze.maxlen = MAXPATHLEN;
  647. analyze.cont = 1; /* don't start with a slash */
  648. analyze.imp = imp;
  649. analyze.fields = ISO_SUSP_SLINK;
  650. return (cd9660_rrip_loop(isodir, &analyze, rrip_table_getsymname) &
  651. ISO_SUSP_SLINK);
  652. }
  653. static RRIP_TABLE rrip_table_extref[] = {
  654. { "ER", cd9660_rrip_extref, 0, ISO_SUSP_EXTREF },
  655. { "CE", cd9660_rrip_cont, 0, ISO_SUSP_CONT },
  656. { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP },
  657. { "", 0, 0, 0 }
  658. };
  659. /*
  660. * Check for Rock Ridge Extension and return offset of its fields.
  661. * Note: We insist on the ER field.
  662. */
  663. int
  664. cd9660_rrip_offset(isodir, imp)
  665. struct iso_directory_record *isodir;
  666. struct iso_mnt *imp;
  667. {
  668. ISO_RRIP_OFFSET *p;
  669. ISO_RRIP_ANALYZE analyze;
  670. imp->rr_skip0 = 0;
  671. p = (ISO_RRIP_OFFSET *)(isodir->name + 1);
  672. if (bcmp(p, "SP\7\1\276\357", 6)) {
  673. /* Maybe, it's a CDROM XA disc? */
  674. imp->rr_skip0 = 15;
  675. p = (ISO_RRIP_OFFSET *)((char *)p + 15);
  676. if (bcmp(p, "SP\7\1\276\357", 6))
  677. return (-1);
  678. }
  679. analyze.imp = imp;
  680. analyze.fields = ISO_SUSP_EXTREF;
  681. if (!(cd9660_rrip_loop(isodir, &analyze, rrip_table_extref) &
  682. ISO_SUSP_EXTREF))
  683. return (-1);
  684. return (isonum_711(p->skip));
  685. }