init/do_mounts.c
Source file repositories/reference/linux-study-clean/init/do_mounts.c
File Facts
- System
- Linux kernel
- Corpus path
init/do_mounts.c- Extension
.c- Size
- 11217 bytes
- Lines
- 521
- Domain
- Core OS
- Bucket
- Boot And Init
- 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/module.hlinux/sched.hlinux/ctype.hlinux/fd.hlinux/tty.hlinux/suspend.hlinux/root_dev.hlinux/security.hlinux/delay.hlinux/mount.hlinux/device.hlinux/init.hlinux/fs.hlinux/initrd.hlinux/async.hlinux/fs_struct.hlinux/slab.hlinux/ramfs.hlinux/shmem_fs.hlinux/ktime.hlinux/nfs_fs.hlinux/nfs_fs_sb.hlinux/nfs_mount.hlinux/raid/detect.huapi/linux/mount.hdo_mounts.h
Detected Declarations
function readonlyfunction readwritefunction root_dev_setupfunction rootwait_setupfunction rootwait_timeout_setupfunction root_data_setupfunction fs_names_setupfunction root_delay_setupfunction split_fs_namesfunction do_mount_rootfunction mount_root_genericfunction mount_nfs_rootfunction mount_nfs_rootfunction mount_cifs_rootfunction mount_nodev_rootfunction mount_block_rootfunction mount_block_rootfunction wait_for_rootfunction parse_root_devicefunction prepare_namespacefunction rootfs_init_fs_contextfunction init_rootfs
Annotated Snippet
if (p[-1] == ',') {
p[-1] = '\0';
count++;
}
}
return count;
}
static int __init do_mount_root(const char *name, const char *fs,
const int flags, const void *data)
{
struct super_block *s;
char *data_page = NULL;
int ret;
if (data) {
/* init_mount() requires a full page as fifth argument */
data_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!data_page)
return -ENOMEM;
strscpy_pad(data_page, data, PAGE_SIZE);
}
ret = init_mount(name, "/root", fs, flags, data_page);
if (ret)
goto out;
init_chdir("/root");
s = current->fs->pwd.dentry->d_sb;
ROOT_DEV = s->s_dev;
printk(KERN_INFO
"VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
s->s_type->name,
sb_rdonly(s) ? " readonly" : "",
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
out:
kfree(data_page);
return ret;
}
void __init mount_root_generic(char *name, char *pretty_name, int flags)
{
char *fs_names = kmalloc(PAGE_SIZE, GFP_KERNEL);
char *p;
char b[BDEVNAME_SIZE];
int num_fs, i;
if (!fs_names)
panic("VFS: Unable to mount root fs: not enough memory");
scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
if (root_fs_names)
num_fs = split_fs_names(fs_names, PAGE_SIZE);
else
num_fs = list_bdev_fs_names(fs_names, PAGE_SIZE);
retry:
for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1) {
int err;
if (!*p)
continue;
err = do_mount_root(name, p, flags, root_mount_data);
switch (err) {
case 0:
goto out;
case -EACCES:
case -EINVAL:
#ifdef CONFIG_BLOCK
init_flush_fput();
#endif
continue;
}
/*
* Allow the user to distinguish between failed sys_open
* and bad superblock on root device.
* and give them a list of the available devices
*/
printk("VFS: Cannot open root device \"%s\" or %s: error %d\n",
pretty_name, b, err);
printk("Please append a correct \"root=\" boot option; here are the available partitions:\n");
printk_all_partitions();
if (root_fs_names)
num_fs = list_bdev_fs_names(fs_names, PAGE_SIZE);
if (!num_fs)
pr_err("Can't find any bdev filesystem to be used for mount!\n");
else {
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/ctype.h`, `linux/fd.h`, `linux/tty.h`, `linux/suspend.h`, `linux/root_dev.h`, `linux/security.h`.
- Detected declarations: `function readonly`, `function readwrite`, `function root_dev_setup`, `function rootwait_setup`, `function rootwait_timeout_setup`, `function root_data_setup`, `function fs_names_setup`, `function root_delay_setup`, `function split_fs_names`, `function do_mount_root`.
- Atlas domain: Core OS / Boot And Init.
- 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.