Skip to content

Commit 25610ff

Browse files
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: be71b5c ("fs/ntfs3: Add attrib operations") Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 3cdad49 commit 25610ff

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fs/ntfs3/attrib.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
231231
struct ntfs_sb_info *sbi;
232232
struct ATTRIB *attr_s;
233233
struct MFT_REC *rec;
234-
u32 used, asize, rsize, aoff, align;
234+
u32 used, asize, rsize, aoff;
235235
bool is_data;
236236
CLST len, alen;
237237
char *next;
@@ -252,10 +252,13 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
252252
rsize = le32_to_cpu(attr->res.data_size);
253253
is_data = attr->type == ATTR_DATA && !attr->name_len;
254254

255-
align = sbi->cluster_size;
256-
if (is_attr_compressed(attr))
257-
align <<= NTFS_LZNT_CUNIT;
258-
len = (rsize + align - 1) >> sbi->cluster_bits;
255+
/* len - how many clusters required to store 'rsize' bytes */
256+
if (is_attr_compressed(attr)) {
257+
u8 shift = sbi->cluster_bits + NTFS_LZNT_CUNIT;
258+
len = ((rsize + (1u << shift) - 1) >> shift) << NTFS_LZNT_CUNIT;
259+
} else {
260+
len = bytes_to_cluster(sbi, rsize);
261+
}
259262

260263
run_init(run);
261264

0 commit comments

Comments
 (0)