]> arthur.barton.de Git - netatalk.git/blob - include/atalk/tdb.h
Writing metadata xattr on directories with sticky bit set, FR#94
[netatalk.git] / include / atalk / tdb.h
1 #ifndef USE_BUILTIN_TDB
2 #  include <tdb.h>
3 #else
4 #  ifndef __TDB_H__
5 #    define __TDB_H__
6
7 /* 
8    Unix SMB/CIFS implementation.
9
10    trivial database library
11
12    Copyright (C) Andrew Tridgell 1999-2004
13    
14      ** NOTE! The following LGPL license applies to the tdb
15      ** library. This does NOT imply that all of Samba is released
16      ** under the LGPL
17    
18    This library is free software; you can redistribute it and/or
19    modify it under the terms of the GNU Lesser General Public
20    License as published by the Free Software Foundation; either
21    version 3 of the License, or (at your option) any later version.
22
23    This library is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26    Lesser General Public License for more details.
27
28    You should have received a copy of the GNU Lesser General Public
29    License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 */
31
32 #ifdef  __cplusplus
33 extern "C" {
34 #endif
35
36 #include <sys/types.h>
37 #include <signal.h>
38
39 /* flags to tdb_store() */
40 #define TDB_REPLACE 1           /* Unused */
41 #define TDB_INSERT 2            /* Don't overwrite an existing entry */
42 #define TDB_MODIFY 3            /* Don't create an existing entry    */
43
44 /* flags for tdb_open() */
45 #define TDB_DEFAULT 0 /* just a readability place holder */
46 #define TDB_CLEAR_IF_FIRST 1
47 #define TDB_INTERNAL 2 /* don't store on disk */
48 #define TDB_NOLOCK   4 /* don't do any locking */
49 #define TDB_NOMMAP   8 /* don't use mmap */
50 #define TDB_CONVERT 16 /* convert endian (internal use) */
51 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
52 #define TDB_NOSYNC   64 /* don't use synchronous transactions */
53 #define TDB_SEQNUM   128 /* maintain a sequence number */
54 #define TDB_VOLATILE   256 /* Activate the per-hashchain freelist, default 5 */
55 #define TDB_ALLOW_NESTING 512 /* Allow transactions to nest */
56 #define TDB_DISALLOW_NESTING 1024 /* Disallow transactions to nest */
57
58 /* error codes */
59 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, 
60                 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
61                 TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY,
62                 TDB_ERR_NESTING};
63
64 /* debugging uses one of the following levels */
65 enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, 
66                       TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
67
68 typedef struct TDB_DATA {
69         unsigned char *dptr;
70         size_t dsize;
71 } TDB_DATA;
72
73 #ifndef PRINTF_ATTRIBUTE
74 #if (__GNUC__ >= 3)
75 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
76  * the parameter containing the format, and a2 the index of the first
77  * argument. Note that some gcc 2.x versions don't handle this
78  * properly **/
79 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
80 #else
81 #define PRINTF_ATTRIBUTE(a1, a2)
82 #endif
83 #endif
84
85 /* this is the context structure that is returned from a db open */
86 typedef struct tdb_context TDB_CONTEXT;
87
88 typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
89 typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
90 typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
91
92 struct tdb_logging_context {
93         tdb_log_func log_fn;
94         void *log_private;
95 };
96
97 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
98                       int open_flags, mode_t mode);
99 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
100                          int open_flags, mode_t mode,
101                          const struct tdb_logging_context *log_ctx,
102                          tdb_hash_func hash_fn);
103 void tdb_set_max_dead(struct tdb_context *tdb, int max_dead);
104
105 int tdb_reopen(struct tdb_context *tdb);
106 int tdb_reopen_all(int parent_longlived);
107 void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx);
108 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
109 const char *tdb_errorstr(struct tdb_context *tdb);
110 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
111 int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
112                      int (*parser)(TDB_DATA key, TDB_DATA data,
113                                    void *private_data),
114                      void *private_data);
115 int tdb_delete(struct tdb_context *tdb, TDB_DATA key);
116 int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
117 int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
118 int tdb_close(struct tdb_context *tdb);
119 TDB_DATA tdb_firstkey(struct tdb_context *tdb);
120 TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
121 int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *);
122 int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *);
123 int tdb_exists(struct tdb_context *tdb, TDB_DATA key);
124 int tdb_lockall(struct tdb_context *tdb);
125 int tdb_lockall_nonblock(struct tdb_context *tdb);
126 int tdb_unlockall(struct tdb_context *tdb);
127 int tdb_lockall_read(struct tdb_context *tdb);
128 int tdb_lockall_read_nonblock(struct tdb_context *tdb);
129 int tdb_unlockall_read(struct tdb_context *tdb);
130 int tdb_lockall_mark(struct tdb_context *tdb);
131 int tdb_lockall_unmark(struct tdb_context *tdb);
132 const char *tdb_name(struct tdb_context *tdb);
133 int tdb_fd(struct tdb_context *tdb);
134 tdb_log_func tdb_log_fn(struct tdb_context *tdb);
135 void *tdb_get_logging_private(struct tdb_context *tdb);
136 int tdb_transaction_start(struct tdb_context *tdb);
137 int tdb_transaction_prepare_commit(struct tdb_context *tdb);
138 int tdb_transaction_commit(struct tdb_context *tdb);
139 int tdb_transaction_cancel(struct tdb_context *tdb);
140 int tdb_transaction_recover(struct tdb_context *tdb);
141 int tdb_get_seqnum(struct tdb_context *tdb);
142 int tdb_hash_size(struct tdb_context *tdb);
143 size_t tdb_map_size(struct tdb_context *tdb);
144 int tdb_get_flags(struct tdb_context *tdb);
145 void tdb_add_flags(struct tdb_context *tdb, unsigned flag);
146 void tdb_remove_flags(struct tdb_context *tdb, unsigned flag);
147 void tdb_enable_seqnum(struct tdb_context *tdb);
148 void tdb_increment_seqnum_nonblock(struct tdb_context *tdb);
149 int tdb_check(struct tdb_context *tdb,
150               int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
151               void *private_data);
152
153 /* Low level locking functions: use with care */
154 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
155 int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
156 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
157 int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
158 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
159 int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
160 int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
161
162 void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);
163
164 /* wipe and repack */
165 int tdb_wipe_all(struct tdb_context *tdb);
166 int tdb_repack(struct tdb_context *tdb);
167
168 /* Debug functions. Not used in production. */
169 void tdb_dump_all(struct tdb_context *tdb);
170 int tdb_printfreelist(struct tdb_context *tdb);
171 int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries);
172 int tdb_freelist_size(struct tdb_context *tdb);
173
174 extern TDB_DATA tdb_null;
175
176 #ifdef  __cplusplus
177 }
178 #endif
179
180 #  endif /* tdb.h */
181 #endif /* USE_BUILTIN_TDB */