Commit df6aef6f authored by Mike Hibler's avatar Mike Hibler
Browse files

Make sure hash boundaries are relative to the partition (image) start.

parent 87efd715
...@@ -92,6 +92,7 @@ static unsigned int hashlen; ...@@ -92,6 +92,7 @@ static unsigned int hashlen;
static unsigned char *(*hashfunc)(const unsigned char *, size_t, static unsigned char *(*hashfunc)(const unsigned char *, size_t,
unsigned char *); unsigned char *);
static int imagefd; static int imagefd;
static uint32_t poffset = ~0;
/* /*
* time the operation, updating the global_v (of type 'struct timeval') * time the operation, updating the global_v (of type 'struct timeval')
...@@ -280,11 +281,13 @@ add_to_range(struct range **tailp, uint32_t start, uint32_t size) ...@@ -280,11 +281,13 @@ add_to_range(struct range **tailp, uint32_t start, uint32_t size)
* for IO. * for IO.
*/ */
static int static int
readhashinfo(char *hfile, struct hashinfo **hinfop, uint32_t ssect) readhashinfo(char *hfile, struct hashinfo **hinfop)
{ {
struct hashinfo hi, *hinfo; struct hashinfo hi, *hinfo;
int fd, nregbytes, cc, i; int fd, nregbytes, cc, i;
assert(poffset != ~0);
fd = open(hfile, O_RDONLY); fd = open(hfile, O_RDONLY);
if (fd < 0) { if (fd < 0) {
perror(hfile); perror(hfile);
...@@ -325,7 +328,7 @@ readhashinfo(char *hfile, struct hashinfo **hinfop, uint32_t ssect) ...@@ -325,7 +328,7 @@ readhashinfo(char *hfile, struct hashinfo **hinfop, uint32_t ssect)
struct hashregion *hreg = &hinfo->regions[i]; struct hashregion *hreg = &hinfo->regions[i];
assert(hreg->region.size <= hashblksize); assert(hreg->region.size <= hashblksize);
hreg->region.start += ssect; hreg->region.start += poffset;
#ifdef HASHSTATS #ifdef HASHSTATS
hashstats.orig_allocated += hreg->region.size; hashstats.orig_allocated += hreg->region.size;
#endif #endif
...@@ -359,11 +362,13 @@ int hashmap_blocksize(void) ...@@ -359,11 +362,13 @@ int hashmap_blocksize(void)
* Signature file will be given either the explicit 'fname' or will * Signature file will be given either the explicit 'fname' or will
* be derived from 'iname' if 'fname' is ''. * be derived from 'iname' if 'fname' is ''.
*/ */
int hashmap_write_hashfile(char *fname, char *iname, uint32_t ssect) int hashmap_write_hashfile(char *fname, char *iname)
{ {
int ofd, i, cc, count; int ofd, i, cc, count;
char *hfile; char *hfile;
assert(poffset != ~0);
if (nhinfo == NULL) { if (nhinfo == NULL) {
fprintf(stderr, "No hashinfo to write!?\n"); fprintf(stderr, "No hashinfo to write!?\n");
return -1; return -1;
...@@ -373,9 +378,9 @@ int hashmap_write_hashfile(char *fname, char *iname, uint32_t ssect) ...@@ -373,9 +378,9 @@ int hashmap_write_hashfile(char *fname, char *iname, uint32_t ssect)
for (i = 0; i < nhinfo->nregions; i++) { for (i = 0; i < nhinfo->nregions; i++) {
struct hashregion *hreg = &nhinfo->regions[i]; struct hashregion *hreg = &nhinfo->regions[i];
assert(hreg->region.size <= nhinfo->blksize); assert(hreg->region.size <= nhinfo->blksize);
assert(hreg->region.start >= ssect); assert(hreg->region.start >= poffset);
hreg->region.start -= ssect; hreg->region.start -= poffset;
} }
/* /*
...@@ -516,7 +521,14 @@ add_to_hashmap(struct hashinfo **hinfop, uint32_t rstart, uint32_t rsize, ...@@ -516,7 +521,14 @@ add_to_hashmap(struct hashinfo **hinfop, uint32_t rstart, uint32_t rsize,
assert(hinfop != NULL); assert(hinfop != NULL);
offset = rstart % hashblksize; /*
* Internally, ranges are absolute disk sector sizes.
* However, we want to compute hash boundaries relative to
* the image (partition) base.
*/
assert(poffset != ~0);
offset = (rstart - poffset) % hashblksize;
while (rsize > 0) { while (rsize > 0) {
if (offset) { if (offset) {
hsize = hashblksize - offset; hsize = hashblksize - offset;
...@@ -625,6 +637,7 @@ hashmap_compute_delta(struct range *curranges, char *hfile, int infd, ...@@ -625,6 +637,7 @@ hashmap_compute_delta(struct range *curranges, char *hfile, int infd,
assert(curranges != NULL); assert(curranges != NULL);
imagefd = infd; imagefd = infd;
poffset = ssect;
/* /*
* First we read the hashfile to get hash ranges and values. * First we read the hashfile to get hash ranges and values.
...@@ -632,7 +645,7 @@ hashmap_compute_delta(struct range *curranges, char *hfile, int infd, ...@@ -632,7 +645,7 @@ hashmap_compute_delta(struct range *curranges, char *hfile, int infd,
* for an empty file. * for an empty file.
*/ */
if (hfile != NULL) { if (hfile != NULL) {
retval = readhashinfo(hfile, &hinfo, ssect); retval = readhashinfo(hfile, &hinfo);
if (retval < 0) { if (retval < 0) {
fprintf(stderr, "readhashinfo: failed !\n"); fprintf(stderr, "readhashinfo: failed !\n");
return -1; return -1;
......
...@@ -25,5 +25,5 @@ int hashmap_blocksize(void); ...@@ -25,5 +25,5 @@ int hashmap_blocksize(void);
void hashmap_update_chunk(uint32_t, uint32_t, int); void hashmap_update_chunk(uint32_t, uint32_t, int);
int hashmap_compute_delta(struct range *, char *, int, u_int32_t, char *, int hashmap_compute_delta(struct range *, char *, int, u_int32_t, char *,
struct range **); struct range **);
int hashmap_write_hashfile(char *, char *, u_int32_t); int hashmap_write_hashfile(char *, char *);
void hashmap_dump_stats(int pnum); void hashmap_dump_stats(int pnum);
...@@ -889,7 +889,7 @@ main(int argc, char *argv[]) ...@@ -889,7 +889,7 @@ main(int argc, char *argv[])
* Write out new signature file. * Write out new signature file.
*/ */
if (newhashfile && if (newhashfile &&
hashmap_write_hashfile(newhashfile, outfilename, inputminsec)) hashmap_write_hashfile(newhashfile, outfilename))
fprintf(stderr, "Could not write new hashfile!\n"); fprintf(stderr, "Could not write new hashfile!\n");
#endif #endif
} }
......
Markdown is supported
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