exfat: fix inode->i_blocks for non-512 byte sector size device
authorYuezhang Mo <Yuezhang.Mo@sony.com>
Wed, 4 Jan 2023 06:37:47 +0000 (14:37 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Mon, 27 Feb 2023 12:14:45 +0000 (21:14 +0900)
inode->i_blocks is not real number of blocks, but 512 byte ones.

Fixes: 98d917047e8b ("exfat: add file operations")
Cc: stable@vger.kernel.org # v5.7+
Reported-by: Wang Yugui <wangyugui@e16-tech.com>
Tested-by: Wang Yugui <wangyugui@e16-tech.com>
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/file.c
fs/exfat/inode.c
fs/exfat/namei.c
fs/exfat/super.c

index f5b29072775de9221ac8e5bbf165d67abf91febc..b33431c74c8afeb8bb7aeeb20d2240a5aca4247b 100644 (file)
@@ -209,8 +209,7 @@ void exfat_truncate(struct inode *inode)
        if (err)
                goto write_size;
 
-       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
-                               inode->i_blkbits;
+       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
 write_size:
        aligned_size = i_size_read(inode);
        if (aligned_size & (blocksize - 1)) {
index 5b644cb057fa8060bf5c136dfc2071f31b66ec29..481dd338f2b8e7e3ccdc9fd3f59dea9f5e7e330b 100644 (file)
@@ -220,8 +220,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
                num_clusters += num_to_be_allocated;
                *clu = new_clu.dir;
 
-               inode->i_blocks +=
-                       num_to_be_allocated << sbi->sect_per_clus_bits;
+               inode->i_blocks += EXFAT_CLU_TO_B(num_to_be_allocated, sbi) >> 9;
 
                /*
                 * Move *clu pointer along FAT chains (hole care) because the
@@ -576,8 +575,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
 
        exfat_save_attr(inode, info->attr);
 
-       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
-                               inode->i_blkbits;
+       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
        inode->i_mtime = info->mtime;
        inode->i_ctime = info->mtime;
        ei->i_crtime = info->crtime;
index 5f995eba5dbbe78c007400e1d9ed6e2fb66bdf2a..7442fead02793047acaebc0913bf5c0a1e9a6a4f 100644 (file)
@@ -396,7 +396,7 @@ static int exfat_find_empty_entry(struct inode *inode,
                ei->i_size_ondisk += sbi->cluster_size;
                ei->i_size_aligned += sbi->cluster_size;
                ei->flags = p_dir->flags;
-               inode->i_blocks += 1 << sbi->sect_per_clus_bits;
+               inode->i_blocks += sbi->cluster_size >> 9;
        }
 
        return dentry;
index 35f0305cd493cc1fd961ca170e5c033c6928dd17..8c32460e031e804a8acf8136b43348fc8839a7df 100644 (file)
@@ -373,8 +373,7 @@ static int exfat_read_root(struct inode *inode)
        inode->i_op = &exfat_dir_inode_operations;
        inode->i_fop = &exfat_dir_operations;
 
-       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
-                               inode->i_blkbits;
+       inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
        ei->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff;
        ei->i_size_aligned = i_size_read(inode);
        ei->i_size_ondisk = i_size_read(inode);