fs/namespace.c
Source file repositories/reference/linux-study-clean/fs/namespace.c
File Facts
- System
- Linux kernel
- Corpus path
fs/namespace.c- Extension
.c- Size
- 169311 bytes
- Lines
- 6556
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/syscalls.hlinux/export.hlinux/capability.hlinux/mnt_namespace.hlinux/user_namespace.hlinux/namei.hlinux/security.hlinux/cred.hlinux/idr.hlinux/init.hlinux/fs_struct.hlinux/fsnotify.hlinux/file.hlinux/uaccess.hlinux/proc_ns.hlinux/magic.hlinux/memblock.hlinux/proc_fs.hlinux/task_work.hlinux/sched/task.huapi/linux/mount.hlinux/fs_context.hlinux/shmem_fs.hlinux/mnt_idmapping.hlinux/pidfs.hlinux/nstree.hpnode.hinternal.h
Detected Declarations
syscall umountsyscall oldumountsyscall open_treesyscall mountsyscall fsmountsyscall move_mountsyscall pivot_rootsyscall mount_setattrsyscall open_tree_attrsyscall statmountsyscall listmountstruct mount_kattrstruct pinned_mountpointstruct kstatmountstruct klistmountenum mount_kattr_flags_tenum umount_tree_flagsenum mnt_tree_flags_tenum mount_copy_flags_tfunction set_mhash_entriesfunction set_mphash_entriesfunction initramfs_options_setupfunction mnt_ns_releasefunction mnt_ns_tree_removefunction lock_mount_hashfunction unlock_mount_hashfunction mnt_alloc_idfunction mnt_free_idfunction mnt_alloc_group_idfunction mnt_release_group_idfunction mnt_add_countfunction mnt_get_countfunction for_each_possible_cpufunction IS_RDONLYfunction mnt_inc_writersfunction mnt_dec_writersfunction mnt_get_writersfunction for_each_possible_cpufunction mnt_is_readonlyfunction startfunction mnt_want_writefunction mnt_writersfunction mnt_writersfunction mnt_get_write_accessfunction mnt_want_writefunction mnt_put_write_access_filefunction mnt_drop_write_filefunction mnt_unhold_writers
Annotated Snippet
SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
{
return ksys_umount(name, flags);
}
#ifdef __ARCH_WANT_SYS_OLDUMOUNT
/*
* The 2.0 compatible umount. No flags.
*/
SYSCALL_DEFINE1(oldumount, char __user *, name)
{
return ksys_umount(name, 0);
}
#endif
static bool is_mnt_ns_file(struct dentry *dentry)
{
struct ns_common *ns;
/* Is this a proxy for a mount namespace? */
if (dentry->d_op != &ns_dentry_operations)
return false;
ns = d_inode(dentry)->i_private;
return ns->ops == &mntns_operations;
}
struct ns_common *from_mnt_ns(struct mnt_namespace *mnt)
{
return &mnt->ns;
}
struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mntns, bool previous)
{
struct ns_common *ns;
guard(rcu)();
for (;;) {
ns = ns_tree_adjoined_rcu(mntns, previous);
if (IS_ERR(ns))
return ERR_CAST(ns);
mntns = to_mnt_ns(ns);
/*
* The last passive reference count is put with RCU
* delay so accessing the mount namespace is not just
* safe but all relevant members are still valid.
*/
if (!ns_capable_noaudit(mntns->user_ns, CAP_SYS_ADMIN))
continue;
/*
* We need an active reference count as we're persisting
* the mount namespace and it might already be on its
* deathbed.
*/
if (!ns_ref_get(mntns))
continue;
return mntns;
}
}
struct mnt_namespace *mnt_ns_from_dentry(struct dentry *dentry)
{
if (!is_mnt_ns_file(dentry))
return NULL;
return to_mnt_ns(get_proc_ns(dentry->d_inode));
}
static bool mnt_ns_loop(struct dentry *dentry)
{
/* Could bind mounting the mount namespace inode cause a
* mount namespace loop?
*/
struct mnt_namespace *mnt_ns = mnt_ns_from_dentry(dentry);
if (!mnt_ns)
return false;
return current->nsproxy->mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
}
struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/export.h`, `linux/capability.h`, `linux/mnt_namespace.h`, `linux/user_namespace.h`, `linux/namei.h`, `linux/security.h`, `linux/cred.h`.
- Detected declarations: `syscall umount`, `syscall oldumount`, `syscall open_tree`, `syscall mount`, `syscall fsmount`, `syscall move_mount`, `syscall pivot_root`, `syscall mount_setattr`, `syscall open_tree_attr`, `syscall statmount`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.