2 * $Id: cnid_update.c,v 1.12.2.2 2001-12-03 15:53:39 jmarcus Exp $
7 #endif /* HAVE_CONFIG_H */
12 #include <sys/param.h>
18 #include <netatalk/endian.h>
19 #include <atalk/adouble.h>
20 #include <atalk/cnid.h>
22 #include "cnid_private.h"
24 /* cnid_update: takes the given cnid and updates the metadata. To
25 * handle the did/name data, there are a bunch of functions to get
26 * and set the various fields. */
27 int cnid_update(void *CNID, const cnid_t id, const struct stat *st,
28 const cnid_t did, const char *name, const int len
29 /*, const char *info, const int infolen*/)
32 DBT key, data, altdata;
36 if (!(db = CNID) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
40 memset(&key, 0, sizeof(key));
41 memset(&altdata, 0, sizeof(altdata));
44 if ((rc = txn_begin(db->dbenv, NULL, &tid, 0))) {
45 syslog(LOG_ERR, "cnid_update: Failed to begin transaction: %s",
50 /* Get the old info. */
51 key.data = (cnid_t *)&id;
52 key.size = sizeof(id);
53 memset(&data, 0, sizeof(data));
54 if ((rc = db->db_cnid->get(db->db_cnid, tid, &key, &data, DB_RMW))) {
57 case DB_LOCK_DEADLOCK:
64 /* Delete the old dev/ino mapping. */
66 key.size = CNID_DEVINO_LEN;
67 if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
69 case DB_LOCK_DEADLOCK:
80 /* Delete the old did/name mapping. */
81 key.data = (char *) data.data + CNID_DEVINO_LEN;
82 key.size = data.size - CNID_DEVINO_LEN;
83 if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
85 case DB_LOCK_DEADLOCK:
96 /* Make a new entry. */
97 data.data = make_cnid_data(st, did, name, len);
98 data.size = CNID_HEADER_LEN + len + 1;
100 /* Update the old CNID with the new info. */
101 key.data = (cnid_t *) &id;
102 key.size = sizeof(id);
103 if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
106 case DB_LOCK_DEADLOCK:
113 /* Put in a new dev/ino mapping. */
114 key.data = data.data;
115 key.size = CNID_DEVINO_LEN;
116 altdata.data = (cnid_t *) &id;
117 altdata.size = sizeof(id);
118 if ((rc = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0))) {
121 case DB_LOCK_DEADLOCK:
128 /* put in a new did/name mapping. */
129 key.data = (char *) data.data + CNID_DEVINO_LEN;
130 key.size = data.size - CNID_DEVINO_LEN;
131 if ((rc = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0))) {
134 case DB_LOCK_DEADLOCK:
142 return txn_commit(tid, 0);
145 syslog(LOG_ERR, "cnid_update: Unable to update CNID %u: %s",
146 ntohl(id), db_strerror(rc));