fs/kernfs/mount.c
Source file repositories/reference/linux-study-clean/fs/kernfs/mount.c
File Facts
- System
- Linux kernel
- Corpus path
fs/kernfs/mount.c- Extension
.c- Size
- 12071 bytes
- Lines
- 473
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/mount.hlinux/init.hlinux/magic.hlinux/slab.hlinux/pagemap.hlinux/namei.hlinux/seq_file.hlinux/exportfs.hlinux/uuid.hlinux/statfs.hkernfs-internal.h
Detected Declarations
function kernfs_sop_show_optionsfunction kernfs_sop_show_pathfunction kernfs_statfsfunction kernfs_encode_fhfunction scoped_guardfunction kernfs_fill_superfunction kernfs_test_superfunction kernfs_set_superfunction kernfs_get_treefunction kernfs_free_fs_contextfunction kernfs_kill_sbfunction kernfs_mutex_initfunction kernfs_lock_initfunction kernfs_init
Annotated Snippet
scoped_guard(rwsem_read, &root->kernfs_rwsem) {
kntmp = find_next_ancestor(kn, knparent);
if (WARN_ON(!kntmp)) {
dput(dentry);
return ERR_PTR(-EINVAL);
}
name = kstrdup(kernfs_rcu_name(kntmp), GFP_KERNEL);
}
if (!name) {
dput(dentry);
return ERR_PTR(-ENOMEM);
}
dtmp = lookup_noperm_positive_unlocked(&QSTR(name), dentry);
dput(dentry);
kfree(name);
if (IS_ERR(dtmp))
return dtmp;
knparent = kntmp;
dentry = dtmp;
} while (true);
}
static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *kfc)
{
struct kernfs_super_info *info = kernfs_info(sb);
struct kernfs_root *kf_root = kfc->root;
struct inode *inode;
struct dentry *root;
info->sb = sb;
/* Userspace would break if executables or devices appear on sysfs */
sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
sb->s_blocksize = PAGE_SIZE;
sb->s_blocksize_bits = PAGE_SHIFT;
sb->s_magic = kfc->magic;
sb->s_op = &kernfs_sops;
sb->s_xattr = kernfs_xattr_handlers;
if (info->root->flags & KERNFS_ROOT_SUPPORT_EXPORTOP)
sb->s_export_op = &kernfs_export_ops;
sb->s_time_gran = 1;
sb->s_maxbytes = MAX_LFS_FILESIZE;
/* sysfs dentries and inodes don't require IO to create */
sb->s_shrink->seeks = 0;
/* get root inode, initialize and unlock it */
down_read(&kf_root->kernfs_rwsem);
inode = kernfs_get_inode(sb, info->root->kn);
up_read(&kf_root->kernfs_rwsem);
if (!inode) {
pr_debug("kernfs: could not get root inode\n");
return -ENOMEM;
}
/* instantiate and link root dentry */
root = d_make_root(inode);
if (!root) {
pr_debug("%s: could not get root dentry!\n", __func__);
return -ENOMEM;
}
sb->s_root = root;
set_default_d_op(sb, &kernfs_dops);
return 0;
}
static int kernfs_test_super(struct super_block *sb, struct fs_context *fc)
{
struct kernfs_super_info *sb_info = kernfs_info(sb);
struct kernfs_super_info *info = fc->s_fs_info;
return sb_info->root == info->root && sb_info->ns == info->ns;
}
static int kernfs_set_super(struct super_block *sb, struct fs_context *fc)
{
struct kernfs_fs_context *kfc = fc->fs_private;
kfc->ns_tag = NULL;
return set_anon_super_fc(sb, fc);
}
/**
* kernfs_super_ns - determine the namespace tag of a kernfs super_block
* @sb: super_block of interest
*
* Return: the namespace tag associated with kernfs super_block @sb.
*/
const struct ns_common *kernfs_super_ns(struct super_block *sb)
{
struct kernfs_super_info *info = kernfs_info(sb);
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mount.h`, `linux/init.h`, `linux/magic.h`, `linux/slab.h`, `linux/pagemap.h`, `linux/namei.h`, `linux/seq_file.h`.
- Detected declarations: `function kernfs_sop_show_options`, `function kernfs_sop_show_path`, `function kernfs_statfs`, `function kernfs_encode_fh`, `function scoped_guard`, `function kernfs_fill_super`, `function kernfs_test_super`, `function kernfs_set_super`, `function kernfs_get_tree`, `function kernfs_free_fs_context`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.