博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微视linux 文件系统之打开文件返回只读
阅读量:4069 次
发布时间:2019-05-25

本文共 1723 字,大约阅读时间需要 5 分钟。

struct file *do_last(struct nameidata *nd, struct path *path,			    int open_flag, int acc_mode,			    int mode, const char *pathname){	if (!(open_flag & O_CREAT)) {		error = do_lookup(nd, &nd->last, path);		if (error)			goto exit;		error = -ENOENT;//不让以创建方式打开,那么如果找不到则返回		if (!path->dentry->d_inode)			goto exit_dput;		goto ok;	}	/* Negative dentry, just create the file */	if (!path->dentry->d_inode) {		error = mnt_want_write(nd->path.mnt);		=>int mnt_want_write(struct vfsmount *mnt)		{			if (__mnt_is_readonly(mnt)) {				dec_mnt_writers(mnt);				ret = -EROFS;//打开失败,由于是只读模式				goto out;			}		out:			return ret;		}		if (error)			goto exit_mutex_unlock;	}ok:	filp = finish_open(nd, open_flag, acc_mode);	=>struct file *finish_open(struct nameidata *nd,				int open_flag, int acc_mode)	{		error = may_open(&nd->path, acc_mode, open_flag);		=>int may_open(struct path *path, int acc_mode, int flag)		{			error = inode_permission(inode, acc_mode);			=>int inode_permission(struct inode *inode, int mask)			{				if (mask & MAY_WRITE) {//写模式下权限的判断					umode_t mode = inode->i_mode;					/*					 * Nobody gets write access to a read-only fs.					 */					if (IS_RDONLY(inode) &&						(S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))						return -EROFS;//只读					/*					 * Nobody gets write access to an immutable file.					 */					if (IS_IMMUTABLE(inode))						return -EACCES;				}			}			if (error)				return error;		}		if (error) {			if (will_truncate)				mnt_drop_write(nd->path.mnt);			goto exit;		}	}	return filp;exit_mutex_unlock:	mutex_unlock(&dir->d_inode->i_mutex);exit_dput:	path_put_conditional(path, nd);exit:	if (!IS_ERR(nd->intent.open.file))		release_open_intent(nd);	path_put(&nd->path);	return ERR_PTR(error);	}

 

转载地址:http://mylji.baihongyu.com/

你可能感兴趣的文章
环境分支-git版本管理
查看>>
uni-app 全局变量
查看>>
js判断空对象的几种方法
查看>>
java 不用递归写tree
查看>>
springboot2 集成Hibernate JPA 用 声明式事物
查看>>
fhs-framework jetcache 缓存维护之自动清除缓存
查看>>
SpringBoot 动态编译 JAVA class 解决 jar in jar 的依赖问题
查看>>
fhs-framework springboot mybatis 解决表关联查询问题的关键方案-翻译服务
查看>>
ZUUL2 使用场景
查看>>
Spring AOP + Redis + 注解实现redis 分布式锁
查看>>
elastic-job 和springboot 集成干货
查看>>
php开发微服务注册到eureka中(使用sidecar)
查看>>
mybatis mybatis plus mybatis jpa hibernate spring data jpa比较
查看>>
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>
【设计模式】学习笔记13:组合模式(Composite)
查看>>
hdu 1011 Starship Troopers (树形背包dp)
查看>>
hdu 1561 The more, The Better (树形背包dp)
查看>>