fs/nsfs.c
Source file repositories/reference/linux-study-clean/fs/nsfs.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nsfs.c- Extension
.c- Size
- 17538 bytes
- Lines
- 714
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mount.hlinux/pseudo_fs.hlinux/file.hlinux/fs.hlinux/proc_fs.hlinux/proc_ns.hlinux/magic.hlinux/ktime.hlinux/seq_file.hlinux/pid_namespace.hlinux/user_namespace.hlinux/nsfs.hlinux/uaccess.hlinux/mnt_namespace.hlinux/ipc_namespace.hlinux/time_namespace.hlinux/utsname.hlinux/exportfs.hlinux/nstree.hnet/net_namespace.hmount.hinternal.h
Detected Declarations
struct ns_get_path_task_argsfunction nsfs_get_rootfunction nsfs_evictfunction ns_get_path_cbfunction ns_get_pathfunction open_namespacefunction open_related_nsfunction copy_ns_info_to_userfunction nsfs_ioctl_validfunction may_use_nsfs_ioctlfunction ns_ioctlfunction ns_get_namefunction proc_ns_filefunction ns_matchfunction nsfs_show_pathfunction nsfs_init_inodefunction nsfs_put_datafunction nsfs_encode_fhfunction is_current_namespacefunction scoped_guardfunction nsfs_export_permissionfunction nsfs_init_fs_contextfunction nsfs_initfunction nsproxy_ns_active_getfunction nsproxy_ns_active_putexport open_related_ns
Annotated Snippet
static const struct file_operations ns_file_operations = {
.unlocked_ioctl = ns_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
{
struct inode *inode = d_inode(dentry);
struct ns_common *ns = inode->i_private;
const struct proc_ns_operations *ns_ops = ns->ops;
return dynamic_dname(buffer, buflen, "%s:[%llu]",
ns_ops->name, inode->i_ino);
}
const struct dentry_operations ns_dentry_operations = {
.d_dname = ns_dname,
.d_prune = stashed_dentry_prune,
};
static void nsfs_evict(struct inode *inode)
{
struct ns_common *ns = inode->i_private;
__ns_ref_active_put(ns);
clear_inode(inode);
ns->ops->put(ns);
}
int ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
void *private_data)
{
struct ns_common *ns;
ns = ns_get_cb(private_data);
if (!ns)
return -ENOENT;
return path_from_stashed(&ns->stashed, nsfs_mnt, ns, path);
}
struct ns_get_path_task_args {
const struct proc_ns_operations *ns_ops;
struct task_struct *task;
};
static struct ns_common *ns_get_path_task(void *private_data)
{
struct ns_get_path_task_args *args = private_data;
return args->ns_ops->get(args->task);
}
int ns_get_path(struct path *path, struct task_struct *task,
const struct proc_ns_operations *ns_ops)
{
struct ns_get_path_task_args args = {
.ns_ops = ns_ops,
.task = task,
};
return ns_get_path_cb(path, ns_get_path_task, &args);
}
struct file *open_namespace_file(struct ns_common *ns)
{
struct path path __free(path_put) = {};
int err;
/* call first to consume reference */
err = path_from_stashed(&ns->stashed, nsfs_mnt, ns, &path);
if (err < 0)
return ERR_PTR(err);
return dentry_open(&path, O_RDONLY, current_cred());
}
/**
* open_namespace - open a namespace
* @ns: the namespace to open
*
* This will consume a reference to @ns indendent of success or failure.
*
* Return: A file descriptor on success or a negative error code on failure.
*/
int open_namespace(struct ns_common *ns)
{
struct path path __free(path_put) = {};
int err;
Annotation
- Immediate include surface: `linux/mount.h`, `linux/pseudo_fs.h`, `linux/file.h`, `linux/fs.h`, `linux/proc_fs.h`, `linux/proc_ns.h`, `linux/magic.h`, `linux/ktime.h`.
- Detected declarations: `struct ns_get_path_task_args`, `function nsfs_get_root`, `function nsfs_evict`, `function ns_get_path_cb`, `function ns_get_path`, `function open_namespace`, `function open_related_ns`, `function copy_ns_info_to_user`, `function nsfs_ioctl_valid`, `function may_use_nsfs_ioctl`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.