summaryrefslogtreecommitdiff
path: root/fs/ntfs3/attrib.c
diff options
context:
space:
mode:
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2024-05-16 01:10:01 +0300
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2024-06-07 14:31:07 +0300
commit25610ff98d4a34e6a85cbe4fd8671be6b0829f8f (patch)
tree408455eb1c61ae770d99c18c98c6981b3d261bc0 /fs/ntfs3/attrib.c
parent3cdad499ac10556fc368a909d35ec821c52ea00e (diff)
downloadlinux-25610ff98d4a34e6a85cbe4fd8671be6b0829f8f.tar.xz
fs/ntfs3: Fix transform resident to nonresident for compressed files
С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>
Diffstat (limited to 'fs/ntfs3/attrib.c')
-rw-r--r--fs/ntfs3/attrib.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 9ccec4519074..8638248d80d9 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -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);