first pass at the database code for Samba. This also includes a test
[jra/samba/.git] / source3 / tdb / tdb.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    Samba database functions
5    Copyright (C) Andrew Tridgell 1999
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 typedef unsigned tdb_len;
23 typedef unsigned tdb_off;
24
25 /* this is stored at the front of every database */
26 struct tdb_header {
27         unsigned version; /* version of the code */
28         unsigned hash_size; /* number of hash entries */
29 };
30
31 typedef struct {
32         char *dptr;
33         size_t dsize;
34 } TDB_DATA;
35
36 /* this is the context structure that is returned from a db open */
37 typedef struct {
38         char *name; /* the name of the database */
39         void *map_ptr; /* where it is currently mapped */
40         int fd; /* open file descriptor for the database */
41         tdb_len map_size; /* how much space has been mapped */
42         int write_locked; /* set if we have the db locked */
43         struct tdb_header header; /* a cached copy of the header */
44 } TDB_CONTEXT;
45
46 #define TDB_REPLACE 1
47 #define TDB_INSERT 2
48
49 #if STANDALONE
50 int tdb_writelock(TDB_CONTEXT *tdb);
51 int tdb_writeunlock(TDB_CONTEXT *tdb);
52 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
53 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
54 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
55 TDB_CONTEXT *tdb_open(char *name, int hash_size, int flags, mode_t mode);
56 int tdb_close(TDB_CONTEXT *tdb);
57 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
58 TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
59 int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf));
60 int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
61 #endif