The patch titled vfs: create file_truncate() helper has been added to the -mm tree. Its filename is vfs-create-file_truncate-helper.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: vfs: create file_truncate() helper From: Miklos Szeredi <mszeredi@xxxxxxx> Clean up do_truncate() API: - create a new function file_truncate() Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/exec.c | 2 +- fs/open.c | 24 ++++++++++++++++++++---- include/linux/fs.h | 2 ++ mm/tiny-shmem.c | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff -puN fs/exec.c~vfs-create-file_truncate-helper fs/exec.c --- a/fs/exec.c~vfs-create-file_truncate-helper +++ a/fs/exec.c @@ -1768,7 +1768,7 @@ int do_coredump(long signr, int exit_cod goto close_fail; if (!file->f_op->write) goto close_fail; - if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0) + if (!ispipe && file_truncate(file, 0, 0) != 0) goto close_fail; retval = binfmt->core_dump(signr, regs, file, core_limit); diff -puN fs/open.c~vfs-create-file_truncate-helper fs/open.c --- a/fs/open.c~vfs-create-file_truncate-helper +++ a/fs/open.c @@ -195,6 +195,13 @@ out: return error; } +/* + * do_truncate - truncate (or extend) an inode + * @dentry: the dentry to truncate + * @length: the new length + * @time_attrs: file times to be updated (e.g. ATTR_MTIME|ATTR_CTIME) + * @filp: an open file or NULL (see file_truncate() as well) + */ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, struct file *filp) { @@ -221,6 +228,17 @@ int do_truncate(struct dentry *dentry, l return err; } +/* + * file_truncate - truncate (or extend) an open file + * @filp: the open file + * @length: the new length + * @time_attrs: file times to be updated (e.g. ATTR_MTIME|ATTR_CTIME) + */ +int file_truncate(struct file *filp, loff_t length, unsigned int time_attrs) +{ + return do_truncate(filp->f_path.dentry, length, time_attrs, filp); +} + static long do_sys_truncate(const char __user * path, loff_t length) { struct nameidata nd; @@ -294,7 +312,6 @@ asmlinkage long sys_truncate(const char static long do_sys_ftruncate(unsigned int fd, loff_t length, int small) { struct inode * inode; - struct dentry *dentry; struct file * file; int error; @@ -310,8 +327,7 @@ static long do_sys_ftruncate(unsigned in if (file->f_flags & O_LARGEFILE) small = 0; - dentry = file->f_path.dentry; - inode = dentry->d_inode; + inode = file->f_path.dentry->d_inode; error = -EINVAL; if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE)) goto out_putf; @@ -327,7 +343,7 @@ static long do_sys_ftruncate(unsigned in error = locks_verify_truncate(inode, file, length); if (!error) - error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); + error = file_truncate(file, length, ATTR_MTIME|ATTR_CTIME); out_putf: fput(file); out: diff -puN include/linux/fs.h~vfs-create-file_truncate-helper include/linux/fs.h --- a/include/linux/fs.h~vfs-create-file_truncate-helper +++ a/include/linux/fs.h @@ -1622,6 +1622,8 @@ static inline int break_lease(struct ino extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, struct file *filp); +extern int file_truncate(struct file *filp, loff_t start, + unsigned int time_attrs); extern long do_sys_open(int dfd, const char __user *filename, int flags, int mode); extern struct file *filp_open(const char *, int, int); diff -puN mm/tiny-shmem.c~vfs-create-file_truncate-helper mm/tiny-shmem.c --- a/mm/tiny-shmem.c~vfs-create-file_truncate-helper +++ a/mm/tiny-shmem.c @@ -80,7 +80,7 @@ struct file *shmem_file_setup(char *name inode->i_nlink = 0; /* It is unlinked */ /* notify everyone as to the change of file size */ - error = do_truncate(dentry, size, 0, file); + error = file_truncate(file, size, 0); if (error < 0) goto close_file; _ Patches currently in -mm which might be from mszeredi@xxxxxxx are git-unprivileged-mounts.patch lockd-dont-return-eagain-for-a-permanent-error.patch locks-add-special-return-value-for-asynchronous-locks.patch locks-cleanup-code-duplication.patch locks-allow-lock-to-return-file_lock_deferred.patch fuse-prepare-lookup-for-nfs-export.patch fuse-add-export-operations.patch fuse-add-fuse_lookup_name-helper.patch fuse-nfs-export-special-lookups.patch fuse-lockd-support.patch nfsd-clean-up-mnt_want_write-calls.patch cgroup-dont-call-vfs_mkdir.patch reiserfs-dont-call-vfs_rmdir.patch reiserfs-dont-call-notify_change.patch sysfs-dont-call-notify_change.patch hpfs-dont-call-notify_change.patch fat-dont-call-notify_change.patch hpfs-dont-call-permission.patch hppfs-remove-hppfs_permission.patch gfs2-dont-call-permission.patch vfs-immutable-inode-checking-cleanup.patch vfs-truncate-dont-check-immutable-twice.patch vfs-create-file_truncate-helper.patch vfs-utimes-immutable-fix.patch vfs-utimes-cleanup.patch vfs-dcache-cleanups.patch vfs-fix-sys_getcwd-for-detached-mounts.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html