Skip to contentSkip to conversation

Fix ctime/mtime update for truncate to same size

PATCH New David Chinner 1 participant 1 message Jan 25, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix ctime/mtime update for truncate to same size

Russell,

Can you test this change to see if it works for you. It appears to do the job here.

Cheers,

Dave.

Signature · 40 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group


---
 fs/xfs/xfs_vnodeops.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Index: 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/xfs_vnodeops.c	2008-01-25 16:03:23.654971763 +1100
+++ 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c	2008-01-25 16:10:30.875397129 +1100
@@ -634,6 +634,15 @@ xfs_setattr(
 	 * Truncate file.  Must have write permission and not be a directory.
 	 */
 	if (mask & XFS_AT_SIZE) {
+		/*
+		 * Only change the c/mtime if we are changing the size
+		 * or we are explicitly asked to change it. This handles
+		 * the semantic difference between truncate() and ftruncate()
+		 * as implemented in the VFS.
+		 */
+		if (vap->va_size != ip->i_size || mask & XFS_AT_CTIME)
+			timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
+
 		if (vap->va_size > ip->i_size) {
 			xfs_igrow_finish(tp, ip, vap->va_size,
 			    !(flags & ATTR_DMI));
@@ -662,10 +671,6 @@ xfs_setattr(
 			 */
 			xfs_iflags_set(ip, XFS_ITRUNCATED);
 		}
-		/*
-		 * Have to do this even if the file's size doesn't change.
-		 */
-		timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
 	}
 
 	/*