[PATCH v2 1/2] vfs: iversion truncate bug fix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a file is opened with O_TRUNC or truncated with truncate()/ftruncate(),
and then closed, iversion is not updated. This patch uses ATTR_OPEN flag,
which is currently used to identify files opened with O_TRUNC,
as an indication to increment iversion.
Also it adds passing of this flag from do_sys_truncate and do_sys_ftruncate.

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@xxxxxxxxx>
---
 fs/attr.c |    3 +++
 fs/open.c |    5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/attr.c b/fs/attr.c
index 7ee7ba4..e02370d 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -176,6 +176,9 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
 			return -EPERM;
 	}
 
+	if ((ia_valid & ATTR_OPEN) && IS_I_VERSION(inode))
+		inode_inc_iversion(inode);
+
 	if ((ia_valid & ATTR_MODE)) {
 		mode_t amode = attr->ia_mode;
 		/* Flag setting protected by i_mutex */
diff --git a/fs/open.c b/fs/open.c
index 22c41b5..4ee6847 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -113,7 +113,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
 	if (!error)
 		error = security_path_truncate(&path);
 	if (!error)
-		error = do_truncate(path.dentry, length, 0, NULL);
+		error = do_truncate(path.dentry, length, ATTR_OPEN, NULL);
 
 put_write_and_out:
 	put_write_access(inode);
@@ -168,7 +168,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
 	if (!error)
 		error = security_path_truncate(&file->f_path);
 	if (!error)
-		error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
+		error = do_truncate(dentry, length,
+				    ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, file);
 out_putf:
 	fput(file);
 out:
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux