Commit 8759fa6c authored by Mike Hibler's avatar Mike Hibler
Browse files

Make sure we are using header lastsect field correctly.

It is (and always has been) the last sector + 1.
parent 18d053da
...@@ -688,7 +688,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg) ...@@ -688,7 +688,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg)
/* XXX should always be zero */ /* XXX should always be zero */
if (cstate->chunkno == 0) if (cstate->chunkno == 0)
cstate->header->firstsect = 0; cstate->header->firstsect = 0;
cstate->header->lastsect = delta.ndz->maphi; cstate->header->lastsect = delta.ndz->maphi + 1;
/* include any relocations */ /* include any relocations */
if (delta.ndz->relocentries > 0) { if (delta.ndz->relocentries > 0) {
......
...@@ -83,7 +83,7 @@ struct blockhdr_V2 { ...@@ -83,7 +83,7 @@ struct blockhdr_V2 {
int32_t regioncount; /* number of regions */ int32_t regioncount; /* number of regions */
/* V2 follows */ /* V2 follows */
uint32_t firstsect; /* first sector described by block */ uint32_t firstsect; /* first sector described by block */
uint32_t lastsect; /* last sector described by block */ uint32_t lastsect; /* first sector past block */
int32_t reloccount; /* number of reloc entries */ int32_t reloccount; /* number of reloc entries */
}; };
...@@ -120,7 +120,7 @@ struct blockhdr_V4 { ...@@ -120,7 +120,7 @@ struct blockhdr_V4 {
int32_t regioncount; /* number of regions */ int32_t regioncount; /* number of regions */
/* V2 follows */ /* V2 follows */
uint32_t firstsect; /* first sector described by block */ uint32_t firstsect; /* first sector described by block */
uint32_t lastsect; /* last sector described by block */ uint32_t lastsect; /* first sector past block */
int32_t reloccount; /* number of reloc entries */ int32_t reloccount; /* number of reloc entries */
/* V4 follows */ /* V4 follows */
uint16_t enc_cipher; /* cipher was used to encrypt */ uint16_t enc_cipher; /* cipher was used to encrypt */
......
...@@ -645,7 +645,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg) ...@@ -645,7 +645,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg)
/* XXX should always be zero */ /* XXX should always be zero */
if (cstate->chunkno == 0) if (cstate->chunkno == 0)
cstate->header->firstsect = 0; cstate->header->firstsect = 0;
cstate->header->lastsect = new.ndz->maphi; cstate->header->lastsect = new.ndz->maphi + 1;
/* include any relocations */ /* include any relocations */
if (new.ndz->relocentries > 0) { if (new.ndz->relocentries > 0) {
......
...@@ -915,7 +915,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg) ...@@ -915,7 +915,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg)
/* XXX should always be zero */ /* XXX should always be zero */
if (cstate->chunkno == 0) if (cstate->chunkno == 0)
cstate->header->firstsect = 0; cstate->header->firstsect = 0;
cstate->header->lastsect = new.ndz->maphi; cstate->header->lastsect = new.ndz->maphi + 1;
/* include any relocations */ /* include any relocations */
if (new.ndz->relocentries > 0) { if (new.ndz->relocentries > 0) {
......
...@@ -267,10 +267,10 @@ ndz_readranges(struct ndz_file *ndz) ...@@ -267,10 +267,10 @@ ndz_readranges(struct ndz_file *ndz)
if (hdr->magic != COMPRESSED_V1) { if (hdr->magic != COMPRESSED_V1) {
if (chunkno == 0) if (chunkno == 0)
first = hdr->firstsect; first = hdr->firstsect;
last = hdr->lastsect; last = hdr->lastsect - 1;
#ifdef USE_CHUNKMAP #ifdef USE_CHUNKMAP
clo = hdr->firstsect; clo = hdr->firstsect;
chi = hdr->lastsect; chi = hdr->lastsect - 1;
#endif #endif
} }
......
...@@ -121,7 +121,7 @@ ndz_reloc_put(struct ndz_file *ndz, blockhdr_t *hdr, void *buf) ...@@ -121,7 +121,7 @@ ndz_reloc_put(struct ndz_file *ndz, blockhdr_t *hdr, void *buf)
return -1; return -1;
if (ndz->relocentries == 0 || if (ndz->relocentries == 0 ||
hdr->firstsect > ndz->relochi || hdr->lastsect < ndz->reloclo) hdr->firstsect > ndz->relochi || hdr->lastsect <= ndz->reloclo)
return 0; return 0;
chunkreloc = buf; chunkreloc = buf;
...@@ -129,10 +129,10 @@ ndz_reloc_put(struct ndz_file *ndz, blockhdr_t *hdr, void *buf) ...@@ -129,10 +129,10 @@ ndz_reloc_put(struct ndz_file *ndz, blockhdr_t *hdr, void *buf)
for (i = 0; i < ndz->relocentries; i++) { for (i = 0; i < ndz->relocentries; i++) {
assert(relocdata->sectoff + relocdata->size <= ndz->sectsize); assert(relocdata->sectoff + relocdata->size <= ndz->sectsize);
if (relocdata->sector >= hdr->firstsect && if (relocdata->sector >= hdr->firstsect &&
relocdata->sector <= hdr->lastsect) { relocdata->sector < hdr->lastsect) {
#ifdef RELOC_DEBUG #ifdef RELOC_DEBUG
fprintf(stderr, "found reloc for %u in chunk range [%u-%u]\n", fprintf(stderr, "found reloc for %u in chunk range [%u-%u]\n",
relocdata->sector, hdr->firstsect, hdr->lastsect); relocdata->sector, hdr->firstsect, hdr->lastsect - 1);
#endif #endif
*chunkreloc++ = *relocdata; *chunkreloc++ = *relocdata;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment