2005-04-16 15:20:36 -07:00
|
|
|
/* $Id: capifs.c,v 1.1.2.3 2004/01/16 21:09:26 keil Exp $
|
|
|
|
*
|
|
|
|
* Copyright 2000 by Carsten Paeth <calle@calle.de>
|
|
|
|
*
|
|
|
|
* Heavily based on devpts filesystem from H. Peter Anvin
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mount.h>
|
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>
2010-03-24 01:04:11 -07:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ctype.h>
|
2005-10-30 16:03:48 -07:00
|
|
|
#include <linux/sched.h> /* current */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-01-08 02:05:15 -07:00
|
|
|
#include "capifs.h"
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
MODULE_DESCRIPTION("CAPI4Linux: /dev/capi/ filesystem");
|
|
|
|
MODULE_AUTHOR("Carsten Paeth");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
#define CAPIFS_SUPER_MAGIC (('C'<<8)|'N')
|
|
|
|
|
|
|
|
static struct vfsmount *capifs_mnt;
|
2010-02-08 03:12:08 -07:00
|
|
|
static int capifs_mnt_count;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
static struct {
|
|
|
|
int setuid;
|
|
|
|
int setgid;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
umode_t mode;
|
|
|
|
} config = {.mode = 0600};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
static int capifs_remount(struct super_block *s, int *flags, char *data)
|
|
|
|
{
|
|
|
|
int setuid = 0;
|
|
|
|
int setgid = 0;
|
|
|
|
uid_t uid = 0;
|
|
|
|
gid_t gid = 0;
|
|
|
|
umode_t mode = 0600;
|
|
|
|
char *this_char;
|
2008-02-08 05:21:40 -07:00
|
|
|
char *new_opt = kstrdup(data, GFP_KERNEL);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
this_char = NULL;
|
|
|
|
while ((this_char = strsep(&data, ",")) != NULL) {
|
|
|
|
int n;
|
|
|
|
char dummy;
|
|
|
|
if (!*this_char)
|
|
|
|
continue;
|
|
|
|
if (sscanf(this_char, "uid=%i%c", &n, &dummy) == 1) {
|
|
|
|
setuid = 1;
|
|
|
|
uid = n;
|
|
|
|
} else if (sscanf(this_char, "gid=%i%c", &n, &dummy) == 1) {
|
|
|
|
setgid = 1;
|
|
|
|
gid = n;
|
|
|
|
} else if (sscanf(this_char, "mode=%o%c", &n, &dummy) == 1)
|
|
|
|
mode = n & ~S_IFMT;
|
|
|
|
else {
|
2008-04-28 02:14:41 -07:00
|
|
|
kfree(new_opt);
|
2005-04-16 15:20:36 -07:00
|
|
|
printk("capifs: called with bogus options\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 05:21:40 -07:00
|
|
|
|
2009-05-08 13:23:30 -07:00
|
|
|
mutex_lock(&s->s_root->d_inode->i_mutex);
|
2008-02-08 05:21:40 -07:00
|
|
|
|
2009-05-08 13:23:30 -07:00
|
|
|
replace_mount_options(s, new_opt);
|
2005-04-16 15:20:36 -07:00
|
|
|
config.setuid = setuid;
|
|
|
|
config.setgid = setgid;
|
|
|
|
config.uid = uid;
|
|
|
|
config.gid = gid;
|
|
|
|
config.mode = mode;
|
2008-02-08 05:21:40 -07:00
|
|
|
|
2009-05-08 13:23:30 -07:00
|
|
|
mutex_unlock(&s->s_root->d_inode->i_mutex);
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-21 17:01:09 -07:00
|
|
|
static const struct super_operations capifs_sops =
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
.statfs = simple_statfs,
|
|
|
|
.remount_fs = capifs_remount,
|
2008-02-08 05:21:40 -07:00
|
|
|
.show_options = generic_show_options,
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
capifs_fill_super(struct super_block *s, void *data, int silent)
|
|
|
|
{
|
|
|
|
struct inode * inode;
|
|
|
|
|
|
|
|
s->s_blocksize = 1024;
|
|
|
|
s->s_blocksize_bits = 10;
|
|
|
|
s->s_magic = CAPIFS_SUPER_MAGIC;
|
|
|
|
s->s_op = &capifs_sops;
|
|
|
|
s->s_time_gran = 1;
|
|
|
|
|
|
|
|
inode = new_inode(s);
|
|
|
|
if (!inode)
|
|
|
|
goto fail;
|
|
|
|
inode->i_ino = 1;
|
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
|
|
|
|
inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
|
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
inode->i_nlink = 2;
|
|
|
|
|
2010-02-08 03:12:07 -07:00
|
|
|
s->s_root = d_alloc_root(inode);
|
2005-04-16 15:20:36 -07:00
|
|
|
if (s->s_root)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
printk("capifs: get root dentry failed\n");
|
|
|
|
iput(inode);
|
|
|
|
fail:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 02:02:57 -07:00
|
|
|
static int capifs_get_sb(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 02:02:57 -07:00
|
|
|
return get_sb_single(fs_type, flags, data, capifs_fill_super, mnt);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type capifs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "capifs",
|
|
|
|
.get_sb = capifs_get_sb,
|
|
|
|
.kill_sb = kill_anon_super,
|
|
|
|
};
|
|
|
|
|
2010-02-08 03:12:08 -07:00
|
|
|
static struct dentry *new_ncci(unsigned int number, dev_t device)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2010-02-08 03:12:07 -07:00
|
|
|
struct super_block *s = capifs_mnt->mnt_sb;
|
|
|
|
struct dentry *root = s->s_root;
|
2005-04-16 15:20:36 -07:00
|
|
|
struct dentry *dentry;
|
2010-02-08 03:12:05 -07:00
|
|
|
struct inode *inode;
|
2010-02-08 03:12:06 -07:00
|
|
|
char name[10];
|
|
|
|
int namelen;
|
2009-05-08 13:23:30 -07:00
|
|
|
|
2010-02-08 03:12:07 -07:00
|
|
|
mutex_lock(&root->d_inode->i_mutex);
|
2010-02-08 03:12:06 -07:00
|
|
|
|
|
|
|
namelen = sprintf(name, "%d", number);
|
2010-02-08 03:12:07 -07:00
|
|
|
dentry = lookup_one_len(name, root, namelen);
|
2010-02-08 03:12:06 -07:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
dentry = NULL;
|
2010-02-08 03:12:05 -07:00
|
|
|
goto unlock_out;
|
2010-02-08 03:12:06 -07:00
|
|
|
}
|
2010-02-08 03:12:05 -07:00
|
|
|
|
|
|
|
if (dentry->d_inode) {
|
|
|
|
dput(dentry);
|
2010-02-08 03:12:06 -07:00
|
|
|
dentry = NULL;
|
2010-02-08 03:12:05 -07:00
|
|
|
goto unlock_out;
|
|
|
|
}
|
|
|
|
|
2010-02-08 03:12:07 -07:00
|
|
|
inode = new_inode(s);
|
2010-02-08 03:12:05 -07:00
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
2010-02-08 03:12:06 -07:00
|
|
|
dentry = NULL;
|
2010-02-08 03:12:05 -07:00
|
|
|
goto unlock_out;
|
|
|
|
}
|
2009-05-08 13:23:30 -07:00
|
|
|
|
|
|
|
/* config contents is protected by root's i_mutex */
|
2008-11-13 16:38:42 -07:00
|
|
|
inode->i_uid = config.setuid ? config.uid : current_fsuid();
|
|
|
|
inode->i_gid = config.setgid ? config.gid : current_fsgid();
|
2005-04-16 15:20:36 -07:00
|
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
|
2010-02-08 03:12:05 -07:00
|
|
|
inode->i_ino = number + 2;
|
2005-04-16 15:20:36 -07:00
|
|
|
init_special_inode(inode, S_IFCHR|config.mode, device);
|
|
|
|
|
2010-02-08 03:12:05 -07:00
|
|
|
d_instantiate(dentry, inode);
|
2010-02-08 03:12:06 -07:00
|
|
|
dget(dentry);
|
2010-02-08 03:12:05 -07:00
|
|
|
|
|
|
|
unlock_out:
|
2010-02-08 03:12:07 -07:00
|
|
|
mutex_unlock(&root->d_inode->i_mutex);
|
2010-02-08 03:12:06 -07:00
|
|
|
|
|
|
|
return dentry;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2010-02-08 03:12:08 -07:00
|
|
|
struct dentry *capifs_new_ncci(unsigned int number, dev_t device)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
if (simple_pin_fs(&capifs_fs_type, &capifs_mnt, &capifs_mnt_count) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dentry = new_ncci(number, device);
|
|
|
|
if (!dentry)
|
|
|
|
simple_release_fs(&capifs_mnt, &capifs_mnt_count);
|
|
|
|
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2010-02-08 03:12:06 -07:00
|
|
|
void capifs_free_ncci(struct dentry *dentry)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2010-02-08 03:12:07 -07:00
|
|
|
struct dentry *root = capifs_mnt->mnt_sb->s_root;
|
2010-02-08 03:12:06 -07:00
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
if (!dentry)
|
|
|
|
return;
|
|
|
|
|
2010-02-08 03:12:07 -07:00
|
|
|
mutex_lock(&root->d_inode->i_mutex);
|
2010-02-08 03:12:06 -07:00
|
|
|
|
|
|
|
inode = dentry->d_inode;
|
|
|
|
if (inode) {
|
|
|
|
drop_nlink(inode);
|
|
|
|
d_delete(dentry);
|
2005-04-16 15:20:36 -07:00
|
|
|
dput(dentry);
|
|
|
|
}
|
2010-02-08 03:12:06 -07:00
|
|
|
dput(dentry);
|
|
|
|
|
2010-02-08 03:12:07 -07:00
|
|
|
mutex_unlock(&root->d_inode->i_mutex);
|
2010-02-08 03:12:08 -07:00
|
|
|
|
|
|
|
simple_release_fs(&capifs_mnt, &capifs_mnt_count);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init capifs_init(void)
|
|
|
|
{
|
2010-02-08 03:12:09 -07:00
|
|
|
return register_filesystem(&capifs_fs_type);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit capifs_exit(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&capifs_fs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capifs_new_ncci);
|
|
|
|
EXPORT_SYMBOL(capifs_free_ncci);
|
|
|
|
|
|
|
|
module_init(capifs_init);
|
|
|
|
module_exit(capifs_exit);
|