Linux内核源码分析-卸载文件系统-sys_umount

本文主要参考《深入理解Linux内核》,结合2.6.11.1版的内核代码,分析内核文件子系统中的卸载文件系统函数。

注意:

1、不描述内核同步、错误处理、参数合法性验证相关的内容

2、源码摘自Linux内核2.6.11.1版

3、阅读本文请结合《深入理解Linux内核》第三版相关章节

4、本文会不定时更新

1、sys_umount

函数源码:

/*
* Now umount can handle mount points as well as block devices.
* This is important for filesystems which use unnamed block devices.
*
* We now support a flag for forced unmount like the other 'big iron'
* unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
*/

asmlinkage long sys_umount(char __user * name, int flags)
{
struct nameidata nd;
int retval;

retval = __user_walk(name, LOOKUP_FOLLOW, &nd);
if (retval)
goto out;
retval = -EINVAL;
if (nd.dentry != nd.mnt->mnt_root)
goto dput_and_out;
if (!check_mnt(nd.mnt))
goto dput_and_out;

retval = -EPERM;
if (!capable(CAP_SYS_ADMIN))
goto dput_and_out;

retval = do_umount(nd.mnt, flags);
dput_and_out:
path_release_on_umount(&nd);
out:
return retval;
}

函数处理流程:

1、调用__user_walk函数(path_lookup封装函数)查找路径名信息nameidata对象,并存入局部变量nd中

2、判断查找到的目录是否是安装点目录(nd.dentry 和nd.mnt->mnt_root是否相等),不是则退出

3、调用函数check_mnt验证要卸载的文件系统是否在当前进程的命名空间中,没有则退出

4、调用函数capable验证是否有卸载文件系统的权限

5、调用do_umount卸载文件系统,具体分析见下文

2、do_umount

函数源码:

static

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值