X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=ccan%2Ftdb2%2Fprivate.h;h=1b6cebea229e38d2422cb9acfa45f37873c587f5;hb=ee6f11b307599200a574208372bc962eff81a9b1;hp=c743067a0267fb0059be9218ad56b1305fdcb7fc;hpb=06e0037d97f5e1d83667ec40627cef862f3b7b85;p=ccan diff --git a/ccan/tdb2/private.h b/ccan/tdb2/private.h index c743067a..1b6cebea 100644 --- a/ccan/tdb2/private.h +++ b/ccan/tdb2/private.h @@ -136,7 +136,7 @@ static inline uint64_t rec_extra_padding(const struct tdb_used_record *r) static inline uint64_t rec_hash(const struct tdb_used_record *r) { - return ((r->magic_and_meta >> 32) & ((1ULL << 11) - 1)) << (64 - 11); + return ((r->magic_and_meta >> 32) & ((1ULL << 11) - 1)); } static inline uint16_t rec_magic(const struct tdb_used_record *r) @@ -254,12 +254,18 @@ struct tdb_methods { internal prototypes */ /* tdb.c: */ -/* Returns true if header changed. */ -bool update_header(struct tdb_context *tdb); +/* Returns true if header changed (and updates it). */ +bool header_changed(struct tdb_context *tdb); + +/* Commit header to disk. */ +int write_header(struct tdb_context *tdb); /* Hash random memory. */ uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len); +/* offset of hash table entry for this list/hash value */ +tdb_off_t hash_off(struct tdb_context *tdb, uint64_t list); + /* free.c: */ void tdb_zone_init(struct tdb_context *tdb); @@ -293,20 +299,13 @@ void *tdb_convert(const struct tdb_context *tdb, void *buf, tdb_len_t size); void tdb_munmap(struct tdb_context *tdb); void tdb_mmap(struct tdb_context *tdb); -/* Hand data to a function, direct if possible */ -int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key, - tdb_off_t offset, tdb_len_t len, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); - /* Either make a copy into pad and return that, or return ptr into mmap. * Converts endian (ie. will use pad in that case). */ void *tdb_get(struct tdb_context *tdb, tdb_off_t off, void *pad, size_t len); /* Either alloc a copy, or give direct access. Release frees or noop. */ const void *tdb_access_read(struct tdb_context *tdb, - tdb_off_t off, tdb_len_t len); + tdb_off_t off, tdb_len_t len, bool convert); void tdb_access_release(struct tdb_context *tdb, const void *p); /* Convenience routine to get an offset. */ @@ -334,9 +333,9 @@ bool tdb_read_all(int fd, void *buf, size_t len); /* Allocate and make a copy of some offset. */ void *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len); -/* Munges record and writes it */ +/* Writes a converted copy of a record. */ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off, - void *rec, size_t len); + const void *rec, size_t len); /* Reads record and converts it */ int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off, @@ -349,8 +348,8 @@ uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off); void tdb_lock_init(struct tdb_context *tdb); /* Lock/unlock a particular hash list. */ -int tdb_lock_list(struct tdb_context *tdb, tdb_off_t list, - int ltype, enum tdb_lock_flags waitflag); +tdb_off_t tdb_lock_list(struct tdb_context *tdb, uint64_t hash, + int ltype, enum tdb_lock_flags waitflag); int tdb_unlock_list(struct tdb_context *tdb, tdb_off_t list, int ltype); /* Lock/unlock a particular free list. */