Skip to content

Commit

Permalink
fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated s…
Browse files Browse the repository at this point in the history
…pace)

commit 3880f2b upstream.

Two problems:
1. ntfs3_setattr can't truncate preallocated space;
2. if allocated fragment "cross" valid size, then fragment splits into two parts:
- normal part;
- unwritten part (here we must return FIEMAP_EXTENT_LAST).
Before this commit we returned FIEMAP_EXTENT_LAST for whole fragment.
Fixes xfstest generic/092
Fixes: 4342306 ("fs/ntfs3: Add file operations and implementation")

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
aalexandrovich authored and gregkh committed Jun 9, 2022
1 parent c1e2c32 commit 898bd43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fs/ntfs3/file.c
Expand Up @@ -762,7 +762,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
}
inode_dio_wait(inode);

if (attr->ia_size < oldsize)
if (attr->ia_size <= oldsize)
err = ntfs_truncate(inode, attr->ia_size);
else if (attr->ia_size > oldsize)
err = ntfs_extend(inode, attr->ia_size, 0, NULL);
Expand Down
10 changes: 7 additions & 3 deletions fs/ntfs3/frecord.c
Expand Up @@ -1964,10 +1964,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,

vcn += clen;

if (vbo + bytes >= end) {
if (vbo + bytes >= end)
bytes = end - vbo;
flags |= FIEMAP_EXTENT_LAST;
}

if (vbo + bytes <= valid) {
;
Expand All @@ -1977,6 +1975,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
/* vbo < valid && valid < vbo + bytes */
u64 dlen = valid - vbo;

if (vbo + dlen >= end)
flags |= FIEMAP_EXTENT_LAST;

err = fiemap_fill_next_extent(fieinfo, vbo, lbo, dlen,
flags);
if (err < 0)
Expand All @@ -1995,6 +1996,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
flags |= FIEMAP_EXTENT_UNWRITTEN;
}

if (vbo + bytes >= end)
flags |= FIEMAP_EXTENT_LAST;

err = fiemap_fill_next_extent(fieinfo, vbo, lbo, bytes, flags);
if (err < 0)
break;
Expand Down

0 comments on commit 898bd43

Please sign in to comment.