]> arthur.barton.de Git - netatalk.git/blob - etc/cnid_dbd/dbif.h
dbd now does many things it should do in the end.
[netatalk.git] / etc / cnid_dbd / dbif.h
1 /*
2   $Id: dbif.h,v 1.6 2009-05-14 13:46:08 franklahm Exp $
3  
4   Copyright (C) Joerg Lenneis 2003
5   Copyright (C) Frank Lahm 2009
6   All Rights Reserved.  See COPYING.
7
8
9   API usage
10   =========
11
12   Initialisation
13   --------------
14   1. Provide storage for a DBD * handle
15      DBD *dbd;
16   2. Call dbif_init with a filename to receive a DBD handle:
17      dbd = dbif_init("cnid2.db");
18      Pass NULL to create an in-memory db.
19      Note: the DBD type is NOT from BerkeleyDB ! We've defined it.
20   3. Optional:
21      Call dbif_env_open to open an dbd environment, chdir to it beforehand
22   4. Call dbif_open to finally open the CNID database itself
23   
24   Querying the CNID database
25   --------------------------
26   Call dbif_[get|pget|put|del]. They map to the corresponding BerkeleyDB calls
27   with the same names.
28
29   Transactions
30   ------------
31   We use AUTO_COMMIT for the BDB database accesses. This avoids explicit transactions
32   for every bdb access which speeds up reads. But in order to be able to rollback
33   in case of errors we start a transaction once we encounter the first write from
34   dbif_put or dbif_del.
35   Thus you shouldn't call dbif_txn_[begin|abort|commit], they're used internally.
36
37   Checkpoiting
38   ------------
39   Call dbif_txn_checkpoint.
40
41   Closing
42   -------
43   Call dbif_close.
44 */
45
46 #ifndef CNID_DBD_DBIF_H
47 #define CNID_DBD_DBIF_H 1
48
49 #include <sys/cdefs.h>
50 #include <db.h>
51 #include "db_param.h"
52
53 #define DBIF_DB_CNT 3
54  
55 #define DBIF_CNID          0
56 #define DBIF_IDX_DEVINO    1
57 #define DBIF_IDX_DIDNAME   2
58
59 /* Structures */
60 typedef struct {
61     char     *name;
62     DB       *db;
63     uint32_t flags;
64     uint32_t openflags;
65     DBTYPE   type;
66 } db_table;
67
68 typedef struct {
69     DB_ENV   *db_env;
70     DB_TXN   *db_txn;
71     char     *db_envhome;
72     char     *db_filename;
73     FILE     *db_errlog;
74     db_table db_table[3];
75 } DBD;
76
77 /* Functions */
78 extern DBD *dbif_init(const char *envhome, const char *dbname);
79 extern int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags);
80 extern int dbif_open(DBD *dbd, struct db_param *dbp, int do_truncate);
81 extern int dbif_close(DBD *dbd);
82
83 extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
84 extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
85 extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
86 extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
87
88 extern int dbif_count(DBD *, const int, u_int32_t *);
89 extern int dbif_stamp(DBD *, void *, int);
90 extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
91 extern int dbif_txn_begin(DBD *);
92 extern int dbif_txn_commit(DBD *);
93 extern int dbif_txn_abort(DBD *);
94 extern void dbif_txn_close(DBD *dbd, int ret); /* Switch between commit+abort */
95 extern int dbif_txn_checkpoint(DBD *, u_int32_t, u_int32_t, u_int32_t);
96
97 extern int dbif_dump(DBD *, int dumpindexes);
98
99 #endif