[sheepdog] [PATCH 2/2] util: fix calculation of offset and length in find_zero_blocks()
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed Aug 7 16:39:21 CEST 2013
This fixes bugs introduced by the below commits:
- cfd1a566: the length of a fraction at the beginning of buffer was
wrong.
- 6169a0da: this commit removes memmove() from find_zero_blocks(), so
offset calculation should have been changed.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
lib/util.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 4210ea8..0362dfb 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -409,9 +409,7 @@ void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen)
/* trim zero blocks from the beginning of buffer */
while (len >= BLOCK_SIZE) {
- size_t size = (start + offset) % BLOCK_SIZE;
- if (size == 0)
- size = BLOCK_SIZE;
+ size_t size = BLOCK_SIZE - (start + offset) % BLOCK_SIZE;
if (memcmp(p + offset, zero, size) != 0)
break;
@@ -422,11 +420,11 @@ void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen)
/* trim zero sectors from the end of buffer */
while (len >= BLOCK_SIZE) {
- size_t size = (start + len) % BLOCK_SIZE;
+ size_t size = (start + offset + len) % BLOCK_SIZE;
if (size == 0)
size = BLOCK_SIZE;
- if (memcmp(p + len - size, zero, size) != 0)
+ if (memcmp(p + offset + len - size, zero, size) != 0)
break;
len -= size;
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list