super.c 17 KB

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