#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <err.h>
-#include "tdb1-logging.h"
+#include "logging.h"
-static int tdb1_expand_file_sparse(struct tdb1_context *tdb,
+static int tdb1_expand_file_sparse(struct tdb_context *tdb,
tdb1_off_t size,
tdb1_off_t addition)
{
- if (tdb->read_only || tdb->traverse_read) {
+ if ((tdb->flags & TDB_RDONLY) || tdb->tdb1.traverse_read) {
tdb->last_error = TDB_ERR_RDONLY;
return -1;
}
- if (ftruncate(tdb->fd, size+addition) == -1) {
+ if (ftruncate(tdb->file->fd, size+addition) == -1) {
char b = 0;
- ssize_t written = pwrite(tdb->fd, &b, 1, (size+addition) - 1);
+ ssize_t written = pwrite(tdb->file->fd, &b, 1, (size+addition) - 1);
if (written == 0) {
/* try once more, potentially revealing errno */
- written = pwrite(tdb->fd, &b, 1, (size+addition) - 1);
+ written = pwrite(tdb->file->fd, &b, 1, (size+addition) - 1);
}
if (written == 0) {
/* again - give up, guessing errno */
tdb1_expand_file_sparse
};
-static int test_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
+static int test_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
void *_data)
{
TDB_DATA *expect = _data;
int main(int argc, char *argv[])
{
- struct tdb1_context *tdb;
+ struct tdb_context *tdb;
TDB_DATA key, orig_data, data;
uint32_t hash;
tdb1_off_t rec_ptr;
struct tdb1_record rec;
+ union tdb_attribute hsize;
- plan_tests(24);
- tdb = tdb1_open_ex("run-36-file.tdb", 1024, TDB_DEFAULT,
- O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+ hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
+ hsize.base.next = &tap_log_attr;
+ hsize.tdb1_hashsize.hsize = 1024;
+
+ plan_tests(26);
+ tdb = tdb_open("run-36-file.tdb1", TDB_VERSION1,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
ok1(tdb);
- tdb->methods = &large_io_methods;
+ tdb->tdb1.io = &large_io_methods;
/* Enlarge the file (internally multiplies by 2). */
ok1(tdb1_expand(tdb, 1500000000) == 0);
orig_data.dsize = strlen("world");
orig_data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
+ ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == TDB_SUCCESS);
- data = tdb1_fetch(tdb, key);
+ ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == strlen("world"));
ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
free(data.dptr);
/* That currently fills at the end, make sure that's true. */
- hash = tdb->hash_fn(&key);
+ hash = tdb_hash(tdb, key.dptr, key.dsize);
rec_ptr = tdb1_find_lock_hash(tdb, key, hash, F_RDLCK, &rec);
ok1(rec_ptr);
ok1(rec_ptr > 2U*1024*1024*1024);
/* Transactions should work. */
ok1(tdb1_transaction_start(tdb) == 0);
- ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
+ ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == TDB_SUCCESS);
- data = tdb1_fetch(tdb, key);
+ ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == strlen("world"));
ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
free(data.dptr);
ok1(tdb1_transaction_commit(tdb) == 0);
ok1(tdb1_traverse(tdb, test_traverse, &orig_data) == 1);
- tdb1_close(tdb);
+ tdb_close(tdb);
return exit_status();
}