super.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * linux/fs/hpfs/super.c
  3. *
  4. * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5. *
  6. * mounting, unmounting, error handling
  7. */
  8. #include "hpfs_fn.h"
  9. #include <linux/module.h>
  10. #include <linux/parser.h>
  11. #include <linux/init.h>
  12. #include <linux/statfs.h>
  13. #include <linux/magic.h>
  14. #include <linux/sched.h>
  15. #include <linux/bitmap.h>
  16. #include <linux/slab.h>
  17. /* Mark the filesystem dirty, so that chkdsk checks it when os/2 booted */
  18. static void mark_dirty(struct super_block *s, int remount)
  19. {
  20. if (hpfs_sb(s)->sb_chkdsk && (remount || !(s->s_flags & MS_RDONLY))) {
  21. struct buffer_head *bh;
  22. struct hpfs_spare_block *sb;
  23. if ((sb = hpfs_map_sector(s, 17, &bh, 0))) {
  24. sb->dirty = 1;
  25. sb->old_wrote = 0;
  26. mark_buffer_dirty(bh);
  27. sync_dirty_buffer(bh);
  28. brelse(bh);
  29. }
  30. }
  31. }
  32. /* Mark the filesystem clean (mark it dirty for chkdsk if chkdsk==2 or if there
  33. were errors) */
  34. static void unmark_dirty(struct super_block *s)
  35. {
  36. struct buffer_head *bh;
  37. struct hpfs_spare_block *sb;
  38. if (s->s_flags & MS_RDONLY) return;
  39. sync_blockdev(s->s_bdev);
  40. if ((sb = hpfs_map_sector(s, 17, &bh, 0))) {
  41. sb->dirty = hpfs_sb(s)->sb_chkdsk > 1 - hpfs_sb(s)->sb_was_error;
  42. sb->old_wrote = hpfs_sb(s)->sb_chkdsk >= 2 && !hpfs_sb(s)->sb_was_error;
  43. mark_buffer_dirty(bh);
  44. sync_dirty_buffer(bh);
  45. brelse(bh);
  46. }
  47. }
  48. /* Filesystem error... */
  49. void hpfs_error(struct super_block *s, const char *fmt, ...)
  50. {
  51. struct va_format vaf;
  52. va_list args;
  53. va_start(args, fmt);
  54. vaf.fmt = fmt;
  55. vaf.va = &args;
  56. pr_err("filesystem error: %pV", &vaf);
  57. va_end(args);
  58. if (!hpfs_sb(s)->sb_was_error) {
  59. if (hpfs_sb(s)->sb_err == 2) {
  60. pr_cont("; crashing the system because you wanted it\n");
  61. mark_dirty(s, 0);
  62. panic("HPFS panic");
  63. } else if (hpfs_sb(s)->sb_err == 1) {
  64. if (s->s_flags & MS_RDONLY)
  65. pr_cont("; already mounted read-only\n");
  66. else {
  67. pr_cont("; remounting read-only\n");
  68. mark_dirty(s, 0);
  69. s->s_flags |= MS_RDONLY;
  70. }
  71. } else if (s->s_flags & MS_RDONLY)
  72. pr_cont("; going on - but anything won't be destroyed because it's read-only\n");
  73. else
  74. pr_cont("; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so!\n");
  75. } else
  76. pr_cont("\n");
  77. hpfs_sb(s)->sb_was_error = 1;
  78. }
  79. /*
  80. * A little trick to detect cycles in many hpfs structures and don't let the
  81. * kernel crash on corrupted filesystem. When first called, set c2 to 0.
  82. *
  83. * BTW. chkdsk doesn't detect cycles correctly. When I had 2 lost directories
  84. * nested each in other, chkdsk locked up happilly.
  85. */
  86. int hpfs_stop_cycles(struct super_block *s, int key, int *c1, int *c2,
  87. char *msg)
  88. {
  89. if (*c2 && *c1 == key) {
  90. hpfs_error(s, "cycle detected on key %08x in %s", key, msg);
  91. return 1;
  92. }
  93. (*c2)++;
  94. if (!((*c2 - 1) & *c2)) *c1 = key;
  95. return 0;
  96. }
  97. static void free_sbi(struct hpfs_sb_info *sbi)
  98. {
  99. kfree(sbi->sb_cp_table);
  100. kfree(sbi->sb_bmp_dir);
  101. kfree(sbi);
  102. }
  103. static void lazy_free_sbi(struct rcu_head *rcu)
  104. {
  105. free_sbi(container_of(rcu, struct hpfs_sb_info, rcu));
  106. }
  107. static void hpfs_put_super(struct super_block *s)
  108. {
  109. hpfs_lock(s);
  110. unmark_dirty(s);
  111. hpfs_unlock(s);
  112. call_rcu(&hpfs_sb(s)->rcu, lazy_free_sbi);
  113. }
  114. static unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
  115. {
  116. struct quad_buffer_head qbh;
  117. unsigned long *bits;
  118. unsigned count;
  119. bits = hpfs_map_4sectors(s, secno, &qbh, 0);
  120. if (!bits)
  121. return (unsigned)-1;
  122. count = bitmap_weight(bits, 2048 * BITS_PER_BYTE);
  123. hpfs_brelse4(&qbh);
  124. return count;
  125. }
  126. static unsigned count_bitmaps(struct super_block *s)
  127. {
  128. unsigned n, count, n_bands;
  129. n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
  130. count = 0;
  131. for (n = 0; n < COUNT_RD_AHEAD; n++) {
  132. hpfs_prefetch_bitmap(s, n);
  133. }
  134. for (n = 0; n < n_bands; n++) {
  135. unsigned c;
  136. hpfs_prefetch_bitmap(s, n + COUNT_RD_AHEAD);
  137. c = hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
  138. if (c != (unsigned)-1)
  139. count += c;
  140. }
  141. return count;
  142. }
  143. unsigned hpfs_get_free_dnodes(struct super_block *s)
  144. {
  145. struct hpfs_sb_info *sbi = hpfs_sb(s);
  146. if (sbi->sb_n_free_dnodes == (unsigned)-1) {
  147. unsigned c = hpfs_count_one_bitmap(s, sbi->sb_dmap);
  148. if (c == (unsigned)-1)
  149. return 0;
  150. sbi->sb_n_free_dnodes = c;
  151. }
  152. return sbi->sb_n_free_dnodes;
  153. }
  154. static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  155. {
  156. struct super_block *s = dentry->d_sb;
  157. struct hpfs_sb_info *sbi = hpfs_sb(s);
  158. u64 id = huge_encode_dev(s->s_bdev->bd_dev);
  159. hpfs_lock(s);
  160. if (sbi->sb_n_free == (unsigned)-1)
  161. sbi->sb_n_free = count_bitmaps(s);
  162. buf->f_type = s->s_magic;
  163. buf->f_bsize = 512;
  164. buf->f_blocks = sbi->sb_fs_size;
  165. buf->f_bfree = sbi->sb_n_free;
  166. buf->f_bavail = sbi->sb_n_free;
  167. buf->f_files = sbi->sb_dirband_size / 4;
  168. buf->f_ffree = hpfs_get_free_dnodes(s);
  169. buf->f_fsid.val[0] = (u32)id;
  170. buf->f_fsid.val[1] = (u32)(id >> 32);
  171. buf->f_namelen = 254;
  172. hpfs_unlock(s);
  173. return 0;
  174. }
  175. long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
  176. {
  177. switch (cmd) {
  178. case FITRIM: {
  179. struct fstrim_range range;
  180. secno n_trimmed;
  181. int r;
  182. if (!capable(CAP_SYS_ADMIN))
  183. return -EPERM;
  184. if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
  185. return -EFAULT;
  186. r = hpfs_trim_fs(file_inode(file)->i_sb, range.start >> 9, (range.start + range.len) >> 9, (range.minlen + 511) >> 9, &n_trimmed);
  187. if (r)
  188. return r;
  189. range.len = (u64)n_trimmed << 9;
  190. if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range)))
  191. return -EFAULT;
  192. return 0;
  193. }
  194. default: {
  195. return -ENOIOCTLCMD;
  196. }
  197. }
  198. }
  199. static struct kmem_cache * hpfs_inode_cachep;
  200. static struct inode *hpfs_alloc_inode(struct super_block *sb)
  201. {
  202. struct hpfs_inode_info *ei;
  203. ei = kmem_cache_alloc(hpfs_inode_cachep, GFP_NOFS);
  204. if (!ei)
  205. return NULL;
  206. ei->vfs_inode.i_version = 1;
  207. return &ei->vfs_inode;
  208. }
  209. static void hpfs_i_callback(struct rcu_head *head)
  210. {
  211. struct inode *inode = container_of(head, struct inode, i_rcu);
  212. kmem_cache_free(hpfs_inode_cachep, hpfs_i(inode));
  213. }
  214. static void hpfs_destroy_inode(struct inode *inode)
  215. {
  216. call_rcu(&inode->i_rcu, hpfs_i_callback);
  217. }
  218. static void init_once(void *foo)
  219. {
  220. struct hpfs_inode_info *ei = (struct hpfs_inode_info *) foo;
  221. inode_init_once(&ei->vfs_inode);
  222. }
  223. static int init_inodecache(void)
  224. {
  225. hpfs_inode_cachep = kmem_cache_create("hpfs_inode_cache",
  226. sizeof(struct hpfs_inode_info),
  227. 0, (SLAB_RECLAIM_ACCOUNT|
  228. SLAB_MEM_SPREAD),
  229. init_once);
  230. if (hpfs_inode_cachep == NULL)
  231. return -ENOMEM;
  232. return 0;
  233. }
  234. static void destroy_inodecache(void)
  235. {
  236. /*
  237. * Make sure all delayed rcu free inodes are flushed before we
  238. * destroy cache.
  239. */
  240. rcu_barrier();
  241. kmem_cache_destroy(hpfs_inode_cachep);
  242. }
  243. /*
  244. * A tiny parser for option strings, stolen from dosfs.
  245. * Stolen again from read-only hpfs.
  246. * And updated for table-driven option parsing.
  247. */
  248. enum {
  249. Opt_help, Opt_uid, Opt_gid, Opt_umask, Opt_case_lower, Opt_case_asis,
  250. Opt_check_none, Opt_check_normal, Opt_check_strict,
  251. Opt_err_cont, Opt_err_ro, Opt_err_panic,
  252. Opt_eas_no, Opt_eas_ro, Opt_eas_rw,
  253. Opt_chkdsk_no, Opt_chkdsk_errors, Opt_chkdsk_always,
  254. Opt_timeshift, Opt_err,
  255. };
  256. static const match_table_t tokens = {
  257. {Opt_help, "help"},
  258. {Opt_uid, "uid=%u"},
  259. {Opt_gid, "gid=%u"},
  260. {Opt_umask, "umask=%o"},
  261. {Opt_case_lower, "case=lower"},
  262. {Opt_case_asis, "case=asis"},
  263. {Opt_check_none, "check=none"},
  264. {Opt_check_normal, "check=normal"},
  265. {Opt_check_strict, "check=strict"},
  266. {Opt_err_cont, "errors=continue"},
  267. {Opt_err_ro, "errors=remount-ro"},
  268. {Opt_err_panic, "errors=panic"},
  269. {Opt_eas_no, "eas=no"},
  270. {Opt_eas_ro, "eas=ro"},
  271. {Opt_eas_rw, "eas=rw"},
  272. {Opt_chkdsk_no, "chkdsk=no"},
  273. {Opt_chkdsk_errors, "chkdsk=errors"},
  274. {Opt_chkdsk_always, "chkdsk=always"},
  275. {Opt_timeshift, "timeshift=%d"},
  276. {Opt_err, NULL},
  277. };
  278. static int parse_opts(char *opts, kuid_t *uid, kgid_t *gid, umode_t *umask,
  279. int *lowercase, int *eas, int *chk, int *errs,
  280. int *chkdsk, int *timeshift)
  281. {
  282. char *p;
  283. int option;
  284. if (!opts)
  285. return 1;
  286. /*pr_info("Parsing opts: '%s'\n",opts);*/
  287. while ((p = strsep(&opts, ",")) != NULL) {
  288. substring_t args[MAX_OPT_ARGS];
  289. int token;
  290. if (!*p)
  291. continue;
  292. token = match_token(p, tokens, args);
  293. switch (token) {
  294. case Opt_help:
  295. return 2;
  296. case Opt_uid:
  297. if (match_int(args, &option))
  298. return 0;
  299. *uid = make_kuid(current_user_ns(), option);
  300. if (!uid_valid(*uid))
  301. return 0;
  302. break;
  303. case Opt_gid:
  304. if (match_int(args, &option))
  305. return 0;
  306. *gid = make_kgid(current_user_ns(), option);
  307. if (!gid_valid(*gid))
  308. return 0;
  309. break;
  310. case Opt_umask:
  311. if (match_octal(args, &option))
  312. return 0;
  313. *umask = option;
  314. break;
  315. case Opt_case_lower:
  316. *lowercase = 1;
  317. break;
  318. case Opt_case_asis:
  319. *lowercase = 0;
  320. break;
  321. case Opt_check_none:
  322. *chk = 0;
  323. break;
  324. case Opt_check_normal:
  325. *chk = 1;
  326. break;
  327. case Opt_check_strict:
  328. *chk = 2;
  329. break;
  330. case Opt_err_cont:
  331. *errs = 0;
  332. break;
  333. case Opt_err_ro:
  334. *errs = 1;
  335. break;
  336. case Opt_err_panic:
  337. *errs = 2;
  338. break;
  339. case Opt_eas_no:
  340. *eas = 0;
  341. break;
  342. case Opt_eas_ro:
  343. *eas = 1;
  344. break;
  345. case Opt_eas_rw:
  346. *eas = 2;
  347. break;
  348. case Opt_chkdsk_no:
  349. *chkdsk = 0;
  350. break;
  351. case Opt_chkdsk_errors:
  352. *chkdsk = 1;
  353. break;
  354. case Opt_chkdsk_always:
  355. *chkdsk = 2;
  356. break;
  357. case Opt_timeshift:
  358. {
  359. int m = 1;
  360. char *rhs = args[0].from;
  361. if (!rhs || !*rhs)
  362. return 0;
  363. if (*rhs == '-') m = -1;
  364. if (*rhs == '+' || *rhs == '-') rhs++;
  365. *timeshift = simple_strtoul(rhs, &rhs, 0) * m;
  366. if (*rhs)
  367. return 0;
  368. break;
  369. }
  370. default:
  371. return 0;
  372. }
  373. }
  374. return 1;
  375. }
  376. static inline void hpfs_help(void)
  377. {
  378. pr_info("\n\
  379. HPFS filesystem options:\n\
  380. help do not mount and display this text\n\
  381. uid=xxx set uid of files that don't have uid specified in eas\n\
  382. gid=xxx set gid of files that don't have gid specified in eas\n\
  383. umask=xxx set mode of files that don't have mode specified in eas\n\
  384. case=lower lowercase all files\n\
  385. case=asis do not lowercase files (default)\n\
  386. check=none no fs checks - kernel may crash on corrupted filesystem\n\
  387. check=normal do some checks - it should not crash (default)\n\
  388. check=strict do extra time-consuming checks, used for debugging\n\
  389. errors=continue continue on errors\n\
  390. errors=remount-ro remount read-only if errors found (default)\n\
  391. errors=panic panic on errors\n\
  392. chkdsk=no do not mark fs for chkdsking even if there were errors\n\
  393. chkdsk=errors mark fs dirty if errors found (default)\n\
  394. chkdsk=always always mark fs dirty - used for debugging\n\
  395. eas=no ignore extended attributes\n\
  396. eas=ro read but do not write extended attributes\n\
  397. eas=rw r/w eas => enables chmod, chown, mknod, ln -s (default)\n\
  398. timeshift=nnn add nnn seconds to file times\n\
  399. \n");
  400. }
  401. static int hpfs_remount_fs(struct super_block *s, int *flags, char *data)
  402. {
  403. kuid_t uid;
  404. kgid_t gid;
  405. umode_t umask;
  406. int lowercase, eas, chk, errs, chkdsk, timeshift;
  407. int o;
  408. struct hpfs_sb_info *sbi = hpfs_sb(s);
  409. char *new_opts = kstrdup(data, GFP_KERNEL);
  410. if (!new_opts)
  411. return -ENOMEM;
  412. sync_filesystem(s);
  413. *flags |= MS_NOATIME;
  414. hpfs_lock(s);
  415. uid = sbi->sb_uid; gid = sbi->sb_gid;
  416. umask = 0777 & ~sbi->sb_mode;
  417. lowercase = sbi->sb_lowercase;
  418. eas = sbi->sb_eas; chk = sbi->sb_chk; chkdsk = sbi->sb_chkdsk;
  419. errs = sbi->sb_err; timeshift = sbi->sb_timeshift;
  420. if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase,
  421. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  422. pr_err("bad mount options.\n");
  423. goto out_err;
  424. }
  425. if (o == 2) {
  426. hpfs_help();
  427. goto out_err;
  428. }
  429. if (timeshift != sbi->sb_timeshift) {
  430. pr_err("timeshift can't be changed using remount.\n");
  431. goto out_err;
  432. }
  433. unmark_dirty(s);
  434. sbi->sb_uid = uid; sbi->sb_gid = gid;
  435. sbi->sb_mode = 0777 & ~umask;
  436. sbi->sb_lowercase = lowercase;
  437. sbi->sb_eas = eas; sbi->sb_chk = chk; sbi->sb_chkdsk = chkdsk;
  438. sbi->sb_err = errs; sbi->sb_timeshift = timeshift;
  439. if (!(*flags & MS_RDONLY)) mark_dirty(s, 1);
  440. replace_mount_options(s, new_opts);
  441. hpfs_unlock(s);
  442. return 0;
  443. out_err:
  444. hpfs_unlock(s);
  445. kfree(new_opts);
  446. return -EINVAL;
  447. }
  448. /* Super operations */
  449. static const struct super_operations hpfs_sops =
  450. {
  451. .alloc_inode = hpfs_alloc_inode,
  452. .destroy_inode = hpfs_destroy_inode,
  453. .evict_inode = hpfs_evict_inode,
  454. .put_super = hpfs_put_super,
  455. .statfs = hpfs_statfs,
  456. .remount_fs = hpfs_remount_fs,
  457. .show_options = generic_show_options,
  458. };
  459. static int hpfs_fill_super(struct super_block *s, void *options, int silent)
  460. {
  461. struct buffer_head *bh0, *bh1, *bh2;
  462. struct hpfs_boot_block *bootblock;
  463. struct hpfs_super_block *superblock;
  464. struct hpfs_spare_block *spareblock;
  465. struct hpfs_sb_info *sbi;
  466. struct inode *root;
  467. kuid_t uid;
  468. kgid_t gid;
  469. umode_t umask;
  470. int lowercase, eas, chk, errs, chkdsk, timeshift;
  471. dnode_secno root_dno;
  472. struct hpfs_dirent *de = NULL;
  473. struct quad_buffer_head qbh;
  474. int o;
  475. save_mount_options(s, options);
  476. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  477. if (!sbi) {
  478. return -ENOMEM;
  479. }
  480. s->s_fs_info = sbi;
  481. mutex_init(&sbi->hpfs_mutex);
  482. hpfs_lock(s);
  483. uid = current_uid();
  484. gid = current_gid();
  485. umask = current_umask();
  486. lowercase = 0;
  487. eas = 2;
  488. chk = 1;
  489. errs = 1;
  490. chkdsk = 1;
  491. timeshift = 0;
  492. if (!(o = parse_opts(options, &uid, &gid, &umask, &lowercase,
  493. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  494. pr_err("bad mount options.\n");
  495. goto bail0;
  496. }
  497. if (o==2) {
  498. hpfs_help();
  499. goto bail0;
  500. }
  501. /*sbi->sb_mounting = 1;*/
  502. sb_set_blocksize(s, 512);
  503. sbi->sb_fs_size = -1;
  504. if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1;
  505. if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2;
  506. if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3;
  507. /* Check magics */
  508. if (/*le16_to_cpu(bootblock->magic) != BB_MAGIC
  509. ||*/ le32_to_cpu(superblock->magic) != SB_MAGIC
  510. || le32_to_cpu(spareblock->magic) != SP_MAGIC) {
  511. if (!silent)
  512. pr_err("Bad magic ... probably not HPFS\n");
  513. goto bail4;
  514. }
  515. /* Check version */
  516. if (!(s->s_flags & MS_RDONLY) &&
  517. superblock->funcversion != 2 && superblock->funcversion != 3) {
  518. pr_err("Bad version %d,%d. Mount readonly to go around\n",
  519. (int)superblock->version, (int)superblock->funcversion);
  520. pr_err("please try recent version of HPFS driver at http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi and if it still can't understand this format, contact author - mikulas@artax.karlin.mff.cuni.cz\n");
  521. goto bail4;
  522. }
  523. s->s_flags |= MS_NOATIME;
  524. /* Fill superblock stuff */
  525. s->s_magic = HPFS_SUPER_MAGIC;
  526. s->s_op = &hpfs_sops;
  527. s->s_d_op = &hpfs_dentry_operations;
  528. sbi->sb_root = le32_to_cpu(superblock->root);
  529. sbi->sb_fs_size = le32_to_cpu(superblock->n_sectors);
  530. sbi->sb_bitmaps = le32_to_cpu(superblock->bitmaps);
  531. sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
  532. sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
  533. sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
  534. sbi->sb_uid = uid;
  535. sbi->sb_gid = gid;
  536. sbi->sb_mode = 0777 & ~umask;
  537. sbi->sb_n_free = -1;
  538. sbi->sb_n_free_dnodes = -1;
  539. sbi->sb_lowercase = lowercase;
  540. sbi->sb_eas = eas;
  541. sbi->sb_chk = chk;
  542. sbi->sb_chkdsk = chkdsk;
  543. sbi->sb_err = errs;
  544. sbi->sb_timeshift = timeshift;
  545. sbi->sb_was_error = 0;
  546. sbi->sb_cp_table = NULL;
  547. sbi->sb_c_bitmap = -1;
  548. sbi->sb_max_fwd_alloc = 0xffffff;
  549. if (sbi->sb_fs_size >= 0x80000000) {
  550. hpfs_error(s, "invalid size in superblock: %08x",
  551. (unsigned)sbi->sb_fs_size);
  552. goto bail4;
  553. }
  554. if (spareblock->n_spares_used)
  555. hpfs_load_hotfix_map(s, spareblock);
  556. /* Load bitmap directory */
  557. if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
  558. goto bail4;
  559. /* Check for general fs errors*/
  560. if (spareblock->dirty && !spareblock->old_wrote) {
  561. if (errs == 2) {
  562. pr_err("Improperly stopped, not mounted\n");
  563. goto bail4;
  564. }
  565. hpfs_error(s, "improperly stopped");
  566. }
  567. if (!(s->s_flags & MS_RDONLY)) {
  568. spareblock->dirty = 1;
  569. spareblock->old_wrote = 0;
  570. mark_buffer_dirty(bh2);
  571. }
  572. if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) {
  573. if (errs >= 2) {
  574. pr_err("Spare dnodes used, try chkdsk\n");
  575. mark_dirty(s, 0);
  576. goto bail4;
  577. }
  578. hpfs_error(s, "warning: spare dnodes used, try chkdsk");
  579. if (errs == 0)
  580. pr_err("Proceeding, but your filesystem could be corrupted if you delete files or directories\n");
  581. }
  582. if (chk) {
  583. unsigned a;
  584. if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) ||
  585. le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) {
  586. hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x",
  587. le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->dir_band_end), le32_to_cpu(superblock->n_dir_band));
  588. goto bail4;
  589. }
  590. a = sbi->sb_dirband_size;
  591. sbi->sb_dirband_size = 0;
  592. if (hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->n_dir_band), "dir_band") ||
  593. hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_bitmap), 4, "dir_band_bitmap") ||
  594. hpfs_chk_sectors(s, le32_to_cpu(superblock->bitmaps), 4, "bitmaps")) {
  595. mark_dirty(s, 0);
  596. goto bail4;
  597. }
  598. sbi->sb_dirband_size = a;
  599. } else
  600. pr_err("You really don't want any checks? You are crazy...\n");
  601. /* Load code page table */
  602. if (le32_to_cpu(spareblock->n_code_pages))
  603. if (!(sbi->sb_cp_table = hpfs_load_code_page(s, le32_to_cpu(spareblock->code_page_dir))))
  604. pr_err("code page support is disabled\n");
  605. brelse(bh2);
  606. brelse(bh1);
  607. brelse(bh0);
  608. root = iget_locked(s, sbi->sb_root);
  609. if (!root)
  610. goto bail0;
  611. hpfs_init_inode(root);
  612. hpfs_read_inode(root);
  613. unlock_new_inode(root);
  614. s->s_root = d_make_root(root);
  615. if (!s->s_root)
  616. goto bail0;
  617. /*
  618. * find the root directory's . pointer & finish filling in the inode
  619. */
  620. root_dno = hpfs_fnode_dno(s, sbi->sb_root);
  621. if (root_dno)
  622. de = map_dirent(root, root_dno, "\001\001", 2, NULL, &qbh);
  623. if (!de)
  624. hpfs_error(s, "unable to find root dir");
  625. else {
  626. root->i_atime.tv_sec = local_to_gmt(s, le32_to_cpu(de->read_date));
  627. root->i_atime.tv_nsec = 0;
  628. root->i_mtime.tv_sec = local_to_gmt(s, le32_to_cpu(de->write_date));
  629. root->i_mtime.tv_nsec = 0;
  630. root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date));
  631. root->i_ctime.tv_nsec = 0;
  632. hpfs_i(root)->i_ea_size = le32_to_cpu(de->ea_size);
  633. hpfs_i(root)->i_parent_dir = root->i_ino;
  634. if (root->i_size == -1)
  635. root->i_size = 2048;
  636. if (root->i_blocks == -1)
  637. root->i_blocks = 5;
  638. hpfs_brelse4(&qbh);
  639. }
  640. hpfs_unlock(s);
  641. return 0;
  642. bail4: brelse(bh2);
  643. bail3: brelse(bh1);
  644. bail2: brelse(bh0);
  645. bail1:
  646. bail0:
  647. hpfs_unlock(s);
  648. free_sbi(sbi);
  649. return -EINVAL;
  650. }
  651. static struct dentry *hpfs_mount(struct file_system_type *fs_type,
  652. int flags, const char *dev_name, void *data)
  653. {
  654. return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super);
  655. }
  656. static struct file_system_type hpfs_fs_type = {
  657. .owner = THIS_MODULE,
  658. .name = "hpfs",
  659. .mount = hpfs_mount,
  660. .kill_sb = kill_block_super,
  661. .fs_flags = FS_REQUIRES_DEV,
  662. };
  663. MODULE_ALIAS_FS("hpfs");
  664. static int __init init_hpfs_fs(void)
  665. {
  666. int err = init_inodecache();
  667. if (err)
  668. goto out1;
  669. err = register_filesystem(&hpfs_fs_type);
  670. if (err)
  671. goto out;
  672. return 0;
  673. out:
  674. destroy_inodecache();
  675. out1:
  676. return err;
  677. }
  678. static void __exit exit_hpfs_fs(void)
  679. {
  680. unregister_filesystem(&hpfs_fs_type);
  681. destroy_inodecache();
  682. }
  683. module_init(init_hpfs_fs)
  684. module_exit(exit_hpfs_fs)
  685. MODULE_LICENSE("GPL");