fs/ntfs3: Fix transform resident to nonresident for compressed files
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 15 May 2024 22:10:01 +0000 (01:10 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Fri, 7 Jun 2024 11:31:07 +0000 (14:31 +0300)
Сorrected calculation of required space len (in clusters)
for attribute data storage in case of compression.

Fixes: be71b5cba2e64 ("fs/ntfs3: Add attrib operations")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/attrib.c

index 9ccec45190749cea1e186ecd839cd80aa9b5afb0..8638248d80d934710e7c3b98abfd80e5bc30cc16 100644 (file)
@@ -231,7 +231,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
        struct ntfs_sb_info *sbi;
        struct ATTRIB *attr_s;
        struct MFT_REC *rec;
-       u32 used, asize, rsize, aoff, align;
+       u32 used, asize, rsize, aoff;
        bool is_data;
        CLST len, alen;
        char *next;
@@ -252,10 +252,13 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
        rsize = le32_to_cpu(attr->res.data_size);
        is_data = attr->type == ATTR_DATA && !attr->name_len;
 
-       align = sbi->cluster_size;
-       if (is_attr_compressed(attr))
-               align <<= NTFS_LZNT_CUNIT;
-       len = (rsize + align - 1) >> sbi->cluster_bits;
+       /* len - how many clusters required to store 'rsize' bytes */
+       if (is_attr_compressed(attr)) {
+               u8 shift = sbi->cluster_bits + NTFS_LZNT_CUNIT;
+               len = ((rsize + (1u << shift) - 1) >> shift) << NTFS_LZNT_CUNIT;
+       } else {
+               len = bytes_to_cluster(sbi, rsize);
+       }
 
        run_init(run);