2 * $Id: cnid_cdb_update.c,v 1.2 2005-04-28 20:49:59 bfernhomberg Exp $
7 #endif /* HAVE_CONFIG_H */
9 #ifdef CNID_BACKEND_CDB
10 #include "cnid_cdb_private.h"
14 /* cnid_update: takes the given cnid and updates the metadata. To
15 * handle the did/name data, there are a bunch of functions to get
16 * and set the various fields. */
17 int cnid_cdb_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
18 const cnid_t did, char *name, const int len
19 /*, const char *info, const int infolen*/)
26 char getbuf[CNID_HEADER_LEN + MAXPATHLEN +1];
28 if (!cdb || !(db = cdb->_private) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
32 memset(&key, 0, sizeof(key));
33 memset(&pkey, 0, sizeof(pkey));
34 memset(&data, 0, sizeof(data));
36 buf = make_cnid_data(st, did, name, len);
38 key.data = buf +CNID_DEVINO_OFS;
39 key.size = CNID_DEVINO_LEN;
41 data.size = CNID_HEADER_LEN + MAXPATHLEN + 1;
43 if (0 != (rc = db->db_devino->pget(db->db_devino, tid, &key, &pkey, &data, 0)) ) {
44 #if DB_VERSION_MAJOR >= 4
45 if (rc != DB_NOTFOUND && rc != DB_SECONDARY_BAD) {
47 if (rc != DB_NOTFOUND) {
49 LOG(log_error, logtype_default, "cnid_update: Unable to get devino CNID %u, name %s: %s",
50 ntohl(did), name, db_strerror(rc));
55 if ((rc = db->db_cnid->del(db->db_cnid, tid, &pkey, 0))) {
56 LOG(log_error, logtype_default, "cnid_update: Unable to delete CNID %u: %s",
57 ntohl(id), db_strerror(rc));
61 memset(&pkey, 0, sizeof(pkey));
62 buf = make_cnid_data(st, did, name, len);
63 key.data = buf + CNID_DID_OFS;
64 key.size = CNID_DID_LEN + len + 1;
66 if (0 != (rc = db->db_didname->pget(db->db_didname, tid, &key, &pkey, &data, 0)) ) {
67 #if DB_VERSION_MAJOR >= 4
68 if (rc != DB_NOTFOUND && rc != DB_SECONDARY_BAD) {
70 if (rc != DB_NOTFOUND) {
72 LOG(log_error, logtype_default, "cnid_update: Unable to get didname CNID %u, name %s: %s",
73 ntohl(did), name, db_strerror(rc));
78 if ((rc = db->db_cnid->del(db->db_cnid, tid, &pkey, 0))) {
79 LOG(log_error, logtype_default, "cnid_update: Unable to delete CNID %u: %s",
80 ntohl(id), db_strerror(rc));
85 memset(&key, 0, sizeof(key));
86 key.data = (cnid_t *)&id;
87 key.size = sizeof(id);
89 memset(&data, 0, sizeof(data));
90 /* Make a new entry. */
91 buf = make_cnid_data(st, did, name, len);
93 memcpy(data.data, &id, sizeof(id));
94 data.size = CNID_HEADER_LEN + len + 1;
96 /* Update the old CNID with the new info. */
97 if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
98 LOG(log_error, logtype_default, "cnid_update: (%d) Unable to update CNID %u:%s: %s",
99 notfound, ntohl(id), name, db_strerror(rc));