inode.c 40 KB

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