$NetBSD: patch-ac,v 1.4 2008/03/08 08:56:47 adam Exp $ --- libntfs/attrib.c.orig 2007-09-26 20:28:34.000000000 +0200 +++ libntfs/attrib.c @@ -865,7 +865,7 @@ map_rl: */ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) { - s64 br, to_read, ofs, total, total2; + s64 br, to_read, ofs, total, total2, origcount; ntfs_volume *vol; runlist_element *rl; @@ -892,6 +892,7 @@ s64 ntfs_attr_pread(ntfs_attr *na, const vol = na->ni->vol; if (!count) return 0; + origcount = count; /* Truncate reads beyond end of attribute. */ if (pos + count > na->data_size) { if (pos >= na->data_size) @@ -982,7 +983,7 @@ res_err_out: continue; } /* It is a real lcn, read it into @dst. */ - to_read = min(count, (rl->length << vol->cluster_size_bits) - + to_read = min(origcount, (rl->length << vol->cluster_size_bits) - ofs); retry: ntfs_log_trace("Reading 0x%llx bytes from vcn 0x%llx, " @@ -990,6 +991,12 @@ retry: rl->lcn, ofs); br = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, to_read, b); + /* Zero any overage that we may have read */ + if (br > count) { + memset(b + count, 0, br - count); + total += count; + return total + total2; + } /* If everything ok, update progress counters and continue. */ if (br > 0) { total += br;