From: Filipe Manana <fdmanana@xxxxxxxx> Currently we are limiting the range for zero range operations to stay within the i_size boundary. This is not optimal because like this we lose coverage of the filesystem's zero range implementation, since zero range operations are allowed to cross the i_size. Fix this by limiting the range to 'maxfilelen' and not 'file_size', and update the 'file_size' after each zero range operation if needed. Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx> --- ltp/fsx.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index 9d598a4f..56479eda 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -1244,6 +1244,17 @@ do_zero_range(unsigned offset, unsigned length, int keep_size) } memset(good_buf + offset, '\0', length); + + if (!keep_size && end_offset > file_size) { + /* + * If there's a gap between the old file size and the offset of + * the zero range operation, fill the gap with zeroes. + */ + if (offset > file_size) + memset(good_buf + file_size, '\0', offset - file_size); + + file_size = end_offset; + } } #else @@ -2141,7 +2152,7 @@ have_op: do_punch_hole(offset, size); break; case OP_ZERO_RANGE: - TRIM_OFF_LEN(offset, size, file_size); + TRIM_OFF_LEN(offset, size, maxfilelen); do_zero_range(offset, size, keep_size); break; case OP_COLLAPSE_RANGE: -- 2.11.0