]> arthur.barton.de Git - netatalk.git/blob - etc/cnid_dbd/dbd_search.c
5190c24b12949b66fc83ae66ad221c6ea7a6e1c6
[netatalk.git] / etc / cnid_dbd / dbd_search.c
1 /*
2  * Copyright (C) Frank Lahm 2010
3  * All Rights Reserved.  See COPYING.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif /* HAVE_CONFIG_H */
9
10 #include <string.h>
11 #include <errno.h>
12 #include <netatalk/endian.h>
13 #include <atalk/logger.h>
14 #include <atalk/cnid_dbd_private.h>
15
16 #include "dbif.h"
17 #include "dbd.h"
18 #include "pack.h"
19
20 int dbd_search(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
21 {
22     DBT key;
23     int rc;
24     static char resbuf[DBD_MAX_SRCH_RPLY_PAYLOAD];
25     memset(&key, 0, sizeof(key));
26     rply->namelen = 0;
27
28     key.data = rqst->name;
29     key.size = rqst->namelen;
30
31     if ((rc = dbif_del(dbd, DBIF_IDX_DEVINO, &key, 0)) < 0) {
32         LOG(log_error, logtype_cnid, "dbd_delete: Unable to delete entry for dev/ino: 0x%llx/0x%llx",
33             (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
34         rply->result = CNID_DBD_RES_ERR_DB;
35         return -1;
36     }
37     if (rc) {
38         LOG(log_debug, logtype_cnid, "cnid_delete: deleted dev/ino: 0x%llx/0x%llx",
39             (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
40         rply->result = CNID_DBD_RES_OK;
41     } else {
42         LOG(log_debug, logtype_cnid, "cnid_delete: dev/ino: 0x%llx/0x%llx not in database", 
43             (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
44         rply->result = CNID_DBD_RES_NOTFOUND;
45     }
46
47     return 1;
48 }