All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 01a5fc2e authored by Mike Hibler's avatar Mike Hibler

First "working" imageundelta!

Where "working" == "does not crash and produces a syntactically valid image".
parent e1613a02
......@@ -127,7 +127,7 @@ endif
# Necessary sometimes.
#PTHREADCFLAGS += -DCONDVARS_WORK
PROGS = imagezip imageunzip imagedump imagedelta imagerezip
PROGS = imagezip imageunzip imagedump imagerezip imagedelta imageundelta
CFLAGS = $(SUBDIRCFLAGS) -I$(SRCDIR) $(LDSTATIC)
LIBS = -lz
ZIPCFLAGS = $(CFLAGS) -Wall
......@@ -137,7 +137,7 @@ UNZIPLIBS = $(LIBS) $(PTHREADLIBS)
UNZIPDIRS =
HASHCFLAGS = $(CFLAGS) $(PTHREADCFLAGS) -Wall
HASHLIBS = $(LIBS) -lcrypto $(PTHREADLIBS)
NDZLIBS = $(LIBS) libndz/libndz.a
NDZLIBS = libndz/libndz.a $(LIBS)
# Secure images
ifeq ($(WITH_CRYPTO),1)
......@@ -266,6 +266,12 @@ imagedelta: imagedelta.o version.o $(NDZLIBS)
imagedelta.o: imagedelta.c
$(CC) -c $(CFLAGS) -o imagedelta.o $<
imageundelta: imageundelta.o version.o $(NDZLIBS)
$(CC) $(CFLAGS) imageundelta.o version.o $(NDZLIBS) -o imageundelta
imageundelta.o: imageundelta.c
$(CC) -c $(CFLAGS) -o imageundelta.o $<
imagerezip: imagerezip.o version.o $(NDZLIBS)
$(CC) $(CFLAGS) imagerezip.o version.o $(NDZLIBS) -o imagerezip
......@@ -291,9 +297,10 @@ imagezip.o: sliceinfo.h imagehdr.h global.h range.h hashmap/hashmap.h
imageunzip.o: imagehdr.h
imagehash.o: imagehdr.h imagehash.h
imagedelta.o: imagehdr.h imagehash.h libndz/libndz.h
imageundelta.o: imagehdr.h imagehash.h libndz/libndz.h
imagerezip.o: imagehdr.h imagehash.h libndz/libndz.h
version.c: imagezip.c imageunzip.c imagedump.c imagedelta.c imagerezip.c
version.c: imagezip.c imageunzip.c imagedump.c imagedelta.c imageundelta.c imagerezip.c
echo >$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
install: $(addprefix $(INSTALL_BINDIR)/, $(PROGS))
......
......@@ -681,7 +681,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg)
static void
chunkfunc(struct ndz_rangemap *map, void *ptr)
{
unsigned int chunkno = (int)ptr;
unsigned int chunkno = (uintptr_t)ptr;
printf("chunkno=%u", chunkno);
}
......@@ -705,11 +705,13 @@ main(int argc, char **argv)
hashblksize /= 512;
break;
case 'D':
if (strcmp(optarg, "md5") == 0)
if (strcmp(optarg, "md5") == 0) {
hashtype = HASH_TYPE_MD5;
else if (strcmp(optarg, "sha1") == 0)
hashlen = 16;
} else if (strcmp(optarg, "sha1") == 0) {
hashtype = HASH_TYPE_SHA1;
else {
hashlen = 20;
} else {
fprintf(stderr, "Invalid digest type `%s'\n",
optarg);
usage();
......
......@@ -51,7 +51,7 @@
#include "imagehash.h"
#include "queue.h"
#define TERSE_DUMP_OUTPUT
//#define TERSE_DUMP_OUTPUT
#define HANDLE_SPLIT_HASH
#ifndef linux
......@@ -193,7 +193,11 @@ main(int argc, char **argv)
sanity = 1;
break;
case 'X':
#ifdef HANDLE_SPLIT_HASH
splithash = 1;
#else
fprintf(stderr, "-X not supported, ignored\n");
#endif
break;
case 'h':
case '?':
......@@ -1289,7 +1293,8 @@ hashchunk(int chunkno, char *chunkbufp, struct hashinfo **hinfop)
bytes);
(void)(*hashfunc)(ldata, spanoff+bytes,
hash);
HASH_CHUNKSETSPAN(lhash.chunkno);
lhash.chunkno =
HASH_CHUNKSETSPAN(lhash.chunkno);
addhash(hinfop, lhash.chunkno,
lreg->start, lreg->size+hsize,
hash);
......
......@@ -348,7 +348,7 @@ chunkify(struct ndz_rangemap *mmap, struct ndz_range *range, void *arg)
uint32_t roffset, hstart, hsize;
size_t hbytes;
ssize_t cc;
struct ndz_hashdata *hdata;
struct ndz_hashdata *hdata = NULL;
struct ndz_range *hrange;
#ifdef CHUNKIFY_DEBUG
......@@ -675,7 +675,7 @@ unchunkify(struct ndz_rangemap *omap, struct ndz_range *range, void *arg)
static void
chunkfunc(struct ndz_rangemap *map, void *ptr)
{
unsigned int chunkno = (int)ptr;
unsigned int chunkno = (uintptr_t)ptr;
printf("chunkno=%u", chunkno);
}
......@@ -699,11 +699,13 @@ main(int argc, char **argv)
hashblksize /= 512;
break;
case 'D':
if (strcmp(optarg, "md5") == 0)
if (strcmp(optarg, "md5") == 0) {
hashtype = HASH_TYPE_MD5;
else if (strcmp(optarg, "sha1") == 0)
hashlen = 16;
} else if (strcmp(optarg, "sha1") == 0) {
hashtype = HASH_TYPE_SHA1;
else {
hashlen = 20;
} else {
fprintf(stderr, "Invalid digest type `%s'\n",
optarg);
usage();
......
This diff is collapsed.
......@@ -108,7 +108,7 @@ ndz_readhashinfo(struct ndz_file *ndz, char *sigfile)
unsigned lstart, lsize;
#endif
if (ndz == NULL)
if (ndz == NULL || sigfile == NULL)
return NULL;
if (ndz->hashmap)
return ndz->hashmap;
......@@ -221,7 +221,7 @@ writehinfo(struct ndz_rangemap *map, struct ndz_range *range, void *arg)
{
struct hashregion hr;
struct ndz_hashdata *hd = range->data;
int ofd = (int)arg;
int ofd = (int)(uintptr_t)arg;
if (hd == NULL) {
fprintf(stderr, "no hash info for range [%lu-%lu]\n",
......
......@@ -50,7 +50,7 @@ findchunk(struct ndz_rangemap *map, struct ndz_range *range, void *arg)
{
struct fcarg *fcarg = arg;
if ((ndz_chunkno_t)range->data == fcarg->in_chunkno) {
if ((uintptr_t)range->data == fcarg->in_chunkno) {
fcarg->out_range = range;
return 1;
}
......@@ -88,7 +88,7 @@ ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect, ndz_addr_t sect)
if (range == NULL)
return 0;
chunkno = (ndz_chunkno_t)range->data;
chunkno = (uintptr_t)range->data;
assert(chunkno > 0);
chunkno--;
......@@ -256,7 +256,7 @@ ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect, ndz_addr_t sect)
}
return (ssect - sect);
}
chunkno = (ndz_chunkno_t)range->data;
chunkno = (uintptr_t)range->data;
assert(chunkno != 0);
chunkno--;
if (chunkno != lchunkno) {
......
......@@ -389,8 +389,8 @@ ndz_write(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset)
static int
printrange(struct ndz_rangemap *map, struct ndz_range *range, void *arg)
{
printf(" [%lu - %lu], chunk=%u\n",
range->start, range->end, (unsigned int)range->data - 1);
printf(" [%lu - %lu], chunk=%lu\n",
range->start, range->end, (uintptr_t)range->data - 1);
return 0;
}
......
......@@ -49,6 +49,7 @@ ndz_rangemap_init(ndz_addr_t lo, ndz_addr_t hi)
map->hiaddr = hi;
map->hint = &map->head.next;
map->gen = 1;
map->sectors = 0;
}
return map;
}
......@@ -138,6 +139,7 @@ ndz_rangemap_alloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size,
map->hint = &prev->next;
}
map->gen++;
map->sectors += size;
return 0;
}
......@@ -154,6 +156,7 @@ ndz_rangemap_alloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size,
prev->next = range;
map->hint = &prev->next;
map->gen++;
map->sectors += size;
return 0;
}
......@@ -220,6 +223,7 @@ ndz_rangemap_dealloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size)
range->start = eaddr + 1;
map->hint = &prev->next;
map->gen++;
map->sectors -= size;
return 0;
}
......@@ -228,6 +232,7 @@ ndz_rangemap_dealloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size)
range->end = addr - 1;
map->hint = &prev->next;
map->gen++;
map->sectors -= size;
return 0;
}
......@@ -247,6 +252,7 @@ ndz_rangemap_dealloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size)
range->end = addr - 1;
map->hint = &range->next;
map->gen++;
map->sectors -= size;
return 0;
}
......@@ -340,22 +346,14 @@ ndz_rangemap_last(struct ndz_rangemap *map)
}
/*
* Return the number of entries in the map.
* Return the number of sectors covered by the map.
*
* Does not affect the map hint.
*/
int
ndz_rangemap_count(struct ndz_rangemap *map)
ndz_size_t
ndz_rangemap_sectors(struct ndz_rangemap *map)
{
struct ndz_range *range;
int count = 0;
assert(map);
for (range = map->head.next; range; range = range->next)
count++;
return count;
return map->sectors;
}
/*
......@@ -534,7 +532,8 @@ ndz_rangemap_dump(struct ndz_rangemap *map, int summaryonly,
unsigned long elements = 0;
int nrange = 0;
printf("MAP: %p (hint=%p, gen=%lu)\n", map, map->hint, map->gen);
printf("MAP: %p (hint=%p, gen=%lu, sectors=%lu)\n",
map, map->hint, map->gen, map->sectors);
ndz_rangemap_dumpstats(map);
for (range = map->head.next; range; range = range->next) {
if (!summaryonly) {
......
......@@ -20,11 +20,11 @@
*
* }}}
*/
#include <sys/types.h>
#ifndef _NDZ_RANGEMAP_H_
#define _NDZ_RANGEMAP_H_
#include <inttypes.h>
#define NDZ_RANGEMAP_STATS
typedef uint64_t ndz_addr_t;
......@@ -56,6 +56,7 @@ struct ndz_rangemap {
ndz_addr_t loaddr;
ndz_addr_t hiaddr;
uint64_t gen;
ndz_size_t sectors;
#ifdef NDZ_RANGEMAP_STATS
struct ndz_rangemap_stats stats;
#endif
......@@ -74,7 +75,7 @@ int ndz_rangemap_iterate(struct ndz_rangemap *map,
void *arg);
struct ndz_range *ndz_rangemap_first(struct ndz_rangemap *map);
struct ndz_range *ndz_rangemap_last(struct ndz_rangemap *map);
int ndz_rangemap_count(struct ndz_rangemap *map);
ndz_size_t ndz_rangemap_sectors(struct ndz_rangemap *map);
struct ndz_range *ndz_rangemap_lookup(struct ndz_rangemap *map,
ndz_addr_t addr,
struct ndz_range **prev);
......
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