original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

652 lines
15 KiB

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
12 years ago
affs: stop setting bm_flags AFFS stores values '1' and '2' in 'bm_flags', and I fail to see any logic when it prefers one or another. AFFS writes '1' only from '->put_super()', while '->sync_fs()' and '->write_super()' store value '2'. So on the first glance, it looks like we want to have '1' if we unmount. However, this does not really happen in these cases: 1. superblock is written via 'write_super()' then we unmount; 2. we re-mount R/O, then unmount. which are quite typical. I could not find good documentation describing this field, except of one random piece of documentation in the internet which says that -1 means that the root block is valid, which is not consistent with what we have in the Linux AFFS driver. Jan Kara commented on this: "I have some vague recollection that on Amiga boolean was usually encoded as: 0 == false, ~0 == -1 == true. But it has been ages..." Thus, my conclusion is that value of '1' is as good as value of '2' and we can just always use '2'. An Jan Kara suggested to go further: "generally bm_flags handling looks strange. If they are 0, we mount fs read only and thus cannot change them. If they are != 0, we write 2 there. So IMHO if you just removed bm_flags setting, nothing will really happen." So this patch removes the bm_flags setting completely. This makes the "clean" argument of the 'affs_commit_super()' function unneeded, so it is also removed. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
10 years ago
affs: stop setting bm_flags AFFS stores values '1' and '2' in 'bm_flags', and I fail to see any logic when it prefers one or another. AFFS writes '1' only from '->put_super()', while '->sync_fs()' and '->write_super()' store value '2'. So on the first glance, it looks like we want to have '1' if we unmount. However, this does not really happen in these cases: 1. superblock is written via 'write_super()' then we unmount; 2. we re-mount R/O, then unmount. which are quite typical. I could not find good documentation describing this field, except of one random piece of documentation in the internet which says that -1 means that the root block is valid, which is not consistent with what we have in the Linux AFFS driver. Jan Kara commented on this: "I have some vague recollection that on Amiga boolean was usually encoded as: 0 == false, ~0 == -1 == true. But it has been ages..." Thus, my conclusion is that value of '1' is as good as value of '2' and we can just always use '2'. An Jan Kara suggested to go further: "generally bm_flags handling looks strange. If they are 0, we mount fs read only and thus cannot change them. If they are != 0, we write 2 there. So IMHO if you just removed bm_flags setting, nothing will really happen." So this patch removes the bm_flags setting completely. This makes the "clean" argument of the 'affs_commit_super()' function unneeded, so it is also removed. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
10 years ago
workqueue: deprecate flush[_delayed]_work_sync() flush[_delayed]_work_sync() are now spurious. Mark them deprecated and convert all users to flush[_delayed]_work(). If you're cc'd and wondering what's going on: Now all workqueues are non-reentrant and the regular flushes guarantee that the work item is not pending or running on any CPU on return, so there's no reason to use the sync flushes at all and they're going away. This patch doesn't make any functional difference. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Russell King <linux@arm.linux.org.uk> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Ian Campbell <ian.campbell@citrix.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Mattia Dongili <malattia@linux.it> Cc: Kent Yoder <key@linux.vnet.ibm.com> Cc: David Airlie <airlied@linux.ie> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: Bryan Wu <bryan.wu@canonical.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Alasdair Kergon <agk@redhat.com> Cc: Mauro Carvalho Chehab <mchehab@infradead.org> Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de> Cc: David Woodhouse <dwmw2@infradead.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: linux-wireless@vger.kernel.org Cc: Anton Vorontsov <cbou@mail.ru> Cc: Sangbeom Kim <sbkim73@samsung.com> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Takashi Iwai <tiwai@suse.de> Cc: Steven Whitehouse <swhiteho@redhat.com> Cc: Petr Vandrovec <petr@vandrovec.name> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Avi Kivity <avi@redhat.com>
9 years ago
fs: Limit sys_mount to only request filesystem modules. Modify the request_module to prefix the file system type with "fs-" and add aliases to all of the filesystems that can be built as modules to match. A common practice is to build all of the kernel code and leave code that is not commonly needed as modules, with the result that many users are exposed to any bug anywhere in the kernel. Looking for filesystems with a fs- prefix limits the pool of possible modules that can be loaded by mount to just filesystems trivially making things safer with no real cost. Using aliases means user space can control the policy of which filesystem modules are auto-loaded by editing /etc/modprobe.d/*.conf with blacklist and alias directives. Allowing simple, safe, well understood work-arounds to known problematic software. This also addresses a rare but unfortunate problem where the filesystem name is not the same as it's module name and module auto-loading would not work. While writing this patch I saw a handful of such cases. The most significant being autofs that lives in the module autofs4. This is relevant to user namespaces because we can reach the request module in get_fs_type() without having any special permissions, and people get uncomfortable when a user specified string (in this case the filesystem type) goes all of the way to request_module. After having looked at this issue I don't think there is any particular reason to perform any filtering or permission checks beyond making it clear in the module request that we want a filesystem module. The common pattern in the kernel is to call request_module() without regards to the users permissions. In general all a filesystem module does once loaded is call register_filesystem() and go to sleep. Which means there is not much attack surface exposed by loading a filesytem module unless the filesystem is mounted. In a user namespace filesystems are not mounted unless .fs_flags = FS_USERNS_MOUNT, which most filesystems do not set today. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Reported-by: Kees Cook <keescook@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years ago
  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/slab.h>
  19. #include <linux/writeback.h>
  20. #include "affs.h"
  21. extern struct timezone sys_tz;
  22. static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
  23. static int affs_remount (struct super_block *sb, int *flags, char *data);
  24. static void
  25. affs_commit_super(struct super_block *sb, int wait)
  26. {
  27. struct affs_sb_info *sbi = AFFS_SB(sb);
  28. struct buffer_head *bh = sbi->s_root_bh;
  29. struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
  30. lock_buffer(bh);
  31. secs_to_datestamp(get_seconds(), &tail->disk_change);
  32. affs_fix_checksum(sb, bh);
  33. unlock_buffer(bh);
  34. mark_buffer_dirty(bh);
  35. if (wait)
  36. sync_dirty_buffer(bh);
  37. }
  38. static void
  39. affs_put_super(struct super_block *sb)
  40. {
  41. struct affs_sb_info *sbi = AFFS_SB(sb);
  42. pr_debug("AFFS: put_super()\n");
  43. cancel_delayed_work_sync(&sbi->sb_work);
  44. kfree(sbi->s_prefix);
  45. affs_free_bitmap(sb);
  46. affs_brelse(sbi->s_root_bh);
  47. kfree(sbi);
  48. sb->s_fs_info = NULL;
  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->s_flags & MS_RDONLY)
  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 = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL);
  86. if (!i)
  87. return NULL;
  88. i->vfs_inode.i_version = 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_i_callback(struct rcu_head *head)
  95. {
  96. struct inode *inode = container_of(head, struct inode, i_rcu);
  97. kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
  98. }
  99. static void affs_destroy_inode(struct inode *inode)
  100. {
  101. call_rcu(&inode->i_rcu, affs_i_callback);
  102. }
  103. static void init_once(void *foo)
  104. {
  105. struct affs_inode_info *ei = (struct affs_inode_info *) foo;
  106. sema_init(&ei->i_link_lock, 1);
  107. sema_init(&ei->i_ext_lock, 1);
  108. inode_init_once(&ei->vfs_inode);
  109. }
  110. static int init_inodecache(void)
  111. {
  112. affs_inode_cachep = kmem_cache_create("affs_inode_cache",
  113. sizeof(struct affs_inode_info),
  114. 0, (SLAB_RECLAIM_ACCOUNT|
  115. SLAB_MEM_SPREAD),
  116. init_once);
  117. if (affs_inode_cachep == NULL)
  118. return -ENOMEM;
  119. return 0;
  120. }
  121. static void destroy_inodecache(void)
  122. {
  123. /*
  124. * Make sure all delayed rcu free inodes are flushed before we
  125. * destroy cache.
  126. */
  127. rcu_barrier();
  128. kmem_cache_destroy(affs_inode_cachep);
  129. }
  130. static const struct super_operations affs_sops = {
  131. .alloc_inode = affs_alloc_inode,
  132. .destroy_inode = affs_destroy_inode,
  133. .write_inode = affs_write_inode,
  134. .evict_inode = affs_evict_inode,
  135. .put_super = affs_put_super,
  136. .sync_fs = affs_sync_fs,
  137. .statfs = affs_statfs,
  138. .remount_fs = affs_remount,
  139. .show_options = generic_show_options,
  140. };
  141. enum {
  142. Opt_bs, Opt_mode, Opt_mufs, Opt_prefix, Opt_protect,
  143. Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
  144. Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
  145. };
  146. static const match_table_t tokens = {
  147. {Opt_bs, "bs=%u"},
  148. {Opt_mode, "mode=%o"},
  149. {Opt_mufs, "mufs"},
  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. printk ("AFFS: 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. *mount_opts |= SF_SETMODE;
  202. break;
  203. case Opt_mufs:
  204. *mount_opts |= SF_MUFS;
  205. break;
  206. case Opt_prefix:
  207. *prefix = match_strdup(&args[0]);
  208. if (!*prefix)
  209. return 0;
  210. *mount_opts |= SF_PREFIX;
  211. break;
  212. case Opt_protect:
  213. *mount_opts |= SF_IMMUTABLE;
  214. break;
  215. case Opt_reserved:
  216. if (match_int(&args[0], reserved))
  217. return 0;
  218. break;
  219. case Opt_root:
  220. if (match_int(&args[0], root))
  221. return 0;
  222. break;
  223. case Opt_setgid:
  224. if (match_int(&args[0], &option))
  225. return 0;
  226. *gid = make_kgid(current_user_ns(), option);
  227. if (!gid_valid(*gid))
  228. return 0;
  229. *mount_opts |= SF_SETGID;
  230. break;
  231. case Opt_setuid:
  232. if (match_int(&args[0], &option))
  233. return 0;
  234. *uid = make_kuid(current_user_ns(), option);
  235. if (!uid_valid(*uid))
  236. return 0;
  237. *mount_opts |= SF_SETUID;
  238. break;
  239. case Opt_verbose:
  240. *mount_opts |= SF_VERBOSE;
  241. break;
  242. case Opt_volume: {
  243. char *vol = match_strdup(&args[0]);
  244. if (!vol)
  245. return 0;
  246. strlcpy(volume, vol, 32);
  247. kfree(vol);
  248. break;
  249. }
  250. case Opt_ignore:
  251. /* Silently ignore the quota options */
  252. break;
  253. default:
  254. printk("AFFS: Unrecognized mount option \"%s\" "
  255. "or missing value\n", p);
  256. return 0;
  257. }
  258. }
  259. return 1;
  260. }
  261. /* This function definitely needs to be split up. Some fine day I'll
  262. * hopefully have the guts to do so. Until then: sorry for the mess.
  263. */
  264. static int affs_fill_super(struct super_block *sb, void *data, int silent)
  265. {
  266. struct affs_sb_info *sbi;
  267. struct buffer_head *root_bh = NULL;
  268. struct buffer_head *boot_bh;
  269. struct inode *root_inode = NULL;
  270. s32 root_block;
  271. int size, blocksize;
  272. u32 chksum;
  273. int num_bm;
  274. int i, j;
  275. s32 key;
  276. kuid_t uid;
  277. kgid_t gid;
  278. int reserved;
  279. unsigned long mount_flags;
  280. int tmp_flags; /* fix remount prototype... */
  281. u8 sig[4];
  282. int ret = -EINVAL;
  283. save_mount_options(sb, data);
  284. pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
  285. sb->s_magic = AFFS_SUPER_MAGIC;
  286. sb->s_op = &affs_sops;
  287. sb->s_flags |= MS_NODIRATIME;
  288. sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
  289. if (!sbi)
  290. return -ENOMEM;
  291. sb->s_fs_info = sbi;
  292. sbi->sb = sb;
  293. mutex_init(&sbi->s_bmlock);
  294. spin_lock_init(&sbi->symlink_lock);
  295. spin_lock_init(&sbi->work_lock);
  296. INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock);
  297. if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
  298. &blocksize,&sbi->s_prefix,
  299. sbi->s_volume, &mount_flags)) {
  300. printk(KERN_ERR "AFFS: Error parsing options\n");
  301. kfree(sbi->s_prefix);
  302. kfree(sbi);
  303. return -EINVAL;
  304. }
  305. /* N.B. after this point s_prefix must be released */
  306. sbi->s_flags = mount_flags;
  307. sbi->s_mode = i;
  308. sbi->s_uid = uid;
  309. sbi->s_gid = gid;
  310. sbi->s_reserved= reserved;
  311. /* Get the size of the device in 512-byte blocks.
  312. * If we later see that the partition uses bigger
  313. * blocks, we will have to change it.
  314. */
  315. size = sb->s_bdev->bd_inode->i_size >> 9;
  316. pr_debug("AFFS: initial blocksize=%d, #blocks=%d\n", 512, size);
  317. affs_set_blocksize(sb, PAGE_SIZE);
  318. /* Try to find root block. Its location depends on the block size. */
  319. i = 512;
  320. j = 4096;
  321. if (blocksize > 0) {
  322. i = j = blocksize;
  323. size = size / (blocksize / 512);
  324. }
  325. for (blocksize = i, key = 0; blocksize <= j; blocksize <<= 1, size >>= 1) {
  326. sbi->s_root_block = root_block;
  327. if (root_block < 0)
  328. sbi->s_root_block = (reserved + size - 1) / 2;
  329. pr_debug("AFFS: setting blocksize to %d\n", blocksize);
  330. affs_set_blocksize(sb, blocksize);
  331. sbi->s_partition_size = size;
  332. /* The root block location that was calculated above is not
  333. * correct if the partition size is an odd number of 512-
  334. * byte blocks, which will be rounded down to a number of
  335. * 1024-byte blocks, and if there were an even number of
  336. * reserved blocks. Ideally, all partition checkers should
  337. * report the real number of blocks of the real blocksize,
  338. * but since this just cannot be done, we have to try to
  339. * find the root block anyways. In the above case, it is one
  340. * block behind the calculated one. So we check this one, too.
  341. */
  342. for (num_bm = 0; num_bm < 2; num_bm++) {
  343. pr_debug("AFFS: Dev %s, trying root=%u, bs=%d, "
  344. "size=%d, reserved=%d\n",
  345. sb->s_id,
  346. sbi->s_root_block + num_bm,
  347. blocksize, size, reserved);
  348. root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
  349. if (!root_bh)
  350. continue;
  351. if (!affs_checksum_block(sb, root_bh) &&
  352. be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT &&
  353. be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) {
  354. sbi->s_hashsize = blocksize / 4 - 56;
  355. sbi->s_root_block += num_bm;
  356. key = 1;
  357. goto got_root;
  358. }
  359. affs_brelse(root_bh);
  360. root_bh = NULL;
  361. }
  362. }
  363. if (!silent)
  364. printk(KERN_ERR "AFFS: No valid root block on device %s\n",
  365. sb->s_id);
  366. goto out_error;
  367. /* N.B. after this point bh must be released */
  368. got_root:
  369. root_block = sbi->s_root_block;
  370. /* Find out which kind of FS we have */
  371. boot_bh = sb_bread(sb, 0);
  372. if (!boot_bh) {
  373. printk(KERN_ERR "AFFS: Cannot read boot block\n");
  374. goto out_error;
  375. }
  376. memcpy(sig, boot_bh->b_data, 4);
  377. brelse(boot_bh);
  378. chksum = be32_to_cpu(*(__be32 *)sig);
  379. /* Dircache filesystems are compatible with non-dircache ones
  380. * when reading. As long as they aren't supported, writing is
  381. * not recommended.
  382. */
  383. if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
  384. || chksum == MUFS_DCOFS) && !(sb->s_flags & MS_RDONLY)) {
  385. printk(KERN_NOTICE "AFFS: Dircache FS - mounting %s read only\n",
  386. sb->s_id);
  387. sb->s_flags |= MS_RDONLY;
  388. }
  389. switch (chksum) {
  390. case MUFS_FS:
  391. case MUFS_INTLFFS:
  392. case MUFS_DCFFS:
  393. sbi->s_flags |= SF_MUFS;
  394. /* fall thru */
  395. case FS_INTLFFS:
  396. case FS_DCFFS:
  397. sbi->s_flags |= SF_INTL;
  398. break;
  399. case MUFS_FFS:
  400. sbi->s_flags |= SF_MUFS;
  401. break;
  402. case FS_FFS:
  403. break;
  404. case MUFS_OFS:
  405. sbi->s_flags |= SF_MUFS;
  406. /* fall thru */
  407. case FS_OFS:
  408. sbi->s_flags |= SF_OFS;
  409. sb->s_flags |= MS_NOEXEC;
  410. break;
  411. case MUFS_DCOFS:
  412. case MUFS_INTLOFS:
  413. sbi->s_flags |= SF_MUFS;
  414. case FS_DCOFS:
  415. case FS_INTLOFS:
  416. sbi->s_flags |= SF_INTL | SF_OFS;
  417. sb->s_flags |= MS_NOEXEC;
  418. break;
  419. default:
  420. printk(KERN_ERR "AFFS: Unknown filesystem on device %s: %08X\n",
  421. sb->s_id, chksum);
  422. goto out_error;
  423. }
  424. if (mount_flags & SF_VERBOSE) {
  425. u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
  426. printk(KERN_NOTICE "AFFS: 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 |= MS_NODEV | MS_NOSUID;
  432. sbi->s_data_blksize = sb->s_blocksize;
  433. if (sbi->s_flags & SF_OFS)
  434. sbi->s_data_blksize -= 24;
  435. /* Keep super block in cache */
  436. sbi->s_root_bh = root_bh;
  437. /* N.B. after this point s_root_bh must be released */
  438. tmp_flags = sb->s_flags;
  439. if (affs_init_bitmap(sb, &tmp_flags))
  440. goto out_error;
  441. sb->s_flags = tmp_flags;
  442. /* set up enough so that it can read an inode */
  443. root_inode = affs_iget(sb, root_block);
  444. if (IS_ERR(root_inode)) {
  445. ret = PTR_ERR(root_inode);
  446. goto out_error;
  447. }
  448. if (AFFS_SB(sb)->s_flags & SF_INTL)
  449. sb->s_d_op = &affs_intl_dentry_operations;
  450. else
  451. sb->s_d_op = &affs_dentry_operations;
  452. sb->s_root = d_make_root(root_inode);
  453. if (!sb->s_root) {
  454. printk(KERN_ERR "AFFS: Get root inode failed\n");
  455. goto out_error;
  456. }
  457. pr_debug("AFFS: s_flags=%lX\n",sb->s_flags);
  458. return 0;
  459. /*
  460. * Begin the cascaded cleanup ...
  461. */
  462. out_error:
  463. kfree(sbi->s_bitmap);
  464. affs_brelse(root_bh);
  465. kfree(sbi->s_prefix);
  466. kfree(sbi);
  467. sb->s_fs_info = NULL;
  468. return ret;
  469. }
  470. static int
  471. affs_remount(struct super_block *sb, int *flags, char *data)
  472. {
  473. struct affs_sb_info *sbi = AFFS_SB(sb);
  474. int blocksize;
  475. kuid_t uid;
  476. kgid_t gid;
  477. int mode;
  478. int reserved;
  479. int root_block;
  480. unsigned long mount_flags;
  481. int res = 0;
  482. char *new_opts = kstrdup(data, GFP_KERNEL);
  483. char volume[32];
  484. char *prefix = NULL;
  485. pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data);
  486. *flags |= MS_NODIRATIME;
  487. memcpy(volume, sbi->s_volume, 32);
  488. if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
  489. &blocksize, &prefix, volume,
  490. &mount_flags)) {
  491. kfree(prefix);
  492. kfree(new_opts);
  493. return -EINVAL;
  494. }
  495. flush_delayed_work(&sbi->sb_work);
  496. replace_mount_options(sb, new_opts);
  497. sbi->s_flags = mount_flags;
  498. sbi->s_mode = mode;
  499. sbi->s_uid = uid;
  500. sbi->s_gid = gid;
  501. /* protect against readers */
  502. spin_lock(&sbi->symlink_lock);
  503. if (prefix) {
  504. kfree(sbi->s_prefix);
  505. sbi->s_prefix = prefix;
  506. }
  507. memcpy(sbi->s_volume, volume, 32);
  508. spin_unlock(&sbi->symlink_lock);
  509. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  510. return 0;
  511. if (*flags & MS_RDONLY)
  512. affs_free_bitmap(sb);
  513. else
  514. res = affs_init_bitmap(sb, flags);
  515. return res;
  516. }
  517. static int
  518. affs_statfs(struct dentry *dentry, struct kstatfs *buf)
  519. {
  520. struct super_block *sb = dentry->d_sb;
  521. int free;
  522. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  523. pr_debug("AFFS: statfs() partsize=%d, reserved=%d\n",AFFS_SB(sb)->s_partition_size,
  524. AFFS_SB(sb)->s_reserved);
  525. free = affs_count_free_blocks(sb);
  526. buf->f_type = AFFS_SUPER_MAGIC;
  527. buf->f_bsize = sb->s_blocksize;
  528. buf->f_blocks = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
  529. buf->f_bfree = free;
  530. buf->f_bavail = free;
  531. buf->f_fsid.val[0] = (u32)id;
  532. buf->f_fsid.val[1] = (u32)(id >> 32);
  533. buf->f_namelen = 30;
  534. return 0;
  535. }
  536. static struct dentry *affs_mount(struct file_system_type *fs_type,
  537. int flags, const char *dev_name, void *data)
  538. {
  539. return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super);
  540. }
  541. static struct file_system_type affs_fs_type = {
  542. .owner = THIS_MODULE,
  543. .name = "affs",
  544. .mount = affs_mount,
  545. .kill_sb = kill_block_super,
  546. .fs_flags = FS_REQUIRES_DEV,
  547. };
  548. MODULE_ALIAS_FS("affs");
  549. static int __init init_affs_fs(void)
  550. {
  551. int err = init_inodecache();
  552. if (err)
  553. goto out1;
  554. err = register_filesystem(&affs_fs_type);
  555. if (err)
  556. goto out;
  557. return 0;
  558. out:
  559. destroy_inodecache();
  560. out1:
  561. return err;
  562. }
  563. static void __exit exit_affs_fs(void)
  564. {
  565. unregister_filesystem(&affs_fs_type);
  566. destroy_inodecache();
  567. }
  568. MODULE_DESCRIPTION("Amiga filesystem support for Linux");
  569. MODULE_LICENSE("GPL");
  570. module_init(init_affs_fs)
  571. module_exit(exit_affs_fs)