Skip to content

Commit d738f70

Browse files
wangzijieJaegeuk Kim
authored andcommitted
f2fs: don't allow unaligned truncation to smaller/equal size on pinned file
To prevent scattered pin block generation, don't allow non-section aligned truncation to smaller or equal size on pinned file. But for truncation to larger size, after commit 3fdd89b("f2fs: prevent writing without fallocate() for pinned files"), we only support overwrite IO to pinned file, so we don't need to consider attr->ia_size > i_size case. Signed-off-by: wangzijie <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent a919ae7 commit d738f70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/f2fs/file.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,17 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
10641064
!IS_ALIGNED(attr->ia_size,
10651065
F2FS_BLK_TO_BYTES(fi->i_cluster_size)))
10661066
return -EINVAL;
1067+
/*
1068+
* To prevent scattered pin block generation, we don't allow
1069+
* smaller/equal size unaligned truncation for pinned file.
1070+
* We only support overwrite IO to pinned file, so don't
1071+
* care about larger size truncation.
1072+
*/
1073+
if (f2fs_is_pinned_file(inode) &&
1074+
attr->ia_size <= i_size_read(inode) &&
1075+
!IS_ALIGNED(attr->ia_size,
1076+
F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi))))
1077+
return -EINVAL;
10671078
}
10681079

10691080
err = setattr_prepare(idmap, dentry, attr);

0 commit comments

Comments
 (0)