History

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".

Matthew Wilcox (Oracle) committed 11 months ago

Commit 37d369f1 parent a77a5956 files · +11 −9Browse files

Unified · Split

6 files
  1. include/linux/mm.h +4 −4
  2. include/linux/shmem_fs.h +1 −1
  3. include/linux/types.h +1 −0
  4. include/uapi/asm-generic/posix_types.h +1 −0
  5. mm/shmem.c +3 −3
  6. mm/truncate.c +1 −1
include/linux/mm.h+4−4
@@ -3495,10 +3495,10 @@ struct vm_unmapped_area_info { · 3494 unmodified lines
34953495 extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info);
34963496
34973497 /* truncate.c */
3498−extern void truncate_inode_pages(struct address_space *, loff_t);
3499−extern void truncate_inode_pages_range(struct address_space *,
3500− loff_t lstart, loff_t lend);
3501−extern void truncate_inode_pages_final(struct address_space *);
3498+void truncate_inode_pages(struct address_space *mapping, loff_t lstart);
3499+void truncate_inode_pages_range(struct address_space *mapping, loff_t lstart,
3500+ uoff_t lend);
3501+void truncate_inode_pages_final(struct address_space *mapping);
35023502
35033503 /* generic vm_area_ops exported for stackable file systems */
35043504 extern vm_fault_t filemap_fault(struct vm_fault *vmf);
include/linux/shmem_fs.h+1−1
@@ -111,7 +111,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, · 110 unmodified lines
111111 pgoff_t index, gfp_t gfp_mask);
112112 int shmem_writeout(struct folio *folio, struct swap_iocb **plug,
113113 struct list_head *folio_list);
114−void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
114+void shmem_truncate_range(struct inode *inode, loff_t start, uoff_t end);
115115 int shmem_unuse(unsigned int type);
116116
117117 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
include/linux/types.h+1−0
@@ -50,6 +50,7 @@ typedef __kernel_old_gid_t old_gid_t; · 49 unmodified lines
5050
5151 #if defined(__GNUC__)
5252 typedef __kernel_loff_t loff_t;
53+typedef __kernel_uoff_t uoff_t;
5354 #endif
5455
5556 /*
include/uapi/asm-generic/posix_types.h+1−0
@@ -86,6 +86,7 @@ typedef struct { · 85 unmodified lines
8686 */
8787 typedef __kernel_long_t __kernel_off_t;
8888 typedef long long __kernel_loff_t;
89+typedef unsigned long long __kernel_uoff_t;
8990 typedef __kernel_long_t __kernel_old_time_t;
9091 #ifndef __KERNEL__
9192 typedef __kernel_long_t __kernel_time_t;
mm/shmem.c+3−3
@@ -1076,7 +1076,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) · 1075 unmodified lines
10761076 * Remove range of pages and swap entries from page cache, and free them.
10771077 * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate.
10781078 */
1079−static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
1079+static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend,
10801080 bool unfalloc)
10811081 {
10821082 struct address_space *mapping = inode->i_mapping;
@@ -1227,7 +1227,7 @@ whole_folios: · 144 unmodified lines
12271227 shmem_recalc_inode(inode, 0, -nr_swaps_freed);
12281228 }
12291229
1230−void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
1230+void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
12311231 {
12321232 shmem_undo_range(inode, lstart, lend, false);
12331233 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
@@ -5776,7 +5776,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, · 4542 unmodified lines
57765776 }
57775777 #endif
57785778
5779−void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
5779+void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
57805780 {
57815781 truncate_inode_pages_range(inode->i_mapping, lstart, lend);
57825782 }
mm/truncate.c+1−1
@@ -339,7 +339,7 @@ long mapping_evict_folio(struct address_space *mapping, struct folio *folio) · 338 unmodified lines
339339 * page aligned properly.
340340 */
341341 void truncate_inode_pages_range(struct address_space *mapping,
342− loff_t lstart, loff_t lend)
342+ loff_t lstart, uoff_t lend)
343343 {
344344 pgoff_t start; /* inclusive */
345345 pgoff_t end; /* exclusive */