2
* $Id: cnid_db3_update.c,v 1.1.4.2.2.1 2005/01/30 20:56:22 didg Exp $
7
#endif /* HAVE_CONFIG_H */
9
#ifdef CNID_BACKEND_DB3
13
#include <sys/param.h>
16
#include <atalk/logger.h>
23
#include <netatalk/endian.h>
24
#include <atalk/adouble.h>
27
#include "cnid_db3_private.h"
29
/* cnid_update: takes the given cnid and updates the metadata. To
30
* handle the did/name data, there are a bunch of functions to get
31
* and set the various fields. */
32
int cnid_db3_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
33
const cnid_t did, char *name, const int len
34
/*, const char *info, const int infolen*/)
37
DBT key, data, altdata;
41
if (!cdb || !(db = cdb->_private) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
45
memset(&key, 0, sizeof(key));
46
memset(&altdata, 0, sizeof(altdata));
49
if ((rc = db3_txn_begin(db->dbenv, NULL, &tid, 0))) {
50
LOG(log_error, logtype_default, "cnid_update: Failed to begin transaction: %s", db_strerror(rc));
54
/* Get the old info. */
55
key.data = (cnid_t *)&id;
56
key.size = sizeof(id);
57
memset(&data, 0, sizeof(data));
58
if ((rc = db->db_cnid->get(db->db_cnid, tid, &key, &data, DB_RMW))) {
61
case DB_LOCK_DEADLOCK:
64
/* Silently fail here. We're allowed to do this since this CNID
65
* might have been deleted out from under us, or someone has
66
* called cnid_lookup then cnid_update (which is redundant). */
73
/* Delete the old dev/ino mapping. */
75
key.size = CNID_DEVINO_LEN;
76
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
78
case DB_LOCK_DEADLOCK:
89
/* Delete the old did/name mapping. */
90
key.data = (char *) data.data + CNID_DEVINO_LEN;
91
key.size = data.size - CNID_DEVINO_LEN;
92
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
94
case DB_LOCK_DEADLOCK:
105
/* Make a new entry. */
106
data.data = make_cnid_data(st, did, name, len);
107
data.size = CNID_HEADER_LEN + len + 1;
109
/* Update the old CNID with the new info. */
110
key.data = (cnid_t *) &id;
111
key.size = sizeof(id);
112
if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
115
case DB_LOCK_DEADLOCK:
122
/* Put in a new dev/ino mapping. */
123
key.data = data.data;
124
key.size = CNID_DEVINO_LEN;
125
altdata.data = (cnid_t *) &id;
126
altdata.size = sizeof(id);
127
if ((rc = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0))) {
130
case DB_LOCK_DEADLOCK:
137
/* put in a new did/name mapping. */
138
key.data = (char *) data.data + CNID_DEVINO_LEN;
139
key.size = data.size - CNID_DEVINO_LEN;
140
if ((rc = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0))) {
143
case DB_LOCK_DEADLOCK:
151
return db3_txn_commit(tid, 0);
154
LOG(log_error, logtype_default, "cnid_update: Unable to update CNID %u: %s",
155
ntohl(id), db_strerror(rc));
159
#endif /* CNID_BACKEND_DB3 */