3 * Copyright (C) Joerg Lenneis 2005
4 * All Rights Reserved. See COPYING.
9 #endif /* HAVE_CONFIG_H */
13 #include <arpa/inet.h>
15 #include <atalk/logger.h>
16 #include <atalk/cnid_bdb_private.h>
23 /* rebuild_add: Enter all fields (including the CNID) into the database and
24 update the current cnid, for emergency repairs. */
26 int dbd_rebuild_add(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
31 memset(&key, 0, sizeof(key));
32 memset(&data, 0, sizeof(data));
36 key.data = &rqst->cnid;
37 key.size = sizeof(cnid_t);
39 data.data = pack_cnid_data(rqst);
40 data.size = CNID_HEADER_LEN + rqst->namelen + 1;
41 memcpy(data.data, &rqst->cnid, sizeof(cnid_t));
43 /* FIXME: In cnid_cdb.c Bjoern does a lookup here and returns the CNID found if sucessful. Why? */
45 if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0) {
46 rply->result = CNID_DBD_RES_ERR_DB;
50 LOG(log_debug, logtype_cnid,
51 "dbd_rebuild_add(CNID: %u, did: %u, name: \"%s\", dev/ino:0x%llx/0x%llx): success",
52 ntohl(rqst->cnid), ntohl(rqst->did), rqst->name,
53 (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
55 key.data = ROOTINFO_KEY;
56 key.size = ROOTINFO_KEYLEN;
58 if (dbif_get(dbd, DBIF_CNID, &key, &data, 0) <= 0) {
59 /* FIXME: If we cannot find ROOTINFO_KEY, should this be considered
60 fatal or should we just return 0 and roll back? */
61 rply->result = CNID_DBD_RES_ERR_DB;
65 memcpy(&tmp, (char *) data.data + CNID_TYPE_OFS, sizeof(cnid_t));
67 id = ntohl(rqst->cnid);
70 data.size = ROOTINFO_DATALEN;
71 memcpy((char *) data.data + CNID_TYPE_OFS, &rqst->cnid, sizeof(cnid_t));
72 if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0) {
73 rply->result = CNID_DBD_RES_ERR_DB;
78 rply->cnid = rqst->cnid;
79 rply->result = CNID_DBD_RES_OK;