fs/init.c
Source file repositories/reference/linux-study-clean/fs/init.c
File Facts
- System
- Linux kernel
- Corpus path
fs/init.c- Extension
.c- Size
- 4957 bytes
- Lines
- 219
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/mount.hlinux/namei.hlinux/fs.hlinux/fs_struct.hlinux/file.hlinux/init_syscalls.hlinux/security.hinternal.h
Detected Declarations
function init_pivot_rootfunction init_mountfunction init_umountfunction init_chdirfunction init_chrootfunction init_chownfunction init_chmodfunction init_eaccessfunction init_statfunction init_mknodfunction init_linkfunction init_symlinkfunction init_unlinkfunction init_mkdirfunction init_rmdirfunction init_utimesfunction init_dup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Routines that mimic syscalls, but don't use the user address space or file
* descriptors. Only for init/ and related early init code.
*/
#include <linux/init.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/file.h>
#include <linux/init_syscalls.h>
#include <linux/security.h>
#include "internal.h"
int __init init_pivot_root(const char *new_root, const char *put_old)
{
struct path new_path __free(path_put) = {};
struct path old_path __free(path_put) = {};
int ret;
ret = kern_path(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &new_path);
if (ret)
return ret;
ret = kern_path(put_old, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &old_path);
if (ret)
return ret;
return path_pivot_root(&new_path, &old_path);
}
int __init init_mount(const char *dev_name, const char *dir_name,
const char *type_page, unsigned long flags, void *data_page)
{
struct path path;
int ret;
ret = kern_path(dir_name, LOOKUP_FOLLOW, &path);
if (ret)
return ret;
ret = path_mount(dev_name, &path, type_page, flags, data_page);
path_put(&path);
return ret;
}
int __init init_umount(const char *name, int flags)
{
int lookup_flags = LOOKUP_MOUNTPOINT;
struct path path;
int ret;
if (!(flags & UMOUNT_NOFOLLOW))
lookup_flags |= LOOKUP_FOLLOW;
ret = kern_path(name, lookup_flags, &path);
if (ret)
return ret;
return path_umount(&path, flags);
}
int __init init_chdir(const char *filename)
{
struct path path;
int error;
error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
if (error)
return error;
error = path_permission(&path, MAY_EXEC | MAY_CHDIR);
if (!error)
set_fs_pwd(current->fs, &path);
path_put(&path);
return error;
}
int __init init_chroot(const char *filename)
{
struct path path;
int error;
error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
if (error)
return error;
error = path_permission(&path, MAY_EXEC | MAY_CHDIR);
if (error)
goto dput_and_out;
error = -EPERM;
if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
goto dput_and_out;
error = security_path_chroot(&path);
Annotation
- Immediate include surface: `linux/init.h`, `linux/mount.h`, `linux/namei.h`, `linux/fs.h`, `linux/fs_struct.h`, `linux/file.h`, `linux/init_syscalls.h`, `linux/security.h`.
- Detected declarations: `function init_pivot_root`, `function init_mount`, `function init_umount`, `function init_chdir`, `function init_chroot`, `function init_chown`, `function init_chmod`, `function init_eaccess`, `function init_stat`, `function init_mknod`.
- 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.