super.c 18 KB

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