M7350/kernel/fs/sysfs/mount.c

80 lines
1.7 KiB
C
Raw Normal View History

2024-09-09 08:52:07 +00:00
/*
* 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.
*/
2024-09-09 08:57:42 +00:00
#define DEBUG
2024-09-09 08:52:07 +00:00
#include <linux/fs.h>
2024-09-09 08:57:42 +00:00
#include <linux/magic.h>
2024-09-09 08:52:07 +00:00
#include <linux/mount.h>
#include <linux/init.h>
2024-09-09 08:57:42 +00:00
#include <linux/user_namespace.h>
2024-09-09 08:52:07 +00:00
#include "sysfs.h"
2024-09-09 08:57:42 +00:00
static struct kernfs_root *sysfs_root;
struct kernfs_node *sysfs_root_kn;
2024-09-09 08:52:07 +00:00
static struct dentry *sysfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
2024-09-09 08:57:42 +00:00
struct dentry *root;
void *ns;
bool new_sb;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if (!(flags & MS_KERNMOUNT)) {
if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
return ERR_PTR(-EPERM);
2024-09-09 08:52:07 +00:00
}
2024-09-09 08:57:42 +00:00
ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
root = kernfs_mount_ns(fs_type, flags, sysfs_root,
SYSFS_MAGIC, &new_sb, ns);
if (IS_ERR(root) || !new_sb)
kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
return root;
2024-09-09 08:52:07 +00:00
}
static void sysfs_kill_sb(struct super_block *sb)
{
2024-09-09 08:57:42 +00:00
void *ns = (void *)kernfs_super_ns(sb);
kernfs_kill_sb(sb);
kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
2024-09-09 08:52:07 +00:00
}
static struct file_system_type sysfs_fs_type = {
.name = "sysfs",
.mount = sysfs_mount,
.kill_sb = sysfs_kill_sb,
2024-09-09 08:57:42 +00:00
.fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT,
2024-09-09 08:52:07 +00:00
};
int __init sysfs_init(void)
{
2024-09-09 08:57:42 +00:00
int err;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
NULL);
if (IS_ERR(sysfs_root))
return PTR_ERR(sysfs_root);
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
sysfs_root_kn = sysfs_root->kn;
2024-09-09 08:52:07 +00:00
err = register_filesystem(&sysfs_fs_type);
2024-09-09 08:57:42 +00:00
if (err) {
kernfs_destroy_root(sysfs_root);
return err;
}
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
return 0;
2024-09-09 08:52:07 +00:00
}