diff options
author | Andrew Tridgell <tridge@samba.org> | 1999-12-21 03:04:37 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1999-12-21 03:04:37 +0000 |
commit | c2c42b8694be0b2ce271613153cca71dc8e83a9f (patch) | |
tree | 8c068082fa8b9010c61f06c7285f05ffe1a3d8f9 /source3/tdb/tdb.h | |
parent | e004340f715743e16f599bd0be3e9dad4c53bf2d (diff) | |
download | samba-c2c42b8694be0b2ce271613153cca71dc8e83a9f.tar.gz samba-c2c42b8694be0b2ce271613153cca71dc8e83a9f.tar.bz2 samba-c2c42b8694be0b2ce271613153cca71dc8e83a9f.zip |
first pass at the database code for Samba. This also includes a test
suite and a very simple tool for manuipulating the databases.
the main code is in tdb/tdb.c and includes both mmap and file based
IO. All databases auto-expand and allow multiple simultaneous writers.
the next step is using this new capability in lots of places in Samba
where we have existing ad-hoc databases
(This used to be commit c89d29cc5e3b6d568928acace01144059f1668b3)
Diffstat (limited to 'source3/tdb/tdb.h')
-rw-r--r-- | source3/tdb/tdb.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source3/tdb/tdb.h b/source3/tdb/tdb.h new file mode 100644 index 0000000000..316338606b --- /dev/null +++ b/source3/tdb/tdb.h @@ -0,0 +1,61 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + Samba database functions + Copyright (C) Andrew Tridgell 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +typedef unsigned tdb_len; +typedef unsigned tdb_off; + +/* this is stored at the front of every database */ +struct tdb_header { + unsigned version; /* version of the code */ + unsigned hash_size; /* number of hash entries */ +}; + +typedef struct { + char *dptr; + size_t dsize; +} TDB_DATA; + +/* this is the context structure that is returned from a db open */ +typedef struct { + char *name; /* the name of the database */ + void *map_ptr; /* where it is currently mapped */ + int fd; /* open file descriptor for the database */ + tdb_len map_size; /* how much space has been mapped */ + int write_locked; /* set if we have the db locked */ + struct tdb_header header; /* a cached copy of the header */ +} TDB_CONTEXT; + +#define TDB_REPLACE 1 +#define TDB_INSERT 2 + +#if STANDALONE +int tdb_writelock(TDB_CONTEXT *tdb); +int tdb_writeunlock(TDB_CONTEXT *tdb); +TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); +TDB_CONTEXT *tdb_open(char *name, int hash_size, int flags, mode_t mode); +int tdb_close(TDB_CONTEXT *tdb); +TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); +TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)); +int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); +#endif |