super.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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 "affs.h"
  24. static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
  25. static int affs_show_options(struct seq_file *m, struct dentry *root);
  26. static int affs_remount (struct super_block *sb, int *flags, char *data);
  27. static void
  28. affs_commit_super(struct super_block *sb, int wait)
  29. {
  30. struct affs_sb_info *sbi = AFFS_SB(sb);
  31. struct buffer_head *bh = sbi->s_root_bh;
  32. struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
  33. lock_buffer(bh);
  34. affs_secs_to_datestamp(ktime_get_real_seconds(), &tail->disk_change);
  35. affs_fix_checksum(sb, bh);
  36. unlock_buffer(bh);
  37. mark_buffer_dirty(bh);
  38. if (wait)
  39. sync_dirty_buffer(bh);
  40. }
  41. static void
  42. affs_put_super(struct super_block *sb)
  43. {
  44. struct affs_sb_info *sbi = AFFS_SB(sb);
  45. pr_debug("%s()\n", __func__);
  46. cancel_delayed_work_sync(&sbi->sb_work);
  47. }
  48. static int
  49. affs_sync_fs(struct super_block *sb, int wait)
  50. {
  51. affs_commit_super(sb, wait);
  52. return 0;
  53. }
  54. static void flush_superblock(struct work_struct *work)
  55. {
  56. struct affs_sb_info *sbi;
  57. struct super_block *sb;
  58. sbi = container_of(work, struct affs_sb_info, sb_work.work);
  59. sb = sbi->sb;
  60. spin_lock(&sbi->work_lock);
  61. sbi->work_queued = 0;
  62. spin_unlock(&sbi->work_lock);
  63. affs_commit_super(sb, 1);
  64. }
  65. void affs_mark_sb_dirty(struct super_block *sb)
  66. {
  67. struct affs_sb_info *sbi = AFFS_SB(sb);
  68. unsigned long delay;
  69. if (sb_rdonly(sb))
  70. return;
  71. spin_lock(&sbi->work_lock);
  72. if (!sbi->work_queued) {
  73. delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  74. queue_delayed_work(system_long_wq, &sbi->sb_work, delay);
  75. sbi->work_queued = 1;
  76. }
  77. spin_unlock(&sbi->work_lock);
  78. }
  79. static struct kmem_cache * affs_inode_cachep;
  80. static struct inode *affs_alloc_inode(struct super_block *sb)
  81. {
  82. struct affs_inode_info *i;
  83. i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL);
  84. if (!i)
  85. return NULL;
  86. i->vfs_inode.i_version = 1;
  87. i->i_lc = NULL;
  88. i->i_ext_bh = NULL;
  89. i->i_pa_cnt = 0;
  90. return &i->vfs_inode;
  91. }
  92. static void affs_i_callback(struct rcu_head *head)
  93. {
  94. struct inode *inode = container_of(head, struct inode, i_rcu);
  95. kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
  96. }
  97. static void affs_destroy_inode(struct inode *inode)
  98. {
  99. call_rcu(&inode->i_rcu, affs_i_callback);
  100. }
  101. static void init_once(void *foo)
  102. {
  103. struct affs_inode_info *ei = (struct affs_inode_info *) foo;
  104. sema_init(&ei->i_link_lock, 1);
  105. sema_init(&ei->i_ext_lock, 1);
  106. inode_init_once(&ei->vfs_inode);
  107. }
  108. static int __init init_inodecache(void)
  109. {
  110. affs_inode_cachep = kmem_cache_create("affs_inode_cache",
  111. sizeof(struct affs_inode_info),
  112. 0, (SLAB_RECLAIM_ACCOUNT|
  113. SLAB_MEM_SPREAD|SLAB_ACCOUNT),
  114. init_once);
  115. if (affs_inode_cachep == NULL)
  116. return -ENOMEM;
  117. return 0;
  118. }
  119. static void destroy_inodecache(void)
  120. {
  121. /*
  122. * Make sure all delayed rcu free inodes are flushed before we
  123. * destroy cache.
  124. */
  125. rcu_barrier();
  126. kmem_cache_destroy(affs_inode_cachep);
  127. }
  128. static const struct super_operations affs_sops = {
  129. .alloc_inode = affs_alloc_inode,
  130. .destroy_inode = affs_destroy_inode,
  131. .write_inode = affs_write_inode,
  132. .evict_inode = affs_evict_inode,
  133. .put_super = affs_put_super,
  134. .sync_fs = affs_sync_fs,
  135. .statfs = affs_statfs,
  136. .remount_fs = affs_remount,
  137. .show_options = affs_show_options,
  138. };
  139. enum {
  140. Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect,
  141. Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
  142. Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
  143. };
  144. static const match_table_t tokens = {
  145. {Opt_bs, "bs=%u"},
  146. {Opt_mode, "mode=%o"},
  147. {Opt_mufs, "mufs"},
  148. {Opt_notruncate, "nofilenametruncate"},
  149. {Opt_prefix, "prefix=%s"},
  150. {Opt_protect, "protect"},
  151. {Opt_reserved, "reserved=%u"},
  152. {Opt_root, "root=%u"},
  153. {Opt_setgid, "setgid=%u"},
  154. {Opt_setuid, "setuid=%u"},
  155. {Opt_verbose, "verbose"},
  156. {Opt_volume, "volume=%s"},
  157. {Opt_ignore, "grpquota"},
  158. {Opt_ignore, "noquota"},
  159. {Opt_ignore, "quota"},
  160. {Opt_ignore, "usrquota"},
  161. {Opt_err, NULL},
  162. };
  163. static int
  164. parse_options(char *options, kuid_t *uid, kgid_t *gid, int *mode, int *reserved, s32 *root,
  165. int *blocksize, char **prefix, char *volume, unsigned long *mount_opts)
  166. {
  167. char *p;
  168. substring_t args[MAX_OPT_ARGS];
  169. /* Fill in defaults */
  170. *uid = current_uid();
  171. *gid = current_gid();
  172. *reserved = 2;
  173. *root = -1;
  174. *blocksize = -1;
  175. volume[0] = ':';
  176. volume[1] = 0;
  177. *mount_opts = 0;
  178. if (!options)
  179. return 1;
  180. while ((p = strsep(&options, ",")) != NULL) {
  181. int token, n, option;
  182. if (!*p)
  183. continue;
  184. token = match_token(p, tokens, args);
  185. switch (token) {
  186. case Opt_bs:
  187. if (match_int(&args[0], &n))
  188. return 0;
  189. if (n != 512 && n != 1024 && n != 2048
  190. && n != 4096) {
  191. pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n");
  192. return 0;
  193. }
  194. *blocksize = n;
  195. break;
  196. case Opt_mode:
  197. if (match_octal(&args[0], &option))
  198. return 0;
  199. *mode = option & 0777;
  200. affs_set_opt(*mount_opts, SF_SETMODE);
  201. break;
  202. case Opt_mufs:
  203. affs_set_opt(*mount_opts, SF_MUFS);
  204. break;
  205. case Opt_notruncate:
  206. affs_set_opt(*mount_opts, SF_NO_TRUNCATE);
  207. break;
  208. case Opt_prefix:
  209. *prefix = match_strdup(&args[0]);
  210. if (!*prefix)
  211. return 0;
  212. affs_set_opt(*mount_opts, SF_PREFIX);
  213. break;
  214. case Opt_protect:
  215. affs_set_opt(*mount_opts, SF_IMMUTABLE);
  216. break;
  217. case Opt_reserved:
  218. if (match_int(&args[0], reserved))
  219. return 0;
  220. break;
  221. case Opt_root:
  222. if (match_int(&args[0], root))
  223. return 0;
  224. break;
  225. case Opt_setgid:
  226. if (match_int(&args[0], &option))
  227. return 0;
  228. *gid = make_kgid(current_user_ns(), option);
  229. if (!gid_valid(*gid))
  230. return 0;
  231. affs_set_opt(*mount_opts, SF_SETGID);
  232. break;
  233. case Opt_setuid:
  234. if (match_int(&args[0], &option))
  235. return 0;
  236. *uid = make_kuid(current_user_ns(), option);
  237. if (!uid_valid(*uid))
  238. return 0;
  239. affs_set_opt(*mount_opts, SF_SETUID);
  240. break;
  241. case Opt_verbose:
  242. affs_set_opt(*mount_opts, SF_VERBOSE);
  243. break;
  244. case Opt_volume: {
  245. char *vol = match_strdup(&args[0]);
  246. if (!vol)
  247. return 0;
  248. strlcpy(volume, vol, 32);
  249. kfree(vol);
  250. break;
  251. }
  252. case Opt_ignore:
  253. /* Silently ignore the quota options */
  254. break;
  255. default:
  256. pr_warn("Unrecognized mount option \"%s\" or missing value\n",
  257. p);
  258. return 0;
  259. }
  260. }
  261. return 1;
  262. }
  263. static int affs_show_options(struct seq_file *m, struct dentry *root)
  264. {
  265. struct super_block *sb = root->d_sb;
  266. struct affs_sb_info *sbi = AFFS_SB(sb);
  267. if (sb->s_blocksize)
  268. seq_printf(m, ",bs=%lu", sb->s_blocksize);
  269. if (affs_test_opt(sbi->s_flags, SF_SETMODE))
  270. seq_printf(m, ",mode=%o", sbi->s_mode);
  271. if (affs_test_opt(sbi->s_flags, SF_MUFS))
  272. seq_puts(m, ",mufs");
  273. if (affs_test_opt(sbi->s_flags, SF_NO_TRUNCATE))
  274. seq_puts(m, ",nofilenametruncate");
  275. if (affs_test_opt(sbi->s_flags, SF_PREFIX))
  276. seq_printf(m, ",prefix=%s", sbi->s_prefix);
  277. if (affs_test_opt(sbi->s_flags, SF_IMMUTABLE))
  278. seq_puts(m, ",protect");
  279. if (sbi->s_reserved != 2)
  280. seq_printf(m, ",reserved=%u", sbi->s_reserved);
  281. if (sbi->s_root_block != (sbi->s_reserved + sbi->s_partition_size - 1) / 2)
  282. seq_printf(m, ",root=%u", sbi->s_root_block);
  283. if (affs_test_opt(sbi->s_flags, SF_SETGID))
  284. seq_printf(m, ",setgid=%u",
  285. from_kgid_munged(&init_user_ns, sbi->s_gid));
  286. if (affs_test_opt(sbi->s_flags, SF_SETUID))
  287. seq_printf(m, ",setuid=%u",
  288. from_kuid_munged(&init_user_ns, sbi->s_uid));
  289. if (affs_test_opt(sbi->s_flags, SF_VERBOSE))
  290. seq_puts(m, ",verbose");
  291. if (sbi->s_volume[0])
  292. seq_printf(m, ",volume=%s", sbi->s_volume);
  293. return 0;
  294. }
  295. /* This function definitely needs to be split up. Some fine day I'll
  296. * hopefully have the guts to do so. Until then: sorry for the mess.
  297. */
  298. static int affs_fill_super(struct super_block *sb, void *data, int silent)
  299. {
  300. struct affs_sb_info *sbi;
  301. struct buffer_head *root_bh = NULL;
  302. struct buffer_head *boot_bh;
  303. struct inode *root_inode = NULL;
  304. s32 root_block;
  305. int size, blocksize;
  306. u32 chksum;
  307. int num_bm;
  308. int i, j;
  309. kuid_t uid;
  310. kgid_t gid;
  311. int reserved;
  312. unsigned long mount_flags;
  313. int tmp_flags; /* fix remount prototype... */
  314. u8 sig[4];
  315. int ret;
  316. pr_debug("read_super(%s)\n", data ? (const char *)data : "no options");
  317. sb->s_magic = AFFS_SUPER_MAGIC;
  318. sb->s_op = &affs_sops;
  319. sb->s_flags |= MS_NODIRATIME;
  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 = i_size_read(sb->s_bdev->bd_inode) >> 9;
  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 |= MS_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. /* fall thru */
  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. /* fall thru */
  436. case FS_OFS:
  437. affs_set_opt(sbi->s_flags, SF_OFS);
  438. sb->s_flags |= MS_NOEXEC;
  439. break;
  440. case MUFS_DCOFS:
  441. case MUFS_INTLOFS:
  442. affs_set_opt(sbi->s_flags, SF_MUFS);
  443. case FS_DCOFS:
  444. case FS_INTLOFS:
  445. affs_set_opt(sbi->s_flags, SF_INTL);
  446. affs_set_opt(sbi->s_flags, SF_OFS);
  447. sb->s_flags |= MS_NOEXEC;
  448. break;
  449. default:
  450. pr_err("Unknown filesystem on device %s: %08X\n",
  451. sb->s_id, chksum);
  452. return -EINVAL;
  453. }
  454. if (affs_test_opt(mount_flags, SF_VERBOSE)) {
  455. u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
  456. pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
  457. len > 31 ? 31 : len,
  458. AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
  459. sig, sig[3] + '0', blocksize);
  460. }
  461. sb->s_flags |= MS_NODEV | MS_NOSUID;
  462. sbi->s_data_blksize = sb->s_blocksize;
  463. if (affs_test_opt(sbi->s_flags, SF_OFS))
  464. sbi->s_data_blksize -= 24;
  465. tmp_flags = sb->s_flags;
  466. ret = affs_init_bitmap(sb, &tmp_flags);
  467. if (ret)
  468. return ret;
  469. sb->s_flags = tmp_flags;
  470. /* set up enough so that it can read an inode */
  471. root_inode = affs_iget(sb, root_block);
  472. if (IS_ERR(root_inode))
  473. return PTR_ERR(root_inode);
  474. if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL))
  475. sb->s_d_op = &affs_intl_dentry_operations;
  476. else
  477. sb->s_d_op = &affs_dentry_operations;
  478. sb->s_root = d_make_root(root_inode);
  479. if (!sb->s_root) {
  480. pr_err("AFFS: Get root inode failed\n");
  481. return -ENOMEM;
  482. }
  483. sb->s_export_op = &affs_export_ops;
  484. pr_debug("s_flags=%lX\n", sb->s_flags);
  485. return 0;
  486. }
  487. static int
  488. affs_remount(struct super_block *sb, int *flags, char *data)
  489. {
  490. struct affs_sb_info *sbi = AFFS_SB(sb);
  491. int blocksize;
  492. kuid_t uid;
  493. kgid_t gid;
  494. int mode;
  495. int reserved;
  496. int root_block;
  497. unsigned long mount_flags;
  498. int res = 0;
  499. char *new_opts;
  500. char volume[32];
  501. char *prefix = NULL;
  502. new_opts = kstrdup(data, GFP_KERNEL);
  503. if (data && !new_opts)
  504. return -ENOMEM;
  505. pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
  506. sync_filesystem(sb);
  507. *flags |= MS_NODIRATIME;
  508. memcpy(volume, sbi->s_volume, 32);
  509. if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
  510. &blocksize, &prefix, volume,
  511. &mount_flags)) {
  512. kfree(prefix);
  513. kfree(new_opts);
  514. return -EINVAL;
  515. }
  516. flush_delayed_work(&sbi->sb_work);
  517. sbi->s_flags = mount_flags;
  518. sbi->s_mode = mode;
  519. sbi->s_uid = uid;
  520. sbi->s_gid = gid;
  521. /* protect against readers */
  522. spin_lock(&sbi->symlink_lock);
  523. if (prefix) {
  524. kfree(sbi->s_prefix);
  525. sbi->s_prefix = prefix;
  526. }
  527. memcpy(sbi->s_volume, volume, 32);
  528. spin_unlock(&sbi->symlink_lock);
  529. if ((bool)(*flags & MS_RDONLY) == sb_rdonly(sb))
  530. return 0;
  531. if (*flags & MS_RDONLY)
  532. affs_free_bitmap(sb);
  533. else
  534. res = affs_init_bitmap(sb, flags);
  535. return res;
  536. }
  537. static int
  538. affs_statfs(struct dentry *dentry, struct kstatfs *buf)
  539. {
  540. struct super_block *sb = dentry->d_sb;
  541. int free;
  542. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  543. pr_debug("%s() partsize=%d, reserved=%d\n",
  544. __func__, AFFS_SB(sb)->s_partition_size,
  545. AFFS_SB(sb)->s_reserved);
  546. free = affs_count_free_blocks(sb);
  547. buf->f_type = AFFS_SUPER_MAGIC;
  548. buf->f_bsize = sb->s_blocksize;
  549. buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
  550. buf->f_bfree = free;
  551. buf->f_bavail = free;
  552. buf->f_fsid.val[0] = (u32)id;
  553. buf->f_fsid.val[1] = (u32)(id >> 32);
  554. buf->f_namelen = AFFSNAMEMAX;
  555. return 0;
  556. }
  557. static struct dentry *affs_mount(struct file_system_type *fs_type,
  558. int flags, const char *dev_name, void *data)
  559. {
  560. return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super);
  561. }
  562. static void affs_kill_sb(struct super_block *sb)
  563. {
  564. struct affs_sb_info *sbi = AFFS_SB(sb);
  565. kill_block_super(sb);
  566. if (sbi) {
  567. affs_free_bitmap(sb);
  568. affs_brelse(sbi->s_root_bh);
  569. kfree(sbi->s_prefix);
  570. mutex_destroy(&sbi->s_bmlock);
  571. kfree(sbi);
  572. }
  573. }
  574. static struct file_system_type affs_fs_type = {
  575. .owner = THIS_MODULE,
  576. .name = "affs",
  577. .mount = affs_mount,
  578. .kill_sb = affs_kill_sb,
  579. .fs_flags = FS_REQUIRES_DEV,
  580. };
  581. MODULE_ALIAS_FS("affs");
  582. static int __init init_affs_fs(void)
  583. {
  584. int err = init_inodecache();
  585. if (err)
  586. goto out1;
  587. err = register_filesystem(&affs_fs_type);
  588. if (err)
  589. goto out;
  590. return 0;
  591. out:
  592. destroy_inodecache();
  593. out1:
  594. return err;
  595. }
  596. static void __exit exit_affs_fs(void)
  597. {
  598. unregister_filesystem(&affs_fs_type);
  599. destroy_inodecache();
  600. }
  601. MODULE_DESCRIPTION("Amiga filesystem support for Linux");
  602. MODULE_LICENSE("GPL");
  603. module_init(init_affs_fs)
  604. module_exit(exit_affs_fs)