2 * Copyright (C) Joerg Lenneis 2003
3 * Copyright (C) Frank Lahm 2009,2010
4 * All Rights Reserved. See COPYING.
9 #endif /* HAVE_CONFIG_H */
13 #include <atalk/logger.h>
14 #include <arpa/inet.h>
16 #include <atalk/cnid_bdb_private.h>
25 cnid_update: takes the given cnid and updates the metadata.
26 First, delete given CNID, then re-insert.
29 int dbd_update(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
33 memset(&key, 0, sizeof(key));
34 memset(&data, 0, sizeof(data));
37 /* Try to wipe everything, also using the indexes */
38 if (dbd_delete(dbd, rqst, rply, DBIF_CNID) < 0)
40 if (dbd_delete(dbd, rqst, rply, DBIF_IDX_DEVINO) < 0)
42 if (dbd_delete(dbd, rqst, rply, DBIF_IDX_DIDNAME) < 0)
45 /* Make a new entry. */
46 key.data = &rqst->cnid;
47 key.size = sizeof(rqst->cnid);
48 data.data = pack_cnid_data(rqst);
49 data.size = CNID_HEADER_LEN + rqst->namelen + 1;
50 memcpy(data.data, &rqst->cnid, sizeof(rqst->cnid));
52 if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
55 LOG(log_debug, logtype_cnid, "dbd_update: Updated dbd with dev/ino: 0x%llx/0x%llx, did: %u, name: %s, cnid: %u",
56 (unsigned long long)rqst->dev, (unsigned long long)rqst->ino, ntohl(rqst->did), rqst->name, ntohl(rqst->cnid));
58 rply->result = CNID_DBD_RES_OK;
62 LOG(log_error, logtype_cnid, "dbd_update: Unable to update CNID: %u, dev/ino: 0x%llx/0x%llx, DID: %u: %s",
63 ntohl(rqst->cnid), (unsigned long long)rqst->dev, (unsigned long long)rqst->ino, ntohl(rqst->did), rqst->name);
65 rply->result = CNID_DBD_RES_ERR_DB;