rock.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * linux/fs/isofs/rock.c
  3. *
  4. * (C) 1992, 1993 Eric Youngdale
  5. *
  6. * Rock Ridge Extensions to iso9660
  7. */
  8. #include <linux/slab.h>
  9. #include <linux/pagemap.h>
  10. #include "isofs.h"
  11. #include "rock.h"
  12. /*
  13. * These functions are designed to read the system areas of a directory record
  14. * and extract relevant information. There are different functions provided
  15. * depending upon what information we need at the time. One function fills
  16. * out an inode structure, a second one extracts a filename, a third one
  17. * returns a symbolic link name, and a fourth one returns the extent number
  18. * for the file.
  19. */
  20. #define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */
  21. struct rock_state {
  22. void *buffer;
  23. unsigned char *chr;
  24. int len;
  25. int cont_size;
  26. int cont_extent;
  27. int cont_offset;
  28. int cont_loops;
  29. struct inode *inode;
  30. };
  31. /*
  32. * This is a way of ensuring that we have something in the system
  33. * use fields that is compatible with Rock Ridge. Return zero on success.
  34. */
  35. static int check_sp(struct rock_ridge *rr, struct inode *inode)
  36. {
  37. if (rr->u.SP.magic[0] != 0xbe)
  38. return -1;
  39. if (rr->u.SP.magic[1] != 0xef)
  40. return -1;
  41. ISOFS_SB(inode->i_sb)->s_rock_offset = rr->u.SP.skip;
  42. return 0;
  43. }
  44. static void setup_rock_ridge(struct iso_directory_record *de,
  45. struct inode *inode, struct rock_state *rs)
  46. {
  47. rs->len = sizeof(struct iso_directory_record) + de->name_len[0];
  48. if (rs->len & 1)
  49. (rs->len)++;
  50. rs->chr = (unsigned char *)de + rs->len;
  51. rs->len = *((unsigned char *)de) - rs->len;
  52. if (rs->len < 0)
  53. rs->len = 0;
  54. if (ISOFS_SB(inode->i_sb)->s_rock_offset != -1) {
  55. rs->len -= ISOFS_SB(inode->i_sb)->s_rock_offset;
  56. rs->chr += ISOFS_SB(inode->i_sb)->s_rock_offset;
  57. if (rs->len < 0)
  58. rs->len = 0;
  59. }
  60. }
  61. static void init_rock_state(struct rock_state *rs, struct inode *inode)
  62. {
  63. memset(rs, 0, sizeof(*rs));
  64. rs->inode = inode;
  65. }
  66. /* Maximum number of Rock Ridge continuation entries */
  67. #define RR_MAX_CE_ENTRIES 32
  68. /*
  69. * Returns 0 if the caller should continue scanning, 1 if the scan must end
  70. * and -ve on error.
  71. */
  72. static int rock_continue(struct rock_state *rs)
  73. {
  74. int ret = 1;
  75. int blocksize = 1 << rs->inode->i_blkbits;
  76. const int min_de_size = offsetof(struct rock_ridge, u);
  77. kfree(rs->buffer);
  78. rs->buffer = NULL;
  79. if ((unsigned)rs->cont_offset > blocksize - min_de_size ||
  80. (unsigned)rs->cont_size > blocksize ||
  81. (unsigned)(rs->cont_offset + rs->cont_size) > blocksize) {
  82. printk(KERN_NOTICE "rock: corrupted directory entry. "
  83. "extent=%d, offset=%d, size=%d\n",
  84. rs->cont_extent, rs->cont_offset, rs->cont_size);
  85. ret = -EIO;
  86. goto out;
  87. }
  88. if (rs->cont_extent) {
  89. struct buffer_head *bh;
  90. rs->buffer = kmalloc(rs->cont_size, GFP_KERNEL);
  91. if (!rs->buffer) {
  92. ret = -ENOMEM;
  93. goto out;
  94. }
  95. ret = -EIO;
  96. if (++rs->cont_loops >= RR_MAX_CE_ENTRIES)
  97. goto out;
  98. bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
  99. if (bh) {
  100. memcpy(rs->buffer, bh->b_data + rs->cont_offset,
  101. rs->cont_size);
  102. put_bh(bh);
  103. rs->chr = rs->buffer;
  104. rs->len = rs->cont_size;
  105. rs->cont_extent = 0;
  106. rs->cont_size = 0;
  107. rs->cont_offset = 0;
  108. return 0;
  109. }
  110. printk("Unable to read rock-ridge attributes\n");
  111. }
  112. out:
  113. kfree(rs->buffer);
  114. rs->buffer = NULL;
  115. return ret;
  116. }
  117. /*
  118. * We think there's a record of type `sig' at rs->chr. Parse the signature
  119. * and make sure that there's really room for a record of that type.
  120. */
  121. static int rock_check_overflow(struct rock_state *rs, int sig)
  122. {
  123. int len;
  124. switch (sig) {
  125. case SIG('S', 'P'):
  126. len = sizeof(struct SU_SP_s);
  127. break;
  128. case SIG('C', 'E'):
  129. len = sizeof(struct SU_CE_s);
  130. break;
  131. case SIG('E', 'R'):
  132. len = sizeof(struct SU_ER_s);
  133. break;
  134. case SIG('R', 'R'):
  135. len = sizeof(struct RR_RR_s);
  136. break;
  137. case SIG('P', 'X'):
  138. len = sizeof(struct RR_PX_s);
  139. break;
  140. case SIG('P', 'N'):
  141. len = sizeof(struct RR_PN_s);
  142. break;
  143. case SIG('S', 'L'):
  144. len = sizeof(struct RR_SL_s);
  145. break;
  146. case SIG('N', 'M'):
  147. len = sizeof(struct RR_NM_s);
  148. break;
  149. case SIG('C', 'L'):
  150. len = sizeof(struct RR_CL_s);
  151. break;
  152. case SIG('P', 'L'):
  153. len = sizeof(struct RR_PL_s);
  154. break;
  155. case SIG('T', 'F'):
  156. len = sizeof(struct RR_TF_s);
  157. break;
  158. case SIG('Z', 'F'):
  159. len = sizeof(struct RR_ZF_s);
  160. break;
  161. default:
  162. len = 0;
  163. break;
  164. }
  165. len += offsetof(struct rock_ridge, u);
  166. if (len > rs->len) {
  167. printk(KERN_NOTICE "rock: directory entry would overflow "
  168. "storage\n");
  169. printk(KERN_NOTICE "rock: sig=0x%02x, size=%d, remaining=%d\n",
  170. sig, len, rs->len);
  171. return -EIO;
  172. }
  173. return 0;
  174. }
  175. /*
  176. * return length of name field; 0: not found, -1: to be ignored
  177. */
  178. int get_rock_ridge_filename(struct iso_directory_record *de,
  179. char *retname, struct inode *inode)
  180. {
  181. struct rock_state rs;
  182. struct rock_ridge *rr;
  183. int sig;
  184. int retnamlen = 0;
  185. int truncate = 0;
  186. int ret = 0;
  187. char *p;
  188. int len;
  189. if (!ISOFS_SB(inode->i_sb)->s_rock)
  190. return 0;
  191. *retname = 0;
  192. init_rock_state(&rs, inode);
  193. setup_rock_ridge(de, inode, &rs);
  194. repeat:
  195. while (rs.len > 2) { /* There may be one byte for padding somewhere */
  196. rr = (struct rock_ridge *)rs.chr;
  197. /*
  198. * Ignore rock ridge info if rr->len is out of range, but
  199. * don't return -EIO because that would make the file
  200. * invisible.
  201. */
  202. if (rr->len < 3)
  203. goto out; /* Something got screwed up here */
  204. sig = isonum_721(rs.chr);
  205. if (rock_check_overflow(&rs, sig))
  206. goto eio;
  207. rs.chr += rr->len;
  208. rs.len -= rr->len;
  209. /*
  210. * As above, just ignore the rock ridge info if rr->len
  211. * is bogus.
  212. */
  213. if (rs.len < 0)
  214. goto out; /* Something got screwed up here */
  215. switch (sig) {
  216. case SIG('R', 'R'):
  217. if ((rr->u.RR.flags[0] & RR_NM) == 0)
  218. goto out;
  219. break;
  220. case SIG('S', 'P'):
  221. if (check_sp(rr, inode))
  222. goto out;
  223. break;
  224. case SIG('C', 'E'):
  225. rs.cont_extent = isonum_733(rr->u.CE.extent);
  226. rs.cont_offset = isonum_733(rr->u.CE.offset);
  227. rs.cont_size = isonum_733(rr->u.CE.size);
  228. break;
  229. case SIG('N', 'M'):
  230. if (truncate)
  231. break;
  232. if (rr->len < 5)
  233. break;
  234. /*
  235. * If the flags are 2 or 4, this indicates '.' or '..'.
  236. * We don't want to do anything with this, because it
  237. * screws up the code that calls us. We don't really
  238. * care anyways, since we can just use the non-RR
  239. * name.
  240. */
  241. if (rr->u.NM.flags & 6)
  242. break;
  243. if (rr->u.NM.flags & ~1) {
  244. printk("Unsupported NM flag settings (%d)\n",
  245. rr->u.NM.flags);
  246. break;
  247. }
  248. len = rr->len - 5;
  249. if (retnamlen + len >= 254) {
  250. truncate = 1;
  251. break;
  252. }
  253. p = memchr(rr->u.NM.name, '\0', len);
  254. if (unlikely(p))
  255. len = p - rr->u.NM.name;
  256. memcpy(retname + retnamlen, rr->u.NM.name, len);
  257. retnamlen += len;
  258. retname[retnamlen] = '\0';
  259. break;
  260. case SIG('R', 'E'):
  261. kfree(rs.buffer);
  262. return -1;
  263. default:
  264. break;
  265. }
  266. }
  267. ret = rock_continue(&rs);
  268. if (ret == 0)
  269. goto repeat;
  270. if (ret == 1)
  271. return retnamlen; /* If 0, this file did not have a NM field */
  272. out:
  273. kfree(rs.buffer);
  274. return ret;
  275. eio:
  276. ret = -EIO;
  277. goto out;
  278. }
  279. #define RR_REGARD_XA 1
  280. #define RR_RELOC_DE 2
  281. static int
  282. parse_rock_ridge_inode_internal(struct iso_directory_record *de,
  283. struct inode *inode, int flags)
  284. {
  285. int symlink_len = 0;
  286. int cnt, sig;
  287. unsigned int reloc_block;
  288. struct inode *reloc;
  289. struct rock_ridge *rr;
  290. int rootflag;
  291. struct rock_state rs;
  292. int ret = 0;
  293. if (!ISOFS_SB(inode->i_sb)->s_rock)
  294. return 0;
  295. init_rock_state(&rs, inode);
  296. setup_rock_ridge(de, inode, &rs);
  297. if (flags & RR_REGARD_XA) {
  298. rs.chr += 14;
  299. rs.len -= 14;
  300. if (rs.len < 0)
  301. rs.len = 0;
  302. }
  303. repeat:
  304. while (rs.len > 2) { /* There may be one byte for padding somewhere */
  305. rr = (struct rock_ridge *)rs.chr;
  306. /*
  307. * Ignore rock ridge info if rr->len is out of range, but
  308. * don't return -EIO because that would make the file
  309. * invisible.
  310. */
  311. if (rr->len < 3)
  312. goto out; /* Something got screwed up here */
  313. sig = isonum_721(rs.chr);
  314. if (rock_check_overflow(&rs, sig))
  315. goto eio;
  316. rs.chr += rr->len;
  317. rs.len -= rr->len;
  318. /*
  319. * As above, just ignore the rock ridge info if rr->len
  320. * is bogus.
  321. */
  322. if (rs.len < 0)
  323. goto out; /* Something got screwed up here */
  324. switch (sig) {
  325. #ifndef CONFIG_ZISOFS /* No flag for SF or ZF */
  326. case SIG('R', 'R'):
  327. if ((rr->u.RR.flags[0] &
  328. (RR_PX | RR_TF | RR_SL | RR_CL)) == 0)
  329. goto out;
  330. break;
  331. #endif
  332. case SIG('S', 'P'):
  333. if (check_sp(rr, inode))
  334. goto out;
  335. break;
  336. case SIG('C', 'E'):
  337. rs.cont_extent = isonum_733(rr->u.CE.extent);
  338. rs.cont_offset = isonum_733(rr->u.CE.offset);
  339. rs.cont_size = isonum_733(rr->u.CE.size);
  340. break;
  341. case SIG('E', 'R'):
  342. /* Invalid length of ER tag id? */
  343. if (rr->u.ER.len_id + offsetof(struct rock_ridge, u.ER.data) > rr->len)
  344. goto out;
  345. ISOFS_SB(inode->i_sb)->s_rock = 1;
  346. printk(KERN_DEBUG "ISO 9660 Extensions: ");
  347. {
  348. int p;
  349. for (p = 0; p < rr->u.ER.len_id; p++)
  350. printk(KERN_CONT "%c", rr->u.ER.data[p]);
  351. }
  352. printk(KERN_CONT "\n");
  353. break;
  354. case SIG('P', 'X'):
  355. inode->i_mode = isonum_733(rr->u.PX.mode);
  356. set_nlink(inode, isonum_733(rr->u.PX.n_links));
  357. i_uid_write(inode, isonum_733(rr->u.PX.uid));
  358. i_gid_write(inode, isonum_733(rr->u.PX.gid));
  359. break;
  360. case SIG('P', 'N'):
  361. {
  362. int high, low;
  363. high = isonum_733(rr->u.PN.dev_high);
  364. low = isonum_733(rr->u.PN.dev_low);
  365. /*
  366. * The Rock Ridge standard specifies that if
  367. * sizeof(dev_t) <= 4, then the high field is
  368. * unused, and the device number is completely
  369. * stored in the low field. Some writers may
  370. * ignore this subtlety,
  371. * and as a result we test to see if the entire
  372. * device number is
  373. * stored in the low field, and use that.
  374. */
  375. if ((low & ~0xff) && high == 0) {
  376. inode->i_rdev =
  377. MKDEV(low >> 8, low & 0xff);
  378. } else {
  379. inode->i_rdev =
  380. MKDEV(high, low);
  381. }
  382. }
  383. break;
  384. case SIG('T', 'F'):
  385. /*
  386. * Some RRIP writers incorrectly place ctime in the
  387. * TF_CREATE field. Try to handle this correctly for
  388. * either case.
  389. */
  390. /* Rock ridge never appears on a High Sierra disk */
  391. cnt = 0;
  392. if (rr->u.TF.flags & TF_CREATE) {
  393. inode->i_ctime.tv_sec =
  394. iso_date(rr->u.TF.times[cnt++].time,
  395. 0);
  396. inode->i_ctime.tv_nsec = 0;
  397. }
  398. if (rr->u.TF.flags & TF_MODIFY) {
  399. inode->i_mtime.tv_sec =
  400. iso_date(rr->u.TF.times[cnt++].time,
  401. 0);
  402. inode->i_mtime.tv_nsec = 0;
  403. }
  404. if (rr->u.TF.flags & TF_ACCESS) {
  405. inode->i_atime.tv_sec =
  406. iso_date(rr->u.TF.times[cnt++].time,
  407. 0);
  408. inode->i_atime.tv_nsec = 0;
  409. }
  410. if (rr->u.TF.flags & TF_ATTRIBUTES) {
  411. inode->i_ctime.tv_sec =
  412. iso_date(rr->u.TF.times[cnt++].time,
  413. 0);
  414. inode->i_ctime.tv_nsec = 0;
  415. }
  416. break;
  417. case SIG('S', 'L'):
  418. {
  419. int slen;
  420. struct SL_component *slp;
  421. struct SL_component *oldslp;
  422. slen = rr->len - 5;
  423. slp = &rr->u.SL.link;
  424. inode->i_size = symlink_len;
  425. while (slen > 1) {
  426. rootflag = 0;
  427. switch (slp->flags & ~1) {
  428. case 0:
  429. inode->i_size +=
  430. slp->len;
  431. break;
  432. case 2:
  433. inode->i_size += 1;
  434. break;
  435. case 4:
  436. inode->i_size += 2;
  437. break;
  438. case 8:
  439. rootflag = 1;
  440. inode->i_size += 1;
  441. break;
  442. default:
  443. printk("Symlink component flag "
  444. "not implemented\n");
  445. }
  446. slen -= slp->len + 2;
  447. oldslp = slp;
  448. slp = (struct SL_component *)
  449. (((char *)slp) + slp->len + 2);
  450. if (slen < 2) {
  451. if (((rr->u.SL.
  452. flags & 1) != 0)
  453. &&
  454. ((oldslp->
  455. flags & 1) == 0))
  456. inode->i_size +=
  457. 1;
  458. break;
  459. }
  460. /*
  461. * If this component record isn't
  462. * continued, then append a '/'.
  463. */
  464. if (!rootflag
  465. && (oldslp->flags & 1) == 0)
  466. inode->i_size += 1;
  467. }
  468. }
  469. symlink_len = inode->i_size;
  470. break;
  471. case SIG('R', 'E'):
  472. printk(KERN_WARNING "Attempt to read inode for "
  473. "relocated directory\n");
  474. goto out;
  475. case SIG('C', 'L'):
  476. if (flags & RR_RELOC_DE) {
  477. printk(KERN_ERR
  478. "ISOFS: Recursive directory relocation "
  479. "is not supported\n");
  480. goto eio;
  481. }
  482. reloc_block = isonum_733(rr->u.CL.location);
  483. if (reloc_block == ISOFS_I(inode)->i_iget5_block &&
  484. ISOFS_I(inode)->i_iget5_offset == 0) {
  485. printk(KERN_ERR
  486. "ISOFS: Directory relocation points to "
  487. "itself\n");
  488. goto eio;
  489. }
  490. ISOFS_I(inode)->i_first_extent = reloc_block;
  491. reloc = isofs_iget_reloc(inode->i_sb, reloc_block, 0);
  492. if (IS_ERR(reloc)) {
  493. ret = PTR_ERR(reloc);
  494. goto out;
  495. }
  496. inode->i_mode = reloc->i_mode;
  497. set_nlink(inode, reloc->i_nlink);
  498. inode->i_uid = reloc->i_uid;
  499. inode->i_gid = reloc->i_gid;
  500. inode->i_rdev = reloc->i_rdev;
  501. inode->i_size = reloc->i_size;
  502. inode->i_blocks = reloc->i_blocks;
  503. inode->i_atime = reloc->i_atime;
  504. inode->i_ctime = reloc->i_ctime;
  505. inode->i_mtime = reloc->i_mtime;
  506. iput(reloc);
  507. break;
  508. #ifdef CONFIG_ZISOFS
  509. case SIG('Z', 'F'): {
  510. int algo;
  511. if (ISOFS_SB(inode->i_sb)->s_nocompress)
  512. break;
  513. algo = isonum_721(rr->u.ZF.algorithm);
  514. if (algo == SIG('p', 'z')) {
  515. int block_shift =
  516. isonum_711(&rr->u.ZF.parms[1]);
  517. if (block_shift > 17) {
  518. printk(KERN_WARNING "isofs: "
  519. "Can't handle ZF block "
  520. "size of 2^%d\n",
  521. block_shift);
  522. } else {
  523. /*
  524. * Note: we don't change
  525. * i_blocks here
  526. */
  527. ISOFS_I(inode)->i_file_format =
  528. isofs_file_compressed;
  529. /*
  530. * Parameters to compression
  531. * algorithm (header size,
  532. * block size)
  533. */
  534. ISOFS_I(inode)->i_format_parm[0] =
  535. isonum_711(&rr->u.ZF.parms[0]);
  536. ISOFS_I(inode)->i_format_parm[1] =
  537. isonum_711(&rr->u.ZF.parms[1]);
  538. inode->i_size =
  539. isonum_733(rr->u.ZF.
  540. real_size);
  541. }
  542. } else {
  543. printk(KERN_WARNING
  544. "isofs: Unknown ZF compression "
  545. "algorithm: %c%c\n",
  546. rr->u.ZF.algorithm[0],
  547. rr->u.ZF.algorithm[1]);
  548. }
  549. break;
  550. }
  551. #endif
  552. default:
  553. break;
  554. }
  555. }
  556. ret = rock_continue(&rs);
  557. if (ret == 0)
  558. goto repeat;
  559. if (ret == 1)
  560. ret = 0;
  561. out:
  562. kfree(rs.buffer);
  563. return ret;
  564. eio:
  565. ret = -EIO;
  566. goto out;
  567. }
  568. static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
  569. {
  570. int slen;
  571. int rootflag;
  572. struct SL_component *oldslp;
  573. struct SL_component *slp;
  574. slen = rr->len - 5;
  575. slp = &rr->u.SL.link;
  576. while (slen > 1) {
  577. rootflag = 0;
  578. switch (slp->flags & ~1) {
  579. case 0:
  580. if (slp->len > plimit - rpnt)
  581. return NULL;
  582. memcpy(rpnt, slp->text, slp->len);
  583. rpnt += slp->len;
  584. break;
  585. case 2:
  586. if (rpnt >= plimit)
  587. return NULL;
  588. *rpnt++ = '.';
  589. break;
  590. case 4:
  591. if (2 > plimit - rpnt)
  592. return NULL;
  593. *rpnt++ = '.';
  594. *rpnt++ = '.';
  595. break;
  596. case 8:
  597. if (rpnt >= plimit)
  598. return NULL;
  599. rootflag = 1;
  600. *rpnt++ = '/';
  601. break;
  602. default:
  603. printk("Symlink component flag not implemented (%d)\n",
  604. slp->flags);
  605. }
  606. slen -= slp->len + 2;
  607. oldslp = slp;
  608. slp = (struct SL_component *)((char *)slp + slp->len + 2);
  609. if (slen < 2) {
  610. /*
  611. * If there is another SL record, and this component
  612. * record isn't continued, then add a slash.
  613. */
  614. if ((!rootflag) && (rr->u.SL.flags & 1) &&
  615. !(oldslp->flags & 1)) {
  616. if (rpnt >= plimit)
  617. return NULL;
  618. *rpnt++ = '/';
  619. }
  620. break;
  621. }
  622. /*
  623. * If this component record isn't continued, then append a '/'.
  624. */
  625. if (!rootflag && !(oldslp->flags & 1)) {
  626. if (rpnt >= plimit)
  627. return NULL;
  628. *rpnt++ = '/';
  629. }
  630. }
  631. return rpnt;
  632. }
  633. int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode,
  634. int relocated)
  635. {
  636. int flags = relocated ? RR_RELOC_DE : 0;
  637. int result = parse_rock_ridge_inode_internal(de, inode, flags);
  638. /*
  639. * if rockridge flag was reset and we didn't look for attributes
  640. * behind eventual XA attributes, have a look there
  641. */
  642. if ((ISOFS_SB(inode->i_sb)->s_rock_offset == -1)
  643. && (ISOFS_SB(inode->i_sb)->s_rock == 2)) {
  644. result = parse_rock_ridge_inode_internal(de, inode,
  645. flags | RR_REGARD_XA);
  646. }
  647. return result;
  648. }
  649. /*
  650. * readpage() for symlinks: reads symlink contents into the page and either
  651. * makes it uptodate and returns 0 or returns error (-EIO)
  652. */
  653. static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
  654. {
  655. struct inode *inode = page->mapping->host;
  656. struct iso_inode_info *ei = ISOFS_I(inode);
  657. struct isofs_sb_info *sbi = ISOFS_SB(inode->i_sb);
  658. char *link = page_address(page);
  659. unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
  660. struct buffer_head *bh;
  661. char *rpnt = link;
  662. unsigned char *pnt;
  663. struct iso_directory_record *raw_de;
  664. unsigned long block, offset;
  665. int sig;
  666. struct rock_ridge *rr;
  667. struct rock_state rs;
  668. int ret;
  669. if (!sbi->s_rock)
  670. goto error;
  671. init_rock_state(&rs, inode);
  672. block = ei->i_iget5_block;
  673. bh = sb_bread(inode->i_sb, block);
  674. if (!bh)
  675. goto out_noread;
  676. offset = ei->i_iget5_offset;
  677. pnt = (unsigned char *)bh->b_data + offset;
  678. raw_de = (struct iso_directory_record *)pnt;
  679. /*
  680. * If we go past the end of the buffer, there is some sort of error.
  681. */
  682. if (offset + *pnt > bufsize)
  683. goto out_bad_span;
  684. /*
  685. * Now test for possible Rock Ridge extensions which will override
  686. * some of these numbers in the inode structure.
  687. */
  688. setup_rock_ridge(raw_de, inode, &rs);
  689. repeat:
  690. while (rs.len > 2) { /* There may be one byte for padding somewhere */
  691. rr = (struct rock_ridge *)rs.chr;
  692. if (rr->len < 3)
  693. goto out; /* Something got screwed up here */
  694. sig = isonum_721(rs.chr);
  695. if (rock_check_overflow(&rs, sig))
  696. goto out;
  697. rs.chr += rr->len;
  698. rs.len -= rr->len;
  699. if (rs.len < 0)
  700. goto out; /* corrupted isofs */
  701. switch (sig) {
  702. case SIG('R', 'R'):
  703. if ((rr->u.RR.flags[0] & RR_SL) == 0)
  704. goto out;
  705. break;
  706. case SIG('S', 'P'):
  707. if (check_sp(rr, inode))
  708. goto out;
  709. break;
  710. case SIG('S', 'L'):
  711. rpnt = get_symlink_chunk(rpnt, rr,
  712. link + (PAGE_SIZE - 1));
  713. if (rpnt == NULL)
  714. goto out;
  715. break;
  716. case SIG('C', 'E'):
  717. /* This tells is if there is a continuation record */
  718. rs.cont_extent = isonum_733(rr->u.CE.extent);
  719. rs.cont_offset = isonum_733(rr->u.CE.offset);
  720. rs.cont_size = isonum_733(rr->u.CE.size);
  721. default:
  722. break;
  723. }
  724. }
  725. ret = rock_continue(&rs);
  726. if (ret == 0)
  727. goto repeat;
  728. if (ret < 0)
  729. goto fail;
  730. if (rpnt == link)
  731. goto fail;
  732. brelse(bh);
  733. *rpnt = '\0';
  734. SetPageUptodate(page);
  735. unlock_page(page);
  736. return 0;
  737. /* error exit from macro */
  738. out:
  739. kfree(rs.buffer);
  740. goto fail;
  741. out_noread:
  742. printk("unable to read i-node block");
  743. goto fail;
  744. out_bad_span:
  745. printk("symlink spans iso9660 blocks\n");
  746. fail:
  747. brelse(bh);
  748. error:
  749. SetPageError(page);
  750. unlock_page(page);
  751. return -EIO;
  752. }
  753. const struct address_space_operations isofs_symlink_aops = {
  754. .readpage = rock_ridge_symlink_readpage
  755. };