super.c 19 KB

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