super.c 18 KB

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