Skip to content

Commit 4129a3a

Browse files
dxdxdtnamjaejeon
authored andcommitted
exfat: fix s_maxbytes
With fallocate support, xfstest unit generic/213 fails with QA output created by 213 We should get: fallocate: No space left on device Strangely, xfs_io sometimes says "Success" when something went wrong -fallocate: No space left on device +fallocate: File too large because sb->s_maxbytes is set to the volume size. To be in line with other non-extent-based filesystems, set to max volume size possible with the cluster size of the volume. Signed-off-by: David Timber <dxdt@dev.snart.me> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 73f0125 commit 4129a3a

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

fs/exfat/exfat_raw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define EXFAT_FIRST_CLUSTER 2
2626
#define EXFAT_DATA_CLUSTER_COUNT(sbi) \
2727
((sbi)->num_clusters - EXFAT_RESERVED_CLUSTERS)
28+
#define EXFAT_MAX_NUM_CLUSTER (0xFFFFFFF5)
2829

2930
/* AllocationPossible and NoFatChain field in GeneralSecondaryFlags Field */
3031
#define ALLOC_POSSIBLE 0x01

fs/exfat/file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
3434
return ret;
3535

3636
num_clusters = EXFAT_B_TO_CLU(exfat_ondisk_size(inode), sbi);
37+
/* integer overflow is already checked in inode_newsize_ok(). */
3738
new_num_clusters = EXFAT_B_TO_CLU_ROUND_UP(size, sbi);
3839

3940
if (new_num_clusters == num_clusters)

fs/exfat/super.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,14 @@ static int exfat_read_boot_sector(struct super_block *sb)
531531
if (sbi->vol_flags & MEDIA_FAILURE)
532532
exfat_warn(sb, "Medium has reported failures. Some data may be lost.");
533533

534-
/* exFAT file size is limited by a disk volume size */
535-
sb->s_maxbytes = (u64)(sbi->num_clusters - EXFAT_RESERVED_CLUSTERS) <<
536-
sbi->cluster_size_bits;
534+
/*
535+
* Set to the max possible volume size for this volume's cluster size so
536+
* that any integer overflow from bytes to cluster size conversion is
537+
* checked in inode_newsize_ok(). Clamped to MAX_LFS_FILESIZE for 32-bit
538+
* machines.
539+
*/
540+
sb->s_maxbytes = min(MAX_LFS_FILESIZE,
541+
EXFAT_CLU_TO_B((loff_t)EXFAT_MAX_NUM_CLUSTER, sbi));
537542

538543
/* check logical sector size */
539544
if (exfat_calibrate_blocksize(sb, 1 << p_boot->sect_size_bits))

0 commit comments

Comments
 (0)