Skip to content

Commit

Permalink
fs/ntfs3: Update inode->i_mapping->a_ops on compression state change
Browse files Browse the repository at this point in the history
Update inode->i_mapping->a_ops when the compression state changes to
ensure correct address space operations.
Clear ATTR_FLAG_SPARSED/FILE_ATTRIBUTE_SPARSE_FILE when enabling
compression to prevent flag conflicts.

Fixes: 6b39bfa ("fs/ntfs3: Add support for the compression attribute")
Reported-by: Kun Hu <huk23@m.fudan.edu.cn>, Jiaji Qin <jjtan24@m.fudan.edu.cn>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
  • Loading branch information
aalexandrovich committed Jan 23, 2025
1 parent 55ad333 commit 938ed10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions fs/ntfs3/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,7 @@ int attr_set_compress(struct ntfs_inode *ni, bool compr)

/* Update data attribute flags. */
if (compr) {
attr->flags &= ATTR_FLAG_SPARSED;
attr->flags |= ATTR_FLAG_COMPRESSED;
attr->nres.c_unit = NTFS_LZNT_CUNIT;
} else {
Expand Down
2 changes: 2 additions & 0 deletions fs/ntfs3/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
int err = ni_set_compress(inode, flags & FS_COMPR_FL);
if (err)
return err;
inode->i_mapping->a_ops =
(flags & FS_COMPR_FL) ? &ntfs_aops_cmpr : &ntfs_aops;
}

inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
Expand Down
6 changes: 4 additions & 2 deletions fs/ntfs3/frecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -3434,10 +3434,12 @@ int ni_set_compress(struct inode *inode, bool compr)
}

ni->std_fa = std->fa;
if (compr)
if (compr) {
std->fa &= ~FILE_ATTRIBUTE_SPARSE_FILE;
std->fa |= FILE_ATTRIBUTE_COMPRESSED;
else
} else {
std->fa &= ~FILE_ATTRIBUTE_COMPRESSED;
}

if (ni->std_fa != std->fa) {
ni->std_fa = std->fa;
Expand Down

0 comments on commit 938ed10

Please sign in to comment.