inode.c 39 KB

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