[patch 10/24] vfs: truncate: append-only checking cleanup

From: Miklos Szeredi
Date: Tue May 06 2008 - 05:19:11 EST


From: Miklos Szeredi <mszeredi@xxxxxxx>

Move the append-only checks from truncate to notify_change(). Checks
for append-only files are always performed by the VFS and not by the
filesystem so this belongs in notify_change(), and not in
inode_change_ok().

Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxx>
---
fs/attr.c | 6 ++++++
fs/namei.c | 2 --
fs/open.c | 8 --------
3 files changed, 6 insertions(+), 10 deletions(-)

Index: linux-2.6/fs/open.c
===================================================================
--- linux-2.6.orig/fs/open.c 2008-05-06 11:04:35.000000000 +0200
+++ linux-2.6/fs/open.c 2008-05-06 11:04:36.000000000 +0200
@@ -253,10 +253,6 @@ static long do_sys_truncate(const char _
if (error)
goto mnt_drop_write_and_out;

- error = -EPERM;
- if (IS_APPEND(inode))
- goto mnt_drop_write_and_out;
-
error = get_write_access(inode);
if (error)
goto mnt_drop_write_and_out;
@@ -321,10 +317,6 @@ static long do_sys_ftruncate(unsigned in
if (small && length > MAX_NON_LFS)
goto out_putf;

- error = -EPERM;
- if (IS_APPEND(inode))
- goto out_putf;
-
error = locks_verify_truncate(inode, file, length);
if (!error)
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
Index: linux-2.6/fs/attr.c
===================================================================
--- linux-2.6.orig/fs/attr.c 2008-05-06 11:04:35.000000000 +0200
+++ linux-2.6/fs/attr.c 2008-05-06 11:04:36.000000000 +0200
@@ -114,6 +114,12 @@ int notify_change(struct dentry * dentry
return -EPERM;
}

+ /*
+ * IS_IMMUTABLE() is checked by caller for truncation
+ */
+ if ((ia_valid & ATTR_SIZE) && IS_APPEND(inode))
+ return -EPERM;
+
now = current_fs_time(inode->i_sb);

attr->ia_ctime = now;
Index: linux-2.6/fs/namei.c
===================================================================
--- linux-2.6.orig/fs/namei.c 2008-05-06 11:04:29.000000000 +0200
+++ linux-2.6/fs/namei.c 2008-05-06 11:04:36.000000000 +0200
@@ -1639,8 +1639,6 @@ int may_open(struct nameidata *nd, int a
if (IS_APPEND(inode)) {
if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
return -EPERM;
- if (flag & O_TRUNC)
- return -EPERM;
}

/* O_NOATIME can only be set by the owner or superuser */

--
--
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/