super.c 19 KB

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