]> arthur.barton.de Git - netatalk.git/blob - etc/cnid_dbd/dbif.h
Set cachesize for rebuild db
[netatalk.git] / etc / cnid_dbd / dbif.h
1 /*
2   $Id: dbif.h,v 1.9 2009-12-21 06:41:09 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. Pass a db_param here for on-disk databases.
22   4. Call dbif_open to finally open the CNID database itself. Pass db_param
23      here for in-memory database.
24   
25   Querying the CNID database
26   --------------------------
27   Call dbif_[get|pget|put|del]. They map to the corresponding BerkeleyDB calls
28   with the same names.
29
30   Transactions
31   ------------
32   We use AUTO_COMMIT for the BDB database accesses. This avoids explicit transactions
33   for every bdb access which speeds up reads. But in order to be able to rollback
34   in case of errors we start a transaction once we encounter the first write from
35   dbif_put or dbif_del.
36   Thus you shouldn't call dbif_txn_[begin|abort|commit], they're used internally.
37
38   Checkpoiting
39   ------------
40   Call dbif_txn_checkpoint.
41
42   Closing
43   -------
44   Call dbif_close.
45
46   Silent Upgrade Support
47   ----------------------
48
49   On cnid_dbd shutdown we reopen the environment with recovery, close and then
50   remove it. This enables an upgraded netatalk installation possibly linked against
51   a newer bdb lib to succesfully open/create an environment and then silently
52   upgrade the database itself. How nice!
53 */
54
55 #ifndef CNID_DBD_DBIF_H
56 #define CNID_DBD_DBIF_H 1
57
58 #include <sys/cdefs.h>
59 #include <db.h>
60 #include <atalk/adouble.h>
61 #include "db_param.h"
62
63 #define DBIF_DB_CNT 3
64  
65 #define DBIF_CNID          0
66 #define DBIF_IDX_DEVINO    1
67 #define DBIF_IDX_DIDNAME   2
68
69 /* Structures */
70 typedef struct {
71     char     *name;
72     DB       *db;
73     uint32_t flags;
74     uint32_t openflags;
75     DBTYPE   type;
76 } db_table;
77
78 typedef struct {
79     DB_ENV   *db_env;
80     DB_TXN   *db_txn;
81     DBC      *db_cur;              /* for dbif_walk */
82     char     *db_envhome;
83     char     *db_filename;
84     FILE     *db_errlog;
85     db_table db_table[3];
86 } DBD;
87
88 /* Functions */
89 extern DBD *dbif_init(const char *envhome, const char *dbname);
90 extern int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags);
91 extern int dbif_open(DBD *dbd, struct db_param *dbp, int reindex);
92 extern int dbif_close(DBD *dbd);
93 extern int dbif_prep_upgrade(const char *path);
94
95 extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
96 extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
97 extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
98 extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
99 extern int dbif_count(DBD *, const int, u_int32_t *);
100 extern int dbif_stamp(DBD *, void *, int);
101 extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
102 extern int dbif_txn_begin(DBD *);
103 extern int dbif_txn_commit(DBD *);
104 extern int dbif_txn_abort(DBD *);
105 extern void dbif_txn_close(DBD *dbd, int ret); /* Switch between commit+abort */
106 extern int dbif_txn_checkpoint(DBD *, u_int32_t, u_int32_t, u_int32_t);
107
108 extern int dbif_dump(DBD *dbd, int dumpindexes);
109 extern int dbif_idwalk(DBD *dbd, cnid_t *cnid, int close);
110 #endif