libndz.h 3.31 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 29
#include "rangemap.h"

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

#ifdef maybenotneeded
struct ndz_chunkmap {
    ndz_addr_t start;
    ndz_addr_t end;
};
#endif
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 49 50 51 52
    ndz_chunkno_t nchunks;
    ndz_chunk_t chunkobj;
    ndz_addr_t chunksect;
    unsigned chunkuses;
    unsigned chunkhits;
53
    struct ndz_rangemap *rangemap;
Mike Hibler's avatar
Mike Hibler committed
54
    unsigned hashtype;
55 56 57
    unsigned hashblksize;
    void *hashdata;
    struct ndz_rangemap *hashmap;
58 59 60 61
    /* per-chunk info to verify */
    /* readahead cache stuff */
};

Mike Hibler's avatar
Mike Hibler committed
62 63 64 65
/* flags */
#define NDZ_FILE_WRITE		1
#define NDZ_FILE_SEEKABLE	2

66 67 68 69 70 71 72 73 74 75 76
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
77
ssize_t ndz_write(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset);
78 79
int ndz_readahead(struct ndz_file *ndz, void *buf, size_t bytes, off_t offset);

80
int ndz_readchunkheader(struct ndz_file *ndz, ndz_chunkno_t chunkno,
81
			struct ndz_chunkhdr *chunkhdr);
Mike Hibler's avatar
Mike Hibler committed
82 83
ndz_size_t ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect,
			ndz_addr_t sect);
84 85 86
struct ndz_rangemap *ndz_readranges(struct ndz_file *ndz);
void ndz_dumpranges(struct ndz_rangemap *map);

87 88 89 90
ndz_chunk_t ndz_chunk_open(struct ndz_file *ndz, ndz_chunkno_t chunkno);
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);
Mike Hibler's avatar
Mike Hibler committed
91 92 93 94 95
ndz_chunk_t ndz_chunk_create(struct ndz_file *ndz, ndz_chunkno_t chunkno);
void ndz_chunk_flush(ndz_chunk_t chobj);
ssize_t ndz_chunk_left(ndz_chunk_t chobj);
ssize_t ndz_chunk_append(ndz_chunk_t chobj, ndz_addr_t ssect,
			 void *buf, size_t bytes);
96 97

struct ndz_rangemap *ndz_readhashinfo(struct ndz_file *ndz, char *sigfile);
Mike Hibler's avatar
Mike Hibler committed
98 99 100 101
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);
102

103 104 105 106 107 108 109 110 111
#endif /* _LIBNDZ_H_ */

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