提交 a78ef704 编写于 作者: M Miklos Szeredi 提交者: Christoph Hellwig

vfs: protect i_nlink

Prevent direct modification of i_nlink by making it const and adding a
non-const __i_nlink alias.
Signed-off-by: NMiklos Szeredi <mszeredi@suse.cz>
Tested-by: NToshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
Signed-off-by: NChristoph Hellwig <hch@lst.de>
上级 bfe86848
......@@ -142,7 +142,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
atomic_set(&inode->i_count, 1);
inode->i_op = &empty_iops;
inode->i_fop = &empty_fops;
inode->i_nlink = 1;
inode->__i_nlink = 1;
inode->i_opflags = 0;
inode->i_uid = 0;
inode->i_gid = 0;
......
......@@ -768,7 +768,17 @@ struct inode {
/* Stat data, not accessed from path walking */
unsigned long i_ino;
unsigned int i_nlink;
/*
* Filesystems may only read i_nlink directly. They shall use the
* following functions for modification:
*
* (set|clear|inc|drop)_nlink
* inode_(inc|dec)_link_count
*/
union {
const unsigned int i_nlink;
unsigned int __i_nlink;
};
dev_t i_rdev;
loff_t i_size;
struct timespec i_atime;
......@@ -1764,7 +1774,7 @@ static inline void mark_inode_dirty_sync(struct inode *inode)
*/
static inline void set_nlink(struct inode *inode, unsigned int nlink)
{
inode->i_nlink = nlink;
inode->__i_nlink = nlink;
}
/**
......@@ -1777,7 +1787,7 @@ static inline void set_nlink(struct inode *inode, unsigned int nlink)
*/
static inline void inc_nlink(struct inode *inode)
{
inode->i_nlink++;
inode->__i_nlink++;
}
static inline void inode_inc_link_count(struct inode *inode)
......@@ -1799,7 +1809,7 @@ static inline void inode_inc_link_count(struct inode *inode)
*/
static inline void drop_nlink(struct inode *inode)
{
inode->i_nlink--;
inode->__i_nlink--;
}
/**
......@@ -1812,7 +1822,7 @@ static inline void drop_nlink(struct inode *inode)
*/
static inline void clear_nlink(struct inode *inode)
{
inode->i_nlink = 0;
inode->__i_nlink = 0;
}
static inline void inode_dec_link_count(struct inode *inode)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册