]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: pass on FTRUNCATE_* flags to do_truncate
authorChristoph Hellwig <hch@lst.de>
Mon, 23 Mar 2026 07:01:45 +0000 (08:01 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 23 Mar 2026 11:41:57 +0000 (12:41 +0100)
Pass the flags one level down to replace the somewhat confusing small
argument, and clean up do_truncate as a result.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260323070205.2939118-3-hch@lst.de
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/internal.h
fs/open.c
io_uring/truncate.c

index 2663823e273a1f032bc64a8a19ad51d0c445e543..52e4c354e7a4d1556b23f045d1fcf95792062ce6 100644 (file)
@@ -198,7 +198,7 @@ extern struct open_how build_open_how(int flags, umode_t mode);
 extern int build_open_flags(const struct open_how *how, struct open_flags *op);
 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
 
-int do_ftruncate(struct file *file, loff_t length, int small);
+int do_ftruncate(struct file *file, loff_t length, unsigned int flags);
 int chmod_common(const struct path *path, umode_t mode);
 int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
                int flag);
index 412d0d6fbaa7577de63fe4c8c6f2b96c0499d800..181c1597e73c1998442a0140ca0db4a399d0bf55 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -161,23 +161,21 @@ COMPAT_SYSCALL_DEFINE2(truncate, const char __user *, path, compat_off_t, length
 }
 #endif
 
-int do_ftruncate(struct file *file, loff_t length, int small)
+int do_ftruncate(struct file *file, loff_t length, unsigned int flags)
 {
-       struct inode *inode;
-       struct dentry *dentry;
+       struct dentry *dentry = file->f_path.dentry;
+       struct inode *inode = dentry->d_inode;
        int error;
 
-       /* explicitly opened as large or we are on 64-bit box */
-       if (file->f_flags & O_LARGEFILE)
-               small = 0;
-
-       dentry = file->f_path.dentry;
-       inode = dentry->d_inode;
        if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
                return -EINVAL;
 
-       /* Cannot ftruncate over 2^31 bytes without large file support */
-       if (small && length > MAX_NON_LFS)
+       /*
+        * Cannot ftruncate over 2^31 bytes without large file support, either
+        * through opening with O_LARGEFILE or by using ftruncate64().
+        */
+       if (length > MAX_NON_LFS &&
+           !(file->f_flags & O_LARGEFILE) && !(flags & FTRUNCATE_LFS))
                return -EINVAL;
 
        /* Check IS_APPEND on real upper inode */
@@ -205,7 +203,7 @@ int ksys_ftruncate(unsigned int fd, loff_t length, unsigned int flags)
        if (fd_empty(f))
                return -EBADF;
 
-       return do_ftruncate(fd_file(f), length, !(flags & FTRUNCATE_LFS));
+       return do_ftruncate(fd_file(f), length, flags);
 }
 
 SYSCALL_DEFINE2(ftruncate, unsigned int, fd, off_t, length)
index 487baf23b44e26233d565073ef1503b25d995c36..c88d8bd8d20e4de3cd81e5069dd17b279c285d39 100644 (file)
@@ -41,7 +41,7 @@ int io_ftruncate(struct io_kiocb *req, unsigned int issue_flags)
 
        WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
 
-       ret = do_ftruncate(req->file, ft->len, 1);
+       ret = do_ftruncate(req->file, ft->len, 0);
 
        io_req_set_res(req, ret, 0);
        return IOU_COMPLETE;