inode.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. /*
  2. * linux/fs/isofs/inode.c
  3. *
  4. * (C) 1991 Linus Torvalds - minix filesystem
  5. * 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem.
  6. * 1994 Eberhard Mönkeberg - multi session handling.
  7. * 1995 Mark Dobie - allow mounting of some weird VideoCDs and PhotoCDs.
  8. * 1997 Gordon Chaffee - Joliet CDs
  9. * 1998 Eric Lammerts - ISO 9660 Level 3
  10. * 2004 Paul Serice - Inode Support pushed out from 4GB to 128GB
  11. * 2004 Paul Serice - NFS Export Operations
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/nls.h>
  17. #include <linux/ctype.h>
  18. #include <linux/smp_lock.h>
  19. #include <linux/statfs.h>
  20. #include <linux/cdrom.h>
  21. #include <linux/parser.h>
  22. #include "isofs.h"
  23. #include "zisofs.h"
  24. #define BEQUIET
  25. static int isofs_hashi(struct dentry *parent, struct qstr *qstr);
  26. static int isofs_hash(struct dentry *parent, struct qstr *qstr);
  27. static int isofs_dentry_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
  28. static int isofs_dentry_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b);
  29. #ifdef CONFIG_JOLIET
  30. static int isofs_hashi_ms(struct dentry *parent, struct qstr *qstr);
  31. static int isofs_hash_ms(struct dentry *parent, struct qstr *qstr);
  32. static int isofs_dentry_cmpi_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
  33. static int isofs_dentry_cmp_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
  34. #endif
  35. static void isofs_put_super(struct super_block *sb)
  36. {
  37. struct isofs_sb_info *sbi = ISOFS_SB(sb);
  38. #ifdef CONFIG_JOLIET
  39. if (sbi->s_nls_iocharset) {
  40. unload_nls(sbi->s_nls_iocharset);
  41. sbi->s_nls_iocharset = NULL;
  42. }
  43. #endif
  44. kfree(sbi);
  45. sb->s_fs_info = NULL;
  46. return;
  47. }
  48. static int isofs_read_inode(struct inode *);
  49. static int isofs_statfs (struct dentry *, struct kstatfs *);
  50. static struct kmem_cache *isofs_inode_cachep;
  51. static struct inode *isofs_alloc_inode(struct super_block *sb)
  52. {
  53. struct iso_inode_info *ei;
  54. ei = kmem_cache_alloc(isofs_inode_cachep, GFP_KERNEL);
  55. if (!ei)
  56. return NULL;
  57. return &ei->vfs_inode;
  58. }
  59. static void isofs_destroy_inode(struct inode *inode)
  60. {
  61. kmem_cache_free(isofs_inode_cachep, ISOFS_I(inode));
  62. }
  63. static void init_once(struct kmem_cache *cachep, void *foo)
  64. {
  65. struct iso_inode_info *ei = foo;
  66. inode_init_once(&ei->vfs_inode);
  67. }
  68. static int init_inodecache(void)
  69. {
  70. isofs_inode_cachep = kmem_cache_create("isofs_inode_cache",
  71. sizeof(struct iso_inode_info),
  72. 0, (SLAB_RECLAIM_ACCOUNT|
  73. SLAB_MEM_SPREAD),
  74. init_once);
  75. if (isofs_inode_cachep == NULL)
  76. return -ENOMEM;
  77. return 0;
  78. }
  79. static void destroy_inodecache(void)
  80. {
  81. kmem_cache_destroy(isofs_inode_cachep);
  82. }
  83. static int isofs_remount(struct super_block *sb, int *flags, char *data)
  84. {
  85. /* we probably want a lot more here */
  86. *flags |= MS_RDONLY;
  87. return 0;
  88. }
  89. static const struct super_operations isofs_sops = {
  90. .alloc_inode = isofs_alloc_inode,
  91. .destroy_inode = isofs_destroy_inode,
  92. .put_super = isofs_put_super,
  93. .statfs = isofs_statfs,
  94. .remount_fs = isofs_remount,
  95. };
  96. static struct dentry_operations isofs_dentry_ops[] = {
  97. {
  98. .d_hash = isofs_hash,
  99. .d_compare = isofs_dentry_cmp,
  100. },
  101. {
  102. .d_hash = isofs_hashi,
  103. .d_compare = isofs_dentry_cmpi,
  104. },
  105. #ifdef CONFIG_JOLIET
  106. {
  107. .d_hash = isofs_hash_ms,
  108. .d_compare = isofs_dentry_cmp_ms,
  109. },
  110. {
  111. .d_hash = isofs_hashi_ms,
  112. .d_compare = isofs_dentry_cmpi_ms,
  113. },
  114. #endif
  115. };
  116. struct iso9660_options{
  117. char map;
  118. char rock;
  119. char joliet;
  120. char cruft;
  121. char hide;
  122. char showassoc;
  123. char nocompress;
  124. unsigned char check;
  125. unsigned int blocksize;
  126. mode_t mode;
  127. gid_t gid;
  128. uid_t uid;
  129. char *iocharset;
  130. unsigned char utf8;
  131. /* LVE */
  132. s32 session;
  133. s32 sbsector;
  134. };
  135. /*
  136. * Compute the hash for the isofs name corresponding to the dentry.
  137. */
  138. static int
  139. isofs_hash_common(struct dentry *dentry, struct qstr *qstr, int ms)
  140. {
  141. const char *name;
  142. int len;
  143. len = qstr->len;
  144. name = qstr->name;
  145. if (ms) {
  146. while (len && name[len-1] == '.')
  147. len--;
  148. }
  149. qstr->hash = full_name_hash(name, len);
  150. return 0;
  151. }
  152. /*
  153. * Compute the hash for the isofs name corresponding to the dentry.
  154. */
  155. static int
  156. isofs_hashi_common(struct dentry *dentry, struct qstr *qstr, int ms)
  157. {
  158. const char *name;
  159. int len;
  160. char c;
  161. unsigned long hash;
  162. len = qstr->len;
  163. name = qstr->name;
  164. if (ms) {
  165. while (len && name[len-1] == '.')
  166. len--;
  167. }
  168. hash = init_name_hash();
  169. while (len--) {
  170. c = tolower(*name++);
  171. hash = partial_name_hash(c, hash);
  172. }
  173. qstr->hash = end_name_hash(hash);
  174. return 0;
  175. }
  176. /*
  177. * Case insensitive compare of two isofs names.
  178. */
  179. static int isofs_dentry_cmpi_common(struct dentry *dentry, struct qstr *a,
  180. struct qstr *b, int ms)
  181. {
  182. int alen, blen;
  183. /* A filename cannot end in '.' or we treat it like it has none */
  184. alen = a->len;
  185. blen = b->len;
  186. if (ms) {
  187. while (alen && a->name[alen-1] == '.')
  188. alen--;
  189. while (blen && b->name[blen-1] == '.')
  190. blen--;
  191. }
  192. if (alen == blen) {
  193. if (strnicmp(a->name, b->name, alen) == 0)
  194. return 0;
  195. }
  196. return 1;
  197. }
  198. /*
  199. * Case sensitive compare of two isofs names.
  200. */
  201. static int isofs_dentry_cmp_common(struct dentry *dentry, struct qstr *a,
  202. struct qstr *b, int ms)
  203. {
  204. int alen, blen;
  205. /* A filename cannot end in '.' or we treat it like it has none */
  206. alen = a->len;
  207. blen = b->len;
  208. if (ms) {
  209. while (alen && a->name[alen-1] == '.')
  210. alen--;
  211. while (blen && b->name[blen-1] == '.')
  212. blen--;
  213. }
  214. if (alen == blen) {
  215. if (strncmp(a->name, b->name, alen) == 0)
  216. return 0;
  217. }
  218. return 1;
  219. }
  220. static int
  221. isofs_hash(struct dentry *dentry, struct qstr *qstr)
  222. {
  223. return isofs_hash_common(dentry, qstr, 0);
  224. }
  225. static int
  226. isofs_hashi(struct dentry *dentry, struct qstr *qstr)
  227. {
  228. return isofs_hashi_common(dentry, qstr, 0);
  229. }
  230. static int
  231. isofs_dentry_cmp(struct dentry *dentry,struct qstr *a,struct qstr *b)
  232. {
  233. return isofs_dentry_cmp_common(dentry, a, b, 0);
  234. }
  235. static int
  236. isofs_dentry_cmpi(struct dentry *dentry,struct qstr *a,struct qstr *b)
  237. {
  238. return isofs_dentry_cmpi_common(dentry, a, b, 0);
  239. }
  240. #ifdef CONFIG_JOLIET
  241. static int
  242. isofs_hash_ms(struct dentry *dentry, struct qstr *qstr)
  243. {
  244. return isofs_hash_common(dentry, qstr, 1);
  245. }
  246. static int
  247. isofs_hashi_ms(struct dentry *dentry, struct qstr *qstr)
  248. {
  249. return isofs_hashi_common(dentry, qstr, 1);
  250. }
  251. static int
  252. isofs_dentry_cmp_ms(struct dentry *dentry,struct qstr *a,struct qstr *b)
  253. {
  254. return isofs_dentry_cmp_common(dentry, a, b, 1);
  255. }
  256. static int
  257. isofs_dentry_cmpi_ms(struct dentry *dentry,struct qstr *a,struct qstr *b)
  258. {
  259. return isofs_dentry_cmpi_common(dentry, a, b, 1);
  260. }
  261. #endif
  262. enum {
  263. Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore,
  264. Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet,
  265. Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err,
  266. Opt_nocompress, Opt_hide, Opt_showassoc,
  267. };
  268. static match_table_t tokens = {
  269. {Opt_norock, "norock"},
  270. {Opt_nojoliet, "nojoliet"},
  271. {Opt_unhide, "unhide"},
  272. {Opt_hide, "hide"},
  273. {Opt_showassoc, "showassoc"},
  274. {Opt_cruft, "cruft"},
  275. {Opt_utf8, "utf8"},
  276. {Opt_iocharset, "iocharset=%s"},
  277. {Opt_map_a, "map=acorn"},
  278. {Opt_map_a, "map=a"},
  279. {Opt_map_n, "map=normal"},
  280. {Opt_map_n, "map=n"},
  281. {Opt_map_o, "map=off"},
  282. {Opt_map_o, "map=o"},
  283. {Opt_session, "session=%u"},
  284. {Opt_sb, "sbsector=%u"},
  285. {Opt_check_r, "check=relaxed"},
  286. {Opt_check_r, "check=r"},
  287. {Opt_check_s, "check=strict"},
  288. {Opt_check_s, "check=s"},
  289. {Opt_uid, "uid=%u"},
  290. {Opt_gid, "gid=%u"},
  291. {Opt_mode, "mode=%u"},
  292. {Opt_block, "block=%u"},
  293. {Opt_ignore, "conv=binary"},
  294. {Opt_ignore, "conv=b"},
  295. {Opt_ignore, "conv=text"},
  296. {Opt_ignore, "conv=t"},
  297. {Opt_ignore, "conv=mtext"},
  298. {Opt_ignore, "conv=m"},
  299. {Opt_ignore, "conv=auto"},
  300. {Opt_ignore, "conv=a"},
  301. {Opt_nocompress, "nocompress"},
  302. {Opt_err, NULL}
  303. };
  304. static int parse_options(char *options, struct iso9660_options *popt)
  305. {
  306. char *p;
  307. int option;
  308. popt->map = 'n';
  309. popt->rock = 'y';
  310. popt->joliet = 'y';
  311. popt->cruft = 'n';
  312. popt->hide = 'n';
  313. popt->showassoc = 'n';
  314. popt->check = 'u'; /* unset */
  315. popt->nocompress = 0;
  316. popt->blocksize = 1024;
  317. popt->mode = S_IRUGO | S_IXUGO; /*
  318. * r-x for all. The disc could
  319. * be shared with DOS machines so
  320. * virtually anything could be
  321. * a valid executable.
  322. */
  323. popt->gid = 0;
  324. popt->uid = 0;
  325. popt->iocharset = NULL;
  326. popt->utf8 = 0;
  327. popt->session=-1;
  328. popt->sbsector=-1;
  329. if (!options)
  330. return 1;
  331. while ((p = strsep(&options, ",")) != NULL) {
  332. int token;
  333. substring_t args[MAX_OPT_ARGS];
  334. unsigned n;
  335. if (!*p)
  336. continue;
  337. token = match_token(p, tokens, args);
  338. switch (token) {
  339. case Opt_norock:
  340. popt->rock = 'n';
  341. break;
  342. case Opt_nojoliet:
  343. popt->joliet = 'n';
  344. break;
  345. case Opt_hide:
  346. popt->hide = 'y';
  347. break;
  348. case Opt_unhide:
  349. case Opt_showassoc:
  350. popt->showassoc = 'y';
  351. break;
  352. case Opt_cruft:
  353. popt->cruft = 'y';
  354. break;
  355. case Opt_utf8:
  356. popt->utf8 = 1;
  357. break;
  358. #ifdef CONFIG_JOLIET
  359. case Opt_iocharset:
  360. popt->iocharset = match_strdup(&args[0]);
  361. break;
  362. #endif
  363. case Opt_map_a:
  364. popt->map = 'a';
  365. break;
  366. case Opt_map_o:
  367. popt->map = 'o';
  368. break;
  369. case Opt_map_n:
  370. popt->map = 'n';
  371. break;
  372. case Opt_session:
  373. if (match_int(&args[0], &option))
  374. return 0;
  375. n = option;
  376. if (n > 99)
  377. return 0;
  378. popt->session = n + 1;
  379. break;
  380. case Opt_sb:
  381. if (match_int(&args[0], &option))
  382. return 0;
  383. popt->sbsector = option;
  384. break;
  385. case Opt_check_r:
  386. popt->check = 'r';
  387. break;
  388. case Opt_check_s:
  389. popt->check = 's';
  390. break;
  391. case Opt_ignore:
  392. break;
  393. case Opt_uid:
  394. if (match_int(&args[0], &option))
  395. return 0;
  396. popt->uid = option;
  397. break;
  398. case Opt_gid:
  399. if (match_int(&args[0], &option))
  400. return 0;
  401. popt->gid = option;
  402. break;
  403. case Opt_mode:
  404. if (match_int(&args[0], &option))
  405. return 0;
  406. popt->mode = option;
  407. break;
  408. case Opt_block:
  409. if (match_int(&args[0], &option))
  410. return 0;
  411. n = option;
  412. if (n != 512 && n != 1024 && n != 2048)
  413. return 0;
  414. popt->blocksize = n;
  415. break;
  416. case Opt_nocompress:
  417. popt->nocompress = 1;
  418. break;
  419. default:
  420. return 0;
  421. }
  422. }
  423. return 1;
  424. }
  425. /*
  426. * look if the driver can tell the multi session redirection value
  427. *
  428. * don't change this if you don't know what you do, please!
  429. * Multisession is legal only with XA disks.
  430. * A non-XA disk with more than one volume descriptor may do it right, but
  431. * usually is written in a nowhere standardized "multi-partition" manner.
  432. * Multisession uses absolute addressing (solely the first frame of the whole
  433. * track is #0), multi-partition uses relative addressing (each first frame of
  434. * each track is #0), and a track is not a session.
  435. *
  436. * A broken CDwriter software or drive firmware does not set new standards,
  437. * at least not if conflicting with the existing ones.
  438. *
  439. * emoenke@gwdg.de
  440. */
  441. #define WE_OBEY_THE_WRITTEN_STANDARDS 1
  442. static unsigned int isofs_get_last_session(struct super_block *sb, s32 session)
  443. {
  444. struct cdrom_multisession ms_info;
  445. unsigned int vol_desc_start;
  446. struct block_device *bdev = sb->s_bdev;
  447. int i;
  448. vol_desc_start=0;
  449. ms_info.addr_format=CDROM_LBA;
  450. if(session >= 0 && session <= 99) {
  451. struct cdrom_tocentry Te;
  452. Te.cdte_track=session;
  453. Te.cdte_format=CDROM_LBA;
  454. i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te);
  455. if (!i) {
  456. printk(KERN_DEBUG "ISOFS: Session %d start %d type %d\n",
  457. session, Te.cdte_addr.lba,
  458. Te.cdte_ctrl&CDROM_DATA_TRACK);
  459. if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4)
  460. return Te.cdte_addr.lba;
  461. }
  462. printk(KERN_ERR "ISOFS: Invalid session number or type of track\n");
  463. }
  464. i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info);
  465. if (session > 0)
  466. printk(KERN_ERR "ISOFS: Invalid session number\n");
  467. #if 0
  468. printk(KERN_DEBUG "isofs.inode: CDROMMULTISESSION: rc=%d\n",i);
  469. if (i==0) {
  470. printk(KERN_DEBUG "isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no");
  471. printk(KERN_DEBUG "isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba);
  472. }
  473. #endif
  474. if (i==0)
  475. #if WE_OBEY_THE_WRITTEN_STANDARDS
  476. if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
  477. #endif
  478. vol_desc_start=ms_info.addr.lba;
  479. return vol_desc_start;
  480. }
  481. /*
  482. * Initialize the superblock and read the root inode.
  483. *
  484. * Note: a check_disk_change() has been done immediately prior
  485. * to this call, so we don't need to check again.
  486. */
  487. static int isofs_fill_super(struct super_block *s, void *data, int silent)
  488. {
  489. struct buffer_head *bh = NULL, *pri_bh = NULL;
  490. struct hs_primary_descriptor *h_pri = NULL;
  491. struct iso_primary_descriptor *pri = NULL;
  492. struct iso_supplementary_descriptor *sec = NULL;
  493. struct iso_directory_record *rootp;
  494. struct inode *inode;
  495. struct iso9660_options opt;
  496. struct isofs_sb_info *sbi;
  497. unsigned long first_data_zone;
  498. int joliet_level = 0;
  499. int iso_blknum, block;
  500. int orig_zonesize;
  501. int table, error = -EINVAL;
  502. unsigned int vol_desc_start;
  503. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  504. if (!sbi)
  505. return -ENOMEM;
  506. s->s_fs_info = sbi;
  507. if (!parse_options((char *)data, &opt))
  508. goto out_freesbi;
  509. /*
  510. * First of all, get the hardware blocksize for this device.
  511. * If we don't know what it is, or the hardware blocksize is
  512. * larger than the blocksize the user specified, then use
  513. * that value.
  514. */
  515. /*
  516. * What if bugger tells us to go beyond page size?
  517. */
  518. opt.blocksize = sb_min_blocksize(s, opt.blocksize);
  519. sbi->s_high_sierra = 0; /* default is iso9660 */
  520. vol_desc_start = (opt.sbsector != -1) ?
  521. opt.sbsector : isofs_get_last_session(s,opt.session);
  522. for (iso_blknum = vol_desc_start+16;
  523. iso_blknum < vol_desc_start+100; iso_blknum++) {
  524. struct hs_volume_descriptor *hdp;
  525. struct iso_volume_descriptor *vdp;
  526. block = iso_blknum << (ISOFS_BLOCK_BITS - s->s_blocksize_bits);
  527. if (!(bh = sb_bread(s, block)))
  528. goto out_no_read;
  529. vdp = (struct iso_volume_descriptor *)bh->b_data;
  530. hdp = (struct hs_volume_descriptor *)bh->b_data;
  531. /*
  532. * Due to the overlapping physical location of the descriptors,
  533. * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
  534. * proper identification in this case, we first check for ISO.
  535. */
  536. if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) {
  537. if (isonum_711(vdp->type) == ISO_VD_END)
  538. break;
  539. if (isonum_711(vdp->type) == ISO_VD_PRIMARY) {
  540. if (pri == NULL) {
  541. pri = (struct iso_primary_descriptor *)vdp;
  542. /* Save the buffer in case we need it ... */
  543. pri_bh = bh;
  544. bh = NULL;
  545. }
  546. }
  547. #ifdef CONFIG_JOLIET
  548. else if (isonum_711(vdp->type) == ISO_VD_SUPPLEMENTARY) {
  549. sec = (struct iso_supplementary_descriptor *)vdp;
  550. if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) {
  551. if (opt.joliet == 'y') {
  552. if (sec->escape[2] == 0x40)
  553. joliet_level = 1;
  554. else if (sec->escape[2] == 0x43)
  555. joliet_level = 2;
  556. else if (sec->escape[2] == 0x45)
  557. joliet_level = 3;
  558. printk(KERN_DEBUG "ISO 9660 Extensions: "
  559. "Microsoft Joliet Level %d\n",
  560. joliet_level);
  561. }
  562. goto root_found;
  563. } else {
  564. /* Unknown supplementary volume descriptor */
  565. sec = NULL;
  566. }
  567. }
  568. #endif
  569. } else {
  570. if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) {
  571. if (isonum_711(hdp->type) != ISO_VD_PRIMARY)
  572. goto out_freebh;
  573. sbi->s_high_sierra = 1;
  574. opt.rock = 'n';
  575. h_pri = (struct hs_primary_descriptor *)vdp;
  576. goto root_found;
  577. }
  578. }
  579. /* Just skip any volume descriptors we don't recognize */
  580. brelse(bh);
  581. bh = NULL;
  582. }
  583. /*
  584. * If we fall through, either no volume descriptor was found,
  585. * or else we passed a primary descriptor looking for others.
  586. */
  587. if (!pri)
  588. goto out_unknown_format;
  589. brelse(bh);
  590. bh = pri_bh;
  591. pri_bh = NULL;
  592. root_found:
  593. if (joliet_level && (pri == NULL || opt.rock == 'n')) {
  594. /* This is the case of Joliet with the norock mount flag.
  595. * A disc with both Joliet and Rock Ridge is handled later
  596. */
  597. pri = (struct iso_primary_descriptor *) sec;
  598. }
  599. if(sbi->s_high_sierra){
  600. rootp = (struct iso_directory_record *) h_pri->root_directory_record;
  601. sbi->s_nzones = isonum_733(h_pri->volume_space_size);
  602. sbi->s_log_zone_size = isonum_723(h_pri->logical_block_size);
  603. sbi->s_max_size = isonum_733(h_pri->volume_space_size);
  604. } else {
  605. if (!pri)
  606. goto out_freebh;
  607. rootp = (struct iso_directory_record *) pri->root_directory_record;
  608. sbi->s_nzones = isonum_733(pri->volume_space_size);
  609. sbi->s_log_zone_size = isonum_723(pri->logical_block_size);
  610. sbi->s_max_size = isonum_733(pri->volume_space_size);
  611. }
  612. sbi->s_ninodes = 0; /* No way to figure this out easily */
  613. orig_zonesize = sbi->s_log_zone_size;
  614. /*
  615. * If the zone size is smaller than the hardware sector size,
  616. * this is a fatal error. This would occur if the disc drive
  617. * had sectors that were 2048 bytes, but the filesystem had
  618. * blocks that were 512 bytes (which should only very rarely
  619. * happen.)
  620. */
  621. if (orig_zonesize < opt.blocksize)
  622. goto out_bad_size;
  623. /* RDE: convert log zone size to bit shift */
  624. switch (sbi->s_log_zone_size) {
  625. case 512: sbi->s_log_zone_size = 9; break;
  626. case 1024: sbi->s_log_zone_size = 10; break;
  627. case 2048: sbi->s_log_zone_size = 11; break;
  628. default:
  629. goto out_bad_zone_size;
  630. }
  631. s->s_magic = ISOFS_SUPER_MAGIC;
  632. s->s_maxbytes = 0xffffffff; /* We can handle files up to 4 GB */
  633. /*
  634. * The CDROM is read-only, has no nodes (devices) on it, and since
  635. * all of the files appear to be owned by root, we really do not want
  636. * to allow suid. (suid or devices will not show up unless we have
  637. * Rock Ridge extensions)
  638. */
  639. s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */;
  640. /* Set this for reference. Its not currently used except on write
  641. which we don't have .. */
  642. first_data_zone = isonum_733(rootp->extent) +
  643. isonum_711(rootp->ext_attr_length);
  644. sbi->s_firstdatazone = first_data_zone;
  645. #ifndef BEQUIET
  646. printk(KERN_DEBUG "ISOFS: Max size:%ld Log zone size:%ld\n",
  647. sbi->s_max_size, 1UL << sbi->s_log_zone_size);
  648. printk(KERN_DEBUG "ISOFS: First datazone:%ld\n", sbi->s_firstdatazone);
  649. if(sbi->s_high_sierra)
  650. printk(KERN_DEBUG "ISOFS: Disc in High Sierra format.\n");
  651. #endif
  652. /*
  653. * If the Joliet level is set, we _may_ decide to use the
  654. * secondary descriptor, but can't be sure until after we
  655. * read the root inode. But before reading the root inode
  656. * we may need to change the device blocksize, and would
  657. * rather release the old buffer first. So, we cache the
  658. * first_data_zone value from the secondary descriptor.
  659. */
  660. if (joliet_level) {
  661. pri = (struct iso_primary_descriptor *) sec;
  662. rootp = (struct iso_directory_record *)
  663. pri->root_directory_record;
  664. first_data_zone = isonum_733(rootp->extent) +
  665. isonum_711(rootp->ext_attr_length);
  666. }
  667. /*
  668. * We're all done using the volume descriptor, and may need
  669. * to change the device blocksize, so release the buffer now.
  670. */
  671. brelse(pri_bh);
  672. brelse(bh);
  673. /*
  674. * Force the blocksize to 512 for 512 byte sectors. The file
  675. * read primitives really get it wrong in a bad way if we don't
  676. * do this.
  677. *
  678. * Note - we should never be setting the blocksize to something
  679. * less than the hardware sector size for the device. If we
  680. * do, we would end up having to read larger buffers and split
  681. * out portions to satisfy requests.
  682. *
  683. * Note2- the idea here is that we want to deal with the optimal
  684. * zonesize in the filesystem. If we have it set to something less,
  685. * then we have horrible problems with trying to piece together
  686. * bits of adjacent blocks in order to properly read directory
  687. * entries. By forcing the blocksize in this way, we ensure
  688. * that we will never be required to do this.
  689. */
  690. sb_set_blocksize(s, orig_zonesize);
  691. sbi->s_nls_iocharset = NULL;
  692. #ifdef CONFIG_JOLIET
  693. if (joliet_level && opt.utf8 == 0) {
  694. char *p = opt.iocharset ? opt.iocharset : CONFIG_NLS_DEFAULT;
  695. sbi->s_nls_iocharset = load_nls(p);
  696. if (! sbi->s_nls_iocharset) {
  697. /* Fail only if explicit charset specified */
  698. if (opt.iocharset)
  699. goto out_freesbi;
  700. sbi->s_nls_iocharset = load_nls_default();
  701. }
  702. }
  703. #endif
  704. s->s_op = &isofs_sops;
  705. s->s_export_op = &isofs_export_ops;
  706. sbi->s_mapping = opt.map;
  707. sbi->s_rock = (opt.rock == 'y' ? 2 : 0);
  708. sbi->s_rock_offset = -1; /* initial offset, will guess until SP is found*/
  709. sbi->s_cruft = opt.cruft;
  710. sbi->s_hide = opt.hide;
  711. sbi->s_showassoc = opt.showassoc;
  712. sbi->s_uid = opt.uid;
  713. sbi->s_gid = opt.gid;
  714. sbi->s_utf8 = opt.utf8;
  715. sbi->s_nocompress = opt.nocompress;
  716. /*
  717. * It would be incredibly stupid to allow people to mark every file
  718. * on the disk as suid, so we merely allow them to set the default
  719. * permissions.
  720. */
  721. sbi->s_mode = opt.mode & 0777;
  722. /*
  723. * Read the root inode, which _may_ result in changing
  724. * the s_rock flag. Once we have the final s_rock value,
  725. * we then decide whether to use the Joliet descriptor.
  726. */
  727. inode = isofs_iget(s, sbi->s_firstdatazone, 0);
  728. if (IS_ERR(inode))
  729. goto out_no_root;
  730. /*
  731. * If this disk has both Rock Ridge and Joliet on it, then we
  732. * want to use Rock Ridge by default. This can be overridden
  733. * by using the norock mount option. There is still one other
  734. * possibility that is not taken into account: a Rock Ridge
  735. * CD with Unicode names. Until someone sees such a beast, it
  736. * will not be supported.
  737. */
  738. if (sbi->s_rock == 1) {
  739. joliet_level = 0;
  740. } else if (joliet_level) {
  741. sbi->s_rock = 0;
  742. if (sbi->s_firstdatazone != first_data_zone) {
  743. sbi->s_firstdatazone = first_data_zone;
  744. printk(KERN_DEBUG
  745. "ISOFS: changing to secondary root\n");
  746. iput(inode);
  747. inode = isofs_iget(s, sbi->s_firstdatazone, 0);
  748. if (IS_ERR(inode))
  749. goto out_no_root;
  750. }
  751. }
  752. if (opt.check == 'u') {
  753. /* Only Joliet is case insensitive by default */
  754. if (joliet_level)
  755. opt.check = 'r';
  756. else
  757. opt.check = 's';
  758. }
  759. sbi->s_joliet_level = joliet_level;
  760. /* check the root inode */
  761. if (!inode->i_op)
  762. goto out_bad_root;
  763. /* Make sure the root inode is a directory */
  764. if (!S_ISDIR(inode->i_mode)) {
  765. printk(KERN_WARNING
  766. "isofs_fill_super: root inode is not a directory. "
  767. "Corrupted media?\n");
  768. goto out_iput;
  769. }
  770. /* get the root dentry */
  771. s->s_root = d_alloc_root(inode);
  772. if (!(s->s_root))
  773. goto out_no_root;
  774. table = 0;
  775. if (joliet_level)
  776. table += 2;
  777. if (opt.check == 'r')
  778. table++;
  779. s->s_root->d_op = &isofs_dentry_ops[table];
  780. kfree(opt.iocharset);
  781. return 0;
  782. /*
  783. * Display error messages and free resources.
  784. */
  785. out_bad_root:
  786. printk(KERN_WARNING "%s: root inode not initialized\n", __func__);
  787. out_iput:
  788. iput(inode);
  789. goto out_no_inode;
  790. out_no_root:
  791. error = PTR_ERR(inode);
  792. if (error != -ENOMEM)
  793. printk(KERN_WARNING "%s: get root inode failed\n", __func__);
  794. out_no_inode:
  795. #ifdef CONFIG_JOLIET
  796. if (sbi->s_nls_iocharset)
  797. unload_nls(sbi->s_nls_iocharset);
  798. #endif
  799. goto out_freesbi;
  800. out_no_read:
  801. printk(KERN_WARNING "%s: bread failed, dev=%s, iso_blknum=%d, block=%d\n",
  802. __func__, s->s_id, iso_blknum, block);
  803. goto out_freesbi;
  804. out_bad_zone_size:
  805. printk(KERN_WARNING "ISOFS: Bad logical zone size %ld\n",
  806. sbi->s_log_zone_size);
  807. goto out_freebh;
  808. out_bad_size:
  809. printk(KERN_WARNING "ISOFS: Logical zone size(%d) < hardware blocksize(%u)\n",
  810. orig_zonesize, opt.blocksize);
  811. goto out_freebh;
  812. out_unknown_format:
  813. if (!silent)
  814. printk(KERN_WARNING "ISOFS: Unable to identify CD-ROM format.\n");
  815. out_freebh:
  816. brelse(bh);
  817. out_freesbi:
  818. kfree(opt.iocharset);
  819. kfree(sbi);
  820. s->s_fs_info = NULL;
  821. return error;
  822. }
  823. static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
  824. {
  825. struct super_block *sb = dentry->d_sb;
  826. buf->f_type = ISOFS_SUPER_MAGIC;
  827. buf->f_bsize = sb->s_blocksize;
  828. buf->f_blocks = (ISOFS_SB(sb)->s_nzones
  829. << (ISOFS_SB(sb)->s_log_zone_size - sb->s_blocksize_bits));
  830. buf->f_bfree = 0;
  831. buf->f_bavail = 0;
  832. buf->f_files = ISOFS_SB(sb)->s_ninodes;
  833. buf->f_ffree = 0;
  834. buf->f_namelen = NAME_MAX;
  835. return 0;
  836. }
  837. /*
  838. * Get a set of blocks; filling in buffer_heads if already allocated
  839. * or getblk() if they are not. Returns the number of blocks inserted
  840. * (-ve == error.)
  841. */
  842. int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
  843. struct buffer_head **bh, unsigned long nblocks)
  844. {
  845. unsigned long b_off;
  846. unsigned offset, sect_size;
  847. unsigned int firstext;
  848. unsigned long nextblk, nextoff;
  849. long iblock = (long)iblock_s;
  850. int section, rv, error;
  851. struct iso_inode_info *ei = ISOFS_I(inode);
  852. lock_kernel();
  853. error = -EIO;
  854. rv = 0;
  855. if (iblock < 0 || iblock != iblock_s) {
  856. printk(KERN_DEBUG "%s: block number too large\n", __func__);
  857. goto abort;
  858. }
  859. b_off = iblock;
  860. offset = 0;
  861. firstext = ei->i_first_extent;
  862. sect_size = ei->i_section_size >> ISOFS_BUFFER_BITS(inode);
  863. nextblk = ei->i_next_section_block;
  864. nextoff = ei->i_next_section_offset;
  865. section = 0;
  866. while (nblocks) {
  867. /* If we are *way* beyond the end of the file, print a message.
  868. * Access beyond the end of the file up to the next page boundary
  869. * is normal, however because of the way the page cache works.
  870. * In this case, we just return 0 so that we can properly fill
  871. * the page with useless information without generating any
  872. * I/O errors.
  873. */
  874. if (b_off > ((inode->i_size + PAGE_CACHE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) {
  875. printk(KERN_DEBUG "%s: block >= EOF (%ld, %ld)\n",
  876. __func__, iblock, (unsigned long) inode->i_size);
  877. goto abort;
  878. }
  879. /* On the last section, nextblk == 0, section size is likely to
  880. * exceed sect_size by a partial block, and access beyond the
  881. * end of the file will reach beyond the section size, too.
  882. */
  883. while (nextblk && (b_off >= (offset + sect_size))) {
  884. struct inode *ninode;
  885. offset += sect_size;
  886. ninode = isofs_iget(inode->i_sb, nextblk, nextoff);
  887. if (IS_ERR(ninode)) {
  888. error = PTR_ERR(ninode);
  889. goto abort;
  890. }
  891. firstext = ISOFS_I(ninode)->i_first_extent;
  892. sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode);
  893. nextblk = ISOFS_I(ninode)->i_next_section_block;
  894. nextoff = ISOFS_I(ninode)->i_next_section_offset;
  895. iput(ninode);
  896. if (++section > 100) {
  897. printk(KERN_DEBUG "%s: More than 100 file sections ?!?"
  898. " aborting...\n", __func__);
  899. printk(KERN_DEBUG "%s: block=%ld firstext=%u sect_size=%u "
  900. "nextblk=%lu nextoff=%lu\n", __func__,
  901. iblock, firstext, (unsigned) sect_size,
  902. nextblk, nextoff);
  903. goto abort;
  904. }
  905. }
  906. if (*bh) {
  907. map_bh(*bh, inode->i_sb, firstext + b_off - offset);
  908. } else {
  909. *bh = sb_getblk(inode->i_sb, firstext+b_off-offset);
  910. if (!*bh)
  911. goto abort;
  912. }
  913. bh++; /* Next buffer head */
  914. b_off++; /* Next buffer offset */
  915. nblocks--;
  916. rv++;
  917. }
  918. error = 0;
  919. abort:
  920. unlock_kernel();
  921. return rv != 0 ? rv : error;
  922. }
  923. /*
  924. * Used by the standard interfaces.
  925. */
  926. static int isofs_get_block(struct inode *inode, sector_t iblock,
  927. struct buffer_head *bh_result, int create)
  928. {
  929. int ret;
  930. if (create) {
  931. printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__);
  932. return -EROFS;
  933. }
  934. ret = isofs_get_blocks(inode, iblock, &bh_result, 1);
  935. return ret < 0 ? ret : 0;
  936. }
  937. static int isofs_bmap(struct inode *inode, sector_t block)
  938. {
  939. struct buffer_head dummy;
  940. int error;
  941. dummy.b_state = 0;
  942. dummy.b_blocknr = -1000;
  943. error = isofs_get_block(inode, block, &dummy, 0);
  944. if (!error)
  945. return dummy.b_blocknr;
  946. return 0;
  947. }
  948. struct buffer_head *isofs_bread(struct inode *inode, sector_t block)
  949. {
  950. sector_t blknr = isofs_bmap(inode, block);
  951. if (!blknr)
  952. return NULL;
  953. return sb_bread(inode->i_sb, blknr);
  954. }
  955. static int isofs_readpage(struct file *file, struct page *page)
  956. {
  957. return block_read_full_page(page,isofs_get_block);
  958. }
  959. static sector_t _isofs_bmap(struct address_space *mapping, sector_t block)
  960. {
  961. return generic_block_bmap(mapping,block,isofs_get_block);
  962. }
  963. static const struct address_space_operations isofs_aops = {
  964. .readpage = isofs_readpage,
  965. .sync_page = block_sync_page,
  966. .bmap = _isofs_bmap
  967. };
  968. static inline void test_and_set_uid(uid_t *p, uid_t value)
  969. {
  970. if (value)
  971. *p = value;
  972. }
  973. static inline void test_and_set_gid(gid_t *p, gid_t value)
  974. {
  975. if (value)
  976. *p = value;
  977. }
  978. static int isofs_read_level3_size(struct inode *inode)
  979. {
  980. unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
  981. int high_sierra = ISOFS_SB(inode->i_sb)->s_high_sierra;
  982. struct buffer_head *bh = NULL;
  983. unsigned long block, offset, block_saved, offset_saved;
  984. int i = 0;
  985. int more_entries = 0;
  986. struct iso_directory_record *tmpde = NULL;
  987. struct iso_inode_info *ei = ISOFS_I(inode);
  988. inode->i_size = 0;
  989. /* The first 16 blocks are reserved as the System Area. Thus,
  990. * no inodes can appear in block 0. We use this to flag that
  991. * this is the last section. */
  992. ei->i_next_section_block = 0;
  993. ei->i_next_section_offset = 0;
  994. block = ei->i_iget5_block;
  995. offset = ei->i_iget5_offset;
  996. do {
  997. struct iso_directory_record *de;
  998. unsigned int de_len;
  999. if (!bh) {
  1000. bh = sb_bread(inode->i_sb, block);
  1001. if (!bh)
  1002. goto out_noread;
  1003. }
  1004. de = (struct iso_directory_record *) (bh->b_data + offset);
  1005. de_len = *(unsigned char *) de;
  1006. if (de_len == 0) {
  1007. brelse(bh);
  1008. bh = NULL;
  1009. ++block;
  1010. offset = 0;
  1011. continue;
  1012. }
  1013. block_saved = block;
  1014. offset_saved = offset;
  1015. offset += de_len;
  1016. /* Make sure we have a full directory entry */
  1017. if (offset >= bufsize) {
  1018. int slop = bufsize - offset + de_len;
  1019. if (!tmpde) {
  1020. tmpde = kmalloc(256, GFP_KERNEL);
  1021. if (!tmpde)
  1022. goto out_nomem;
  1023. }
  1024. memcpy(tmpde, de, slop);
  1025. offset &= bufsize - 1;
  1026. block++;
  1027. brelse(bh);
  1028. bh = NULL;
  1029. if (offset) {
  1030. bh = sb_bread(inode->i_sb, block);
  1031. if (!bh)
  1032. goto out_noread;
  1033. memcpy((void *)tmpde+slop, bh->b_data, offset);
  1034. }
  1035. de = tmpde;
  1036. }
  1037. inode->i_size += isonum_733(de->size);
  1038. if (i == 1) {
  1039. ei->i_next_section_block = block_saved;
  1040. ei->i_next_section_offset = offset_saved;
  1041. }
  1042. more_entries = de->flags[-high_sierra] & 0x80;
  1043. i++;
  1044. if (i > 100)
  1045. goto out_toomany;
  1046. } while (more_entries);
  1047. out:
  1048. kfree(tmpde);
  1049. if (bh)
  1050. brelse(bh);
  1051. return 0;
  1052. out_nomem:
  1053. if (bh)
  1054. brelse(bh);
  1055. return -ENOMEM;
  1056. out_noread:
  1057. printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block);
  1058. kfree(tmpde);
  1059. return -EIO;
  1060. out_toomany:
  1061. printk(KERN_INFO "%s: More than 100 file sections ?!?, aborting...\n"
  1062. "isofs_read_level3_size: inode=%lu\n",
  1063. __func__, inode->i_ino);
  1064. goto out;
  1065. }
  1066. static int isofs_read_inode(struct inode *inode)
  1067. {
  1068. struct super_block *sb = inode->i_sb;
  1069. struct isofs_sb_info *sbi = ISOFS_SB(sb);
  1070. unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
  1071. unsigned long block;
  1072. int high_sierra = sbi->s_high_sierra;
  1073. struct buffer_head *bh = NULL;
  1074. struct iso_directory_record *de;
  1075. struct iso_directory_record *tmpde = NULL;
  1076. unsigned int de_len;
  1077. unsigned long offset;
  1078. struct iso_inode_info *ei = ISOFS_I(inode);
  1079. int ret = -EIO;
  1080. block = ei->i_iget5_block;
  1081. bh = sb_bread(inode->i_sb, block);
  1082. if (!bh)
  1083. goto out_badread;
  1084. offset = ei->i_iget5_offset;
  1085. de = (struct iso_directory_record *) (bh->b_data + offset);
  1086. de_len = *(unsigned char *) de;
  1087. if (offset + de_len > bufsize) {
  1088. int frag1 = bufsize - offset;
  1089. tmpde = kmalloc(de_len, GFP_KERNEL);
  1090. if (tmpde == NULL) {
  1091. printk(KERN_INFO "%s: out of memory\n", __func__);
  1092. ret = -ENOMEM;
  1093. goto fail;
  1094. }
  1095. memcpy(tmpde, bh->b_data + offset, frag1);
  1096. brelse(bh);
  1097. bh = sb_bread(inode->i_sb, ++block);
  1098. if (!bh)
  1099. goto out_badread;
  1100. memcpy((char *)tmpde+frag1, bh->b_data, de_len - frag1);
  1101. de = tmpde;
  1102. }
  1103. inode->i_ino = isofs_get_ino(ei->i_iget5_block,
  1104. ei->i_iget5_offset,
  1105. ISOFS_BUFFER_BITS(inode));
  1106. /* Assume it is a normal-format file unless told otherwise */
  1107. ei->i_file_format = isofs_file_normal;
  1108. if (de->flags[-high_sierra] & 2) {
  1109. inode->i_mode = S_IRUGO | S_IXUGO | S_IFDIR;
  1110. inode->i_nlink = 1; /*
  1111. * Set to 1. We know there are 2, but
  1112. * the find utility tries to optimize
  1113. * if it is 2, and it screws up. It is
  1114. * easier to give 1 which tells find to
  1115. * do it the hard way.
  1116. */
  1117. } else {
  1118. /* Everybody gets to read the file. */
  1119. inode->i_mode = sbi->s_mode;
  1120. inode->i_nlink = 1;
  1121. inode->i_mode |= S_IFREG;
  1122. }
  1123. inode->i_uid = sbi->s_uid;
  1124. inode->i_gid = sbi->s_gid;
  1125. inode->i_blocks = 0;
  1126. ei->i_format_parm[0] = 0;
  1127. ei->i_format_parm[1] = 0;
  1128. ei->i_format_parm[2] = 0;
  1129. ei->i_section_size = isonum_733(de->size);
  1130. if (de->flags[-high_sierra] & 0x80) {
  1131. ret = isofs_read_level3_size(inode);
  1132. if (ret < 0)
  1133. goto fail;
  1134. ret = -EIO;
  1135. } else {
  1136. ei->i_next_section_block = 0;
  1137. ei->i_next_section_offset = 0;
  1138. inode->i_size = isonum_733(de->size);
  1139. }
  1140. /*
  1141. * Some dipshit decided to store some other bit of information
  1142. * in the high byte of the file length. Truncate size in case
  1143. * this CDROM was mounted with the cruft option.
  1144. */
  1145. if (sbi->s_cruft == 'y')
  1146. inode->i_size &= 0x00ffffff;
  1147. if (de->interleave[0]) {
  1148. printk(KERN_DEBUG "ISOFS: Interleaved files not (yet) supported.\n");
  1149. inode->i_size = 0;
  1150. }
  1151. /* I have no idea what file_unit_size is used for, so
  1152. we will flag it for now */
  1153. if (de->file_unit_size[0] != 0) {
  1154. printk(KERN_DEBUG "ISOFS: File unit size != 0 for ISO file (%ld).\n",
  1155. inode->i_ino);
  1156. }
  1157. /* I have no idea what other flag bits are used for, so
  1158. we will flag it for now */
  1159. #ifdef DEBUG
  1160. if((de->flags[-high_sierra] & ~2)!= 0){
  1161. printk(KERN_DEBUG "ISOFS: Unusual flag settings for ISO file "
  1162. "(%ld %x).\n",
  1163. inode->i_ino, de->flags[-high_sierra]);
  1164. }
  1165. #endif
  1166. inode->i_mtime.tv_sec =
  1167. inode->i_atime.tv_sec =
  1168. inode->i_ctime.tv_sec = iso_date(de->date, high_sierra);
  1169. inode->i_mtime.tv_nsec =
  1170. inode->i_atime.tv_nsec =
  1171. inode->i_ctime.tv_nsec = 0;
  1172. ei->i_first_extent = (isonum_733(de->extent) +
  1173. isonum_711(de->ext_attr_length));
  1174. /* Set the number of blocks for stat() - should be done before RR */
  1175. inode->i_blocks = (inode->i_size + 511) >> 9;
  1176. /*
  1177. * Now test for possible Rock Ridge extensions which will override
  1178. * some of these numbers in the inode structure.
  1179. */
  1180. if (!high_sierra) {
  1181. parse_rock_ridge_inode(de, inode);
  1182. /* if we want uid/gid set, override the rock ridge setting */
  1183. test_and_set_uid(&inode->i_uid, sbi->s_uid);
  1184. test_and_set_gid(&inode->i_gid, sbi->s_gid);
  1185. }
  1186. /* Install the inode operations vector */
  1187. if (S_ISREG(inode->i_mode)) {
  1188. inode->i_fop = &generic_ro_fops;
  1189. switch (ei->i_file_format) {
  1190. #ifdef CONFIG_ZISOFS
  1191. case isofs_file_compressed:
  1192. inode->i_data.a_ops = &zisofs_aops;
  1193. break;
  1194. #endif
  1195. default:
  1196. inode->i_data.a_ops = &isofs_aops;
  1197. break;
  1198. }
  1199. } else if (S_ISDIR(inode->i_mode)) {
  1200. inode->i_op = &isofs_dir_inode_operations;
  1201. inode->i_fop = &isofs_dir_operations;
  1202. } else if (S_ISLNK(inode->i_mode)) {
  1203. inode->i_op = &page_symlink_inode_operations;
  1204. inode->i_data.a_ops = &isofs_symlink_aops;
  1205. } else
  1206. /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
  1207. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  1208. ret = 0;
  1209. out:
  1210. kfree(tmpde);
  1211. if (bh)
  1212. brelse(bh);
  1213. return ret;
  1214. out_badread:
  1215. printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
  1216. fail:
  1217. goto out;
  1218. }
  1219. struct isofs_iget5_callback_data {
  1220. unsigned long block;
  1221. unsigned long offset;
  1222. };
  1223. static int isofs_iget5_test(struct inode *ino, void *data)
  1224. {
  1225. struct iso_inode_info *i = ISOFS_I(ino);
  1226. struct isofs_iget5_callback_data *d =
  1227. (struct isofs_iget5_callback_data*)data;
  1228. return (i->i_iget5_block == d->block)
  1229. && (i->i_iget5_offset == d->offset);
  1230. }
  1231. static int isofs_iget5_set(struct inode *ino, void *data)
  1232. {
  1233. struct iso_inode_info *i = ISOFS_I(ino);
  1234. struct isofs_iget5_callback_data *d =
  1235. (struct isofs_iget5_callback_data*)data;
  1236. i->i_iget5_block = d->block;
  1237. i->i_iget5_offset = d->offset;
  1238. return 0;
  1239. }
  1240. /* Store, in the inode's containing structure, the block and block
  1241. * offset that point to the underlying meta-data for the inode. The
  1242. * code below is otherwise similar to the iget() code in
  1243. * include/linux/fs.h */
  1244. struct inode *isofs_iget(struct super_block *sb,
  1245. unsigned long block,
  1246. unsigned long offset)
  1247. {
  1248. unsigned long hashval;
  1249. struct inode *inode;
  1250. struct isofs_iget5_callback_data data;
  1251. long ret;
  1252. if (offset >= 1ul << sb->s_blocksize_bits)
  1253. return ERR_PTR(-EINVAL);
  1254. data.block = block;
  1255. data.offset = offset;
  1256. hashval = (block << sb->s_blocksize_bits) | offset;
  1257. inode = iget5_locked(sb, hashval, &isofs_iget5_test,
  1258. &isofs_iget5_set, &data);
  1259. if (!inode)
  1260. return ERR_PTR(-ENOMEM);
  1261. if (inode->i_state & I_NEW) {
  1262. ret = isofs_read_inode(inode);
  1263. if (ret < 0) {
  1264. iget_failed(inode);
  1265. inode = ERR_PTR(ret);
  1266. } else {
  1267. unlock_new_inode(inode);
  1268. }
  1269. }
  1270. return inode;
  1271. }
  1272. static int isofs_get_sb(struct file_system_type *fs_type,
  1273. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  1274. {
  1275. return get_sb_bdev(fs_type, flags, dev_name, data, isofs_fill_super,
  1276. mnt);
  1277. }
  1278. static struct file_system_type iso9660_fs_type = {
  1279. .owner = THIS_MODULE,
  1280. .name = "iso9660",
  1281. .get_sb = isofs_get_sb,
  1282. .kill_sb = kill_block_super,
  1283. .fs_flags = FS_REQUIRES_DEV,
  1284. };
  1285. static int __init init_iso9660_fs(void)
  1286. {
  1287. int err = init_inodecache();
  1288. if (err)
  1289. goto out;
  1290. #ifdef CONFIG_ZISOFS
  1291. err = zisofs_init();
  1292. if (err)
  1293. goto out1;
  1294. #endif
  1295. err = register_filesystem(&iso9660_fs_type);
  1296. if (err)
  1297. goto out2;
  1298. return 0;
  1299. out2:
  1300. #ifdef CONFIG_ZISOFS
  1301. zisofs_cleanup();
  1302. out1:
  1303. #endif
  1304. destroy_inodecache();
  1305. out:
  1306. return err;
  1307. }
  1308. static void __exit exit_iso9660_fs(void)
  1309. {
  1310. unregister_filesystem(&iso9660_fs_type);
  1311. #ifdef CONFIG_ZISOFS
  1312. zisofs_cleanup();
  1313. #endif
  1314. destroy_inodecache();
  1315. }
  1316. module_init(init_iso9660_fs)
  1317. module_exit(exit_iso9660_fs)
  1318. MODULE_LICENSE("GPL");
  1319. /* Actual filesystem name is iso9660, as requested in filesystems.c */
  1320. MODULE_ALIAS("iso9660");