From 82ce1fcdfa193a517fc2108fc6fb59753f5bd16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Tue, 8 Feb 2011 13:52:12 +0100 Subject: [PATCH] Improved appending data to a long hole --- libntfs-3g/attrib.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index ff6583c0..5ceb816f 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -1182,12 +1182,27 @@ static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count) rli++; } size = min(end - pos, NTFS_BUF_SIZE); - written = ntfs_rl_pwrite(vol, rli, ofsi, pos, size, buf); - if (written <= 0) { - ntfs_log_perror("Failed to zero space"); - goto err_free; + /* + * If the zeroed block is fully within a hole, + * we need not write anything, so advance as far + * as possible within the hole. + */ + if ((rli->lcn == (LCN)LCN_HOLE) + && (ofsi <= pos) + && (ofsi + (rli->length << vol->cluster_size_bits) + >= (pos + size))) { + size = min(end - pos, ofsi - pos + + (rli->length << vol->cluster_size_bits)); + pos += size; + } else { + written = ntfs_rl_pwrite(vol, rli, ofsi, pos, + size, buf); + if (written <= 0) { + ntfs_log_perror("Failed to zero space"); + goto err_free; + } + pos += written; } - pos += written; } ret = 0;