super.c 19 KB

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