]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/private.h
tdb2: rework free.c functions to return enum TDB_ERROR.
[ccan] / ccan / tdb2 / private.h
index f0b5cae562db93b5b9bb8cc05607f36ad36556dc..236aa3696d6b4c30efe7e974b53500b51c2f7832 100644 (file)
@@ -73,7 +73,6 @@ typedef uint64_t tdb_off_t;
 #define TDB_RECOVERY_MAGIC (0xf53bc0e7ad124589ULL)
 #define TDB_RECOVERY_INVALID_MAGIC (0x0ULL)
 
-#define TDB_OFF_ERR ((tdb_off_t)-1)
 #define TDB_OFF_IS_ERR(off) unlikely(off >= (tdb_off_t)TDB_ERR_LAST)
 
 /* Packing errors into pointers and v.v. */
@@ -394,13 +393,13 @@ struct tdb_methods {
 /* hash.c: */
 void tdb_hash_init(struct tdb_context *tdb);
 
-int first_in_hash(struct tdb_context *tdb,
-                 struct traverse_info *tinfo,
-                 TDB_DATA *kbuf, size_t *dlen);
+tdb_bool_err first_in_hash(struct tdb_context *tdb,
+                          struct traverse_info *tinfo,
+                          TDB_DATA *kbuf, size_t *dlen);
 
-int next_in_hash(struct tdb_context *tdb,
-                struct traverse_info *tinfo,
-                TDB_DATA *kbuf, size_t *dlen);
+tdb_bool_err next_in_hash(struct tdb_context *tdb,
+                         struct traverse_info *tinfo,
+                         TDB_DATA *kbuf, size_t *dlen);
 
 /* Hash random memory. */
 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len);
@@ -416,38 +415,38 @@ tdb_off_t find_and_lock(struct tdb_context *tdb,
                        struct tdb_used_record *rec,
                        struct traverse_info *tinfo);
 
-int replace_in_hash(struct tdb_context *tdb,
-                   struct hash_info *h,
-                   tdb_off_t new_off);
+enum TDB_ERROR replace_in_hash(struct tdb_context *tdb,
+                              struct hash_info *h,
+                              tdb_off_t new_off);
 
-int add_to_hash(struct tdb_context *tdb, struct hash_info *h,
-               tdb_off_t new_off);
+enum TDB_ERROR add_to_hash(struct tdb_context *tdb, struct hash_info *h,
+                          tdb_off_t new_off);
 
-int delete_from_hash(struct tdb_context *tdb, struct hash_info *h);
+enum TDB_ERROR delete_from_hash(struct tdb_context *tdb, struct hash_info *h);
 
 /* For tdb_check */
 bool is_subhash(tdb_off_t val);
 
 /* free.c: */
-int tdb_ftable_init(struct tdb_context *tdb);
+enum TDB_ERROR tdb_ftable_init(struct tdb_context *tdb);
 
 /* check.c needs these to iterate through free lists. */
 tdb_off_t first_ftable(struct tdb_context *tdb);
 tdb_off_t next_ftable(struct tdb_context *tdb, tdb_off_t ftable);
 
-/* This returns space or TDB_OFF_ERR. */
+/* This returns space or -ve error number. */
 tdb_off_t alloc(struct tdb_context *tdb, size_t keylen, size_t datalen,
                uint64_t hash, unsigned magic, bool growing);
 
 /* Put this record in a free list. */
-int add_free_record(struct tdb_context *tdb,
-                   tdb_off_t off, tdb_len_t len_with_header);
+enum TDB_ERROR add_free_record(struct tdb_context *tdb,
+                              tdb_off_t off, tdb_len_t len_with_header);
 
 /* Set up header for a used/ftable/htable/chain record. */
-int set_header(struct tdb_context *tdb,
-              struct tdb_used_record *rec,
-              unsigned magic, uint64_t keylen, uint64_t datalen,
-              uint64_t actuallen, unsigned hashlow);
+enum TDB_ERROR set_header(struct tdb_context *tdb,
+                         struct tdb_used_record *rec,
+                         unsigned magic, uint64_t keylen, uint64_t datalen,
+                         uint64_t actuallen, unsigned hashlow);
 
 /* Used by tdb_check to verify. */
 unsigned int size_to_bucket(tdb_len_t data_len);
@@ -476,16 +475,17 @@ void *tdb_access_write(struct tdb_context *tdb,
 /* Release result of tdb_access_read/write. */
 void tdb_access_release(struct tdb_context *tdb, const void *p);
 /* Commit result of tdb_acces_write. */
-int tdb_access_commit(struct tdb_context *tdb, void *p);
+enum TDB_ERROR tdb_access_commit(struct tdb_context *tdb, void *p);
 
 /* Convenience routine to get an offset. */
 tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off);
 
 /* Write an offset at an offset. */
-int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val);
+enum TDB_ERROR tdb_write_off(struct tdb_context *tdb, tdb_off_t off,
+                            tdb_off_t val);
 
 /* Clear an ondisk area. */
-int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len);
+enum TDB_ERROR zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len);
 
 /* Return a non-zero offset between >= start < end in this array (or end). */
 tdb_off_t tdb_find_nonzero_off(struct tdb_context *tdb,
@@ -501,12 +501,12 @@ tdb_off_t tdb_find_zero_off(struct tdb_context *tdb, tdb_off_t off,
 void *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len);
 
 /* Writes a converted copy of a record. */
-int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
-                     const void *rec, size_t len);
+enum TDB_ERROR tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
+                                const void *rec, size_t len);
 
 /* Reads record and converts it */
-int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
-                    void *rec, size_t len);
+enum TDB_ERROR tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
+                               void *rec, size_t len);
 
 /* Adds a stat, if it's in range. */
 void add_stat_(struct tdb_context *tdb, uint64_t *stat, size_t val);