2000-12-06 03:05:15 +03:00
# ifndef __TDB_H__
# define __TDB_H__
1999-12-21 06:04:37 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2006-07-11 22:01:26 +04:00
2004-03-28 06:19:58 +04:00
trivial database library
2006-07-11 22:01:26 +04:00
2004-03-28 06:19:58 +04:00
Copyright ( C ) Andrew Tridgell 1999 - 2004
* * NOTE ! The following LGPL license applies to the tdb
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
2007-07-10 05:44:42 +04:00
version 3 of the License , or ( at your option ) any later version .
2004-03-28 06:19:58 +04:00
This library is distributed in the hope that it will be useful ,
1999-12-21 06:04:37 +03:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2004-03-28 06:19:58 +04:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
2006-07-11 22:01:26 +04:00
2004-03-28 06:19:58 +04:00
You should have received a copy of the GNU Lesser General Public
2007-07-10 07:42:26 +04:00
License along with this library ; if not , see < http : //www.gnu.org/licenses/>.
1999-12-21 06:04:37 +03:00
*/
2000-12-06 03:05:15 +03:00
# ifdef __cplusplus
extern " C " {
# endif
1999-12-21 06:04:37 +03:00
2008-09-19 23:15:46 +04:00
# include "signal.h"
2000-01-07 06:01:55 +03:00
2000-12-06 03:05:15 +03:00
/* flags to tdb_store() */
2007-11-08 01:24:36 +03:00
# define TDB_REPLACE 1 /* Unused */
# define TDB_INSERT 2 /* Don't overwrite an existing entry */
# define TDB_MODIFY 3 /* Don't create an existing entry */
2000-12-06 03:05:15 +03:00
/* flags for tdb_open() */
# define TDB_DEFAULT 0 /* just a readability place holder */
# define TDB_CLEAR_IF_FIRST 1
# define TDB_INTERNAL 2 /* don't store on disk */
# define TDB_NOLOCK 4 /* don't do any locking */
# define TDB_NOMMAP 8 /* don't use mmap */
# define TDB_CONVERT 16 /* convert endian (internal use) */
2002-07-15 14:35:28 +04:00
# define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
2006-07-11 22:01:26 +04:00
# define TDB_NOSYNC 64 /* don't use synchronous transactions */
# define TDB_SEQNUM 128 /* maintain a sequence number */
2007-05-27 13:22:11 +04:00
# define TDB_VOLATILE 256 /* Activate the per-hashchain freelist, default 5 */
2000-12-06 03:05:15 +03:00
# define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
/* error codes */
enum TDB_ERROR { TDB_SUCCESS = 0 , TDB_ERR_CORRUPT , TDB_ERR_IO , TDB_ERR_LOCK ,
2004-03-28 06:19:58 +04:00
TDB_ERR_OOM , TDB_ERR_EXISTS , TDB_ERR_NOLOCK , TDB_ERR_LOCK_TIMEOUT ,
2006-07-11 22:01:26 +04:00
TDB_ERR_NOEXIST , TDB_ERR_EINVAL , TDB_ERR_RDONLY } ;
1999-12-21 06:04:37 +03:00
2006-10-20 13:55:47 +04:00
/* debugging uses one of the following levels */
enum tdb_debug_level { TDB_DEBUG_FATAL = 0 , TDB_DEBUG_ERROR ,
TDB_DEBUG_WARNING , TDB_DEBUG_TRACE } ;
2006-07-11 22:01:26 +04:00
typedef struct TDB_DATA {
2007-03-29 13:35:51 +04:00
unsigned char * dptr ;
1999-12-21 06:04:37 +03:00
size_t dsize ;
} TDB_DATA ;
2006-07-11 22:01:26 +04:00
# ifndef PRINTF_ATTRIBUTE
# if (__GNUC__ >= 3)
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format , and a2 the index of the first
* argument . Note that some gcc 2. x versions don ' t handle this
* properly * */
# define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
# else
# define PRINTF_ATTRIBUTE(a1, a2)
# endif
# endif
2000-06-15 19:30:37 +04:00
1999-12-21 06:04:37 +03:00
/* this is the context structure that is returned from a db open */
2006-07-11 22:01:26 +04:00
typedef struct tdb_context TDB_CONTEXT ;
typedef int ( * tdb_traverse_func ) ( struct tdb_context * , TDB_DATA , TDB_DATA , void * ) ;
2006-10-20 13:55:47 +04:00
typedef void ( * tdb_log_func ) ( struct tdb_context * , enum tdb_debug_level , const char * , . . . ) PRINTF_ATTRIBUTE ( 3 , 4 ) ;
2006-07-11 22:01:26 +04:00
typedef unsigned int ( * tdb_hash_func ) ( TDB_DATA * key ) ;
2006-10-20 13:55:47 +04:00
struct tdb_logging_context {
tdb_log_func log_fn ;
void * log_private ;
} ;
2006-07-11 22:01:26 +04:00
struct tdb_context * tdb_open ( const char * name , int hash_size , int tdb_flags ,
2001-12-04 14:25:44 +03:00
int open_flags , mode_t mode ) ;
2006-07-11 22:01:26 +04:00
struct tdb_context * tdb_open_ex ( const char * name , int hash_size , int tdb_flags ,
2001-12-04 16:21:15 +03:00
int open_flags , mode_t mode ,
2006-10-20 13:55:47 +04:00
const struct tdb_logging_context * log_ctx ,
2004-08-25 05:04:02 +04:00
tdb_hash_func hash_fn ) ;
2007-03-06 13:11:15 +03:00
void tdb_set_max_dead ( struct tdb_context * tdb , int max_dead ) ;
2001-12-04 16:21:15 +03:00
2006-07-11 22:01:26 +04:00
int tdb_reopen ( struct tdb_context * tdb ) ;
int tdb_reopen_all ( int parent_longlived ) ;
2006-11-21 22:45:53 +03:00
void tdb_set_logging_function ( struct tdb_context * tdb , const struct tdb_logging_context * log_ctx ) ;
2006-07-11 22:01:26 +04:00
enum TDB_ERROR tdb_error ( struct tdb_context * tdb ) ;
const char * tdb_errorstr ( struct tdb_context * tdb ) ;
TDB_DATA tdb_fetch ( struct tdb_context * tdb , TDB_DATA key ) ;
2007-02-19 14:19:53 +03:00
int tdb_parse_record ( struct tdb_context * tdb , TDB_DATA key ,
int ( * parser ) ( TDB_DATA key , TDB_DATA data ,
void * private_data ) ,
void * private_data ) ;
2006-07-11 22:01:26 +04:00
int tdb_delete ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_store ( struct tdb_context * tdb , TDB_DATA key , TDB_DATA dbuf , int flag ) ;
int tdb_append ( struct tdb_context * tdb , TDB_DATA key , TDB_DATA new_dbuf ) ;
int tdb_close ( struct tdb_context * tdb ) ;
TDB_DATA tdb_firstkey ( struct tdb_context * tdb ) ;
TDB_DATA tdb_nextkey ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_traverse ( struct tdb_context * tdb , tdb_traverse_func fn , void * ) ;
int tdb_traverse_read ( struct tdb_context * tdb , tdb_traverse_func fn , void * ) ;
int tdb_exists ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_lockall ( struct tdb_context * tdb ) ;
2007-11-07 09:57:35 +03:00
int tdb_lockall_nonblock ( struct tdb_context * tdb ) ;
2006-10-20 13:55:47 +04:00
int tdb_unlockall ( struct tdb_context * tdb ) ;
int tdb_lockall_read ( struct tdb_context * tdb ) ;
2007-11-07 09:57:35 +03:00
int tdb_lockall_read_nonblock ( struct tdb_context * tdb ) ;
2006-10-20 13:55:47 +04:00
int tdb_unlockall_read ( struct tdb_context * tdb ) ;
2007-11-07 09:57:35 +03:00
int tdb_lockall_mark ( struct tdb_context * tdb ) ;
int tdb_lockall_unmark ( struct tdb_context * tdb ) ;
2006-07-11 22:01:26 +04:00
const char * tdb_name ( struct tdb_context * tdb ) ;
int tdb_fd ( struct tdb_context * tdb ) ;
tdb_log_func tdb_log_fn ( struct tdb_context * tdb ) ;
2006-10-20 13:55:47 +04:00
void * tdb_get_logging_private ( struct tdb_context * tdb ) ;
2006-07-11 22:01:26 +04:00
int tdb_transaction_start ( struct tdb_context * tdb ) ;
int tdb_transaction_commit ( struct tdb_context * tdb ) ;
int tdb_transaction_cancel ( struct tdb_context * tdb ) ;
int tdb_transaction_recover ( struct tdb_context * tdb ) ;
int tdb_get_seqnum ( struct tdb_context * tdb ) ;
int tdb_hash_size ( struct tdb_context * tdb ) ;
2006-10-20 13:55:47 +04:00
size_t tdb_map_size ( struct tdb_context * tdb ) ;
int tdb_get_flags ( struct tdb_context * tdb ) ;
2008-01-12 02:08:37 +03:00
void tdb_add_flags ( struct tdb_context * tdb , unsigned flag ) ;
void tdb_remove_flags ( struct tdb_context * tdb , unsigned flag ) ;
2007-11-07 09:57:35 +03:00
void tdb_enable_seqnum ( struct tdb_context * tdb ) ;
void tdb_increment_seqnum_nonblock ( struct tdb_context * tdb ) ;
2000-12-06 03:05:15 +03:00
/* Low level locking functions: use with care */
2006-07-11 22:01:26 +04:00
int tdb_chainlock ( struct tdb_context * tdb , TDB_DATA key ) ;
2007-11-07 09:57:35 +03:00
int tdb_chainlock_nonblock ( struct tdb_context * tdb , TDB_DATA key ) ;
2006-07-11 22:01:26 +04:00
int tdb_chainunlock ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_chainlock_read ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_chainunlock_read ( struct tdb_context * tdb , TDB_DATA key ) ;
2007-11-07 09:57:35 +03:00
int tdb_chainlock_mark ( struct tdb_context * tdb , TDB_DATA key ) ;
int tdb_chainlock_unmark ( struct tdb_context * tdb , TDB_DATA key ) ;
2001-12-04 16:21:15 +03:00
2007-11-07 08:47:57 +03:00
void tdb_setalarm_sigptr ( struct tdb_context * tdb , volatile sig_atomic_t * sigptr ) ;
2001-12-04 16:21:15 +03:00
/* Debug functions. Not used in production. */
2006-07-11 22:01:26 +04:00
void tdb_dump_all ( struct tdb_context * tdb ) ;
int tdb_printfreelist ( struct tdb_context * tdb ) ;
2006-11-30 06:05:55 +03:00
int tdb_validate_freelist ( struct tdb_context * tdb , int * pnum_entries ) ;
2008-01-12 02:08:37 +03:00
int tdb_wipe_all ( struct tdb_context * tdb ) ;
int tdb_freelist_size ( struct tdb_context * tdb ) ;
2001-12-04 16:21:15 +03:00
2000-12-06 03:05:15 +03:00
extern TDB_DATA tdb_null ;
2002-01-03 02:28:55 +03:00
2000-12-06 03:05:15 +03:00
# ifdef __cplusplus
}
1999-12-21 06:04:37 +03:00
# endif
2000-12-06 03:05:15 +03:00
# endif /* tdb.h */