2 * $Id: dbd_update.c,v 1.1.4.12 2004-03-21 23:04:07 lenneis Exp $
4 * Copyright (C) Joerg Lenneis 2003
5 * All Rights Reserved. See COPYING.
10 #endif /* HAVE_CONFIG_H */
14 #include <atalk/logger.h>
15 #include <netatalk/endian.h>
16 #include <atalk/cnid_dbd_private.h>
24 /* cnid_update: takes the given cnid and updates the metadata. */
26 /* FIXME: This calls pack_cnid_data(rqst) three times without modifying rqst */
27 /* FIXME: (Only tested with DB 4.1.25):
29 dbif_pget on the secondary index followed by dbif_del with the CNID on the
30 main cnid db could be replaced by a single dbif_del on the secondary index. That
31 deletes the secondary, the corresponding entry from the main cnid db as well as the
32 other secondary index.
35 int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
41 char getbuf[CNID_HEADER_LEN + MAXPATHLEN +1];
46 memset(&key, 0, sizeof(key));
47 memset(&pkey, 0, sizeof(pkey));
48 memset(&data, 0, sizeof(data));
52 buf = pack_cnid_data(rqst);
53 key.data = buf +CNID_DEVINO_OFS;
54 key.size = CNID_DEVINO_LEN;
57 data.size = CNID_HEADER_LEN + MAXPATHLEN + 1;
58 if ((rc = dbif_pget(DBIF_IDX_DEVINO, &key, &pkey, &data, 0)) < 0 ) {
63 memcpy(&tmpcnid, pkey.data, sizeof(cnid_t));
64 LOG(log_info, logtype_cnid, "dbd_update: Deleting %u corresponding to dev/ino %s from cnid2.db",
65 ntohl(tmpcnid), stringify_devino(rqst->dev, rqst->ino));
67 if ((rc = dbif_del(DBIF_IDX_CNID, &pkey, 0)) < 0 ) {
71 LOG(log_error, logtype_cnid, "dbd_update: delete DEVINO %u %s", ntohl(rqst->cnid), db_strerror(errno));
78 buf = pack_cnid_data(rqst);
79 key.data = buf + CNID_DID_OFS;
80 key.size = CNID_DID_LEN + rqst->namelen +1;
81 memset(&pkey, 0, sizeof(pkey));
83 if ((rc = dbif_pget(DBIF_IDX_DIDNAME, &key, &pkey, &data, 0)) < 0) {
88 memcpy(&tmpcnid, pkey.data, sizeof(cnid_t));
89 LOG(log_info, logtype_cnid, "dbd_update: Deleting %u corresponding to did %u name %s from cnid2.db",
90 ntohl(tmpcnid), ntohl(rqst->did), rqst->name);
92 if ((rc = dbif_del(DBIF_IDX_CNID, &pkey, 0)) < 0) {
96 LOG(log_error, logtype_cnid, "dbd_update: delete DIDNAME %u %s", ntohl(rqst->cnid), db_strerror(errno));
103 memset(&key, 0, sizeof(key));
104 key.data = (cnid_t *) &rqst->cnid;
105 key.size = sizeof(rqst->cnid);
107 memset(&data, 0, sizeof(data));
108 /* Make a new entry. */
109 data.data = pack_cnid_data(rqst);
110 memcpy(data.data, &rqst->cnid, sizeof(rqst->cnid));
111 data.size = CNID_HEADER_LEN + rqst->namelen + 1;
113 if (dbif_put(DBIF_IDX_CNID, &key, &data, 0) < 0)
116 LOG(log_info, logtype_cnid, "dbd_update: Updated cnid2.db with dev/ino %s did %u name %s cnid %u",
117 stringify_devino(rqst->dev, rqst->ino),
118 ntohl(rqst->did), rqst->name, ntohl(rqst->cnid));
120 rply->result = CNID_DBD_RES_OK;
125 LOG(log_error, logtype_cnid, "dbd_update: Unable to update CNID %u dev/ino %s, DID %x:%s",
126 ntohl(rqst->cnid), stringify_devino(rqst->ino, rqst->did), rqst->name);
128 rply->result = CNID_DBD_RES_ERR_DB;