2 * $Id: cnid_update.c,v 1.4 2001-08-15 02:16:25 srittau Exp $
7 #endif /* HAVE_CONFIG_H */
11 #include <sys/param.h>
17 #include <netatalk/endian.h>
18 #include <atalk/adouble.h>
19 #include <atalk/cnid.h>
21 #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;
35 if (!(db = CNID) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO))
38 memset(&key, 0, sizeof(key));
39 memset(&data, 0, sizeof(data));
40 memset(&altdata, 0, sizeof(altdata));
42 /* begin a transaction */
44 if ((errno = txn_begin(db->dbenv, NULL, &tid, 0))) {
48 /* get the old info */
49 key.data = (cnid_t *) &id;
50 key.size = sizeof(id);
51 if ((errno = db->db_cnid->get(db->db_cnid, tid, &key, &data, 0))) {
58 /* delete the old dev/ino mapping */
60 key.size = CNID_DEVINO_LEN;
61 if ((errno = db->db_devino->del(db->db_devino, tid, &key, 0))) {
62 if (errno == EAGAIN) {
67 /* silently fail on a non-existent entry */
68 if (errno != DB_NOTFOUND) {
74 /* delete the old did/name mapping */
75 key.data = (char *) data.data + CNID_DEVINO_LEN;
76 key.size = data.size - CNID_DEVINO_LEN;
77 if ((errno = db->db_didname->del(db->db_didname, tid, &key, 0))) {
78 if (errno == EAGAIN) {
83 /* silently fail on a non-existent entry */
84 if (errno != DB_NOTFOUND) {
90 /* delete the old aliases if necessary */
93 /* make a new entry */
94 data.data = make_cnid_data(st, did, name, len);
95 data.size = CNID_HEADER_LEN + len + 1;
97 /* put a new dev/ino mapping in */
99 key.size = CNID_DEVINO_LEN;
100 altdata.data = (cnid_t *) &id;
101 altdata.size = sizeof(id);
102 if ((errno = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0))) {
104 if (errno == EAGAIN) {
110 /* put a new did/name mapping in */
111 key.data = (char *) data.data + CNID_DEVINO_LEN;
112 key.size = data.size - CNID_DEVINO_LEN;
113 if ((errno = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0))) {
115 if (errno == EAGAIN) {
121 /* update the old CNID with the new info */
122 key.data = (cnid_t *) &id;
123 key.size = sizeof(id);
124 if ((errno = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
126 if (errno == EAGAIN) {
132 /* end transaction */
133 return txn_commit(tid, 0);
136 syslog(LOG_ERR, "cnid_update: can't update CNID(%x)", id);