tdb 1.2.9

include/tdb.h

00001 #ifndef __TDB_H__
00002 #define __TDB_H__
00003 
00004 /* 
00005    Unix SMB/CIFS implementation.
00006 
00007    trivial database library
00008 
00009    Copyright (C) Andrew Tridgell 1999-2004
00010    
00011      ** NOTE! The following LGPL license applies to the tdb
00012      ** library. This does NOT imply that all of Samba is released
00013      ** under the LGPL
00014    
00015    This library is free software; you can redistribute it and/or
00016    modify it under the terms of the GNU Lesser General Public
00017    License as published by the Free Software Foundation; either
00018    version 3 of the License, or (at your option) any later version.
00019 
00020    This library is distributed in the hope that it will be useful,
00021    but WITHOUT ANY WARRANTY; without even the implied warranty of
00022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023    Lesser General Public License for more details.
00024 
00025    You should have received a copy of the GNU Lesser General Public
00026    License along with this library; if not, see <http://www.gnu.org/licenses/>.
00027 */
00028 
00029 #ifdef  __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 #include "signal.h"
00034 
00065 #define TDB_REPLACE 1           
00066 #define TDB_INSERT 2            
00067 #define TDB_MODIFY 3            
00070 #define TDB_DEFAULT 0 
00071 #define TDB_CLEAR_IF_FIRST 1 
00072 #define TDB_INTERNAL 2 
00073 #define TDB_NOLOCK   4 
00074 #define TDB_NOMMAP   8 
00075 #define TDB_CONVERT 16 
00076 #define TDB_BIGENDIAN 32 
00077 #define TDB_NOSYNC   64 
00078 #define TDB_SEQNUM   128 
00079 #define TDB_VOLATILE   256 
00080 #define TDB_ALLOW_NESTING 512 
00081 #define TDB_DISALLOW_NESTING 1024 
00082 #define TDB_INCOMPATIBLE_HASH 2048 
00085 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, 
00086                 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
00087                 TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY,
00088                 TDB_ERR_NESTING};
00089 
00091 enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, 
00092                       TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
00093 
00095 typedef struct TDB_DATA {
00096         unsigned char *dptr;
00097         size_t dsize;
00098 } TDB_DATA;
00099 
00100 #ifndef PRINTF_ATTRIBUTE
00101 #if (__GNUC__ >= 3)
00102 
00106 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
00107 #else
00108 #define PRINTF_ATTRIBUTE(a1, a2)
00109 #endif
00110 #endif
00111 
00113 typedef struct tdb_context TDB_CONTEXT;
00114 
00115 typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
00116 typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
00117 typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
00118 
00119 struct tdb_logging_context {
00120         tdb_log_func log_fn;
00121         void *log_private;
00122 };
00123 
00153 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
00154                       int open_flags, mode_t mode);
00155 
00195 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
00196                          int open_flags, mode_t mode,
00197                          const struct tdb_logging_context *log_ctx,
00198                          tdb_hash_func hash_fn);
00199 
00207 void tdb_set_max_dead(struct tdb_context *tdb, int max_dead);
00208 
00219 int tdb_reopen(struct tdb_context *tdb);
00220 
00234 int tdb_reopen_all(int parent_longlived);
00235 
00243 void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx);
00244 
00254 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
00255 
00263 const char *tdb_errorstr(struct tdb_context *tdb);
00264 
00280 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
00281 
00305 int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
00306                               int (*parser)(TDB_DATA key, TDB_DATA data,
00307                                             void *private_data),
00308                               void *private_data);
00309 
00319 int tdb_delete(struct tdb_context *tdb, TDB_DATA key);
00320 
00341 int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
00342 
00359 int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
00360 
00368 int tdb_close(struct tdb_context *tdb);
00369 
00380 TDB_DATA tdb_firstkey(struct tdb_context *tdb);
00381 
00394 TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
00395 
00416 int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *private_data);
00417 
00435 int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *private_data);
00436 
00450 int tdb_exists(struct tdb_context *tdb, TDB_DATA key);
00451 
00462 int tdb_lockall(struct tdb_context *tdb);
00463 
00477 int tdb_lockall_nonblock(struct tdb_context *tdb);
00478 
00490 int tdb_unlockall(struct tdb_context *tdb);
00491 
00502 int tdb_lockall_read(struct tdb_context *tdb);
00503 
00517 int tdb_lockall_read_nonblock(struct tdb_context *tdb);
00518 
00530 int tdb_unlockall_read(struct tdb_context *tdb);
00531 
00544 int tdb_lockall_mark(struct tdb_context *tdb);
00545 
00558 int tdb_lockall_unmark(struct tdb_context *tdb);
00559 
00569 const char *tdb_name(struct tdb_context *tdb);
00570 
00581 int tdb_fd(struct tdb_context *tdb);
00582 
00594 tdb_log_func tdb_log_fn(struct tdb_context *tdb);
00595 
00605 void *tdb_get_logging_private(struct tdb_context *tdb);
00606 
00635 int tdb_transaction_start(struct tdb_context *tdb);
00636 
00648 int tdb_transaction_start_nonblock(struct tdb_context *tdb);
00649 
00665 int tdb_transaction_prepare_commit(struct tdb_context *tdb);
00666 
00679 int tdb_transaction_commit(struct tdb_context *tdb);
00680 
00694 int tdb_transaction_cancel(struct tdb_context *tdb);
00695 
00714 int tdb_get_seqnum(struct tdb_context *tdb);
00715 
00723 int tdb_hash_size(struct tdb_context *tdb);
00724 
00732 size_t tdb_map_size(struct tdb_context *tdb);
00733 
00741 int tdb_get_flags(struct tdb_context *tdb);
00742 
00750 void tdb_add_flags(struct tdb_context *tdb, unsigned flag);
00751 
00759 void tdb_remove_flags(struct tdb_context *tdb, unsigned flag);
00760 
00768 void tdb_enable_seqnum(struct tdb_context *tdb);
00769 
00781 void tdb_increment_seqnum_nonblock(struct tdb_context *tdb);
00782 
00790 unsigned int tdb_jenkins_hash(TDB_DATA *key);
00791 
00813 int tdb_check(struct tdb_context *tdb,
00814               int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
00815               void *private_data);
00816 
00817 /* @} ******************************************************************/
00818 
00819 /* Low level locking functions: use with care */
00820 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
00821 int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
00822 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
00823 int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
00824 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
00825 int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
00826 int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
00827 
00828 void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);
00829 
00830 /* wipe and repack */
00831 int tdb_wipe_all(struct tdb_context *tdb);
00832 int tdb_repack(struct tdb_context *tdb);
00833 
00834 /* Debug functions. Not used in production. */
00835 void tdb_dump_all(struct tdb_context *tdb);
00836 int tdb_printfreelist(struct tdb_context *tdb);
00837 int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries);
00838 int tdb_freelist_size(struct tdb_context *tdb);
00839 char *tdb_summary(struct tdb_context *tdb);
00840 
00841 extern TDB_DATA tdb_null;
00842 
00843 #ifdef  __cplusplus
00844 }
00845 #endif
00846 
00847 #endif /* tdb.h */