drivers/base/devtmpfs.c
Source file repositories/reference/linux-study-clean/drivers/base/devtmpfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/devtmpfs.c- Extension
.c- Size
- 11028 bytes
- Lines
- 515
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/syscalls.hlinux/mount.hlinux/device.hlinux/blkdev.hlinux/namei.hlinux/fs.hlinux/shmem_fs.hlinux/ramfs.hlinux/sched.hlinux/slab.hlinux/kthread.hlinux/init_syscalls.huapi/linux/mount.hbase.h
Detected Declarations
function mount_paramfunction devtmpfs_get_treefunction devtmpfs_init_fs_contextfunction devtmpfs_submit_reqfunction devtmpfs_create_nodefunction devtmpfs_delete_nodefunction dev_mkdirfunction create_pathfunction handle_createfunction dev_rmdirfunction delete_pathfunction dev_mynodefunction handle_removefunction devtmpfs_mountfunction handlefunction devtmpfs_work_loopfunction devtmpfs_setupfunction devtmpfsdfunction underlyingfunction devtmpfs_init
Annotated Snippet
while (requests) {
struct req *req = requests;
requests = NULL;
spin_unlock(&req_lock);
while (req) {
struct req *next = req->next;
req->err = handle(req->name, req->mode,
req->uid, req->gid, req->dev);
complete(&req->done);
req = next;
}
spin_lock(&req_lock);
}
__set_current_state(TASK_INTERRUPTIBLE);
spin_unlock(&req_lock);
schedule();
}
}
static noinline int __init devtmpfs_setup(void *p)
{
int err;
err = ksys_unshare(CLONE_NEWNS);
if (err)
goto out;
err = init_mount("devtmpfs", "/", "devtmpfs", DEVTMPFS_MFLAGS, NULL);
if (err)
goto out;
init_chdir("/.."); /* will traverse into overmounted root */
init_chroot(".");
out:
*(int *)p = err;
return err;
}
/*
* The __ref is because devtmpfs_setup needs to be __init for the routines it
* calls. That call is done while devtmpfs_init, which is marked __init,
* synchronously waits for it to complete.
*/
static int __ref devtmpfsd(void *p)
{
int err = devtmpfs_setup(p);
complete(&setup_done);
if (err)
return err;
devtmpfs_work_loop();
return 0;
}
/*
* Get the underlying (shmem/ramfs) context ops to build ours
*/
static int devtmpfs_configure_context(void)
{
struct fs_context *fc;
fc = fs_context_for_reconfigure(mnt->mnt_root, mnt->mnt_sb->s_flags,
MS_RMT_MASK);
if (IS_ERR(fc))
return PTR_ERR(fc);
/* Set up devtmpfs_context_ops based on underlying type */
devtmpfs_context_ops.free = fc->ops->free;
devtmpfs_context_ops.dup = fc->ops->dup;
devtmpfs_context_ops.parse_param = fc->ops->parse_param;
devtmpfs_context_ops.parse_monolithic = fc->ops->parse_monolithic;
devtmpfs_context_ops.get_tree = &devtmpfs_get_tree;
devtmpfs_context_ops.reconfigure = fc->ops->reconfigure;
put_fs_context(fc);
return 0;
}
/*
* Create devtmpfs instance, driver-core devices will add their device
* nodes here.
*/
int __init devtmpfs_init(void)
{
char opts[] = "mode=0755";
int err;
mnt = vfs_kern_mount(&internal_fs_type, 0, "devtmpfs", opts);
if (IS_ERR(mnt)) {
pr_err("unable to create devtmpfs %ld\n", PTR_ERR(mnt));
return PTR_ERR(mnt);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/syscalls.h`, `linux/mount.h`, `linux/device.h`, `linux/blkdev.h`, `linux/namei.h`, `linux/fs.h`, `linux/shmem_fs.h`.
- Detected declarations: `function mount_param`, `function devtmpfs_get_tree`, `function devtmpfs_init_fs_context`, `function devtmpfs_submit_req`, `function devtmpfs_create_node`, `function devtmpfs_delete_node`, `function dev_mkdir`, `function create_path`, `function handle_create`, `function dev_rmdir`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: source implementation candidate.
- 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.