fs/fs_context.c
Source file repositories/reference/linux-study-clean/fs/fs_context.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fs_context.c- Extension
.c- Size
- 14643 bytes
- Lines
- 569
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/fs_context.hlinux/fs_parser.hlinux/fs.hlinux/mount.hlinux/nsproxy.hlinux/slab.hlinux/magic.hlinux/security.hlinux/mnt_namespace.hlinux/pid_namespace.hlinux/user_namespace.hnet/net_namespace.hasm/sections.hmount.hinternal.h
Detected Declarations
function vfs_parse_sb_flagfunction vfs_parse_fs_param_sourcefunction vfs_parse_fs_paramfunction vfs_parse_fs_qstrfunction vfs_parse_monolithic_sepfunction generic_parse_monolithicfunction superblockfunction fc_drop_lockedfunction logfcfunction put_fc_logfunction put_fs_contextfunction parse_monolithic_mount_datafunction finish_clean_contextfunction finish_clean_contextexport vfs_parse_fs_param_sourceexport vfs_parse_fs_paramexport vfs_parse_fs_qstrexport vfs_parse_monolithic_sepexport generic_parse_monolithicexport fs_context_for_mountexport fs_context_for_submountexport vfs_dup_fs_contextexport logfcexport put_fs_context
Annotated Snippet
if (*key) {
char *value = strchr(key, '=');
if (value) {
if (unlikely(value == key))
continue;
*value++ = 0;
}
ret = vfs_parse_fs_string(fc, key, value);
if (ret < 0)
break;
}
}
return ret;
}
EXPORT_SYMBOL(vfs_parse_monolithic_sep);
static char *vfs_parse_comma_sep(char **s)
{
return strsep(s, ",");
}
/**
* generic_parse_monolithic - Parse key[=val][,key[=val]]* mount data
* @fc: The superblock configuration to fill in.
* @data: The data to parse
*
* Parse a blob of data that's in key[=val][,key[=val]]* form. This can be
* called from the ->monolithic_mount_data() fs_context operation.
*
* Returns 0 on success or the error returned by the ->parse_option() fs_context
* operation on failure.
*/
int generic_parse_monolithic(struct fs_context *fc, void *data)
{
return vfs_parse_monolithic_sep(fc, data, vfs_parse_comma_sep);
}
EXPORT_SYMBOL(generic_parse_monolithic);
/**
* alloc_fs_context - Create a filesystem context.
* @fs_type: The filesystem type.
* @reference: The dentry from which this one derives (or NULL)
* @sb_flags: Filesystem/superblock flags (SB_*)
* @sb_flags_mask: Applicable members of @sb_flags
* @purpose: The purpose that this configuration shall be used for.
*
* Open a filesystem and create a mount context. The mount context is
* initialised with the supplied flags and, if a submount/automount from
* another superblock (referred to by @reference) is supplied, may have
* parameters such as namespaces copied across from that superblock.
*/
static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
struct dentry *reference,
unsigned int sb_flags,
unsigned int sb_flags_mask,
enum fs_context_purpose purpose)
{
struct fs_context *fc;
int ret = -ENOMEM;
fc = kzalloc_obj(struct fs_context, GFP_KERNEL_ACCOUNT);
if (!fc)
return ERR_PTR(-ENOMEM);
fc->purpose = purpose;
fc->sb_flags = sb_flags;
fc->sb_flags_mask = sb_flags_mask;
fc->fs_type = get_filesystem(fs_type);
fc->cred = get_current_cred();
fc->net_ns = get_net(current->nsproxy->net_ns);
fc->log.prefix = fs_type->name;
mutex_init(&fc->uapi_mutex);
switch (purpose) {
case FS_CONTEXT_FOR_MOUNT:
fc->user_ns = get_user_ns(fc->cred->user_ns);
break;
case FS_CONTEXT_FOR_SUBMOUNT:
fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
break;
case FS_CONTEXT_FOR_RECONFIGURE:
atomic_inc(&reference->d_sb->s_active);
fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
fc->root = dget(reference);
break;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/fs_context.h`, `linux/fs_parser.h`, `linux/fs.h`, `linux/mount.h`, `linux/nsproxy.h`, `linux/slab.h`, `linux/magic.h`.
- Detected declarations: `function vfs_parse_sb_flag`, `function vfs_parse_fs_param_source`, `function vfs_parse_fs_param`, `function vfs_parse_fs_qstr`, `function vfs_parse_monolithic_sep`, `function generic_parse_monolithic`, `function superblock`, `function fc_drop_locked`, `function logfc`, `function put_fc_log`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.