super.c 18 KB

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