2 * $Id: cnid_cdb_update.c,v 1.1.4.1 2003-09-09 16:42:21 didg Exp $
7 #endif /* HAVE_CONFIG_H */
9 #ifdef CNID_BACKEND_CDB
13 #include <sys/param.h>
16 #include <atalk/logger.h>
19 #include <netatalk/endian.h>
20 #include <atalk/adouble.h>
23 #include "cnid_cdb_private.h"
27 /* cnid_update: takes the given cnid and updates the metadata. To
28 * handle the did/name data, there are a bunch of functions to get
29 * and set the various fields. */
30 int cnid_cdb_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
31 const cnid_t did, const char *name, const int len
32 /*, const char *info, const int infolen*/)
40 if (!cdb || !(db = cdb->_private) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
44 memset(&key, 0, sizeof(key));
46 buf = make_cnid_data(st, did, name, len);
48 key.data = buf +CNID_DEVINO_OFS;
49 key.size = CNID_DEVINO_LEN;
51 if (0 != (rc = db->db_devino->del(db->db_devino, tid, &key, 0)) ) {
52 if (rc != DB_NOTFOUND && rc != DB_SECONDARY_BAD) {
53 LOG(log_error, logtype_default, "cnid_update: Unable to del devino CNID %u, name %s: %s",
54 ntohl(did), name, db_strerror(rc));
60 buf = make_cnid_data(st, did, name, len);
61 key.data = buf + CNID_DID_OFS;
62 key.size = CNID_DID_LEN + len + 1;
64 if (0 != (rc = db->db_didname->del(db->db_didname, tid, &key, 0)) ) {
65 if (rc != DB_NOTFOUND && rc != DB_SECONDARY_BAD) {
66 LOG(log_error, logtype_default, "cnid_update: Unable to del didname CNID %u, name %s: %s",
67 ntohl(did), name, db_strerror(rc));
73 memset(&key, 0, sizeof(key));
74 key.data = (cnid_t *)&id;
75 key.size = sizeof(id);
77 memset(&data, 0, sizeof(data));
78 /* Make a new entry. */
79 buf = make_cnid_data(st, did, name, len);
81 memcpy(data.data, &id, sizeof(id));
82 data.size = CNID_HEADER_LEN + len + 1;
84 /* Update the old CNID with the new info. */
85 if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
86 LOG(log_error, logtype_default, "cnid_update: (%d) Unable to update CNID %u:%s: %s",
87 notfound, ntohl(id), name, db_strerror(rc));