Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: pass on FTRUNCATE_* flags to do_truncate

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>

authored by

Christoph Hellwig and committed by
Christian Brauner
0924f6b8 e43dce8a

+12 -14
+1 -1
fs/internal.h
··· 198 198 extern int build_open_flags(const struct open_how *how, struct open_flags *op); 199 199 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd); 200 200 201 - int do_ftruncate(struct file *file, loff_t length, int small); 201 + int do_ftruncate(struct file *file, loff_t length, unsigned int flags); 202 202 int chmod_common(const struct path *path, umode_t mode); 203 203 int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, 204 204 int flag);
+10 -12
fs/open.c
··· 161 161 } 162 162 #endif 163 163 164 - int do_ftruncate(struct file *file, loff_t length, int small) 164 + int do_ftruncate(struct file *file, loff_t length, unsigned int flags) 165 165 { 166 - struct inode *inode; 167 - struct dentry *dentry; 166 + struct dentry *dentry = file->f_path.dentry; 167 + struct inode *inode = dentry->d_inode; 168 168 int error; 169 169 170 - /* explicitly opened as large or we are on 64-bit box */ 171 - if (file->f_flags & O_LARGEFILE) 172 - small = 0; 173 - 174 - dentry = file->f_path.dentry; 175 - inode = dentry->d_inode; 176 170 if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE)) 177 171 return -EINVAL; 178 172 179 - /* Cannot ftruncate over 2^31 bytes without large file support */ 180 - if (small && length > MAX_NON_LFS) 173 + /* 174 + * Cannot ftruncate over 2^31 bytes without large file support, either 175 + * through opening with O_LARGEFILE or by using ftruncate64(). 176 + */ 177 + if (length > MAX_NON_LFS && 178 + !(file->f_flags & O_LARGEFILE) && !(flags & FTRUNCATE_LFS)) 181 179 return -EINVAL; 182 180 183 181 /* Check IS_APPEND on real upper inode */ ··· 203 205 if (fd_empty(f)) 204 206 return -EBADF; 205 207 206 - return do_ftruncate(fd_file(f), length, !(flags & FTRUNCATE_LFS)); 208 + return do_ftruncate(fd_file(f), length, flags); 207 209 } 208 210 209 211 SYSCALL_DEFINE2(ftruncate, unsigned int, fd, off_t, length)
+1 -1
io_uring/truncate.c
··· 41 41 42 42 WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK); 43 43 44 - ret = do_ftruncate(req->file, ft->len, 1); 44 + ret = do_ftruncate(req->file, ft->len, 0); 45 45 46 46 io_req_set_res(req, ret, 0); 47 47 return IOU_COMPLETE;