]> arthur.barton.de Git - netatalk.git/blob - etc/cnid_dbd/dbif.h
577ee8442e4e62b746b439737bd0c5051763fb2a
[netatalk.git] / etc / cnid_dbd / dbif.h
1 /*
2   $Id: dbif.h,v 1.8 2009-09-03 08:35:15 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. Call dbif_env_open to open an dbd environment if you called dbif_init
21      with a filename.
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   Silent Upgrade Support
46   ----------------------
47
48   On cnid_dbd shutdown we reopen the environment with recovery, close and then
49   remove it. This enables an upgraded netatalk installation possibly linked against
50   a newer bdb lib to succesfully open/create an environment and then silently
51   upgrade the database itself. How nice!
52 */
53
54 #ifndef CNID_DBD_DBIF_H
55 #define CNID_DBD_DBIF_H 1
56
57 #include <sys/cdefs.h>
58 #include <db.h>
59 #include <atalk/adouble.h>
60 #include "db_param.h"
61
62 #define DBIF_DB_CNT 3
63  
64 #define DBIF_CNID          0
65 #define DBIF_IDX_DEVINO    1
66 #define DBIF_IDX_DIDNAME   2
67
68 /* Structures */
69 typedef struct {
70     char     *name;
71     DB       *db;
72     uint32_t flags;
73     uint32_t openflags;
74     DBTYPE   type;
75 } db_table;
76
77 typedef struct {
78     DB_ENV   *db_env;
79     DB_TXN   *db_txn;
80     DBC      *db_cur;              /* for dbif_walk */
81     char     *db_envhome;
82     char     *db_filename;
83     FILE     *db_errlog;
84     db_table db_table[3];
85 } DBD;
86
87 /* Functions */
88 extern DBD *dbif_init(const char *envhome, const char *dbname);
89 extern int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags);
90 extern int dbif_open(DBD *dbd, struct db_param *dbp, int reindex);
91 extern int dbif_close(DBD *dbd);
92 extern int dbif_prep_upgrade(const char *path);
93
94 extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
95 extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
96 extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
97 extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
98 extern int dbif_count(DBD *, const int, u_int32_t *);
99 extern int dbif_stamp(DBD *, void *, int);
100 extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
101 extern int dbif_txn_begin(DBD *);
102 extern int dbif_txn_commit(DBD *);
103 extern int dbif_txn_abort(DBD *);
104 extern void dbif_txn_close(DBD *dbd, int ret); /* Switch between commit+abort */
105 extern int dbif_txn_checkpoint(DBD *, u_int32_t, u_int32_t, u_int32_t);
106
107 extern int dbif_dump(DBD *dbd, int dumpindexes);
108 extern int dbif_idwalk(DBD *dbd, cnid_t *cnid, int close);
109 #endif