super.c 18 KB

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