super.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/fs/hpfs/super.c
  4. *
  5. * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  6. *
  7. * mounting, unmounting, error handling
  8. */
  9. #include "hpfs_fn.h"
  10. #include <linux/module.h>
  11. #include <linux/parser.h>
  12. #include <linux/init.h>
  13. #include <linux/statfs.h>
  14. #include <linux/magic.h>
  15. #include <linux/sched.h>
  16. #include <linux/bitmap.h>
  17. #include <linux/slab.h>
  18. #include <linux/seq_file.h>
  19. /* Mark the filesystem dirty, so that chkdsk checks it when os/2 booted */
  20. static void mark_dirty(struct super_block *s, int remount)
  21. {
  22. if (hpfs_sb(s)->sb_chkdsk && (remount || !sb_rdonly(s))) {
  23. struct buffer_head *bh;
  24. struct hpfs_spare_block *sb;
  25. if ((sb = hpfs_map_sector(s, 17, &bh, 0))) {
  26. sb->dirty = 1;
  27. sb->old_wrote = 0;
  28. mark_buffer_dirty(bh);
  29. sync_dirty_buffer(bh);
  30. brelse(bh);
  31. }
  32. }
  33. }
  34. /* Mark the filesystem clean (mark it dirty for chkdsk if chkdsk==2 or if there
  35. were errors) */
  36. static void unmark_dirty(struct super_block *s)
  37. {
  38. struct buffer_head *bh;
  39. struct hpfs_spare_block *sb;
  40. if (sb_rdonly(s)) return;
  41. sync_blockdev(s->s_bdev);
  42. if ((sb = hpfs_map_sector(s, 17, &bh, 0))) {
  43. sb->dirty = hpfs_sb(s)->sb_chkdsk > 1 - hpfs_sb(s)->sb_was_error;
  44. sb->old_wrote = hpfs_sb(s)->sb_chkdsk >= 2 && !hpfs_sb(s)->sb_was_error;
  45. mark_buffer_dirty(bh);
  46. sync_dirty_buffer(bh);
  47. brelse(bh);
  48. }
  49. }
  50. /* Filesystem error... */
  51. void hpfs_error(struct super_block *s, const char *fmt, ...)
  52. {
  53. struct va_format vaf;
  54. va_list args;
  55. va_start(args, fmt);
  56. vaf.fmt = fmt;
  57. vaf.va = &args;
  58. pr_err("filesystem error: %pV", &vaf);
  59. va_end(args);
  60. if (!hpfs_sb(s)->sb_was_error) {
  61. if (hpfs_sb(s)->sb_err == 2) {
  62. pr_cont("; crashing the system because you wanted it\n");
  63. mark_dirty(s, 0);
  64. panic("HPFS panic");
  65. } else if (hpfs_sb(s)->sb_err == 1) {
  66. if (sb_rdonly(s))
  67. pr_cont("; already mounted read-only\n");
  68. else {
  69. pr_cont("; remounting read-only\n");
  70. mark_dirty(s, 0);
  71. s->s_flags |= SB_RDONLY;
  72. }
  73. } else if (sb_rdonly(s))
  74. pr_cont("; going on - but anything won't be destroyed because it's read-only\n");
  75. else
  76. pr_cont("; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so!\n");
  77. } else
  78. pr_cont("\n");
  79. hpfs_sb(s)->sb_was_error = 1;
  80. }
  81. /*
  82. * A little trick to detect cycles in many hpfs structures and don't let the
  83. * kernel crash on corrupted filesystem. When first called, set c2 to 0.
  84. *
  85. * BTW. chkdsk doesn't detect cycles correctly. When I had 2 lost directories
  86. * nested each in other, chkdsk locked up happilly.
  87. */
  88. int hpfs_stop_cycles(struct super_block *s, int key, int *c1, int *c2,
  89. char *msg)
  90. {
  91. if (*c2 && *c1 == key) {
  92. hpfs_error(s, "cycle detected on key %08x in %s", key, msg);
  93. return 1;
  94. }
  95. (*c2)++;
  96. if (!((*c2 - 1) & *c2)) *c1 = key;
  97. return 0;
  98. }
  99. static void free_sbi(struct hpfs_sb_info *sbi)
  100. {
  101. kfree(sbi->sb_cp_table);
  102. kfree(sbi->sb_bmp_dir);
  103. kfree(sbi);
  104. }
  105. static void lazy_free_sbi(struct rcu_head *rcu)
  106. {
  107. free_sbi(container_of(rcu, struct hpfs_sb_info, rcu));
  108. }
  109. static void hpfs_put_super(struct super_block *s)
  110. {
  111. hpfs_lock(s);
  112. unmark_dirty(s);
  113. hpfs_unlock(s);
  114. call_rcu(&hpfs_sb(s)->rcu, lazy_free_sbi);
  115. }
  116. static unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
  117. {
  118. struct quad_buffer_head qbh;
  119. unsigned long *bits;
  120. unsigned count;
  121. bits = hpfs_map_4sectors(s, secno, &qbh, 0);
  122. if (!bits)
  123. return (unsigned)-1;
  124. count = bitmap_weight(bits, 2048 * BITS_PER_BYTE);
  125. hpfs_brelse4(&qbh);
  126. return count;
  127. }
  128. static unsigned count_bitmaps(struct super_block *s)
  129. {
  130. unsigned n, count, n_bands;
  131. n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
  132. count = 0;
  133. for (n = 0; n < COUNT_RD_AHEAD; n++) {
  134. hpfs_prefetch_bitmap(s, n);
  135. }
  136. for (n = 0; n < n_bands; n++) {
  137. unsigned c;
  138. hpfs_prefetch_bitmap(s, n + COUNT_RD_AHEAD);
  139. c = hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
  140. if (c != (unsigned)-1)
  141. count += c;
  142. }
  143. return count;
  144. }
  145. unsigned hpfs_get_free_dnodes(struct super_block *s)
  146. {
  147. struct hpfs_sb_info *sbi = hpfs_sb(s);
  148. if (sbi->sb_n_free_dnodes == (unsigned)-1) {
  149. unsigned c = hpfs_count_one_bitmap(s, sbi->sb_dmap);
  150. if (c == (unsigned)-1)
  151. return 0;
  152. sbi->sb_n_free_dnodes = c;
  153. }
  154. return sbi->sb_n_free_dnodes;
  155. }
  156. static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  157. {
  158. struct super_block *s = dentry->d_sb;
  159. struct hpfs_sb_info *sbi = hpfs_sb(s);
  160. u64 id = huge_encode_dev(s->s_bdev->bd_dev);
  161. hpfs_lock(s);
  162. if (sbi->sb_n_free == (unsigned)-1)
  163. sbi->sb_n_free = count_bitmaps(s);
  164. buf->f_type = s->s_magic;
  165. buf->f_bsize = 512;
  166. buf->f_blocks = sbi->sb_fs_size;
  167. buf->f_bfree = sbi->sb_n_free;
  168. buf->f_bavail = sbi->sb_n_free;
  169. buf->f_files = sbi->sb_dirband_size / 4;
  170. buf->f_ffree = hpfs_get_free_dnodes(s);
  171. buf->f_fsid = u64_to_fsid(id);
  172. buf->f_namelen = 254;
  173. hpfs_unlock(s);
  174. return 0;
  175. }
  176. long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
  177. {
  178. switch (cmd) {
  179. case FITRIM: {
  180. struct fstrim_range range;
  181. secno n_trimmed;
  182. int r;
  183. if (!capable(CAP_SYS_ADMIN))
  184. return -EPERM;
  185. if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
  186. return -EFAULT;
  187. r = hpfs_trim_fs(file_inode(file)->i_sb, range.start >> 9, (range.start + range.len) >> 9, (range.minlen + 511) >> 9, &n_trimmed);
  188. if (r)
  189. return r;
  190. range.len = (u64)n_trimmed << 9;
  191. if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range)))
  192. return -EFAULT;
  193. return 0;
  194. }
  195. default: {
  196. return -ENOIOCTLCMD;
  197. }
  198. }
  199. }
  200. static struct kmem_cache * hpfs_inode_cachep;
  201. static struct inode *hpfs_alloc_inode(struct super_block *sb)
  202. {
  203. struct hpfs_inode_info *ei;
  204. ei = kmem_cache_alloc(hpfs_inode_cachep, GFP_NOFS);
  205. if (!ei)
  206. return NULL;
  207. return &ei->vfs_inode;
  208. }
  209. static void hpfs_free_inode(struct inode *inode)
  210. {
  211. kmem_cache_free(hpfs_inode_cachep, hpfs_i(inode));
  212. }
  213. static void init_once(void *foo)
  214. {
  215. struct hpfs_inode_info *ei = (struct hpfs_inode_info *) foo;
  216. inode_init_once(&ei->vfs_inode);
  217. }
  218. static int init_inodecache(void)
  219. {
  220. hpfs_inode_cachep = kmem_cache_create("hpfs_inode_cache",
  221. sizeof(struct hpfs_inode_info),
  222. 0, (SLAB_RECLAIM_ACCOUNT|
  223. SLAB_MEM_SPREAD|SLAB_ACCOUNT),
  224. init_once);
  225. if (hpfs_inode_cachep == NULL)
  226. return -ENOMEM;
  227. return 0;
  228. }
  229. static void destroy_inodecache(void)
  230. {
  231. /*
  232. * Make sure all delayed rcu free inodes are flushed before we
  233. * destroy cache.
  234. */
  235. rcu_barrier();
  236. kmem_cache_destroy(hpfs_inode_cachep);
  237. }
  238. /*
  239. * A tiny parser for option strings, stolen from dosfs.
  240. * Stolen again from read-only hpfs.
  241. * And updated for table-driven option parsing.
  242. */
  243. enum {
  244. Opt_help, Opt_uid, Opt_gid, Opt_umask, Opt_case_lower, Opt_case_asis,
  245. Opt_check_none, Opt_check_normal, Opt_check_strict,
  246. Opt_err_cont, Opt_err_ro, Opt_err_panic,
  247. Opt_eas_no, Opt_eas_ro, Opt_eas_rw,
  248. Opt_chkdsk_no, Opt_chkdsk_errors, Opt_chkdsk_always,
  249. Opt_timeshift, Opt_err,
  250. };
  251. static const match_table_t tokens = {
  252. {Opt_help, "help"},
  253. {Opt_uid, "uid=%u"},
  254. {Opt_gid, "gid=%u"},
  255. {Opt_umask, "umask=%o"},
  256. {Opt_case_lower, "case=lower"},
  257. {Opt_case_asis, "case=asis"},
  258. {Opt_check_none, "check=none"},
  259. {Opt_check_normal, "check=normal"},
  260. {Opt_check_strict, "check=strict"},
  261. {Opt_err_cont, "errors=continue"},
  262. {Opt_err_ro, "errors=remount-ro"},
  263. {Opt_err_panic, "errors=panic"},
  264. {Opt_eas_no, "eas=no"},
  265. {Opt_eas_ro, "eas=ro"},
  266. {Opt_eas_rw, "eas=rw"},
  267. {Opt_chkdsk_no, "chkdsk=no"},
  268. {Opt_chkdsk_errors, "chkdsk=errors"},
  269. {Opt_chkdsk_always, "chkdsk=always"},
  270. {Opt_timeshift, "timeshift=%d"},
  271. {Opt_err, NULL},
  272. };
  273. static int parse_opts(char *opts, kuid_t *uid, kgid_t *gid, umode_t *umask,
  274. int *lowercase, int *eas, int *chk, int *errs,
  275. int *chkdsk, int *timeshift)
  276. {
  277. char *p;
  278. int option;
  279. if (!opts)
  280. return 1;
  281. /*pr_info("Parsing opts: '%s'\n",opts);*/
  282. while ((p = strsep(&opts, ",")) != NULL) {
  283. substring_t args[MAX_OPT_ARGS];
  284. int token;
  285. if (!*p)
  286. continue;
  287. token = match_token(p, tokens, args);
  288. switch (token) {
  289. case Opt_help:
  290. return 2;
  291. case Opt_uid:
  292. if (match_int(args, &option))
  293. return 0;
  294. *uid = make_kuid(current_user_ns(), option);
  295. if (!uid_valid(*uid))
  296. return 0;
  297. break;
  298. case Opt_gid:
  299. if (match_int(args, &option))
  300. return 0;
  301. *gid = make_kgid(current_user_ns(), option);
  302. if (!gid_valid(*gid))
  303. return 0;
  304. break;
  305. case Opt_umask:
  306. if (match_octal(args, &option))
  307. return 0;
  308. *umask = option;
  309. break;
  310. case Opt_case_lower:
  311. *lowercase = 1;
  312. break;
  313. case Opt_case_asis:
  314. *lowercase = 0;
  315. break;
  316. case Opt_check_none:
  317. *chk = 0;
  318. break;
  319. case Opt_check_normal:
  320. *chk = 1;
  321. break;
  322. case Opt_check_strict:
  323. *chk = 2;
  324. break;
  325. case Opt_err_cont:
  326. *errs = 0;
  327. break;
  328. case Opt_err_ro:
  329. *errs = 1;
  330. break;
  331. case Opt_err_panic:
  332. *errs = 2;
  333. break;
  334. case Opt_eas_no:
  335. *eas = 0;
  336. break;
  337. case Opt_eas_ro:
  338. *eas = 1;
  339. break;
  340. case Opt_eas_rw:
  341. *eas = 2;
  342. break;
  343. case Opt_chkdsk_no:
  344. *chkdsk = 0;
  345. break;
  346. case Opt_chkdsk_errors:
  347. *chkdsk = 1;
  348. break;
  349. case Opt_chkdsk_always:
  350. *chkdsk = 2;
  351. break;
  352. case Opt_timeshift:
  353. {
  354. int m = 1;
  355. char *rhs = args[0].from;
  356. if (!rhs || !*rhs)
  357. return 0;
  358. if (*rhs == '-') m = -1;
  359. if (*rhs == '+' || *rhs == '-') rhs++;
  360. *timeshift = simple_strtoul(rhs, &rhs, 0) * m;
  361. if (*rhs)
  362. return 0;
  363. break;
  364. }
  365. default:
  366. return 0;
  367. }
  368. }
  369. return 1;
  370. }
  371. static inline void hpfs_help(void)
  372. {
  373. pr_info("\n\
  374. HPFS filesystem options:\n\
  375. help do not mount and display this text\n\
  376. uid=xxx set uid of files that don't have uid specified in eas\n\
  377. gid=xxx set gid of files that don't have gid specified in eas\n\
  378. umask=xxx set mode of files that don't have mode specified in eas\n\
  379. case=lower lowercase all files\n\
  380. case=asis do not lowercase files (default)\n\
  381. check=none no fs checks - kernel may crash on corrupted filesystem\n\
  382. check=normal do some checks - it should not crash (default)\n\
  383. check=strict do extra time-consuming checks, used for debugging\n\
  384. errors=continue continue on errors\n\
  385. errors=remount-ro remount read-only if errors found (default)\n\
  386. errors=panic panic on errors\n\
  387. chkdsk=no do not mark fs for chkdsking even if there were errors\n\
  388. chkdsk=errors mark fs dirty if errors found (default)\n\
  389. chkdsk=always always mark fs dirty - used for debugging\n\
  390. eas=no ignore extended attributes\n\
  391. eas=ro read but do not write extended attributes\n\
  392. eas=rw r/w eas => enables chmod, chown, mknod, ln -s (default)\n\
  393. timeshift=nnn add nnn seconds to file times\n\
  394. \n");
  395. }
  396. static int hpfs_remount_fs(struct super_block *s, int *flags, char *data)
  397. {
  398. kuid_t uid;
  399. kgid_t gid;
  400. umode_t umask;
  401. int lowercase, eas, chk, errs, chkdsk, timeshift;
  402. int o;
  403. struct hpfs_sb_info *sbi = hpfs_sb(s);
  404. sync_filesystem(s);
  405. *flags |= SB_NOATIME;
  406. hpfs_lock(s);
  407. uid = sbi->sb_uid; gid = sbi->sb_gid;
  408. umask = 0777 & ~sbi->sb_mode;
  409. lowercase = sbi->sb_lowercase;
  410. eas = sbi->sb_eas; chk = sbi->sb_chk; chkdsk = sbi->sb_chkdsk;
  411. errs = sbi->sb_err; timeshift = sbi->sb_timeshift;
  412. if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase,
  413. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  414. pr_err("bad mount options.\n");
  415. goto out_err;
  416. }
  417. if (o == 2) {
  418. hpfs_help();
  419. goto out_err;
  420. }
  421. if (timeshift != sbi->sb_timeshift) {
  422. pr_err("timeshift can't be changed using remount.\n");
  423. goto out_err;
  424. }
  425. unmark_dirty(s);
  426. sbi->sb_uid = uid; sbi->sb_gid = gid;
  427. sbi->sb_mode = 0777 & ~umask;
  428. sbi->sb_lowercase = lowercase;
  429. sbi->sb_eas = eas; sbi->sb_chk = chk; sbi->sb_chkdsk = chkdsk;
  430. sbi->sb_err = errs; sbi->sb_timeshift = timeshift;
  431. if (!(*flags & SB_RDONLY)) mark_dirty(s, 1);
  432. hpfs_unlock(s);
  433. return 0;
  434. out_err:
  435. hpfs_unlock(s);
  436. return -EINVAL;
  437. }
  438. static int hpfs_show_options(struct seq_file *seq, struct dentry *root)
  439. {
  440. struct hpfs_sb_info *sbi = hpfs_sb(root->d_sb);
  441. seq_printf(seq, ",uid=%u", from_kuid_munged(&init_user_ns, sbi->sb_uid));
  442. seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, sbi->sb_gid));
  443. seq_printf(seq, ",umask=%03o", (~sbi->sb_mode & 0777));
  444. if (sbi->sb_lowercase)
  445. seq_printf(seq, ",case=lower");
  446. if (!sbi->sb_chk)
  447. seq_printf(seq, ",check=none");
  448. if (sbi->sb_chk == 2)
  449. seq_printf(seq, ",check=strict");
  450. if (!sbi->sb_err)
  451. seq_printf(seq, ",errors=continue");
  452. if (sbi->sb_err == 2)
  453. seq_printf(seq, ",errors=panic");
  454. if (!sbi->sb_chkdsk)
  455. seq_printf(seq, ",chkdsk=no");
  456. if (sbi->sb_chkdsk == 2)
  457. seq_printf(seq, ",chkdsk=always");
  458. if (!sbi->sb_eas)
  459. seq_printf(seq, ",eas=no");
  460. if (sbi->sb_eas == 1)
  461. seq_printf(seq, ",eas=ro");
  462. if (sbi->sb_timeshift)
  463. seq_printf(seq, ",timeshift=%d", sbi->sb_timeshift);
  464. return 0;
  465. }
  466. /* Super operations */
  467. static const struct super_operations hpfs_sops =
  468. {
  469. .alloc_inode = hpfs_alloc_inode,
  470. .free_inode = hpfs_free_inode,
  471. .evict_inode = hpfs_evict_inode,
  472. .put_super = hpfs_put_super,
  473. .statfs = hpfs_statfs,
  474. .remount_fs = hpfs_remount_fs,
  475. .show_options = hpfs_show_options,
  476. };
  477. static int hpfs_fill_super(struct super_block *s, void *options, int silent)
  478. {
  479. struct buffer_head *bh0, *bh1, *bh2;
  480. struct hpfs_boot_block *bootblock;
  481. struct hpfs_super_block *superblock;
  482. struct hpfs_spare_block *spareblock;
  483. struct hpfs_sb_info *sbi;
  484. struct inode *root;
  485. kuid_t uid;
  486. kgid_t gid;
  487. umode_t umask;
  488. int lowercase, eas, chk, errs, chkdsk, timeshift;
  489. dnode_secno root_dno;
  490. struct hpfs_dirent *de = NULL;
  491. struct quad_buffer_head qbh;
  492. int o;
  493. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  494. if (!sbi) {
  495. return -ENOMEM;
  496. }
  497. s->s_fs_info = sbi;
  498. mutex_init(&sbi->hpfs_mutex);
  499. hpfs_lock(s);
  500. uid = current_uid();
  501. gid = current_gid();
  502. umask = current_umask();
  503. lowercase = 0;
  504. eas = 2;
  505. chk = 1;
  506. errs = 1;
  507. chkdsk = 1;
  508. timeshift = 0;
  509. if (!(o = parse_opts(options, &uid, &gid, &umask, &lowercase,
  510. &eas, &chk, &errs, &chkdsk, &timeshift))) {
  511. pr_err("bad mount options.\n");
  512. goto bail0;
  513. }
  514. if (o==2) {
  515. hpfs_help();
  516. goto bail0;
  517. }
  518. /*sbi->sb_mounting = 1;*/
  519. sb_set_blocksize(s, 512);
  520. sbi->sb_fs_size = -1;
  521. if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1;
  522. if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2;
  523. if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3;
  524. /* Check magics */
  525. if (/*le16_to_cpu(bootblock->magic) != BB_MAGIC
  526. ||*/ le32_to_cpu(superblock->magic) != SB_MAGIC
  527. || le32_to_cpu(spareblock->magic) != SP_MAGIC) {
  528. if (!silent)
  529. pr_err("Bad magic ... probably not HPFS\n");
  530. goto bail4;
  531. }
  532. /* Check version */
  533. if (!sb_rdonly(s) && superblock->funcversion != 2 && superblock->funcversion != 3) {
  534. pr_err("Bad version %d,%d. Mount readonly to go around\n",
  535. (int)superblock->version, (int)superblock->funcversion);
  536. pr_err("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");
  537. goto bail4;
  538. }
  539. s->s_flags |= SB_NOATIME;
  540. /* Fill superblock stuff */
  541. s->s_magic = HPFS_SUPER_MAGIC;
  542. s->s_op = &hpfs_sops;
  543. s->s_d_op = &hpfs_dentry_operations;
  544. s->s_time_min = local_to_gmt(s, 0);
  545. s->s_time_max = local_to_gmt(s, U32_MAX);
  546. sbi->sb_root = le32_to_cpu(superblock->root);
  547. sbi->sb_fs_size = le32_to_cpu(superblock->n_sectors);
  548. sbi->sb_bitmaps = le32_to_cpu(superblock->bitmaps);
  549. sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
  550. sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
  551. sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
  552. sbi->sb_uid = uid;
  553. sbi->sb_gid = gid;
  554. sbi->sb_mode = 0777 & ~umask;
  555. sbi->sb_n_free = -1;
  556. sbi->sb_n_free_dnodes = -1;
  557. sbi->sb_lowercase = lowercase;
  558. sbi->sb_eas = eas;
  559. sbi->sb_chk = chk;
  560. sbi->sb_chkdsk = chkdsk;
  561. sbi->sb_err = errs;
  562. sbi->sb_timeshift = timeshift;
  563. sbi->sb_was_error = 0;
  564. sbi->sb_cp_table = NULL;
  565. sbi->sb_c_bitmap = -1;
  566. sbi->sb_max_fwd_alloc = 0xffffff;
  567. if (sbi->sb_fs_size >= 0x80000000) {
  568. hpfs_error(s, "invalid size in superblock: %08x",
  569. (unsigned)sbi->sb_fs_size);
  570. goto bail4;
  571. }
  572. if (spareblock->n_spares_used)
  573. hpfs_load_hotfix_map(s, spareblock);
  574. /* Load bitmap directory */
  575. if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
  576. goto bail4;
  577. /* Check for general fs errors*/
  578. if (spareblock->dirty && !spareblock->old_wrote) {
  579. if (errs == 2) {
  580. pr_err("Improperly stopped, not mounted\n");
  581. goto bail4;
  582. }
  583. hpfs_error(s, "improperly stopped");
  584. }
  585. if (!sb_rdonly(s)) {
  586. spareblock->dirty = 1;
  587. spareblock->old_wrote = 0;
  588. mark_buffer_dirty(bh2);
  589. }
  590. if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) {
  591. if (errs >= 2) {
  592. pr_err("Spare dnodes used, try chkdsk\n");
  593. mark_dirty(s, 0);
  594. goto bail4;
  595. }
  596. hpfs_error(s, "warning: spare dnodes used, try chkdsk");
  597. if (errs == 0)
  598. pr_err("Proceeding, but your filesystem could be corrupted if you delete files or directories\n");
  599. }
  600. if (chk) {
  601. unsigned a;
  602. if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) ||
  603. le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) {
  604. hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x",
  605. le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->dir_band_end), le32_to_cpu(superblock->n_dir_band));
  606. goto bail4;
  607. }
  608. a = sbi->sb_dirband_size;
  609. sbi->sb_dirband_size = 0;
  610. if (hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->n_dir_band), "dir_band") ||
  611. hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_bitmap), 4, "dir_band_bitmap") ||
  612. hpfs_chk_sectors(s, le32_to_cpu(superblock->bitmaps), 4, "bitmaps")) {
  613. mark_dirty(s, 0);
  614. goto bail4;
  615. }
  616. sbi->sb_dirband_size = a;
  617. } else
  618. pr_err("You really don't want any checks? You are crazy...\n");
  619. /* Load code page table */
  620. if (le32_to_cpu(spareblock->n_code_pages))
  621. if (!(sbi->sb_cp_table = hpfs_load_code_page(s, le32_to_cpu(spareblock->code_page_dir))))
  622. pr_err("code page support is disabled\n");
  623. brelse(bh2);
  624. brelse(bh1);
  625. brelse(bh0);
  626. root = iget_locked(s, sbi->sb_root);
  627. if (!root)
  628. goto bail0;
  629. hpfs_init_inode(root);
  630. hpfs_read_inode(root);
  631. unlock_new_inode(root);
  632. s->s_root = d_make_root(root);
  633. if (!s->s_root)
  634. goto bail0;
  635. /*
  636. * find the root directory's . pointer & finish filling in the inode
  637. */
  638. root_dno = hpfs_fnode_dno(s, sbi->sb_root);
  639. if (root_dno)
  640. de = map_dirent(root, root_dno, "\001\001", 2, NULL, &qbh);
  641. if (!de)
  642. hpfs_error(s, "unable to find root dir");
  643. else {
  644. root->i_atime.tv_sec = local_to_gmt(s, le32_to_cpu(de->read_date));
  645. root->i_atime.tv_nsec = 0;
  646. root->i_mtime.tv_sec = local_to_gmt(s, le32_to_cpu(de->write_date));
  647. root->i_mtime.tv_nsec = 0;
  648. root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date));
  649. root->i_ctime.tv_nsec = 0;
  650. hpfs_i(root)->i_ea_size = le32_to_cpu(de->ea_size);
  651. hpfs_i(root)->i_parent_dir = root->i_ino;
  652. if (root->i_size == -1)
  653. root->i_size = 2048;
  654. if (root->i_blocks == -1)
  655. root->i_blocks = 5;
  656. hpfs_brelse4(&qbh);
  657. }
  658. hpfs_unlock(s);
  659. return 0;
  660. bail4: brelse(bh2);
  661. bail3: brelse(bh1);
  662. bail2: brelse(bh0);
  663. bail1:
  664. bail0:
  665. hpfs_unlock(s);
  666. free_sbi(sbi);
  667. return -EINVAL;
  668. }
  669. static struct dentry *hpfs_mount(struct file_system_type *fs_type,
  670. int flags, const char *dev_name, void *data)
  671. {
  672. return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super);
  673. }
  674. static struct file_system_type hpfs_fs_type = {
  675. .owner = THIS_MODULE,
  676. .name = "hpfs",
  677. .mount = hpfs_mount,
  678. .kill_sb = kill_block_super,
  679. .fs_flags = FS_REQUIRES_DEV,
  680. };
  681. MODULE_ALIAS_FS("hpfs");
  682. static int __init init_hpfs_fs(void)
  683. {
  684. int err = init_inodecache();
  685. if (err)
  686. goto out1;
  687. err = register_filesystem(&hpfs_fs_type);
  688. if (err)
  689. goto out;
  690. return 0;
  691. out:
  692. destroy_inodecache();
  693. out1:
  694. return err;
  695. }
  696. static void __exit exit_hpfs_fs(void)
  697. {
  698. unregister_filesystem(&hpfs_fs_type);
  699. destroy_inodecache();
  700. }
  701. module_init(init_hpfs_fs)
  702. module_exit(exit_hpfs_fs)
  703. MODULE_LICENSE("GPL");
  704. MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);