2 * $Id: cnid_tdb_lookup.c,v 1.2 2005-04-28 20:50:02 bfernhomberg Exp $
9 #ifdef CNID_BACKEND_TDB
12 #include <atalk/logger.h>
14 cnid_t cnid_tdb_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did, char *name, const int len)
17 struct _cnid_tdb_private *db;
18 TDB_DATA key, devdata, diddata;
19 int devino = 1, didname = 1;
22 if (!cdb || !(db = cdb->_private) || !st || !name) {
26 if ((buf = make_tdb_data(st, did, name, len)) == NULL) {
27 LOG(log_error, logtype_default, "tdb_lookup: Pathname is too long");
31 memset(&key, 0, sizeof(key));
32 memset(&devdata, 0, sizeof(devdata));
33 memset(&diddata, 0, sizeof(diddata));
35 /* Look for a CNID. We have two options: dev/ino or did/name. If we
36 * only get a match in one of them, that means a file has moved. */
38 key.dsize = TDB_DEVINO_LEN;
39 devdata = tdb_fetch(db->tdb_devino, key);
44 key.dptr = buf + TDB_DEVINO_LEN;
45 key.dsize = TDB_DID_LEN + len + 1;
46 diddata = tdb_fetch(db->tdb_didname, key);
50 /* Set id. Honor did/name over dev/ino as dev/ino isn't necessarily
53 memcpy(&id, diddata.dptr, sizeof(id));
56 memcpy(&id, devdata.dptr, sizeof(id));
60 /* Either entries are in both databases or neither of them. */
61 if ((devino && didname) || !(devino || didname)) {
65 /* Fix up the database. */
66 cnid_tdb_update(cdb, id, st, did, name, len);