super.c 19 KB

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