mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anton Altaparmakov <aia21@cam.ac.uk>
To: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>,
	Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>
Cc: fsdevel <linux-fsdevel@vger.kernel.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: truncate(2) sometimes updates ctime and sometimes ctime and mtime!
Date: Fri, 30 Sep 2005 16:04:47 +0100	[thread overview]
Message-ID: <1128092687.5715.12.camel@imp.csi.cam.ac.uk> (raw)

Hi,

There is an inconsistency in the way truncate works which was introduced
(relatively) recently.

fs/open.c::sys_truncate
  -> do_sys_truncate
    -> do_truncate does:

        newattrs.ia_size = length;
        newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;

        down(&dentry->d_inode->i_sem);
        err = notify_change(dentry, &newattrs);
        up(&dentry->d_inode->i_sem);

This changes the ctime only.

But fs/attr.c::notify_change
  -> inode_setattr [happens when !inode->i_op || !inode->i_op->setattr]

which does:

        if (ia_valid & ATTR_SIZE) {
                if (attr->ia_size != i_size_read(inode)) {
                        error = vmtruncate(inode, attr->ia_size);
                        if (error || (ia_valid == ATTR_SIZE))
                                goto out;
                } else {
                        /*
                         * We skipped the truncate but must still update
                         * timestamps
                         */
                        ia_valid |= ATTR_MTIME|ATTR_CTIME;
                }
        }

Which changes both mtime and ctime when the size does not change.

Also, the man page for stat(2) says:

<quote>
The  field st_mtime is changed by file modifications, e.g. by mknod(2),
truncate(2), utime(2) and write(2) (of more than  zero  bytes).
Moreover, st_mtime of a directory is changed by the creation or deletion
of files in that directory.  The st_mtime field is not changed for
changes in owner, group, hard link count, or mode.
</quote>

So it suggests mtime is always modified on truncate.

So what is correct?  mtime and ctime or just ctime?  If just ctime,
Linus please apply below patch to remove the superfluous ATTR_MTIME from
fs/attr.c::inode_setattr().

Also someone ought to fix the man pages if they are not fixed already
(mine are man-pages-2.01-2 from SUSE 9.3)...

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>

Best regards,

        Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/

--- ntfs-2.6/fs/attr.c.old	2005-09-30 16:00:29.000000000 +0100
+++ ntfs-2.6/fs/attr.c	2005-09-30 16:00:47.000000000 +0100
@@ -79,7 +79,7 @@ int inode_setattr(struct inode * inode, 
 			 * We skipped the truncate but must still update
 			 * timestamps
 			 */
-			ia_valid |= ATTR_MTIME|ATTR_CTIME;
+			ia_valid |= ATTR_CTIME;
 		}
 	}
 



             reply	other threads:[~2005-09-30 15:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-30 15:04 Anton Altaparmakov [this message]
2005-09-30 15:36 ` Linus Torvalds
2005-09-30 15:59   ` Anton Altaparmakov
2005-10-04 10:31     ` [PATCH 2.6] Do not set ATTR_CTIME in do_truncate(). - was: " Anton Altaparmakov
2005-10-04 10:55       ` Miklos Szeredi

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=1128092687.5715.12.camel@imp.csi.cam.ac.uk \
    --to=aia21@cam.ac.uk \
    --cc=akpm@osdl.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®