chiark / gitweb /
WIP before any changes resulting from reading SM API stuff
[inn-innduct.git] / include / dbz.h
1 #ifndef __DBZ_H__
2 #define __DBZ_H__
3
4 /* Need the definition of HASH. */
5 #include "libinn.h"
6
7 BEGIN_DECLS
8
9 /* This is the number of bytes of the md5 to actually store in
10  * the .pag file.  This number directly effects the collision
11  * rate and memory usage.  You can probably set this number as
12  * low as 5 w/o problems and some sites may want to set it as
13  * high as 8.  Anything higher than that is probably not useful.
14  * Note at the internal hash size isn't the only factor that
15  * effects collision rate.  The table index is used as an implicit
16  * part of the hash value stored also.
17  */
18 #ifdef  DO_TAGGED_HASH
19 #define DBZMAXKEY       255
20 #define DBZ_INTERNAL_HASH_SIZE   4
21 #else
22 #define DBZ_INTERNAL_HASH_SIZE   6
23 #endif
24
25 typedef enum {DBZSTORE_OK, DBZSTORE_EXISTS, DBZSTORE_ERROR} DBZSTORE_RESULT;
26 typedef enum {INCORE_NO, INCORE_MEM, INCORE_MMAP} dbz_incore_val;
27
28 typedef struct {
29     /* Whether to write to the filesystem in addition to updating the incore
30        copy.  This will replace a single large write to disk when dbzsync is
31        called.  */
32     bool             writethrough;
33     /* Whether to do hash lookups from disk, memory or a mmap'ed file */
34     dbz_incore_val   pag_incore;
35     dbz_incore_val   exists_incore;
36     /* Whether dbzstore should update the database async or sync.  This
37        is only applicable if you're not mmaping the database */
38     bool             nonblock;
39 } dbzoptions;
40
41 #ifdef __GNUC__
42 #define PACKED __attribute__ ((packed))
43 #else
44 #if !defined(PACKED)
45 #define PACKED
46 #endif
47 #endif
48
49 #if !defined(lint) && (defined(__SUNPRO_C) || defined(_nec_ews))
50 #pragma pack(1)
51 #endif /* nor lint, nor __SUNPRO_C, nor sgi, nor _nec_ews */
52 typedef struct {
53     char                hash[DBZ_INTERNAL_HASH_SIZE];
54 } PACKED erec;
55 #if !defined(lint) && (defined(__SUNPRO_C) || defined(_nec_ews))
56 #pragma pack()
57 #endif /* nor lint, nor__SUNPRO_C, nor _nec_ews */
58
59 /* standard dbm functions */
60 extern bool dbzinit(const char *name);
61 extern bool dbzclose(void);
62
63 /* new stuff for dbz */
64 extern bool dbzfresh(const char *name, off_t size);
65 extern bool dbzagain(const char *name, const char *oldname);
66 extern bool dbzexists(const HASH key);
67 extern bool dbzfetch(const HASH key, off_t *value);
68 extern DBZSTORE_RESULT dbzstore(const HASH key, off_t data);
69 extern bool dbzsync(void);
70 extern long dbzsize(off_t contents);
71 extern void dbzsetoptions(const dbzoptions options);
72 extern void dbzgetoptions(dbzoptions *options);
73
74 END_DECLS
75
76 #endif /* __DBZ_H__ */