首页 > 代码库 > linux mount 操作

linux mount 操作

1、调用:从用户态陷入到内核态:

SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
		char __user *, type, unsigned long, flags, void __user *, data)
{
	int ret;
	char *kernel_type;
	struct filename *kernel_dir;
	char *kernel_dev;
	unsigned long data_page;
        /* 从用户空间向内核空间拷贝数据:类型,挂载路径,参数等 */
	ret = copy_mount_string(type, &kernel_type);  
	if (ret < 0)
		goto out_type;

	kernel_dir = getname(dir_name);
	if (IS_ERR(kernel_dir)) {
		ret = PTR_ERR(kernel_dir);
		goto out_dir;
	}

	ret = copy_mount_string(dev_name, &kernel_dev); 
	if (ret < 0)
		goto out_dev;

	ret = copy_mount_options(data, &data_page); 
	if (ret < 0)
		goto out_data;

	ret = do_mount(kernel_dev, kernel_dir->name, kernel_type, flags,
		(void *) data_page);

	free_page(data_page);
out_data:
	kfree(kernel_dev);
out_dev:
	putname(kernel_dir);
out_dir:
	kfree(kernel_type);
out_type:
	return ret;
}

备注:struct filename *kernel_dir

struct filename {
	const char		*name;	/* pointer to actual string */
	const __user char	*uptr;	/* original userland pointer */
	struct audit_names	*aname;
	bool			separate; /* should "name" be freed? */
};

  

linux mount 操作