linux mount 操作

Posted yunlion

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 操作的主要内容,如果未能解决你的问题,请参考以下文章

linux的mount(挂载)命令详解

Linux mount/unmount命令(6/16)

linux mount 操作

linux0.11 mount_root函数疑问分析

linux的mount(挂载)命令详解

linux的mount(挂载)NFS 共享,命令详解