memzap

replay memory writes
git clone git://git.2f30.org/memzap
Log | Files | Refs | README | LICENSE

commit bb2230c5eaf520f3103555e4580bb8b78661925a
parent 03ed1051952b9238cf96d94635cc1af71f7d0e41
Author: sin <sin@2f30.org>
Date:   Mon,  4 Mar 2013 14:11:32 +0000

mem: Handle things properly when the blocksize is less than the diff pattern

Diffstat:
Mmdiff.c | 2+-
Mmem.c | 18+++++++++++++-----
Mmemzap.c | 3+--
3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/mdiff.c b/mdiff.c @@ -164,7 +164,7 @@ mdiff_append_rdiff(int fd, struct mem_region_diff *rdiff) if (ret != (ssize_t)md->len) err(1, "write"); } - return 0; + return i; } void diff --git a/mem.c b/mem.c @@ -256,16 +256,24 @@ diff_mem_region(struct mem_tree *dst, find.weak_sum = mb->weak_sum; me = RB_FIND(mem_tree, dst, &find); if (me) { - /* We might have a weak sum collision - * so check the strong sum as well */ for (j = 0; j < me->nmblks; j++) { - if (!memcmp(me->mblks[j]->digest, - mb->digest, - MD5_DIGEST_LENGTH)) { + if (me->mblks[j]->offset == mb->offset) { found = true; break; } } + if (found) { + /* We might have a weak sum collision + * so check the strong sum as well */ + for (j = 0; j < me->nmblks; j++) { + if (!memcmp(me->mblks[j]->digest, + mb->digest, + MD5_DIGEST_LENGTH)) { + found = true; + break; + } + } + } } if (!found) { /* Cool, this is a modified block - update the rdiff */ diff --git a/memzap.c b/memzap.c @@ -160,8 +160,7 @@ main(int argc, char *argv[]) rdiff = diff_mem_region(mt_old, mr_new); if (rdiff->nmrdiffs) { apply_diff(mr_old, rdiff); - mdiff_append_rdiff(fd, rdiff); - hdr.nregions++; + hdr.nregions += mdiff_append_rdiff(fd, rdiff); } free_mem_region(mr_old);