linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jffs2: modify the mtime and ctime when truncate file
@ 2018-10-15  7:42 ZhuangShengen
  0 siblings, 0 replies; only message in thread
From: ZhuangShengen @ 2018-10-15  7:42 UTC (permalink / raw)
  To: dwmw2, linux-mtd, linux-kernel
  Cc: arnd, boris.brezillon, viro, houtao1, zhuangshengen

The syscall truncate don't modify the mtime or ctime of the file.
The reason is that it only check the ATTR_MTIME or ATTR_CTIME flag
in function jffs2_do_setattr,and the syscall truncate has not set these
two flags in VFS layer.

Fix the problem by checking the ATTR_SIZE flag when modify the
mtime or ctime of the file in jffs2_do_setattr.

This fix solve the same problem with commit 3972f2603d85 ("btrfs:
update timestamps on truncate()")

Signed-off-by: ZhuangShengen <zhuangshengen@huawei.com>
---
 fs/jffs2/fs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index eab04ec..98261f6 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -113,8 +113,10 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
 
 	ri->isize = cpu_to_je32((ivalid & ATTR_SIZE)?iattr->ia_size:inode->i_size);
 	ri->atime = cpu_to_je32(I_SEC((ivalid & ATTR_ATIME)?iattr->ia_atime:inode->i_atime));
-	ri->mtime = cpu_to_je32(I_SEC((ivalid & ATTR_MTIME)?iattr->ia_mtime:inode->i_mtime));
-	ri->ctime = cpu_to_je32(I_SEC((ivalid & ATTR_CTIME)?iattr->ia_ctime:inode->i_ctime));
+	ri->mtime = cpu_to_je32(I_SEC((ivalid & (ATTR_SIZE | ATTR_MTIME)) ?
+		iattr->ia_mtime:inode->i_mtime));
+	ri->ctime = cpu_to_je32(I_SEC((ivalid & (ATTR_SIZE | ATTR_CTIME)) ?
+		iattr->ia_ctime:inode->i_ctime));
 
 	ri->offset = cpu_to_je32(0);
 	ri->csize = ri->dsize = cpu_to_je32(mdatalen);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-15  7:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15  7:42 [PATCH] jffs2: modify the mtime and ctime when truncate file ZhuangShengen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).