libndz.h 3.96 KB
Newer Older
1
/*
2
 * Copyright (c) 2014-2015 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
 */

#ifndef _LIBNDZ_H_
#define	_LIBNDZ_H_

27
#include "imagehdr.h"
28
#include "imagehash.h"
29 30
#include "rangemap.h"

31 32 33 34
typedef uint32_t ndz_chunkno_t;
/* XXX keep this opaque so we don't create dependencies on zlib */
typedef void * ndz_chunk_t;

35 36 37 38
struct ndz_hashdata {
    ndz_chunkno_t chunkno;
    uint32_t hashlen;
    uint8_t hash[HASH_MAXSIZE];
39
};
40 41 42

struct ndz_file {
    int fd;
Mike Hibler's avatar
Mike Hibler committed
43
    int flags;
44
    off_t curoff;
45 46 47
    char *fname;
    int sectsize;
    int chunksize;
48
    ndz_chunkno_t nchunks;
49 50 51
    ndz_addr_t maplo, maphi;
    struct ndz_rangemap *rangemap;
    /* chunk object info */
52 53 54 55
    ndz_chunk_t chunkobj;
    ndz_addr_t chunksect;
    unsigned chunkuses;
    unsigned chunkhits;
56
    unsigned chunkreopens;
57
    /* hash (signature) info */
Mike Hibler's avatar
Mike Hibler committed
58
    unsigned hashtype;
59
    unsigned hashblksize;
60 61 62
    unsigned hashentries;
    unsigned hashcurentry;
    struct ndz_hashdata *hashdata;
63
    struct ndz_rangemap *hashmap;
64 65 66 67
    /* per-chunk info to verify */
    /* readahead cache stuff */
};

Mike Hibler's avatar
Mike Hibler committed
68 69 70 71
/* flags */
#define NDZ_FILE_WRITE		1
#define NDZ_FILE_SEEKABLE	2

72 73 74 75 76 77 78 79 80 81 82
struct ndz_chunkhdr {
    blockhdr_t *header;
    struct region *region;
    struct blockreloc *reloc;
    char data[DEFAULTREGIONSIZE];
};

struct ndz_file *ndz_open(const char *name, int flags);
int ndz_close(struct ndz_file *ndz);
char *ndz_filename(struct ndz_file *ndz);
ssize_t ndz_read(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset);
Mike Hibler's avatar
Mike Hibler committed
83
ssize_t ndz_write(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset);
84 85
int ndz_readahead(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset);

86
int ndz_readchunkheader(struct ndz_file *ndz, ndz_chunkno_t chunkno,
87
			struct ndz_chunkhdr *chunkhdr);
Mike Hibler's avatar
Mike Hibler committed
88 89
ndz_size_t ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect,
			ndz_addr_t sect);
90 91 92
struct ndz_rangemap *ndz_readranges(struct ndz_file *ndz);
void ndz_dumpranges(struct ndz_rangemap *map);

93
ndz_chunk_t ndz_chunk_open(struct ndz_file *ndz, ndz_chunkno_t chunkno);
94
int ndz_chunk_rewind(ndz_chunk_t chobj);
95 96 97
void ndz_chunk_close(ndz_chunk_t chobj);
ssize_t ndz_chunk_read(ndz_chunk_t chobj, void *buf, size_t bytes);
ndz_chunkno_t ndz_chunk_chunkno(ndz_chunk_t chobj);
98 99 100 101 102
blockhdr_t *ndz_chunk_header(ndz_chunk_t chobj);
ssize_t ndz_chunk_datasize(ndz_chunk_t chobj);
ndz_chunk_t ndz_chunk_create(struct ndz_file *ndz, ndz_chunkno_t chunkno,
			     int clevel);
int ndz_chunk_flush(ndz_chunk_t chobj, int withheader);
Mike Hibler's avatar
Mike Hibler committed
103
ssize_t ndz_chunk_left(ndz_chunk_t chobj);
104
ssize_t ndz_chunk_append(ndz_chunk_t chobj, void *buf, size_t bytes);
105 106

struct ndz_rangemap *ndz_readhashinfo(struct ndz_file *ndz, char *sigfile);
107
int ndz_writehashinfo(struct ndz_file *ndz, char *sigfile, char *ifile);
108 109
void ndz_hash_data(struct ndz_file *ndz, unsigned char *data,
		   unsigned long count, unsigned char *hash);
Mike Hibler's avatar
Mike Hibler committed
110 111 112 113
char *ndz_hash_dump(unsigned char *h, int hlen);
void ndz_hashmap_dump(struct ndz_rangemap *map, int summaryonly);
struct ndz_rangemap *ndz_compute_delta(struct ndz_rangemap *omap,
				       struct ndz_rangemap *nmap);
114 115
struct ndz_rangemap *ndz_compute_delta_sigmap(struct ndz_rangemap *omap,
					      struct ndz_rangemap *nmap);
116

117 118 119 120 121 122 123 124 125
#endif /* _LIBNDZ_H_ */

/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * End:
 */