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.

Dependency Surface

Detected Declarations

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

Implementation Notes