super.c 18 KB

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