inode.c 40 KB

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