inode.c 40 KB

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