fs/filesystems.c
Source file repositories/reference/linux-study-clean/fs/filesystems.c
File Facts
- System
- Linux kernel
- Corpus path
fs/filesystems.c- Extension
.c- Size
- 9775 bytes
- Lines
- 414
- 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/fs.hlinux/proc_fs.hlinux/seq_file.hlinux/kmod.hlinux/init.hlinux/module.hlinux/slab.hlinux/uaccess.hlinux/fs_parser.hlinux/rculist.h
Detected Declarations
syscall sysfsstruct file_systems_stringfunction invalidate_filesystems_stringfunction put_filesystemfunction register_filesystemfunction unregister_filesystemfunction fs_indexfunction fs_namefunction scoped_guardfunction fs_maxindexfunction list_bdev_fs_namesfunction invalidate_filesystems_stringfunction regen_filesystems_stringfunction filesystems_proc_show_fallbackfunction filesystems_proc_showfunction scoped_guardfunction proc_filesystems_initmodule init proc_filesystems_initexport register_filesystemexport unregister_filesystemexport get_fs_type
Annotated Snippet
SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
{
int retval = -EINVAL;
switch (option) {
case 1:
retval = fs_index((const char __user *) arg1);
break;
case 2:
retval = fs_name(arg1, (char __user *) arg2);
break;
case 3:
retval = fs_maxindex();
break;
}
return retval;
}
#endif
int __init list_bdev_fs_names(char *buf, size_t size)
{
struct file_system_type *p;
size_t len;
int count = 0;
guard(rcu)();
hlist_for_each_entry_rcu(p, &file_systems, list) {
if (!(p->fs_flags & FS_REQUIRES_DEV))
continue;
len = strlen(p->name) + 1;
if (len > size) {
pr_warn("%s: truncating file system list\n", __func__);
break;
}
memcpy(buf, p->name, len);
buf += len;
size -= len;
count++;
}
return count;
}
#ifdef CONFIG_PROC_FS
static void invalidate_filesystems_string(void)
{
struct file_systems_string *old;
lockdep_assert_held_write(&file_systems_lock);
file_systems_gen++;
old = rcu_replace_pointer(file_systems_string, NULL,
lockdep_is_held(&file_systems_lock));
if (old)
kfree_rcu(old, rcu);
}
static __cold noinline int regen_filesystems_string(void)
{
struct file_system_type *p;
struct file_systems_string *old, *new;
size_t newlen, usedlen;
unsigned long gen;
retry:
newlen = 0;
/* pre-calc space for each fs */
spin_lock(&file_systems_lock);
gen = file_systems_gen;
hlist_for_each_entry_rcu(p, &file_systems, list) {
if (!(p->fs_flags & FS_REQUIRES_DEV))
newlen += strlen("nodev");
newlen += strlen("\t") + strlen(p->name) + strlen("\n");
}
spin_unlock(&file_systems_lock);
new = kmalloc(offsetof(struct file_systems_string, string) + newlen + 1,
GFP_KERNEL);
if (!new)
return -ENOMEM;
new->gen = gen;
new->len = newlen;
new->string[newlen] = '\0';
spin_lock(&file_systems_lock);
old = file_systems_string;
/*
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/fs.h`, `linux/proc_fs.h`, `linux/seq_file.h`, `linux/kmod.h`, `linux/init.h`, `linux/module.h`, `linux/slab.h`.
- Detected declarations: `syscall sysfs`, `struct file_systems_string`, `function invalidate_filesystems_string`, `function put_filesystem`, `function register_filesystem`, `function unregister_filesystem`, `function fs_index`, `function fs_name`, `function scoped_guard`, `function fs_maxindex`.
- 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.