• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/netatalk-2.2.0/etc/cnid_dbd/
1/*
2  Copyright (C) Joerg Lenneis 2003
3  Copyright (C) Frank Lahm 2009
4  All Rights Reserved.  See COPYING.
5
6
7  API usage
8  =========
9
10  Initialisation
11  --------------
12  1. Provide storage for a DBD * handle
13     DBD *dbd;
14  2. Call dbif_init with a filename to receive a DBD handle:
15     dbd = dbif_init("cnid2.db");
16     Pass NULL to create an in-memory db.
17     Note: the DBD type is NOT from BerkeleyDB ! We've defined it.
18  3. Call dbif_env_open to open an dbd environment if you called dbif_init
19     with a filename. Pass a db_param here for on-disk databases.
20  4. Call dbif_open to finally open the CNID database itself. Pass db_param
21     here for in-memory database.
22
23  Querying the CNID database
24  --------------------------
25  Call dbif_[get|pget|put|del]. They map to the corresponding BerkeleyDB calls
26  with the same names.
27
28  Transactions
29  ------------
30  We use AUTO_COMMIT for the BDB database accesses. This avoids explicit transactions
31  for every bdb access which speeds up reads. But in order to be able to rollback
32  in case of errors we start a transaction once we encounter the first write from
33  dbif_put or dbif_del.
34  Thus you shouldn't call dbif_txn_[begin|abort|commit], they're used internally.
35
36  Checkpoiting
37  ------------
38  Call dbif_txn_checkpoint.
39
40  Closing
41  -------
42  Call dbif_close.
43
44  Silent Upgrade Support
45  ----------------------
46
47  On cnid_dbd shutdown we reopen the environment with recovery, close and then
48  remove it. This enables an upgraded netatalk installation possibly linked against
49  a newer bdb lib to succesfully open/create an environment and then silently
50  upgrade the database itself. How nice!
51*/
52
53#ifndef CNID_DBD_DBIF_H
54#define CNID_DBD_DBIF_H 1
55
56#include <sys/cdefs.h>
57#include <db.h>
58#include <atalk/adouble.h>
59#include "db_param.h"
60
61#define DBIF_DB_CNT 4
62
63#define DBIF_CNID          0
64#define DBIF_IDX_DEVINO    1
65#define DBIF_IDX_DIDNAME   2
66#define DBIF_IDX_NAME      3
67
68/* get_lock cmd and return value */
69#define LOCKFILENAME  "lock"
70#define LOCK_FREE          0
71#define LOCK_UNLOCK        1
72#define LOCK_EXCL          2
73#define LOCK_SHRD          3
74
75/* Structures */
76typedef struct {
77    char     *name;
78    DB       *db;
79    uint32_t flags;
80    uint32_t openflags;
81    DBTYPE   type;
82} db_table;
83
84typedef struct {
85    DB_ENV   *db_env;
86    struct db_param db_param;
87    DB_TXN   *db_txn;
88    DBC      *db_cur;              /* for dbif_walk */
89    char     *db_envhome;
90    char     *db_filename;
91    FILE     *db_errlog;
92    db_table db_table[DBIF_DB_CNT];
93} DBD;
94
95/* Functions */
96extern int get_lock(int cmd, const char *dbpath);
97
98extern DBD *dbif_init(const char *envhome, const char *dbname);
99extern int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags);
100extern int dbif_open(DBD *dbd, struct db_param *dbp, int reindex);
101extern int dbif_close(DBD *dbd);
102extern int dbif_env_remove(const char *path);
103
104extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
105extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
106extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
107extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
108extern int dbif_count(DBD *, const int, u_int32_t *);
109extern int dbif_search(DBD *dbd, DBT *key, char *resbuf);
110extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
111extern int dbif_txn_begin(DBD *);
112extern int dbif_txn_commit(DBD *);
113extern int dbif_txn_abort(DBD *);
114extern int dbif_txn_close(DBD *dbd, int ret); /* Switch between commit+abort */
115extern int dbif_txn_checkpoint(DBD *, u_int32_t, u_int32_t, u_int32_t);
116
117extern int dbif_dump(DBD *dbd, int dumpindexes);
118extern int dbif_idwalk(DBD *dbd, cnid_t *cnid, int close);
119#endif
120