Blame view
fs/sysfs/mount.c
1.76 KB
1da177e4c Linux-2.6.12-rc2 |
1 |
/* |
6d66f5cd2 sysfs: add copyri... |
2 3 4 5 6 7 8 9 10 |
* fs/sysfs/symlink.c - operations for initializing and mounting sysfs * * Copyright (c) 2001-3 Patrick Mochel * Copyright (c) 2007 SUSE Linux Products GmbH * Copyright (c) 2007 Tejun Heo <teheo@suse.de> * * This file is released under the GPLv2. * * Please see Documentation/filesystems/sysfs.txt for more information. |
1da177e4c Linux-2.6.12-rc2 |
11 |
*/ |
6b8fbde41 sysfs: Fixed a tr... |
12 |
#define DEBUG |
1da177e4c Linux-2.6.12-rc2 |
13 14 |
#include <linux/fs.h> |
c9482a5bd kernfs: move the ... |
15 |
#include <linux/magic.h> |
1da177e4c Linux-2.6.12-rc2 |
16 |
#include <linux/mount.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
#include <linux/init.h> |
87a8ebd63 userns: Restrict ... |
18 |
#include <linux/user_namespace.h> |
1da177e4c Linux-2.6.12-rc2 |
19 20 |
#include "sysfs.h" |
ba7443bc6 sysfs, kernfs: im... |
21 |
static struct kernfs_root *sysfs_root; |
324a56e16 kernfs: s/sysfs_d... |
22 |
struct kernfs_node *sysfs_root_kn; |
061447a49 sysfs, kernfs: in... |
23 |
|
d0e46f88b convert sysfs |
24 25 |
static struct dentry *sysfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) |
1da177e4c Linux-2.6.12-rc2 |
26 |
{ |
4b93dc9b1 sysfs, kernfs: pr... |
27 28 |
struct dentry *root; void *ns; |
fed95bab8 sysfs: fix namesp... |
29 |
bool new_sb; |
9e7fdd25b sysfs: Basic supp... |
30 |
|
7dc5dbc87 sysfs: Restrict m... |
31 32 33 |
if (!(flags & MS_KERNMOUNT)) { if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type)) return ERR_PTR(-EPERM); |
c84a3b277 sysfs: drop kobj_... |
34 35 |
if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) return ERR_PTR(-EPERM); |
7dc5dbc87 sysfs: Restrict m... |
36 |
} |
87a8ebd63 userns: Restrict ... |
37 |
|
4b93dc9b1 sysfs, kernfs: pr... |
38 |
ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); |
c9482a5bd kernfs: move the ... |
39 40 |
root = kernfs_mount_ns(fs_type, flags, sysfs_root, SYSFS_MAGIC, &new_sb, ns); |
fed95bab8 sysfs: fix namesp... |
41 |
if (IS_ERR(root) || !new_sb) |
4b93dc9b1 sysfs, kernfs: pr... |
42 43 44 |
kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); return root; } |
9e7fdd25b sysfs: Basic supp... |
45 46 |
static void sysfs_kill_sb(struct super_block *sb) { |
a7560a013 sysfs: fix use-af... |
47 |
void *ns = (void *)kernfs_super_ns(sb); |
4b93dc9b1 sysfs, kernfs: pr... |
48 |
kernfs_kill_sb(sb); |
a7560a013 sysfs: fix use-af... |
49 |
kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); |
4b93dc9b1 sysfs, kernfs: pr... |
50 |
} |
1da177e4c Linux-2.6.12-rc2 |
51 52 |
static struct file_system_type sysfs_fs_type = { .name = "sysfs", |
d0e46f88b convert sysfs |
53 |
.mount = sysfs_mount, |
9e7fdd25b sysfs: Basic supp... |
54 |
.kill_sb = sysfs_kill_sb, |
4f326c006 userns: Allow unp... |
55 |
.fs_flags = FS_USERNS_MOUNT, |
1da177e4c Linux-2.6.12-rc2 |
56 |
}; |
4b93dc9b1 sysfs, kernfs: pr... |
57 58 59 |
int __init sysfs_init(void) { int err; |
e0bf68dde mm: bdi init hooks |
60 |
|
555724a83 kernfs, sysfs, cg... |
61 62 |
sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK, NULL); |
4b93dc9b1 sysfs, kernfs: pr... |
63 64 |
if (IS_ERR(sysfs_root)) return PTR_ERR(sysfs_root); |
324a56e16 kernfs: s/sysfs_d... |
65 |
sysfs_root_kn = sysfs_root->kn; |
ba7443bc6 sysfs, kernfs: im... |
66 |
|
1da177e4c Linux-2.6.12-rc2 |
67 |
err = register_filesystem(&sysfs_fs_type); |
4b93dc9b1 sysfs, kernfs: pr... |
68 69 70 71 |
if (err) { kernfs_destroy_root(sysfs_root); return err; } |
9e30cc959 sysfs, kernfs: no... |
72 73 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
74 |
} |