super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/fs/affs/inode.c
  4. *
  5. * (c) 1996 Hans-Joachim Widmaier - Rewritten
  6. *
  7. * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
  8. *
  9. * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
  10. *
  11. * (C) 1991 Linus Torvalds - minix filesystem
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/statfs.h>
  16. #include <linux/parser.h>
  17. #include <linux/magic.h>
  18. #include <linux/sched.h>
  19. #include <linux/cred.h>
  20. #include <linux/slab.h>
  21. #include <linux/writeback.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/iversion.h>
  25. #include "affs.h"
  26. static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
  27. static int affs_show_options(struct seq_file *m, struct dentry *root);
  28. static int affs_remount (struct super_block *sb, int *flags, char *data);
  29. static void
  30. affs_commit_super(struct super_block *sb, int wait)
  31. {
  32. struct affs_sb_info *sbi = AFFS_SB(sb);
  33. struct buffer_head *bh = sbi->s_root_bh;
  34. struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
  35. lock_buffer(bh);
  36. affs_secs_to_datestamp(ktime_get_real_seconds(), &tail->disk_change);
  37. affs_fix_checksum(sb, bh);
  38. unlock_buffer(bh);
  39. mark_buffer_dirty(bh);
  40. if (wait)
  41. sync_dirty_buffer(bh);
  42. }
  43. static void
  44. affs_put_super(struct super_block *sb)
  45. {
  46. struct affs_sb_info *sbi = AFFS_SB(sb);
  47. pr_debug("%s()\n", __func__);
  48. cancel_delayed_work_sync(&sbi->sb_work);
  49. }
  50. static int
  51. affs_sync_fs(struct super_block *sb, int wait)
  52. {
  53. affs_commit_super(sb, wait);
  54. return 0;
  55. }
  56. static void flush_superblock(struct work_struct *work)
  57. {
  58. struct affs_sb_info *sbi;
  59. struct super_block *sb;
  60. sbi = container_of(work, struct affs_sb_info, sb_work.work);
  61. sb = sbi->sb;
  62. spin_lock(&sbi->work_lock);
  63. sbi->work_queued = 0;
  64. spin_unlock(&sbi->work_lock);
  65. affs_commit_super(sb, 1);
  66. }
  67. void affs_mark_sb_dirty(struct super_block *sb)
  68. {
  69. struct affs_sb_info *sbi = AFFS_SB(sb);
  70. unsigned long delay;
  71. if (sb_rdonly(sb))
  72. return;
  73. spin_lock(&sbi->work_lock);
  74. if (!sbi->work_queued) {
  75. delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  76. queue_delayed_work(system_long_wq, &sbi->sb_work, delay);
  77. sbi->work_queued = 1;
  78. }
  79. spin_unlock(&sbi->work_lock);
  80. }
  81. static struct kmem_cache * affs_inode_cachep;
  82. static struct inode *affs_alloc_inode(struct super_block *sb)
  83. {
  84. struct affs_inode_info *i;
  85. i = alloc_inode_sb(sb, affs_inode_cachep, GFP_KERNEL);
  86. if (!i)
  87. return NULL;
  88. inode_set_iversion(&i->vfs_inode, 1);
  89. i->i_lc = NULL;
  90. i->i_ext_bh = NULL;
  91. i->i_pa_cnt = 0;
  92. return &i->vfs_inode;
  93. }
  94. static void affs_free_inode(struct inode *inode)
  95. {
  96. kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
  97. }
  98. static void init_once(void *foo)
  99. {
  100. struct affs_inode_info *ei = (struct affs_inode_info *) foo;
  101. mutex_init(&ei->i_link_lock);
  102. mutex_init(&ei->i_ext_lock);
  103. inode_init_once(&ei->vfs_inode);
  104. }
  105. static int __init init_inodecache(void)
  106. {
  107. affs_inode_cachep = kmem_cache_create("affs_inode_cache",
  108. sizeof(struct affs_inode_info),
  109. 0, (SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT),
  110. init_once);
  111. if (affs_inode_cachep == NULL)
  112. return -ENOMEM;
  113. return 0;
  114. }
  115. static void destroy_inodecache(void)
  116. {
  117. /*
  118. * Make sure all delayed rcu free inodes are flushed before we
  119. * destroy cache.
  120. */
  121. rcu_barrier();
  122. kmem_cache_destroy(affs_inode_cachep);
  123. }
  124. static const struct super_operations affs_sops = {
  125. .alloc_inode = affs_alloc_inode,
  126. .free_inode = affs_free_inode,
  127. .write_inode = affs_write_inode,
  128. .evict_inode = affs_evict_inode,
  129. .put_super = affs_put_super,
  130. .sync_fs = affs_sync_fs,
  131. .statfs = affs_statfs,
  132. .remount_fs = affs_remount,
  133. .show_options = affs_show_options,
  134. };
  135. enum {
  136. Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect,
  137. Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
  138. Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
  139. };
  140. static const match_table_t tokens = {
  141. {Opt_bs, "bs=%u"},
  142. {Opt_mode, "mode=%o"},
  143. {Opt_mufs, "mufs"},
  144. {Opt_notruncate, "nofilenametruncate"},
  145. {Opt_prefix, "prefix=%s"},
  146. {Opt_protect, "protect"},
  147. {Opt_reserved, "reserved=%u"},
  148. {Opt_root, "root=%u"},
  149. {Opt_setgid, "setgid=%u"},
  150. {Opt_setuid, "setuid=%u"},
  151. {Opt_verbose, "verbose"},
  152. {Opt_volume, "volume=%s"},
  153. {Opt_ignore, "grpquota"},
  154. {Opt_ignore, "noquota"},
  155. {Opt_ignore, "quota"},
  156. {Opt_ignore, "usrquota"},
  157. {Opt_err, NULL},
  158. };
  159. static int
  160. parse_options(char *options, kuid_t *uid, kgid_t *gid, int *mode, int *reserved, s32 *root,
  161. int *blocksize, char **prefix, char *volume, unsigned long *mount_opts)
  162. {
  163. char *p;
  164. substring_t args[MAX_OPT_ARGS];
  165. /* Fill in defaults */
  166. *uid = current_uid();
  167. *gid = current_gid();
  168. *reserved = 2;
  169. *root = -1;
  170. *blocksize = -1;
  171. volume[0] = ':';
  172. volume[1] = 0;
  173. *mount_opts = 0;
  174. if (!options)
  175. return 1;
  176. while ((p = strsep(&options, ",")) != NULL) {
  177. int token, n, option;
  178. if (!*p)
  179. continue;
  180. token = match_token(p, tokens, args);
  181. switch (token) {
  182. case Opt_bs:
  183. if (match_int(&args[0], &n))
  184. return 0;
  185. if (n != 512 && n != 1024 && n != 2048
  186. && n != 4096) {
  187. pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n");
  188. return 0;
  189. }
  190. *blocksize = n;
  191. break;
  192. case Opt_mode:
  193. if (match_octal(&args[0], &option))
  194. return 0;
  195. *mode = option & 0777;
  196. affs_set_opt(*mount_opts, SF_SETMODE);
  197. break;
  198. case Opt_mufs:
  199. affs_set_opt(*mount_opts, SF_MUFS);
  200. break;
  201. case Opt_notruncate:
  202. affs_set_opt(*mount_opts, SF_NO_TRUNCATE);
  203. break;
  204. case Opt_prefix:
  205. kfree(*prefix);
  206. *prefix = match_strdup(&args[0]);
  207. if (!*prefix)
  208. return 0;
  209. affs_set_opt(*mount_opts, SF_PREFIX);
  210. break;
  211. case Opt_protect:
  212. affs_set_opt(*mount_opts, SF_IMMUTABLE);
  213. break;
  214. case Opt_reserved:
  215. if (match_int(&args[0], reserved))
  216. return 0;
  217. break;
  218. case Opt_root:
  219. if (match_int(&args[0], root))
  220. return 0;
  221. break;
  222. case Opt_setgid:
  223. if (match_int(&args[0], &option))
  224. return 0;
  225. *gid = make_kgid(current_user_ns(), option);
  226. if (!gid_valid(*gid))
  227. return 0;
  228. affs_set_opt(*mount_opts, SF_SETGID);
  229. break;
  230. case Opt_setuid:
  231. if (match_int(&args[0], &option))
  232. return 0;
  233. *uid = make_kuid(current_user_ns(), option);
  234. if (!uid_valid(*uid))
  235. return 0;
  236. affs_set_opt(*mount_opts, SF_SETUID);
  237. break;
  238. case Opt_verbose:
  239. affs_set_opt(*mount_opts, SF_VERBOSE);
  240. break;
  241. case Opt_volume: {
  242. char *vol = match_strdup(&args[0]);
  243. if (!vol)
  244. return 0;
  245. strscpy(volume, vol, 32);
  246. kfree(vol);
  247. break;
  248. }
  249. case Opt_ignore:
  250. /* Silently ignore the quota options */
  251. break;
  252. default:
  253. pr_warn("Unrecognized mount option \"%s\" or missing value\n",
  254. p);
  255. return 0;
  256. }
  257. }
  258. return 1;
  259. }
  260. static int affs_show_options(struct seq_file *m, struct dentry *root)
  261. {
  262. struct super_block *sb = root->d_sb;
  263. struct affs_sb_info *sbi = AFFS_SB(sb);
  264. if (sb->s_blocksize)
  265. seq_printf(m, ",bs=%lu", sb->s_blocksize);
  266. if (affs_test_opt(sbi->s_flags, SF_SETMODE))
  267. seq_printf(m, ",mode=%o", sbi->s_mode);
  268. if (affs_test_opt(sbi->s_flags, SF_MUFS))
  269. seq_puts(m, ",mufs");
  270. if (affs_test_opt(sbi->s_flags, SF_NO_TRUNCATE))
  271. seq_puts(m, ",nofilenametruncate");
  272. if (affs_test_opt(sbi->s_flags, SF_PREFIX))
  273. seq_printf(m, ",prefix=%s", sbi->s_prefix);
  274. if (affs_test_opt(sbi->s_flags, SF_IMMUTABLE))
  275. seq_puts(m, ",protect");
  276. if (sbi->s_reserved != 2)
  277. seq_printf(m, ",reserved=%u", sbi->s_reserved);
  278. if (sbi->s_root_block != (sbi->s_reserved + sbi->s_partition_size - 1) / 2)
  279. seq_printf(m, ",root=%u", sbi->s_root_block);
  280. if (affs_test_opt(sbi->s_flags, SF_SETGID))
  281. seq_printf(m, ",setgid=%u",
  282. from_kgid_munged(&init_user_ns, sbi->s_gid));
  283. if (affs_test_opt(sbi->s_flags, SF_SETUID))
  284. seq_printf(m, ",setuid=%u",
  285. from_kuid_munged(&init_user_ns, sbi->s_uid));
  286. if (affs_test_opt(sbi->s_flags, SF_VERBOSE))
  287. seq_puts(m, ",verbose");
  288. if (sbi->s_volume[0])
  289. seq_printf(m, ",volume=%s", sbi->s_volume);
  290. return 0;
  291. }
  292. /* This function definitely needs to be split up. Some fine day I'll
  293. * hopefully have the guts to do so. Until then: sorry for the mess.
  294. */
  295. static int affs_fill_super(struct super_block *sb, void *data, int silent)
  296. {
  297. struct affs_sb_info *sbi;
  298. struct buffer_head *root_bh = NULL;
  299. struct buffer_head *boot_bh;
  300. struct inode *root_inode = NULL;
  301. s32 root_block;
  302. int size, blocksize;
  303. u32 chksum;
  304. int num_bm;
  305. int i, j;
  306. kuid_t uid;
  307. kgid_t gid;
  308. int reserved;
  309. unsigned long mount_flags;
  310. int tmp_flags; /* fix remount prototype... */
  311. u8 sig[4];
  312. int ret;
  313. pr_debug("read_super(%s)\n", data ? (const char *)data : "no options");
  314. sb->s_magic = AFFS_SUPER_MAGIC;
  315. sb->s_op = &affs_sops;
  316. sb->s_flags |= SB_NODIRATIME;
  317. sb->s_time_gran = NSEC_PER_SEC;
  318. sb->s_time_min = sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
  319. sb->s_time_max = 86400LL * U32_MAX + 86400 + sb->s_time_min;
  320. sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
  321. if (!sbi)
  322. return -ENOMEM;
  323. sb->s_fs_info = sbi;
  324. sbi->sb = sb;
  325. mutex_init(&sbi->s_bmlock);
  326. spin_lock_init(&sbi->symlink_lock);
  327. spin_lock_init(&sbi->work_lock);
  328. INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock);
  329. if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
  330. &blocksize,&sbi->s_prefix,
  331. sbi->s_volume, &mount_flags)) {
  332. pr_err("Error parsing options\n");
  333. return -EINVAL;
  334. }
  335. /* N.B. after this point s_prefix must be released */
  336. sbi->s_flags = mount_flags;
  337. sbi->s_mode = i;
  338. sbi->s_uid = uid;
  339. sbi->s_gid = gid;
  340. sbi->s_reserved= reserved;
  341. /* Get the size of the device in 512-byte blocks.
  342. * If we later see that the partition uses bigger
  343. * blocks, we will have to change it.
  344. */
  345. size = bdev_nr_sectors(sb->s_bdev);
  346. pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size);
  347. affs_set_blocksize(sb, PAGE_SIZE);
  348. /* Try to find root block. Its location depends on the block size. */
  349. i = bdev_logical_block_size(sb->s_bdev);
  350. j = PAGE_SIZE;
  351. if (blocksize > 0) {
  352. i = j = blocksize;
  353. size = size / (blocksize / 512);
  354. }
  355. for (blocksize = i; blocksize <= j; blocksize <<= 1, size >>= 1) {
  356. sbi->s_root_block = root_block;
  357. if (root_block < 0)
  358. sbi->s_root_block = (reserved + size - 1) / 2;
  359. pr_debug("setting blocksize to %d\n", blocksize);
  360. affs_set_blocksize(sb, blocksize);
  361. sbi->s_partition_size = size;
  362. /* The root block location that was calculated above is not
  363. * correct if the partition size is an odd number of 512-
  364. * byte blocks, which will be rounded down to a number of
  365. * 1024-byte blocks, and if there were an even number of
  366. * reserved blocks. Ideally, all partition checkers should
  367. * report the real number of blocks of the real blocksize,
  368. * but since this just cannot be done, we have to try to
  369. * find the root block anyways. In the above case, it is one
  370. * block behind the calculated one. So we check this one, too.
  371. */
  372. for (num_bm = 0; num_bm < 2; num_bm++) {
  373. pr_debug("Dev %s, trying root=%u, bs=%d, "
  374. "size=%d, reserved=%d\n",
  375. sb->s_id,
  376. sbi->s_root_block + num_bm,
  377. blocksize, size, reserved);
  378. root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
  379. if (!root_bh)
  380. continue;
  381. if (!affs_checksum_block(sb, root_bh) &&
  382. be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT &&
  383. be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) {
  384. sbi->s_hashsize = blocksize / 4 - 56;
  385. sbi->s_root_block += num_bm;
  386. goto got_root;
  387. }
  388. affs_brelse(root_bh);
  389. root_bh = NULL;
  390. }
  391. }
  392. if (!silent)
  393. pr_err("No valid root block on device %s\n", sb->s_id);
  394. return -EINVAL;
  395. /* N.B. after this point bh must be released */
  396. got_root:
  397. /* Keep super block in cache */
  398. sbi->s_root_bh = root_bh;
  399. root_block = sbi->s_root_block;
  400. /* Find out which kind of FS we have */
  401. boot_bh = sb_bread(sb, 0);
  402. if (!boot_bh) {
  403. pr_err("Cannot read boot block\n");
  404. return -EINVAL;
  405. }
  406. memcpy(sig, boot_bh->b_data, 4);
  407. brelse(boot_bh);
  408. chksum = be32_to_cpu(*(__be32 *)sig);
  409. /* Dircache filesystems are compatible with non-dircache ones
  410. * when reading. As long as they aren't supported, writing is
  411. * not recommended.
  412. */
  413. if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
  414. || chksum == MUFS_DCOFS) && !sb_rdonly(sb)) {
  415. pr_notice("Dircache FS - mounting %s read only\n", sb->s_id);
  416. sb->s_flags |= SB_RDONLY;
  417. }
  418. switch (chksum) {
  419. case MUFS_FS:
  420. case MUFS_INTLFFS:
  421. case MUFS_DCFFS:
  422. affs_set_opt(sbi->s_flags, SF_MUFS);
  423. fallthrough;
  424. case FS_INTLFFS:
  425. case FS_DCFFS:
  426. affs_set_opt(sbi->s_flags, SF_INTL);
  427. break;
  428. case MUFS_FFS:
  429. affs_set_opt(sbi->s_flags, SF_MUFS);
  430. break;
  431. case FS_FFS:
  432. break;
  433. case MUFS_OFS:
  434. affs_set_opt(sbi->s_flags, SF_MUFS);
  435. fallthrough;
  436. case FS_OFS:
  437. affs_set_opt(sbi->s_flags, SF_OFS);
  438. sb->s_flags |= SB_NOEXEC;
  439. break;
  440. case MUFS_DCOFS:
  441. case MUFS_INTLOFS:
  442. affs_set_opt(sbi->s_flags, SF_MUFS);
  443. fallthrough;
  444. case FS_DCOFS:
  445. case FS_INTLOFS:
  446. affs_set_opt(sbi->s_flags, SF_INTL);
  447. affs_set_opt(sbi->s_flags, SF_OFS);
  448. sb->s_flags |= SB_NOEXEC;
  449. break;
  450. default:
  451. pr_err("Unknown filesystem on device %s: %08X\n",
  452. sb->s_id, chksum);
  453. return -EINVAL;
  454. }
  455. if (affs_test_opt(mount_flags, SF_VERBOSE)) {
  456. u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
  457. pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
  458. len > 31 ? 31 : len,
  459. AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
  460. sig, sig[3] + '0', blocksize);
  461. }
  462. sb->s_flags |= SB_NODEV | SB_NOSUID;
  463. sbi->s_data_blksize = sb->s_blocksize;
  464. if (affs_test_opt(sbi->s_flags, SF_OFS))
  465. sbi->s_data_blksize -= 24;
  466. tmp_flags = sb->s_flags;
  467. ret = affs_init_bitmap(sb, &tmp_flags);
  468. if (ret)
  469. return ret;
  470. sb->s_flags = tmp_flags;
  471. /* set up enough so that it can read an inode */
  472. root_inode = affs_iget(sb, root_block);
  473. if (IS_ERR(root_inode))
  474. return PTR_ERR(root_inode);
  475. if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL))
  476. sb->s_d_op = &affs_intl_dentry_operations;
  477. else
  478. sb->s_d_op = &affs_dentry_operations;
  479. sb->s_root = d_make_root(root_inode);
  480. if (!sb->s_root) {
  481. pr_err("AFFS: Get root inode failed\n");
  482. return -ENOMEM;
  483. }
  484. sb->s_export_op = &affs_export_ops;
  485. pr_debug("s_flags=%lX\n", sb->s_flags);
  486. return 0;
  487. }
  488. static int
  489. affs_remount(struct super_block *sb, int *flags, char *data)
  490. {
  491. struct affs_sb_info *sbi = AFFS_SB(sb);
  492. int blocksize;
  493. kuid_t uid;
  494. kgid_t gid;
  495. int mode;
  496. int reserved;
  497. int root_block;
  498. unsigned long mount_flags;
  499. int res = 0;
  500. char volume[32];
  501. char *prefix = NULL;
  502. pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
  503. sync_filesystem(sb);
  504. *flags |= SB_NODIRATIME;
  505. memcpy(volume, sbi->s_volume, 32);
  506. if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
  507. &blocksize, &prefix, volume,
  508. &mount_flags)) {
  509. kfree(prefix);
  510. return -EINVAL;
  511. }
  512. flush_delayed_work(&sbi->sb_work);
  513. sbi->s_flags = mount_flags;
  514. sbi->s_mode = mode;
  515. sbi->s_uid = uid;
  516. sbi->s_gid = gid;
  517. /* protect against readers */
  518. spin_lock(&sbi->symlink_lock);
  519. if (prefix) {
  520. kfree(sbi->s_prefix);
  521. sbi->s_prefix = prefix;
  522. }
  523. memcpy(sbi->s_volume, volume, 32);
  524. spin_unlock(&sbi->symlink_lock);
  525. if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  526. return 0;
  527. if (*flags & SB_RDONLY)
  528. affs_free_bitmap(sb);
  529. else
  530. res = affs_init_bitmap(sb, flags);
  531. return res;
  532. }
  533. static int
  534. affs_statfs(struct dentry *dentry, struct kstatfs *buf)
  535. {
  536. struct super_block *sb = dentry->d_sb;
  537. int free;
  538. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  539. pr_debug("%s() partsize=%d, reserved=%d\n",
  540. __func__, AFFS_SB(sb)->s_partition_size,
  541. AFFS_SB(sb)->s_reserved);
  542. free = affs_count_free_blocks(sb);
  543. buf->f_type = AFFS_SUPER_MAGIC;
  544. buf->f_bsize = sb->s_blocksize;
  545. buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
  546. buf->f_bfree = free;
  547. buf->f_bavail = free;
  548. buf->f_fsid = u64_to_fsid(id);
  549. buf->f_namelen = AFFSNAMEMAX;
  550. return 0;
  551. }
  552. static struct dentry *affs_mount(struct file_system_type *fs_type,
  553. int flags, const char *dev_name, void *data)
  554. {
  555. return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super);
  556. }
  557. static void affs_kill_sb(struct super_block *sb)
  558. {
  559. struct affs_sb_info *sbi = AFFS_SB(sb);
  560. kill_block_super(sb);
  561. if (sbi) {
  562. affs_free_bitmap(sb);
  563. affs_brelse(sbi->s_root_bh);
  564. kfree(sbi->s_prefix);
  565. mutex_destroy(&sbi->s_bmlock);
  566. kfree_rcu(sbi, rcu);
  567. }
  568. }
  569. static struct file_system_type affs_fs_type = {
  570. .owner = THIS_MODULE,
  571. .name = "affs",
  572. .mount = affs_mount,
  573. .kill_sb = affs_kill_sb,
  574. .fs_flags = FS_REQUIRES_DEV,
  575. };
  576. MODULE_ALIAS_FS("affs");
  577. static int __init init_affs_fs(void)
  578. {
  579. int err = init_inodecache();
  580. if (err)
  581. goto out1;
  582. err = register_filesystem(&affs_fs_type);
  583. if (err)
  584. goto out;
  585. return 0;
  586. out:
  587. destroy_inodecache();
  588. out1:
  589. return err;
  590. }
  591. static void __exit exit_affs_fs(void)
  592. {
  593. unregister_filesystem(&affs_fs_type);
  594. destroy_inodecache();
  595. }
  596. MODULE_DESCRIPTION("Amiga filesystem support for Linux");
  597. MODULE_LICENSE("GPL");
  598. module_init(init_affs_fs)
  599. module_exit(exit_affs_fs)