All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH against 2.6.14] truncate() or ftruncate shouldn't change mtime if size doesn't change.
Date: Mon, 31 Oct 2005 17:34:44 +1100	[thread overview]
Message-ID: <1051031063444.9586@suse.de> (raw)
In-Reply-To: 20051031173358.9566.patches@notabene



According to Posix and SUS, truncate(2) and ftruncate(2) only update
ctime and mtime if the size actually changes.  Linux doesn't currently
obey this.

There is no need to test the size under i_sem, as loosing any race
will not make a noticable different the mtime or ctime.

(According to SUS, truncate and ftruncate 'may' clear setuid/setgid
 as well, currently we don't.  Should we?
)


Signed-off-by: Neil Brown <neilb@suse.de>

### Diffstat output
 ./fs/open.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff ./fs/open.c~current~ ./fs/open.c
--- ./fs/open.c~current~	2005-10-31 16:22:44.000000000 +1100
+++ ./fs/open.c	2005-10-31 16:22:44.000000000 +1100
@@ -260,7 +260,8 @@ static inline long do_sys_truncate(const
 		goto dput_and_out;
 
 	error = locks_verify_truncate(inode, NULL, length);
-	if (!error) {
+	if (!error &&
+	    length != i_size_read(dentry->d_inode)) {
 		DQUOT_INIT(inode);
 		error = do_truncate(nd.dentry, length);
 	}
@@ -313,7 +314,8 @@ static inline long do_sys_ftruncate(unsi
 		goto out_putf;
 
 	error = locks_verify_truncate(inode, file, length);
-	if (!error)
+	if (!error &&
+	    length != i_size_read(dentry->d_inode))
 		error = do_truncate(dentry, length);
 out_putf:
 	fput(file);

       reply	other threads:[~2005-10-31  6:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20051031173358.9566.patches@notabene>
2005-10-31  6:34 ` NeilBrown [this message]
2005-10-31  7:48   ` [PATCH against 2.6.14] truncate() or ftruncate shouldn't change mtime if size doesn't change Andrew Morton
2005-10-31  9:48     ` Anton Altaparmakov
2005-10-31 10:16       ` Anton Altaparmakov
2005-10-31 10:41         ` Neil Brown
2005-10-31 10:30       ` Neil Brown
2005-10-31 10:42         ` Anton Altaparmakov
2005-10-31 12:51   ` Trond Myklebust
2005-10-31 13:37     ` Trond Myklebust
2005-10-31 22:53     ` Neil Brown
2005-11-01  0:40       ` Trond Myklebust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1051031063444.9586@suse.de \
    --to=neilb@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.