Make smbd/posix_acls.c use abstract interface.
[Samba.git] / source / tdb / tdb.h
blobf09c6453b5310c34d71efe5958de3097b4b61471
1 #ifndef __TDB_H__
2 #define __TDB_H__
4 /*
5 Unix SMB/Netbios implementation.
6 Version 3.0
7 Samba database functions
8 Copyright (C) Andrew Tridgell 1999
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
30 /* flags to tdb_store() */
31 #define TDB_REPLACE 1
32 #define TDB_INSERT 2
33 #define TDB_MODIFY 3
35 /* flags for tdb_open() */
36 #define TDB_DEFAULT 0 /* just a readability place holder */
37 #define TDB_CLEAR_IF_FIRST 1
38 #define TDB_INTERNAL 2 /* don't store on disk */
39 #define TDB_NOLOCK 4 /* don't do any locking */
40 #define TDB_NOMMAP 8 /* don't use mmap */
41 #define TDB_CONVERT 16 /* convert endian (internal use) */
43 #define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
45 /* error codes */
46 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
47 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST, TDB_ERR_NOLOCK };
49 #ifndef u32
50 #define u32 unsigned
51 #endif
53 typedef struct {
54 char *dptr;
55 size_t dsize;
56 } TDB_DATA;
58 typedef u32 tdb_len;
59 typedef u32 tdb_off;
61 /* this is stored at the front of every database */
62 struct tdb_header {
63 char magic_food[32]; /* for /etc/magic */
64 u32 version; /* version of the code */
65 u32 hash_size; /* number of hash entries */
66 tdb_off rwlocks;
67 tdb_off reserved[31];
70 struct tdb_lock_type {
71 u32 count;
72 u32 ltype;
75 struct tdb_traverse_lock {
76 struct tdb_traverse_lock *next;
77 u32 off;
78 u32 hash;
81 /* this is the context structure that is returned from a db open */
82 typedef struct tdb_context {
83 char *name; /* the name of the database */
84 void *map_ptr; /* where it is currently mapped */
85 int fd; /* open file descriptor for the database */
86 tdb_len map_size; /* how much space has been mapped */
87 int read_only; /* opened read-only */
88 struct tdb_lock_type *locked; /* array of chain locks */
89 enum TDB_ERROR ecode; /* error code for last tdb error */
90 struct tdb_header header; /* a cached copy of the header */
91 u32 flags; /* the flags passed to tdb_open */
92 u32 *lockedkeys; /* array of locked keys: first is #keys */
93 struct tdb_traverse_lock travlocks; /* current traversal locks */
94 struct tdb_context *next; /* all tdbs to avoid multiple opens */
95 dev_t device; /* uniquely identifies this tdb */
96 ino_t inode; /* uniquely identifies this tdb */
97 } TDB_CONTEXT;
99 typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *);
101 TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
102 int open_flags, mode_t mode);
103 enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
104 const char *tdb_errorstr(TDB_CONTEXT *tdb);
105 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
106 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
107 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
108 int tdb_close(TDB_CONTEXT *tdb);
109 TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
110 TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
111 int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
112 int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
113 int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[]);
114 void tdb_unlockkeys(TDB_CONTEXT *tdb);
115 int tdb_lockall(TDB_CONTEXT *tdb);
116 void tdb_unlockall(TDB_CONTEXT *tdb);
118 /* Low level locking functions: use with care */
119 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
120 void tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
121 extern TDB_DATA tdb_null;
122 #ifdef __cplusplus
124 #endif
126 #endif /* tdb.h */