]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/dbd_lookup.c
Remove a lot of warning, from cvs HEAD
[netatalk.git] / etc / cnid_dbd / dbd_lookup.c
index f08ed64e822cd55e3113eb66ce6ef7005e83d96e..7b75328577db02af5087f25d4e254e37932406f3 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * $Id: dbd_lookup.c,v 1.1.4.2 2003-10-21 16:24:58 didg Exp $
+ * $Id: dbd_lookup.c,v 1.1.4.7.2.1 2005-09-27 10:40:41 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
- * All Rights Reserved.  See COPYRIGHT.
+ * All Rights Reserved.  See COPYING.
  */
 
 #ifdef HAVE_CONFIG_H
 #include <stdio.h>
 #include <string.h>
 #include <sys/param.h>
-#include <atalk/logger.h>
 #include <errno.h>
-
-#ifdef HAVE_DB4_DB_H
-#include <db4/db.h>
-#else
-#include <db.h>
-#endif
 #include <netatalk/endian.h>
+#include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
 #include "pack.h"
 
 int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
 {
-    char *buf;
+    unsigned char *buf;
     DBT key, devdata, diddata;
-    dev_t  dev;
-    ino_t  ino;
+    char dev[CNID_DEV_LEN];
+    char ino[CNID_INO_LEN];
     int devino = 1, didname = 1; 
     int rc;
     cnid_t id_devino, id_didname;
@@ -55,8 +49,9 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     rply->cnid = 0;
     
     buf = pack_cnid_data(rqst); 
-    memcpy(&dev, buf + CNID_DEV_OFS, sizeof(dev));
-    memcpy(&ino, buf + CNID_INO_OFS, sizeof(ino));
+    memcpy(dev, buf + CNID_DEV_OFS, CNID_DEV_LEN);
+    /* FIXME: ino is not needed later on, remove? */
+    memcpy(ino, buf + CNID_INO_OFS, CNID_INO_LEN);
 
     /* Look for a CNID.  We have two options: dev/ino or did/name.  If we
        only get a match in one of them, that means a file has moved. */
@@ -74,10 +69,11 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     }
     else {
         memcpy(&id_devino, devdata.data, sizeof(rply->cnid));
-        memcpy(&type_devino, devdata.data +CNID_TYPE_OFS, sizeof(type_devino));
+        memcpy(&type_devino, (char *)devdata.data +CNID_TYPE_OFS, sizeof(type_devino));
         type_devino = ntohl(type_devino);
     }
     
+    /* FIXME: This second call to pack_cnid_data() is redundant, any reason it is here? */
     buf = pack_cnid_data(rqst); 
     key.data = buf +CNID_DID_OFS;
     key.size = CNID_DID_LEN + rqst->namelen + 1;
@@ -93,18 +89,26 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     }
     else {
         memcpy(&id_didname, diddata.data, sizeof(rply->cnid));
-        memcpy(&type_didname, diddata.data +CNID_TYPE_OFS, sizeof(type_didname));
+        memcpy(&type_didname, (char *)diddata.data +CNID_TYPE_OFS, sizeof(type_didname));
         type_didname = ntohl(type_didname);
     }
     
     if (!devino && !didname) {  
         /* not found */
+#ifdef DEBUG
+       LOG(log_info, logtype_cnid, "cnid_lookup: dev/ino %s did %u name %s neither in devino nor didname", 
+           stringify_devino(rqst->dev, rqst->ino), ntohl(rqst->did), rqst->name);
+#endif
         rply->result = CNID_DBD_RES_NOTFOUND;
         return 1;
     }
 
     if (devino && didname && id_devino == id_didname && type_devino == rqst->type) {
         /* the same */
+#ifdef DEBUG
+       LOG(log_info, logtype_cnid, "cnid_lookup: Looked up dev/ino %s did %u name %s as %u", 
+           stringify_devino(rqst->dev, rqst->ino), ntohl(rqst->did), rqst->name, ntohl(id_didname));
+#endif
         rply->cnid = id_didname;
         rply->result = CNID_DBD_RES_OK;
         return 1;
@@ -116,7 +120,7 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
          * if it's the same dev or not the same type
          * just delete it
         */
-        if (!memcmp(&dev, (char *)diddata.data + CNID_DEV_OFS, sizeof(dev)) ||
+        if (!memcmp(dev, (char *)diddata.data + CNID_DEV_OFS, CNID_DEV_LEN) ||
                    type_didname != rqst->type) {
             if (dbd_delete(rqst, rply) < 0) {
                 return -1;
@@ -151,8 +155,8 @@ int dbd_lookup(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
         rply->cnid = rqst->cnid;
     }
 #ifdef DEBUG
-    LOG(log_info, logtype_cnid, "cnid_lookup: Looked up did %u, name %s, as %u (needed update)", 
-    ntohl(rqst->did), rqst->name, ntohl(rply->cnid));
+    LOG(log_info, logtype_cnid, "cnid_lookup: Looked up dev/ino %s did %u name %s as %u (needed update)", 
+       stringify_devino(rqst->dev, rqst->ino), ntohl(rqst->did), rqst->name, ntohl(rply->cnid));
 #endif
     return rc;
 }