[PATCH 1/8] VFS: pass file pointer to filesystem from ftruncate()

From: Miklos Szeredi
Date: Mon Oct 24 2005 - 11:51:40 EST


This patch extends the iattr structure with a file pointer memeber,
and adds an ATTR_FILE validity flag for this member.

This is set if do_truncate() is invoked from ftruncate() or from
do_coredump().

The change is source and binary compatible.

Signed-off-by: Miklos Szeredi <miklos@xxxxxxxxxx>

Index: linux/fs/namei.c
===================================================================
--- linux.orig/fs/namei.c 2005-10-24 12:11:04.000000000 +0200
+++ linux/fs/namei.c 2005-10-24 14:13:40.000000000 +0200
@@ -1459,7 +1459,7 @@ int may_open(struct nameidata *nd, int a
if (!error) {
DQUOT_INIT(inode);

- error = do_truncate(dentry, 0);
+ error = do_truncate(dentry, 0, NULL);
}
put_write_access(inode);
if (error)
Index: linux/include/linux/fs.h
===================================================================
--- linux.orig/include/linux/fs.h 2005-10-24 12:11:05.000000000 +0200
+++ linux/include/linux/fs.h 2005-10-24 14:13:40.000000000 +0200
@@ -266,6 +266,7 @@ typedef void (dio_iodone_t)(struct kiocb
#define ATTR_ATTR_FLAG 1024
#define ATTR_KILL_SUID 2048
#define ATTR_KILL_SGID 4096
+#define ATTR_FILE 8192

/*
* This is the Inode Attributes structure, used for notify_change(). It
@@ -285,6 +286,13 @@ struct iattr {
struct timespec ia_atime;
struct timespec ia_mtime;
struct timespec ia_ctime;
+
+ /*
+ * Not an attribute, but an auxilary info for filesystems wanting to
+ * implement an ftruncate() like method. NOTE: filesystem should
+ * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
+ */
+ struct file *ia_file;
};

/*
@@ -1295,7 +1303,7 @@ static inline int break_lease(struct ino

/* fs/open.c */

-extern int do_truncate(struct dentry *, loff_t start);
+extern int do_truncate(struct dentry *, loff_t start, struct file *filp);
extern long do_sys_open(const char __user *filename, int flags, int mode);
extern struct file *filp_open(const char *, int, int);
extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
Index: linux/fs/exec.c
===================================================================
--- linux.orig/fs/exec.c 2005-10-24 12:11:04.000000000 +0200
+++ linux/fs/exec.c 2005-10-24 14:13:40.000000000 +0200
@@ -1510,7 +1510,7 @@ int do_coredump(long signr, int exit_cod
goto close_fail;
if (!file->f_op->write)
goto close_fail;
- if (do_truncate(file->f_dentry, 0) != 0)
+ if (do_truncate(file->f_dentry, 0, file) != 0)
goto close_fail;

retval = binfmt->core_dump(signr, regs, file);
Index: linux/fs/open.c
===================================================================
--- linux.orig/fs/open.c 2005-10-24 12:11:04.000000000 +0200
+++ linux/fs/open.c 2005-10-24 14:13:40.000000000 +0200
@@ -194,7 +194,7 @@ out:
return error;
}

-int do_truncate(struct dentry *dentry, loff_t length)
+int do_truncate(struct dentry *dentry, loff_t length, struct file *filp)
{
int err;
struct iattr newattrs;
@@ -205,6 +205,10 @@ int do_truncate(struct dentry *dentry, l

newattrs.ia_size = length;
newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
+ if (filp) {
+ newattrs.ia_file = filp;
+ newattrs.ia_valid |= ATTR_FILE;
+ }

down(&dentry->d_inode->i_sem);
err = notify_change(dentry, &newattrs);
@@ -262,7 +266,7 @@ static inline long do_sys_truncate(const
error = locks_verify_truncate(inode, NULL, length);
if (!error) {
DQUOT_INIT(inode);
- error = do_truncate(nd.dentry, length);
+ error = do_truncate(nd.dentry, length, NULL);
}
put_write_access(inode);

@@ -314,7 +318,7 @@ static inline long do_sys_ftruncate(unsi

error = locks_verify_truncate(inode, file, length);
if (!error)
- error = do_truncate(dentry, length);
+ error = do_truncate(dentry, length, file);
out_putf:
fput(file);
out:
-
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/