2 * $Id: cnid_update.c,v 1.2 2001-06-29 14:14:46 rufustfirefly 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, 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))
39 memset(&key, 0, sizeof(key));
40 memset(&data, 0, sizeof(data));
41 memset(&altdata, 0, sizeof(altdata));
42 txnp = db->dbenv.tx_info;
44 /* begin a transaction */
46 if (errno = txn_begin(txnp, NULL, &tid)) {
50 /* get the old info */
52 key.size = sizeof(id);
53 if (errno = db->db_cnid->get(db->db_cnid, tid, &key, &data, 0)) {
60 /* delete the old dev/ino mapping */
62 key.size = CNID_DEVINO_LEN;
63 if (errno = db->db_devino->del(db->db_devino, tid, &key, 0)) {
64 if (errno == EAGAIN) {
69 /* silently fail on a non-existent entry */
70 if (errno != DB_NOTFOUND) {
76 /* delete the old did/name mapping */
77 key.data = data.data + CNID_DEVINO_LEN;
78 key.size = data.size - CNID_DEVINO_LEN;
79 if (errno = db->db_didname->del(db->db_didname, tid, &key, 0)) {
80 if (errno == EAGAIN) {
85 /* silently fail on a non-existent entry */
86 if (errno != DB_NOTFOUND) {
92 /* delete the old aliases if necessary */
95 /* make a new entry */
96 data.data = make_cnid_data(st, did, name, len);
97 data.size = CNID_HEADER_LEN + len + 1;
99 /* put a new dev/ino mapping in */
100 key.data = data.data;
101 key.size = CNID_DEVINO_LEN;
103 altdata.size = sizeof(id);
104 if (errno = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0)) {
106 if (errno == EAGAIN) {
112 /* put a new did/name mapping in */
113 key.data = data.data + CNID_DEVINO_LEN;
114 key.size = data.size - CNID_DEVINO_LEN;
115 if (errno = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0)) {
117 if (errno == EAGAIN) {
123 /* update the old CNID with the new info */
125 key.size = sizeof(id);
126 if (errno = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0)) {
128 if (errno == EAGAIN) {
134 /* end transaction */
135 return txn_commit(tid);
138 syslog(LOG_ERR, "cnid_update: can't update CNID(%x)", id);