super.c 18 KB

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