super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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/fs_parser.h>
  17. #include <linux/fs_context.h>
  18. #include <linux/magic.h>
  19. #include <linux/sched.h>
  20. #include <linux/cred.h>
  21. #include <linux/slab.h>
  22. #include <linux/writeback.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/iversion.h>
  26. #include "affs.h"
  27. static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
  28. static int affs_show_options(struct seq_file *m, struct dentry *root);
  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. .show_options = affs_show_options,
  133. };
  134. enum {
  135. Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect,
  136. Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
  137. Opt_verbose, Opt_volume, Opt_ignore,
  138. };
  139. struct affs_context {
  140. kuid_t uid; /* uid to override */
  141. kgid_t gid; /* gid to override */
  142. unsigned int mode; /* mode to override */
  143. unsigned int reserved; /* Number of reserved blocks */
  144. int root_block; /* FFS root block number */
  145. int blocksize; /* Initial device blksize */
  146. char *prefix; /* Prefix for volumes and assigns */
  147. char volume[32]; /* Vol. prefix for absolute symlinks */
  148. unsigned long mount_flags; /* Options */
  149. };
  150. static const struct fs_parameter_spec affs_param_spec[] = {
  151. fsparam_u32 ("bs", Opt_bs),
  152. fsparam_u32oct ("mode", Opt_mode),
  153. fsparam_flag ("mufs", Opt_mufs),
  154. fsparam_flag ("nofilenametruncate", Opt_notruncate),
  155. fsparam_string ("prefix", Opt_prefix),
  156. fsparam_flag ("protect", Opt_protect),
  157. fsparam_u32 ("reserved", Opt_reserved),
  158. fsparam_u32 ("root", Opt_root),
  159. fsparam_gid ("setgid", Opt_setgid),
  160. fsparam_uid ("setuid", Opt_setuid),
  161. fsparam_flag ("verbose", Opt_verbose),
  162. fsparam_string ("volume", Opt_volume),
  163. fsparam_flag ("grpquota", Opt_ignore),
  164. fsparam_flag ("noquota", Opt_ignore),
  165. fsparam_flag ("quota", Opt_ignore),
  166. fsparam_flag ("usrquota", Opt_ignore),
  167. {},
  168. };
  169. static int affs_parse_param(struct fs_context *fc, struct fs_parameter *param)
  170. {
  171. struct affs_context *ctx = fc->fs_private;
  172. struct fs_parse_result result;
  173. int n;
  174. int opt;
  175. opt = fs_parse(fc, affs_param_spec, param, &result);
  176. if (opt < 0)
  177. return opt;
  178. switch (opt) {
  179. case Opt_bs:
  180. n = result.uint_32;
  181. if (n != 512 && n != 1024 && n != 2048
  182. && n != 4096) {
  183. pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n");
  184. return -EINVAL;
  185. }
  186. ctx->blocksize = n;
  187. break;
  188. case Opt_mode:
  189. ctx->mode = result.uint_32 & 0777;
  190. affs_set_opt(ctx->mount_flags, SF_SETMODE);
  191. break;
  192. case Opt_mufs:
  193. affs_set_opt(ctx->mount_flags, SF_MUFS);
  194. break;
  195. case Opt_notruncate:
  196. affs_set_opt(ctx->mount_flags, SF_NO_TRUNCATE);
  197. break;
  198. case Opt_prefix:
  199. kfree(ctx->prefix);
  200. ctx->prefix = param->string;
  201. param->string = NULL;
  202. affs_set_opt(ctx->mount_flags, SF_PREFIX);
  203. break;
  204. case Opt_protect:
  205. affs_set_opt(ctx->mount_flags, SF_IMMUTABLE);
  206. break;
  207. case Opt_reserved:
  208. ctx->reserved = result.uint_32;
  209. break;
  210. case Opt_root:
  211. ctx->root_block = result.uint_32;
  212. break;
  213. case Opt_setgid:
  214. ctx->gid = result.gid;
  215. affs_set_opt(ctx->mount_flags, SF_SETGID);
  216. break;
  217. case Opt_setuid:
  218. ctx->uid = result.uid;
  219. affs_set_opt(ctx->mount_flags, SF_SETUID);
  220. break;
  221. case Opt_verbose:
  222. affs_set_opt(ctx->mount_flags, SF_VERBOSE);
  223. break;
  224. case Opt_volume:
  225. strscpy(ctx->volume, param->string, 32);
  226. break;
  227. case Opt_ignore:
  228. /* Silently ignore the quota options */
  229. break;
  230. default:
  231. return -EINVAL;
  232. }
  233. return 0;
  234. }
  235. static int affs_show_options(struct seq_file *m, struct dentry *root)
  236. {
  237. struct super_block *sb = root->d_sb;
  238. struct affs_sb_info *sbi = AFFS_SB(sb);
  239. if (sb->s_blocksize)
  240. seq_printf(m, ",bs=%lu", sb->s_blocksize);
  241. if (affs_test_opt(sbi->s_flags, SF_SETMODE))
  242. seq_printf(m, ",mode=%o", sbi->s_mode);
  243. if (affs_test_opt(sbi->s_flags, SF_MUFS))
  244. seq_puts(m, ",mufs");
  245. if (affs_test_opt(sbi->s_flags, SF_NO_TRUNCATE))
  246. seq_puts(m, ",nofilenametruncate");
  247. if (affs_test_opt(sbi->s_flags, SF_PREFIX))
  248. seq_printf(m, ",prefix=%s", sbi->s_prefix);
  249. if (affs_test_opt(sbi->s_flags, SF_IMMUTABLE))
  250. seq_puts(m, ",protect");
  251. if (sbi->s_reserved != 2)
  252. seq_printf(m, ",reserved=%u", sbi->s_reserved);
  253. if (sbi->s_root_block != (sbi->s_reserved + sbi->s_partition_size - 1) / 2)
  254. seq_printf(m, ",root=%u", sbi->s_root_block);
  255. if (affs_test_opt(sbi->s_flags, SF_SETGID))
  256. seq_printf(m, ",setgid=%u",
  257. from_kgid_munged(&init_user_ns, sbi->s_gid));
  258. if (affs_test_opt(sbi->s_flags, SF_SETUID))
  259. seq_printf(m, ",setuid=%u",
  260. from_kuid_munged(&init_user_ns, sbi->s_uid));
  261. if (affs_test_opt(sbi->s_flags, SF_VERBOSE))
  262. seq_puts(m, ",verbose");
  263. if (sbi->s_volume[0])
  264. seq_printf(m, ",volume=%s", sbi->s_volume);
  265. return 0;
  266. }
  267. /* This function definitely needs to be split up. Some fine day I'll
  268. * hopefully have the guts to do so. Until then: sorry for the mess.
  269. */
  270. static int affs_fill_super(struct super_block *sb, struct fs_context *fc)
  271. {
  272. struct affs_sb_info *sbi;
  273. struct affs_context *ctx = fc->fs_private;
  274. struct buffer_head *root_bh = NULL;
  275. struct buffer_head *boot_bh;
  276. struct inode *root_inode = NULL;
  277. int silent = fc->sb_flags & SB_SILENT;
  278. int size, blocksize;
  279. u32 chksum;
  280. int num_bm;
  281. int i, j;
  282. int tmp_flags; /* fix remount prototype... */
  283. u8 sig[4];
  284. int ret;
  285. sb->s_magic = AFFS_SUPER_MAGIC;
  286. sb->s_op = &affs_sops;
  287. sb->s_flags |= SB_NODIRATIME;
  288. sb->s_time_gran = NSEC_PER_SEC;
  289. sb->s_time_min = sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
  290. sb->s_time_max = 86400LL * U32_MAX + 86400 + sb->s_time_min;
  291. sbi = kzalloc_obj(struct affs_sb_info);
  292. if (!sbi)
  293. return -ENOMEM;
  294. sb->s_fs_info = sbi;
  295. sbi->sb = sb;
  296. mutex_init(&sbi->s_bmlock);
  297. spin_lock_init(&sbi->symlink_lock);
  298. spin_lock_init(&sbi->work_lock);
  299. INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock);
  300. sbi->s_flags = ctx->mount_flags;
  301. sbi->s_mode = ctx->mode;
  302. sbi->s_uid = ctx->uid;
  303. sbi->s_gid = ctx->gid;
  304. sbi->s_reserved = ctx->reserved;
  305. sbi->s_prefix = ctx->prefix;
  306. ctx->prefix = NULL;
  307. memcpy(sbi->s_volume, ctx->volume, 32);
  308. /* N.B. after this point s_prefix must be released */
  309. /* Get the size of the device in 512-byte blocks.
  310. * If we later see that the partition uses bigger
  311. * blocks, we will have to change it.
  312. */
  313. size = bdev_nr_sectors(sb->s_bdev);
  314. pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size);
  315. affs_set_blocksize(sb, PAGE_SIZE);
  316. /* Try to find root block. Its location depends on the block size. */
  317. i = bdev_logical_block_size(sb->s_bdev);
  318. j = PAGE_SIZE;
  319. blocksize = ctx->blocksize;
  320. if (blocksize > 0) {
  321. i = j = blocksize;
  322. size = size / (blocksize / 512);
  323. }
  324. for (blocksize = i; blocksize <= j; blocksize <<= 1, size >>= 1) {
  325. sbi->s_root_block = ctx->root_block;
  326. if (ctx->root_block < 0)
  327. sbi->s_root_block = (ctx->reserved + size - 1) / 2;
  328. pr_debug("setting blocksize to %d\n", blocksize);
  329. affs_set_blocksize(sb, blocksize);
  330. sbi->s_partition_size = size;
  331. /* The root block location that was calculated above is not
  332. * correct if the partition size is an odd number of 512-
  333. * byte blocks, which will be rounded down to a number of
  334. * 1024-byte blocks, and if there were an even number of
  335. * reserved blocks. Ideally, all partition checkers should
  336. * report the real number of blocks of the real blocksize,
  337. * but since this just cannot be done, we have to try to
  338. * find the root block anyways. In the above case, it is one
  339. * block behind the calculated one. So we check this one, too.
  340. */
  341. for (num_bm = 0; num_bm < 2; num_bm++) {
  342. pr_debug("Dev %s, trying root=%u, bs=%d, "
  343. "size=%d, reserved=%d\n",
  344. sb->s_id,
  345. sbi->s_root_block + num_bm,
  346. ctx->blocksize, size, ctx->reserved);
  347. root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
  348. if (!root_bh)
  349. continue;
  350. if (!affs_checksum_block(sb, root_bh) &&
  351. be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT &&
  352. be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) {
  353. sbi->s_hashsize = blocksize / 4 - 56;
  354. sbi->s_root_block += num_bm;
  355. goto got_root;
  356. }
  357. affs_brelse(root_bh);
  358. root_bh = NULL;
  359. }
  360. }
  361. if (!silent)
  362. pr_err("No valid root block on device %s\n", sb->s_id);
  363. return -EINVAL;
  364. /* N.B. after this point bh must be released */
  365. got_root:
  366. /* Keep super block in cache */
  367. sbi->s_root_bh = root_bh;
  368. ctx->root_block = sbi->s_root_block;
  369. /* Find out which kind of FS we have */
  370. boot_bh = sb_bread(sb, 0);
  371. if (!boot_bh) {
  372. pr_err("Cannot read boot block\n");
  373. return -EINVAL;
  374. }
  375. memcpy(sig, boot_bh->b_data, 4);
  376. brelse(boot_bh);
  377. chksum = be32_to_cpu(*(__be32 *)sig);
  378. /* Dircache filesystems are compatible with non-dircache ones
  379. * when reading. As long as they aren't supported, writing is
  380. * not recommended.
  381. */
  382. if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
  383. || chksum == MUFS_DCOFS) && !sb_rdonly(sb)) {
  384. pr_notice("Dircache FS - mounting %s read only\n", sb->s_id);
  385. sb->s_flags |= SB_RDONLY;
  386. }
  387. switch (chksum) {
  388. case MUFS_FS:
  389. case MUFS_INTLFFS:
  390. case MUFS_DCFFS:
  391. affs_set_opt(sbi->s_flags, SF_MUFS);
  392. fallthrough;
  393. case FS_INTLFFS:
  394. case FS_DCFFS:
  395. affs_set_opt(sbi->s_flags, SF_INTL);
  396. break;
  397. case MUFS_FFS:
  398. affs_set_opt(sbi->s_flags, SF_MUFS);
  399. break;
  400. case FS_FFS:
  401. break;
  402. case MUFS_OFS:
  403. affs_set_opt(sbi->s_flags, SF_MUFS);
  404. fallthrough;
  405. case FS_OFS:
  406. affs_set_opt(sbi->s_flags, SF_OFS);
  407. sb->s_flags |= SB_NOEXEC;
  408. break;
  409. case MUFS_DCOFS:
  410. case MUFS_INTLOFS:
  411. affs_set_opt(sbi->s_flags, SF_MUFS);
  412. fallthrough;
  413. case FS_DCOFS:
  414. case FS_INTLOFS:
  415. affs_set_opt(sbi->s_flags, SF_INTL);
  416. affs_set_opt(sbi->s_flags, SF_OFS);
  417. sb->s_flags |= SB_NOEXEC;
  418. break;
  419. default:
  420. pr_err("Unknown filesystem on device %s: %08X\n",
  421. sb->s_id, chksum);
  422. return -EINVAL;
  423. }
  424. if (affs_test_opt(ctx->mount_flags, SF_VERBOSE)) {
  425. u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
  426. pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
  427. len > 31 ? 31 : len,
  428. AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
  429. sig, sig[3] + '0', blocksize);
  430. }
  431. sb->s_flags |= SB_NODEV | SB_NOSUID;
  432. sbi->s_data_blksize = sb->s_blocksize;
  433. if (affs_test_opt(sbi->s_flags, SF_OFS))
  434. sbi->s_data_blksize -= 24;
  435. tmp_flags = sb->s_flags;
  436. ret = affs_init_bitmap(sb, &tmp_flags);
  437. if (ret)
  438. return ret;
  439. sb->s_flags = tmp_flags;
  440. /* set up enough so that it can read an inode */
  441. root_inode = affs_iget(sb, ctx->root_block);
  442. if (IS_ERR(root_inode))
  443. return PTR_ERR(root_inode);
  444. if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL))
  445. set_default_d_op(sb, &affs_intl_dentry_operations);
  446. else
  447. set_default_d_op(sb, &affs_dentry_operations);
  448. sb->s_root = d_make_root(root_inode);
  449. if (!sb->s_root) {
  450. pr_err("AFFS: Get root inode failed\n");
  451. return -ENOMEM;
  452. }
  453. sb->s_export_op = &affs_export_ops;
  454. pr_debug("s_flags=%lX\n", sb->s_flags);
  455. return 0;
  456. }
  457. static int affs_reconfigure(struct fs_context *fc)
  458. {
  459. struct super_block *sb = fc->root->d_sb;
  460. struct affs_context *ctx = fc->fs_private;
  461. struct affs_sb_info *sbi = AFFS_SB(sb);
  462. int res = 0;
  463. sync_filesystem(sb);
  464. fc->sb_flags |= SB_NODIRATIME;
  465. flush_delayed_work(&sbi->sb_work);
  466. /*
  467. * NB: Historically, only mount_flags, mode, uid, gic, prefix,
  468. * and volume are accepted during remount.
  469. */
  470. sbi->s_flags = ctx->mount_flags;
  471. sbi->s_mode = ctx->mode;
  472. sbi->s_uid = ctx->uid;
  473. sbi->s_gid = ctx->gid;
  474. /* protect against readers */
  475. spin_lock(&sbi->symlink_lock);
  476. if (ctx->prefix) {
  477. kfree(sbi->s_prefix);
  478. sbi->s_prefix = ctx->prefix;
  479. ctx->prefix = NULL;
  480. }
  481. memcpy(sbi->s_volume, ctx->volume, 32);
  482. spin_unlock(&sbi->symlink_lock);
  483. if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb))
  484. return 0;
  485. if (fc->sb_flags & SB_RDONLY)
  486. affs_free_bitmap(sb);
  487. else
  488. res = affs_init_bitmap(sb, &fc->sb_flags);
  489. return res;
  490. }
  491. static int
  492. affs_statfs(struct dentry *dentry, struct kstatfs *buf)
  493. {
  494. struct super_block *sb = dentry->d_sb;
  495. int free;
  496. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  497. pr_debug("%s() partsize=%d, reserved=%d\n",
  498. __func__, AFFS_SB(sb)->s_partition_size,
  499. AFFS_SB(sb)->s_reserved);
  500. free = affs_count_free_blocks(sb);
  501. buf->f_type = AFFS_SUPER_MAGIC;
  502. buf->f_bsize = sb->s_blocksize;
  503. buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
  504. buf->f_bfree = free;
  505. buf->f_bavail = free;
  506. buf->f_fsid = u64_to_fsid(id);
  507. buf->f_namelen = AFFSNAMEMAX;
  508. return 0;
  509. }
  510. static int affs_get_tree(struct fs_context *fc)
  511. {
  512. return get_tree_bdev(fc, affs_fill_super);
  513. }
  514. static void affs_kill_sb(struct super_block *sb)
  515. {
  516. struct affs_sb_info *sbi = AFFS_SB(sb);
  517. kill_block_super(sb);
  518. if (sbi) {
  519. affs_free_bitmap(sb);
  520. affs_brelse(sbi->s_root_bh);
  521. kfree(sbi->s_prefix);
  522. mutex_destroy(&sbi->s_bmlock);
  523. kfree_rcu(sbi, rcu);
  524. }
  525. }
  526. static void affs_free_fc(struct fs_context *fc)
  527. {
  528. struct affs_context *ctx = fc->fs_private;
  529. kfree(ctx->prefix);
  530. kfree(ctx);
  531. }
  532. static const struct fs_context_operations affs_context_ops = {
  533. .parse_param = affs_parse_param,
  534. .get_tree = affs_get_tree,
  535. .reconfigure = affs_reconfigure,
  536. .free = affs_free_fc,
  537. };
  538. static int affs_init_fs_context(struct fs_context *fc)
  539. {
  540. struct affs_context *ctx;
  541. ctx = kzalloc_obj(struct affs_context);
  542. if (!ctx)
  543. return -ENOMEM;
  544. if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
  545. struct super_block *sb = fc->root->d_sb;
  546. struct affs_sb_info *sbi = AFFS_SB(sb);
  547. /*
  548. * NB: historically, no options other than volume were
  549. * preserved across a remount unless they were explicitly
  550. * passed in.
  551. */
  552. memcpy(ctx->volume, sbi->s_volume, 32);
  553. } else {
  554. ctx->uid = current_uid();
  555. ctx->gid = current_gid();
  556. ctx->reserved = 2;
  557. ctx->root_block = -1;
  558. ctx->blocksize = -1;
  559. ctx->volume[0] = ':';
  560. }
  561. fc->ops = &affs_context_ops;
  562. fc->fs_private = ctx;
  563. return 0;
  564. }
  565. static struct file_system_type affs_fs_type = {
  566. .owner = THIS_MODULE,
  567. .name = "affs",
  568. .kill_sb = affs_kill_sb,
  569. .fs_flags = FS_REQUIRES_DEV,
  570. .init_fs_context = affs_init_fs_context,
  571. .parameters = affs_param_spec,
  572. };
  573. MODULE_ALIAS_FS("affs");
  574. static int __init init_affs_fs(void)
  575. {
  576. int err = init_inodecache();
  577. if (err)
  578. goto out1;
  579. err = register_filesystem(&affs_fs_type);
  580. if (err)
  581. goto out;
  582. return 0;
  583. out:
  584. destroy_inodecache();
  585. out1:
  586. return err;
  587. }
  588. static void __exit exit_affs_fs(void)
  589. {
  590. unregister_filesystem(&affs_fs_type);
  591. destroy_inodecache();
  592. }
  593. MODULE_DESCRIPTION("Amiga filesystem support for Linux");
  594. MODULE_LICENSE("GPL");
  595. module_init(init_affs_fs)
  596. module_exit(exit_affs_fs)