Skip to content

Commit 92fba08

Browse files
cvubrugiernamjaejeon
authored andcommitted
exfat: fix i_blocks for files truncated over 4 GiB
In exfat_truncate(), the computation of inode->i_blocks is wrong if the file is larger than 4 GiB because a 32-bit variable is used as a mask. This is fixed and simplified by using round_up(). Also fix the same buggy computation in exfat_read_root() and another (correct) one in exfat_fill_inode(). The latter was fixed another way last month but can be simplified by using round_up() as well. See: commit 0c336d6 ("exfat: fix incorrect loading of i_blocks for large files") Fixes: 98d9170 ("exfat: add file operations") Cc: [email protected] # v5.7+ Suggested-by: Matthew Wilcox <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Christophe Vu-Brugier <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 7dee6f5 commit 92fba08

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

fs/exfat/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ void exfat_truncate(struct inode *inode, loff_t size)
251251
else
252252
mark_inode_dirty(inode);
253253

254-
inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
255-
~(sbi->cluster_size - 1)) >> inode->i_blkbits;
254+
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
255+
inode->i_blkbits;
256256
write_size:
257257
aligned_size = i_size_read(inode);
258258
if (aligned_size & (blocksize - 1)) {

fs/exfat/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
602602

603603
exfat_save_attr(inode, info->attr);
604604

605-
inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
606-
~((loff_t)sbi->cluster_size - 1)) >> inode->i_blkbits;
605+
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
606+
inode->i_blkbits;
607607
inode->i_mtime = info->mtime;
608608
inode->i_ctime = info->mtime;
609609
ei->i_crtime = info->crtime;

fs/exfat/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ static int exfat_read_root(struct inode *inode)
364364
inode->i_op = &exfat_dir_inode_operations;
365365
inode->i_fop = &exfat_dir_operations;
366366

367-
inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1))
368-
& ~(sbi->cluster_size - 1)) >> inode->i_blkbits;
367+
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
368+
inode->i_blkbits;
369369
ei->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff;
370370
ei->i_size_aligned = i_size_read(inode);
371371
ei->i_size_ondisk = i_size_read(inode);

0 commit comments

Comments
 (0)