]> git.ipfire.org Git - thirdparty/systemd.git/blame - tdb/tdb.h
[PATCH] fix some compiler warnings in the tdb code.
[thirdparty/systemd.git] / tdb / tdb.h
CommitLineData
5ac4a56b
GKH
1#ifndef __TDB_H__
2#define __TDB_H__
3
4/*
5 Unix SMB/CIFS implementation.
6 Samba database functions
7 Copyright (C) Andrew Tridgell 1999
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
74894b53 28#include <signal.h>
5ac4a56b
GKH
29
30/* flags to tdb_store() */
31#define TDB_REPLACE 1
32#define TDB_INSERT 2
33#define TDB_MODIFY 3
34
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) */
42#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
43
44#define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
45
46/* error codes */
47enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
48 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT };
49
50#ifndef u32
51#define u32 unsigned
52#endif
53
54typedef struct {
55 char *dptr;
56 size_t dsize;
57} TDB_DATA;
58
59typedef u32 tdb_len;
60typedef u32 tdb_off;
61
62/* this is stored at the front of every database */
63struct tdb_header {
64 char magic_food[32]; /* for /etc/magic */
65 u32 version; /* version of the code */
66 u32 hash_size; /* number of hash entries */
67 tdb_off rwlocks;
68 tdb_off reserved[31];
69};
70
71struct tdb_lock_type {
72 u32 count;
73 u32 ltype;
74};
75
76struct tdb_traverse_lock {
77 struct tdb_traverse_lock *next;
78 u32 off;
79 u32 hash;
80};
81
82/* this is the context structure that is returned from a db open */
83typedef struct tdb_context {
84 char *name; /* the name of the database */
85 void *map_ptr; /* where it is currently mapped */
86 int fd; /* open file descriptor for the database */
87 tdb_len map_size; /* how much space has been mapped */
88 int read_only; /* opened read-only */
89 struct tdb_lock_type *locked; /* array of chain locks */
90 enum TDB_ERROR ecode; /* error code for last tdb error */
91 struct tdb_header header; /* a cached copy of the header */
92 u32 flags; /* the flags passed to tdb_open */
93 u32 *lockedkeys; /* array of locked keys: first is #keys */
94 struct tdb_traverse_lock travlocks; /* current traversal locks */
95 struct tdb_context *next; /* all tdbs to avoid multiple opens */
96 dev_t device; /* uniquely identifies this tdb */
97 ino_t inode; /* uniquely identifies this tdb */
98 void (*log_fn)(struct tdb_context *tdb, int level, const char *, ...); /* logging function */
99 int open_flags; /* flags used in the open - needed by reopen */
100} TDB_CONTEXT;
101
102typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *);
103typedef void (*tdb_log_func)(TDB_CONTEXT *, int , const char *, ...);
104
105TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
106 int open_flags, mode_t mode);
107TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
108 int open_flags, mode_t mode,
109 tdb_log_func log_fn);
110
111int tdb_reopen(TDB_CONTEXT *tdb);
112int tdb_reopen_all(void);
113void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
114enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
115const char *tdb_errorstr(TDB_CONTEXT *tdb);
116TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
117int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
118int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
119int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
120int tdb_close(TDB_CONTEXT *tdb);
121TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
122TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
123int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
124int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
125int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[]);
126void tdb_unlockkeys(TDB_CONTEXT *tdb);
127int tdb_lockall(TDB_CONTEXT *tdb);
128void tdb_unlockall(TDB_CONTEXT *tdb);
129
130/* Low level locking functions: use with care */
131void tdb_set_lock_alarm(sig_atomic_t *palarm);
132int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
133int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
134
135/* Debug functions. Not used in production. */
136void tdb_dump_all(TDB_CONTEXT *tdb);
137int tdb_printfreelist(TDB_CONTEXT *tdb);
138
9c9fb5f6
GKH
139/* used only in tdbutil.c */
140int tdb_chainlock_read(TDB_CONTEXT *tdb, TDB_DATA key);
141int tdb_chainunlock_read(TDB_CONTEXT *tdb, TDB_DATA key);
142
5ac4a56b
GKH
143extern TDB_DATA tdb_null;
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* tdb.h */