Re: [PATCH against 2.6.14] truncate() or ftruncate shouldn'tchange mtime if size doesn't change.

From: Neil Brown
Date: Mon Oct 31 2005 - 05:42:03 EST


On Monday October 31, aia21@xxxxxxxxx wrote:
>
> In may_open() only truncate when O_TRUNC is set and the file size is not
> zero.

No, this is wrong. open( ..,O_TRUNC) needs to update the mtime, even
if the file is already size==0.

What started me looking at this is that open( O_TRUNC) over NFS
*doesn't* update the mtime on an empty file, which is inconsistent
with local file systems, and dis-obeys SUS:

http://www.opengroup.org/onlinepubs/007908799/xsh/open.html

"If O_TRUNC is set and the file did previously exist, upon
successful completion, open() will mark for update the st_ctime and
st_mtime fields of the file. "

So we DO NOT want this change to may_open (and we DO want a different
change in NFS which I have asked Trond to submit... To be honest, this
first came up a couple of months ago, and Trond suggested a patch
then, but it didn't get any further. I'm just trying to make sure the
important bits do make it into the kernel..
http://lkml.org/lkml/2005/8/31/134
)

NeilBrown



> --- linux-2.6/fs/namei.c.old 2005-10-31 09:28:38.000000000 +0000
> +++ linux-2.6/fs/namei.c 2005-10-31 09:30:39.000000000 +0000
> @@ -1447,7 +1447,7 @@ int may_open(struct nameidata *nd, int a
> if (error)
> return error;
>
> - if (flag & O_TRUNC) {
> + if (flag & O_TRUNC && i_size_read(inode)) {
> error = get_write_access(inode);
> if (error)
> return error;
>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/