inode.c 41 KB

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