super.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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 || !sb_rdonly(s))) {
  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 (sb_rdonly(s)) 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 (sb_rdonly(s))
  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 |= SB_RDONLY;
  71. }
  72. } else if (sb_rdonly(s))
  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. 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|SLAB_ACCOUNT),
  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. sync_filesystem(s);
  410. *flags |= SB_NOATIME;
  411. hpfs_lock(s);
  412. uid = sbi->sb_uid; gid = sbi->sb_gid;
  413. umask = 0777 & ~sbi->sb_mode;
  414. lowercase = sbi->sb_lowercase;
  415. eas = sbi->sb_eas; chk = sbi->sb_chk; chkdsk = sbi->sb_chkdsk;
  416. errs = sbi->sb_err; timeshift = sbi->sb_timeshift;
  417. if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase,
  418. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  419. pr_err("bad mount options.\n");
  420. goto out_err;
  421. }
  422. if (o == 2) {
  423. hpfs_help();
  424. goto out_err;
  425. }
  426. if (timeshift != sbi->sb_timeshift) {
  427. pr_err("timeshift can't be changed using remount.\n");
  428. goto out_err;
  429. }
  430. unmark_dirty(s);
  431. sbi->sb_uid = uid; sbi->sb_gid = gid;
  432. sbi->sb_mode = 0777 & ~umask;
  433. sbi->sb_lowercase = lowercase;
  434. sbi->sb_eas = eas; sbi->sb_chk = chk; sbi->sb_chkdsk = chkdsk;
  435. sbi->sb_err = errs; sbi->sb_timeshift = timeshift;
  436. if (!(*flags & SB_RDONLY)) mark_dirty(s, 1);
  437. hpfs_unlock(s);
  438. return 0;
  439. out_err:
  440. hpfs_unlock(s);
  441. return -EINVAL;
  442. }
  443. static int hpfs_show_options(struct seq_file *seq, struct dentry *root)
  444. {
  445. struct hpfs_sb_info *sbi = hpfs_sb(root->d_sb);
  446. seq_printf(seq, ",uid=%u", from_kuid_munged(&init_user_ns, sbi->sb_uid));
  447. seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, sbi->sb_gid));
  448. seq_printf(seq, ",umask=%03o", (~sbi->sb_mode & 0777));
  449. if (sbi->sb_lowercase)
  450. seq_printf(seq, ",case=lower");
  451. if (!sbi->sb_chk)
  452. seq_printf(seq, ",check=none");
  453. if (sbi->sb_chk == 2)
  454. seq_printf(seq, ",check=strict");
  455. if (!sbi->sb_err)
  456. seq_printf(seq, ",errors=continue");
  457. if (sbi->sb_err == 2)
  458. seq_printf(seq, ",errors=panic");
  459. if (!sbi->sb_chkdsk)
  460. seq_printf(seq, ",chkdsk=no");
  461. if (sbi->sb_chkdsk == 2)
  462. seq_printf(seq, ",chkdsk=always");
  463. if (!sbi->sb_eas)
  464. seq_printf(seq, ",eas=no");
  465. if (sbi->sb_eas == 1)
  466. seq_printf(seq, ",eas=ro");
  467. if (sbi->sb_timeshift)
  468. seq_printf(seq, ",timeshift=%d", sbi->sb_timeshift);
  469. return 0;
  470. }
  471. /* Super operations */
  472. static const struct super_operations hpfs_sops =
  473. {
  474. .alloc_inode = hpfs_alloc_inode,
  475. .destroy_inode = hpfs_destroy_inode,
  476. .evict_inode = hpfs_evict_inode,
  477. .put_super = hpfs_put_super,
  478. .statfs = hpfs_statfs,
  479. .remount_fs = hpfs_remount_fs,
  480. .show_options = hpfs_show_options,
  481. };
  482. static int hpfs_fill_super(struct super_block *s, void *options, int silent)
  483. {
  484. struct buffer_head *bh0, *bh1, *bh2;
  485. struct hpfs_boot_block *bootblock;
  486. struct hpfs_super_block *superblock;
  487. struct hpfs_spare_block *spareblock;
  488. struct hpfs_sb_info *sbi;
  489. struct inode *root;
  490. kuid_t uid;
  491. kgid_t gid;
  492. umode_t umask;
  493. int lowercase, eas, chk, errs, chkdsk, timeshift;
  494. dnode_secno root_dno;
  495. struct hpfs_dirent *de = NULL;
  496. struct quad_buffer_head qbh;
  497. int o;
  498. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  499. if (!sbi) {
  500. return -ENOMEM;
  501. }
  502. s->s_fs_info = sbi;
  503. mutex_init(&sbi->hpfs_mutex);
  504. hpfs_lock(s);
  505. uid = current_uid();
  506. gid = current_gid();
  507. umask = current_umask();
  508. lowercase = 0;
  509. eas = 2;
  510. chk = 1;
  511. errs = 1;
  512. chkdsk = 1;
  513. timeshift = 0;
  514. if (!(o = parse_opts(options, &uid, &gid, &umask, &lowercase,
  515. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  516. pr_err("bad mount options.\n");
  517. goto bail0;
  518. }
  519. if (o==2) {
  520. hpfs_help();
  521. goto bail0;
  522. }
  523. /*sbi->sb_mounting = 1;*/
  524. sb_set_blocksize(s, 512);
  525. sbi->sb_fs_size = -1;
  526. if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1;
  527. if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2;
  528. if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3;
  529. /* Check magics */
  530. if (/*le16_to_cpu(bootblock->magic) != BB_MAGIC
  531. ||*/ le32_to_cpu(superblock->magic) != SB_MAGIC
  532. || le32_to_cpu(spareblock->magic) != SP_MAGIC) {
  533. if (!silent)
  534. pr_err("Bad magic ... probably not HPFS\n");
  535. goto bail4;
  536. }
  537. /* Check version */
  538. if (!sb_rdonly(s) && superblock->funcversion != 2 && superblock->funcversion != 3) {
  539. pr_err("Bad version %d,%d. Mount readonly to go around\n",
  540. (int)superblock->version, (int)superblock->funcversion);
  541. 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");
  542. goto bail4;
  543. }
  544. s->s_flags |= SB_NOATIME;
  545. /* Fill superblock stuff */
  546. s->s_magic = HPFS_SUPER_MAGIC;
  547. s->s_op = &hpfs_sops;
  548. s->s_d_op = &hpfs_dentry_operations;
  549. sbi->sb_root = le32_to_cpu(superblock->root);
  550. sbi->sb_fs_size = le32_to_cpu(superblock->n_sectors);
  551. sbi->sb_bitmaps = le32_to_cpu(superblock->bitmaps);
  552. sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
  553. sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
  554. sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
  555. sbi->sb_uid = uid;
  556. sbi->sb_gid = gid;
  557. sbi->sb_mode = 0777 & ~umask;
  558. sbi->sb_n_free = -1;
  559. sbi->sb_n_free_dnodes = -1;
  560. sbi->sb_lowercase = lowercase;
  561. sbi->sb_eas = eas;
  562. sbi->sb_chk = chk;
  563. sbi->sb_chkdsk = chkdsk;
  564. sbi->sb_err = errs;
  565. sbi->sb_timeshift = timeshift;
  566. sbi->sb_was_error = 0;
  567. sbi->sb_cp_table = NULL;
  568. sbi->sb_c_bitmap = -1;
  569. sbi->sb_max_fwd_alloc = 0xffffff;
  570. if (sbi->sb_fs_size >= 0x80000000) {
  571. hpfs_error(s, "invalid size in superblock: %08x",
  572. (unsigned)sbi->sb_fs_size);
  573. goto bail4;
  574. }
  575. if (spareblock->n_spares_used)
  576. hpfs_load_hotfix_map(s, spareblock);
  577. /* Load bitmap directory */
  578. if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
  579. goto bail4;
  580. /* Check for general fs errors*/
  581. if (spareblock->dirty && !spareblock->old_wrote) {
  582. if (errs == 2) {
  583. pr_err("Improperly stopped, not mounted\n");
  584. goto bail4;
  585. }
  586. hpfs_error(s, "improperly stopped");
  587. }
  588. if (!sb_rdonly(s)) {
  589. spareblock->dirty = 1;
  590. spareblock->old_wrote = 0;
  591. mark_buffer_dirty(bh2);
  592. }
  593. if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) {
  594. if (errs >= 2) {
  595. pr_err("Spare dnodes used, try chkdsk\n");
  596. mark_dirty(s, 0);
  597. goto bail4;
  598. }
  599. hpfs_error(s, "warning: spare dnodes used, try chkdsk");
  600. if (errs == 0)
  601. pr_err("Proceeding, but your filesystem could be corrupted if you delete files or directories\n");
  602. }
  603. if (chk) {
  604. unsigned a;
  605. if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) ||
  606. le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) {
  607. hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x",
  608. le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->dir_band_end), le32_to_cpu(superblock->n_dir_band));
  609. goto bail4;
  610. }
  611. a = sbi->sb_dirband_size;
  612. sbi->sb_dirband_size = 0;
  613. if (hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->n_dir_band), "dir_band") ||
  614. hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_bitmap), 4, "dir_band_bitmap") ||
  615. hpfs_chk_sectors(s, le32_to_cpu(superblock->bitmaps), 4, "bitmaps")) {
  616. mark_dirty(s, 0);
  617. goto bail4;
  618. }
  619. sbi->sb_dirband_size = a;
  620. } else
  621. pr_err("You really don't want any checks? You are crazy...\n");
  622. /* Load code page table */
  623. if (le32_to_cpu(spareblock->n_code_pages))
  624. if (!(sbi->sb_cp_table = hpfs_load_code_page(s, le32_to_cpu(spareblock->code_page_dir))))
  625. pr_err("code page support is disabled\n");
  626. brelse(bh2);
  627. brelse(bh1);
  628. brelse(bh0);
  629. root = iget_locked(s, sbi->sb_root);
  630. if (!root)
  631. goto bail0;
  632. hpfs_init_inode(root);
  633. hpfs_read_inode(root);
  634. unlock_new_inode(root);
  635. s->s_root = d_make_root(root);
  636. if (!s->s_root)
  637. goto bail0;
  638. /*
  639. * find the root directory's . pointer & finish filling in the inode
  640. */
  641. root_dno = hpfs_fnode_dno(s, sbi->sb_root);
  642. if (root_dno)
  643. de = map_dirent(root, root_dno, "\001\001", 2, NULL, &qbh);
  644. if (!de)
  645. hpfs_error(s, "unable to find root dir");
  646. else {
  647. root->i_atime.tv_sec = local_to_gmt(s, le32_to_cpu(de->read_date));
  648. root->i_atime.tv_nsec = 0;
  649. root->i_mtime.tv_sec = local_to_gmt(s, le32_to_cpu(de->write_date));
  650. root->i_mtime.tv_nsec = 0;
  651. root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date));
  652. root->i_ctime.tv_nsec = 0;
  653. hpfs_i(root)->i_ea_size = le32_to_cpu(de->ea_size);
  654. hpfs_i(root)->i_parent_dir = root->i_ino;
  655. if (root->i_size == -1)
  656. root->i_size = 2048;
  657. if (root->i_blocks == -1)
  658. root->i_blocks = 5;
  659. hpfs_brelse4(&qbh);
  660. }
  661. hpfs_unlock(s);
  662. return 0;
  663. bail4: brelse(bh2);
  664. bail3: brelse(bh1);
  665. bail2: brelse(bh0);
  666. bail1:
  667. bail0:
  668. hpfs_unlock(s);
  669. free_sbi(sbi);
  670. return -EINVAL;
  671. }
  672. static struct dentry *hpfs_mount(struct file_system_type *fs_type,
  673. int flags, const char *dev_name, void *data)
  674. {
  675. return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super);
  676. }
  677. static struct file_system_type hpfs_fs_type = {
  678. .owner = THIS_MODULE,
  679. .name = "hpfs",
  680. .mount = hpfs_mount,
  681. .kill_sb = kill_block_super,
  682. .fs_flags = FS_REQUIRES_DEV,
  683. };
  684. MODULE_ALIAS_FS("hpfs");
  685. static int __init init_hpfs_fs(void)
  686. {
  687. int err = init_inodecache();
  688. if (err)
  689. goto out1;
  690. err = register_filesystem(&hpfs_fs_type);
  691. if (err)
  692. goto out;
  693. return 0;
  694. out:
  695. destroy_inodecache();
  696. out1:
  697. return err;
  698. }
  699. static void __exit exit_hpfs_fs(void)
  700. {
  701. unregister_filesystem(&hpfs_fs_type);
  702. destroy_inodecache();
  703. }
  704. module_init(init_hpfs_fs)
  705. module_exit(exit_hpfs_fs)
  706. MODULE_LICENSE("GPL");