super.c 20 KB

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