fs: Add uoff_t
Subsystems (6)
Matthew Wilcox (Oracle)
maintainerPATCH v2 1/1 fs: Add uoff_t
In a recent commit, I inadvertently changed a comparison from being an unsigned comparison (on 64-bit systems) to being a signed comparison (which it had always been on 32-bit systems). This led to a sporadic fstests failure.
To make sure this comparison is always unsigned, introduce a new type, uoff_t which is the unsigned version of loff_t. Generally file sizes are restricted to being a signed integer, but in these two places it is convenient to pass -1 to indicate "up to the end of the file".
---
v2: Fix build issue caused by not converting the !CONFIG_SHMEM case With this patch and reverting b94488503277 ("iomap: use loff_t for file positions and offsets in writeback code"), fstets passes on next-20251121
include/linux/mm.h | 8 ++++---- include/linux/shmem_fs.h | 2 +- include/linux/types.h | 1 + include/uapi/asm-generic/posix_types.h | 1 + mm/shmem.c | 6 +++--- mm/truncate.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-)
include/linux/mm.h +4 -4
@@ -3716,10 +3716,10 @@ struct vm_unmapped_area_info {extern unsigned long vm_unmapped_area (struct vm_unmapped_area_info *info);/* truncate.c */ -extern void truncate_inode_pages (struct address_space *,loff_t ); -extern void truncate_inode_pages_range (struct address_space *, -loff_t lstart,loff_t lend); -extern void truncate_inode_pages_final (struct address_space *); +void truncate_inode_pages (struct address_space *mapping,loff_t lstart); +void truncate_inode_pages_range (struct address_space *mapping,loff_t lstart, +uoff_t lend); +void truncate_inode_pages_final (struct address_space *mapping);/* generic vm_area_ops exported for stackable file systems */ extern vm_fault_t filemap_fault (struct vm_fault *vmf);
include/linux/shmem_fs.h +1 -1
@@ -126,7 +126,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp_mask);int shmem_writeout (struct folio *folio,struct swap_iocb **plug,struct list_head *folio_list); -void shmem_truncate_range (struct inode *inode,loff_t start,loff_t end); +void shmem_truncate_range (struct inode *inode,loff_t start,uoff_t end);int shmem_unuse (unsigned int type);#ifdef CONFIG_TRANSPARENT_HUGEPAGE
include/linux/types.h +1 -0
@@ -50,6 +50,7 @@ typedef __kernel_old_gid_t old_gid_t;#if defined(__GNUC__)typedef __kernel_loff_t loff_t ; +typedef __kernel_uoff_t uoff_t ;#endif /*
include/uapi/asm-generic/posix_types.h +1 -0
@@ -86,6 +86,7 @@ typedef struct {*/ typedef __kernel_long_t __kernel_off_t ;typedef long long __kernel_loff_t ; +typedef unsigned long long __kernel_uoff_t ;typedef __kernel_long_t __kernel_old_time_t ;#ifndef __KERNEL__typedef __kernel_long_t __kernel_time_t ;
mm/shmem.c +3 -3
@@ -1093,7 +1093,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index)* Remove range of pages and swap entries from page cache, and free them. * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate. */ -static void shmem_undo_range (struct inode *inode,loff_t lstart,loff_t lend, +static void shmem_undo_range (struct inode *inode,loff_t lstart,uoff_t lend,bool unfalloc) {struct address_space *mapping = inode->i_mapping;
@@ -1244,7 +1244,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,shmem_recalc_inode (inode,0 , -nr_swaps_freed); } -void shmem_truncate_range (struct inode *inode,loff_t lstart,loff_t lend) +void shmem_truncate_range (struct inode *inode,loff_t lstart,uoff_t lend) {shmem_undo_range (inode, lstart, lend, false);inode_set_mtime_to_ts (inode,inode_set_ctime_current (inode));
@@ -5784,7 +5784,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, }#endif -void shmem_truncate_range (struct inode *inode,loff_t lstart,loff_t lend) +void shmem_truncate_range (struct inode *inode,loff_t lstart,uoff_t lend) {truncate_inode_pages_range (inode->i_mapping, lstart, lend); }
mm/truncate.c +1 -1
@@ -364,7 +364,7 @@ long mapping_evict_folio(struct address_space *mapping, struct folio *folio)* page aligned properly. */ void truncate_inode_pages_range (struct address_space *mapping, -loff_t lstart,loff_t lend) +loff_t lstart,uoff_t lend) {pgoff_t start;/* inclusive */ pgoff_t end;/* exclusive */
Signature · 1 line
2.47.2
Quoted 11 lines · Matthew Wilcox (Oracle)
In a recent commit, I inadvertently changed a comparison from being an unsigned comparison (on 64-bit systems) to being a signed comparison (which it had always been on 32-bit systems). This led to a sporadic fstests failure.
To make sure this comparison is always unsigned, introduce a new type,
uoff_twhich is the unsigned version ofloff_t. Generally file sizes are restricted to being a signed integer, but in these two places it is convenient to pass -1 to indicate "up to the end of the file".[...]
Applied to the vfs-6.19.folio branch of the vfs/vfs.git tree. Patches in the vfs-6.19.folio branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.19.folio
[1/1] fs: Add uoff_t
https://git.kernel.org/vfs/vfs/c/37d369fa97cc