super.c 18 KB

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