]> arthur.barton.de Git - netatalk.git/commitdiff
Merge master
authorFrank Lahm <franklahm@googlemail.com>
Wed, 15 Dec 2010 11:47:54 +0000 (12:47 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Dec 2010 11:47:54 +0000 (12:47 +0100)
etc/cnid_dbd/cmd_dbd.c
etc/cnid_dbd/cmd_dbd.h
etc/cnid_dbd/cmd_dbd_scanvol.c
etc/cnid_dbd/dbif.c
etc/cnid_dbd/dbif.h
etc/cnid_dbd/main.c
etc/cnid_dbd/pack.c

index cb390f321bb886bcdb04ec81c901ad99bb8e719e..0b81b8ccefe3777a89700d3834bcc409d1da9f02 100644 (file)
@@ -82,7 +82,7 @@
 
 int nocniddb = 0;               /* Dont open CNID database, only scan filesystem */
 volatile sig_atomic_t alarmed;
-struct volinfo volinfo;
+struct volinfo volinfo; /* needed by pack.c:idxname() */
 
 static DBD *dbd;
 static int verbose;             /* Logging flag */
index c7449b5067f5d5f26834f2ef46aaaf5c2bd0ebf6..ac6cde42112a9202214c869def22433fec056c0b 100644 (file)
@@ -25,8 +25,6 @@ typedef unsigned int dbd_flags_t;
 
 extern int nocniddb; /* Dont open CNID database, only scan filesystem */
 extern volatile sig_atomic_t alarmed;
-// extern struct volinfo *volinfo;
-extern char cwdbuf[MAXPATHLEN+1];
 
 extern void dbd_log(enum logtype lt, char *fmt, ...);
 extern int cmd_dbd_scanvol(DBD *dbd, struct volinfo *volinfo, dbd_flags_t flags);
index fcc43e46dd8c3fe47ec43c62eb599d8dbc4663f8..240d4150d3312ef2dec686526e541f9b1a3ed0f3 100644 (file)
 #define ADDIR_OK (addir_ok == 0)
 #define ADFILE_OK (adfile_ok == 0)
 
-/* These must be accessible for cmd_dbd_* funcs */
-struct volinfo        *volinfo;
-char                  cwdbuf[MAXPATHLEN+1];
 
-/* Some static vars */
+static struct volinfo *myvolinfo;
+static char           cwdbuf[MAXPATHLEN+1];
 static DBD            *dbd;
 static DBD            *dbd_rebuild;
 static dbd_flags_t    dbd_flags;
@@ -85,22 +83,22 @@ static char *utompath(char *upath)
     u = upath;
     outlen = strlen(upath);
 
-    if ((volinfo->v_casefold & AFPVOL_UTOMUPPER))
+    if ((myvolinfo->v_casefold & AFPVOL_UTOMUPPER))
         flags |= CONV_TOUPPER;
-    else if ((volinfo->v_casefold & AFPVOL_UTOMLOWER))
+    else if ((myvolinfo->v_casefold & AFPVOL_UTOMLOWER))
         flags |= CONV_TOLOWER;
 
-    if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
+    if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
         flags |= CONV__EILSEQ;
     }
 
     /* convert charsets */
-    if ((size_t)-1 == ( outlen = convert_charset(volinfo->v_volcharset,
+    if ((size_t)-1 == ( outlen = convert_charset(myvolinfo->v_volcharset,
                                                  CH_UTF8_MAC,
-                                                 volinfo->v_maccharset,
+                                                 myvolinfo->v_maccharset,
                                                  u, outlen, mpath, MAXPATHLEN, &flags)) ) {
         dbd_log( LOGSTD, "Conversion from %s to %s for %s failed.",
-                 volinfo->v_volcodepage, volinfo->v_maccodepage, u);
+                 myvolinfo->v_volcodepage, myvolinfo->v_maccodepage, u);
         return NULL;
     }
 
@@ -126,17 +124,17 @@ static char *mtoupath(char *mpath)
     }
 
     /* set conversion flags */
-    if (!(volinfo->v_flags & AFPVOL_NOHEX))
+    if (!(myvolinfo->v_flags & AFPVOL_NOHEX))
         flags |= CONV_ESCAPEHEX;
-    if (!(volinfo->v_flags & AFPVOL_USEDOTS))
+    if (!(myvolinfo->v_flags & AFPVOL_USEDOTS))
         flags |= CONV_ESCAPEDOTS;
 
-    if ((volinfo->v_casefold & AFPVOL_MTOUUPPER))
+    if ((myvolinfo->v_casefold & AFPVOL_MTOUUPPER))
         flags |= CONV_TOUPPER;
-    else if ((volinfo->v_casefold & AFPVOL_MTOULOWER))
+    else if ((myvolinfo->v_casefold & AFPVOL_MTOULOWER))
         flags |= CONV_TOLOWER;
 
-    if ((volinfo->v_flags & AFPVOL_EILSEQ)) {
+    if ((myvolinfo->v_flags & AFPVOL_EILSEQ)) {
         flags |= CONV__EILSEQ;
     }
 
@@ -147,11 +145,11 @@ static char *mtoupath(char *mpath)
     outlen = MAXPATHLEN;
 
     if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
-                                                volinfo->v_volcharset,
-                                                volinfo->v_maccharset,
+                                                myvolinfo->v_volcharset,
+                                                myvolinfo->v_maccharset,
                                                 m, inplen, u, outlen, &flags)) ) {
         dbd_log( LOGSTD, "conversion from UTF8-MAC to %s for %s failed.",
-                 volinfo->v_volcodepage, mpath);
+                 myvolinfo->v_volcodepage, mpath);
         return NULL;
     }
 
@@ -224,8 +222,8 @@ static int check_symlink(const char *name, int *adflags)
       and can compare it with the currents volume path
     */
     int i = 0;
-    while (volinfo->v_path[i]) {
-        if ((pathbuf[i] == 0) || (volinfo->v_path[i] != pathbuf[i])) {
+    while (myvolinfo->v_path[i]) {
+        if ((pathbuf[i] == 0) || (myvolinfo->v_path[i] != pathbuf[i])) {
             dbd_log( LOGDEBUG, "extra-share symlink '%s/%s', following", cwdbuf, name);
             return 1;
         }
@@ -306,7 +304,7 @@ static int check_adfile(const char *fname, const struct stat *st)
     else
         adflags = ADFLAGS_DIR;
 
-    adname = volinfo->ad_path(fname, adflags);
+    adname = myvolinfo->ad_path(fname, adflags);
 
     if ((ret = access( adname, F_OK)) != 0) {
         if (errno != ENOENT) {
@@ -322,7 +320,7 @@ static int check_adfile(const char *fname, const struct stat *st)
             return -1;
 
         /* Create ad file */
-        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
 
         if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
             dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
@@ -342,7 +340,7 @@ static int check_adfile(const char *fname, const struct stat *st)
         chmod(adname, st->st_mode);
 #endif
     } else {
-        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
         if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) {
             dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname);
             return -1;
@@ -472,10 +470,10 @@ static int check_addir(int volroot)
     }
 
     /* Check for ".Parent" */
-    if ( (adpar_ok = access(volinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
+    if ( (adpar_ok = access(myvolinfo->ad_path(".", ADFLAGS_DIR), F_OK)) != 0) {
         if (errno != ENOENT) {
             dbd_log(LOGSTD, "Access error on '%s/%s': %s",
-                    cwdbuf, volinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
+                    cwdbuf, myvolinfo->ad_path(".", ADFLAGS_DIR), strerror(errno));
             return -1;
         }
         dbd_log(LOGSTD, "Missing .AppleDouble/.Parent for '%s'", cwdbuf);
@@ -494,7 +492,7 @@ static int check_addir(int volroot)
         }
 
         /* Create ad dir and set name */
-        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
 
         if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad) != 0) {
             dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno));
@@ -515,7 +513,7 @@ static int check_addir(int volroot)
             return -1;
         }
         chown(ADv2_DIRNAME, st.st_uid, st.st_gid);
-        chown(volinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
+        chown(myvolinfo->ad_path(".", ADFLAGS_DIR), st.st_uid, st.st_gid);
     }
 
     return 0;
@@ -534,7 +532,7 @@ static int check_eafile_in_adouble(const char *name)
     char *namep, *namedup = NULL;
 
     /* Check if this is an AFPVOL_EA_AD vol */
-    if (volinfo->v_vfs_ea == AFPVOL_EA_AD) {
+    if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD) {
         /* Does the filename contain "::EA" ? */
         namedup = strdup(name);
         if ((namep = strstr(namedup, "::EA")) == NULL) {
@@ -677,8 +675,8 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
 
     /* Get CNID from ad-file if volume is using AFPVOL_CACHE */
     ad_cnid = 0;
-    if ( (volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
-        ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+    if ( (myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
+        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
         if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
             
             if (dbd_flags & DBD_FLAGS_CLEANUP)
@@ -712,7 +710,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
     memset(&rply, 0, sizeof(struct cnid_dbd_rply));
     rqst.did = did;
     rqst.cnid = ad_cnid;
-    if ( ! (volinfo->v_flags & AFPVOL_NODEV))
+    if ( ! (myvolinfo->v_flags & AFPVOL_NODEV))
         rqst.dev = st->st_dev;
     rqst.ino = st->st_ino;
     rqst.type = S_ISDIR(st->st_mode)?1:0;
@@ -769,12 +767,12 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
                 db_cnid = rply.cnid;
                 dbd_log(LOGSTD, "New CNID for '%s/%s': %u", cwdbuf, name, ntohl(db_cnid));
 
-                if ((volinfo->v_flags & AFPVOL_CACHE)
+                if ((myvolinfo->v_flags & AFPVOL_CACHE)
                     && ADFILE_OK
                     && ( ! (dbd_flags & DBD_FLAGS_SCAN))) {
                     dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
                             cwdbuf, name, ntohl(db_cnid));
-                    ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+                    ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
                     if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
                         dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
                                 cwdbuf, name, strerror(errno));
@@ -808,11 +806,11 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
 
     if ((ad_cnid == 0) && db_cnid) {
         /* in db but zeroID in ad-file, write it to ad-file if AFPVOL_CACHE */
-        if ((volinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
+        if ((myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
             if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
                 dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
                         cwdbuf, name, ntohl(db_cnid));
-                ad_init(&ad, volinfo->v_adouble, volinfo->v_ad_options);
+                ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
                 if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
                     dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
                             cwdbuf, name, strerror(errno));
@@ -956,7 +954,7 @@ static int dbd_readdir(int volroot, cnid_t did)
         }
 
         /* Check EA files */
-        if (volinfo->v_vfs_ea == AFPVOL_EA_AD)
+        if (myvolinfo->v_vfs_ea == AFPVOL_EA_AD)
             check_eafiles(ep->d_name);
 
         /**************************************************************************
@@ -1003,22 +1001,22 @@ static int scanvol(struct volinfo *vi, dbd_flags_t flags)
     }
 
     /* Make this stuff accessible from all funcs easily */
-    volinfo = vi;
+    myvolinfo = vi;
     dbd_flags = flags;
 
     /* Init a fake struct vol with just enough so we can call ea_open and friends */
     volume.v_adouble = AD_VERSION2;
-    volume.v_vfs_ea = volinfo->v_vfs_ea;
+    volume.v_vfs_ea = myvolinfo->v_vfs_ea;
     initvol_vfs(&volume);
 
     /* Run with umask 0 */
     umask(0);
 
     /* Remove trailing slash from volume, chdir to vol */
-    if (volinfo->v_path[strlen(volinfo->v_path) - 1] == '/')
-        volinfo->v_path[strlen(volinfo->v_path) - 1] = 0;
-    strcpy(cwdbuf, volinfo->v_path);
-    chdir(volinfo->v_path);
+    if (myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] == '/')
+        myvolinfo->v_path[strlen(myvolinfo->v_path) - 1] = 0;
+    strcpy(cwdbuf, myvolinfo->v_path);
+    chdir(myvolinfo->v_path);
 
     /* Start recursion */
     if (dbd_readdir(1, htonl(2)) < 0)  /* 2 = volumeroot CNID */
@@ -1128,7 +1126,7 @@ cleanup:
 /*
   Main func called from cmd_dbd.c
 */
-int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
+int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *vi, dbd_flags_t flags)
 {
     int ret = 0;
     struct db_param db_param = { 0 };
@@ -1140,8 +1138,8 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
     dbd = dbd_ref;
 
     /* We only support unicode volumes ! */
-    if ( volinfo->v_volcharset != CH_UTF8) {
-        dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", volinfo->v_volcodepage, volinfo->v_volcharset, CH_UTF8);
+    if ( vi->v_volcharset != CH_UTF8) {
+        dbd_log( LOGSTD, "Not a Unicode volume: %s, %u != %u", vi->v_volcodepage, vi->v_volcharset, CH_UTF8);
         return -1;
     }
 
@@ -1165,7 +1163,7 @@ int cmd_dbd_scanvol(DBD *dbd_ref, struct volinfo *volinfo, dbd_flags_t flags)
         goto exit_cleanup;      /* Got signal, jump from dbd_readdir */
 
     /* scanvol */
-    if ( (scanvol(volinfo, flags)) != 0)
+    if ( (scanvol(vi, flags)) != 0)
         return -1;
 
     if (! nocniddb) {
index dd6439aae0f28d42dd7b08217a64beffe33df4b9..2b5b91ac0f3bcdd7f397b26193840e9f193bbf2d 100644 (file)
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/cdefs.h>
 #include <unistd.h>
-#include <atalk/logger.h>
+
 #include <db.h>
+
+#include <atalk/logger.h>
+#include <atalk/util.h>
+
 #include "db_param.h"
 #include "dbif.h"
 #include "pack.h"
 
 #define DB_ERRLOGFILE "db_errlog"
 
-static char *old_dbfiles[] = {"cnid.db", NULL};
-
-/* --------------- */
-static int upgrade_required(const DBD *dbd)
+/*!
+ * Get the db stamp which is the st_ctime of the file "cnid2.db" and store it in buffer
+ */
+static int dbif_stamp(DBD *dbd, void *buffer, int size)
 {
-    int i;
-    int cwd = -1;
-    int ret = 0;
-    int found = 0;
     struct stat st;
+    int         rc,cwd;
 
-    if ( ! dbd->db_filename)
-        /* in memory db */
-        return 0;
+    if (size < 8)
+        return -1;
 
     /* Remember cwd */
     if ((cwd = open(".", O_RDONLY)) < 0) {
@@ -51,30 +48,140 @@ static int upgrade_required(const DBD *dbd)
     /* chdir to db_envhome */
     if ((chdir(dbd->db_envhome)) != 0) {
         LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));        
-        ret = -1;
-        goto exit;
+        return -1;
     }
 
-    for (i = 0; old_dbfiles[i] != NULL; i++) {
-        if ( !(stat(old_dbfiles[i], &st) < 0) ) {
-            found++;
-            continue;
-        }
-        if (errno != ENOENT) {
-            LOG(log_error, logtype_cnid, "cnid_open: Checking %s gave %s", old_dbfiles[i], strerror(errno));
-            found++;
-        }
+    if ((rc = stat(dbd->db_table[DBIF_CNID].name, &st)) < 0) {
+        LOG(log_error, logtype_cnid, "error stating database %s: %s", dbd->db_table[DBIF_CNID].name, db_strerror(errno));
+        return -1;
     }
 
-exit:
-    if (cwd != -1) {
-        if ((fchdir(cwd)) != 0) {
-            LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));        
-            ret = -1;
-        }
-        close(cwd);
+    LOG(log_maxdebug, logtype_cnid,"stamp: %s", asctime(localtime(&st.st_ctime)));
+
+    memset(buffer, 0, size);
+    memcpy(buffer, &st.st_ctime, sizeof(st.st_ctime));
+
+    if ((fchdir(cwd)) != 0) {
+        LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));        
+        return -1;
+    }
+
+    return 0;
+}
+
+/*!
+ * Inititialize rootinfo key (which has CNID 0 as key)
+ *
+ * This also "stamps" the database, which means storing st.st_ctime of the
+ * "cnid2.db" file in the rootinfo data at the DEV offset
+ *
+ * @param dbd      (rw) database handle
+ * @param version  (r)  database version number
+ *
+ * @returns -1 on error, 0 on success
+ */
+static int dbif_init_rootinfo(DBD *dbd, int version)
+{
+    DBT key, data;
+    uint32_t v;
+    char buf[ROOTINFO_DATALEN];
+
+    LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
+
+    v = version;
+    v = htonl(v);
+
+    memset(&key, 0, sizeof(key));
+    memset(&data, 0, sizeof(data));
+    key.data = ROOTINFO_KEY;
+    key.size = ROOTINFO_KEYLEN;
+    data.data = buf;
+    data.size = ROOTINFO_DATALEN;
+
+    memcpy(buf, ROOTINFO_DATA, ROOTINFO_DATALEN);
+    memcpy(buf + CNID_DID_OFS, &v, sizeof(v));
+    if (dbif_stamp(dbd, buf + CNID_DEV_OFS, CNID_DEV_LEN) < 0)
+        return -1;
+
+    if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
+        return -1;
+
+    return 0;
+}
+
+/*!
+ * Return CNID database version number
+ *
+ * Returns version in *version
+ *
+ * @returns -1 on error, 0 if theres no rootinfo key yet, 1 if *version is returned
+ */
+static int dbif_getversion(DBD *dbd, uint32_t *version)
+{
+    DBT key, data;
+    int ret;
+
+    memset(&key, 0, sizeof(key));
+    memset(&data, 0, sizeof(data));
+    key.data = ROOTINFO_KEY;
+    key.size = ROOTINFO_KEYLEN;
+
+    switch (dbif_get(dbd, DBIF_CNID, &key, &data, 0)) {
+    case 1: /* found */
+        memcpy(version, (char *)data.data + CNID_DID_OFS, sizeof(uint32_t));
+        *version = ntohl(*version);
+        LOG(log_debug, logtype_cnid, "CNID database version %u", *version);
+        ret = 1;
+        break;
+    case 0: /* not found */
+        ret = 0;
+        break;
+    default:
+        ret = -1;
+        break;
     }
-    return (ret < 0 ? ret : found);
+
+    return ret;
+}
+
+/*!
+ * Set CNID database version number
+ *
+ * Initializes rootinfo key as neccessary, as does dbif_getversion
+ * @returns -1 on error, 0 on success
+ */
+static int dbif_setversion(DBD *dbd, uint32_t version)
+{
+    int ret;
+    DBT key, data;
+    uint32_t v;
+
+    LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
+
+    v = version;
+    v = htonl(v);
+
+    memset(&key, 0, sizeof(key));
+    memset(&data, 0, sizeof(data));
+    key.data = ROOTINFO_KEY;
+    key.size = ROOTINFO_KEYLEN;
+
+    if ((ret = dbif_get(dbd, DBIF_CNID, &key, &data, 0)) == -1)
+        return -1;
+    if (ret == 0) {
+        /* No rootinfo key yet, init it */
+        if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
+            return -1;
+        /* Now try again */
+        if (dbif_get(dbd, DBIF_CNID, &key, &data, 0) == -1)
+            return -1;
+    }
+    memcpy((char *)data.data + CNID_DID_OFS, &v, sizeof(v));
+    data.size = ROOTINFO_DATALEN;
+    if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
+        return -1;
+
+    return 0;
 }
 
 /*!
@@ -84,9 +191,9 @@ exit:
  */
 static int dbif_upgrade(DBD *dbd)
 {
-    int version;
+    uint32_t version;
 
-    if ((version = dbif_getversion(dbd)) == -1)
+    if (dbif_getversion(dbd, &version) == -1)
         return -1;
 
     /* 
@@ -199,47 +306,6 @@ exit:
     return ret;
 }
 
-#include <atalk/util.h>
-
-/* --------------- */
-int dbif_stamp(DBD *dbd, void *buffer, int size)
-{
-    struct stat st;
-    int         rc,cwd;
-
-    if (size < 8)
-        return -1;
-
-    /* Remember cwd */
-    if ((cwd = open(".", O_RDONLY)) < 0) {
-        LOG(log_error, logtype_cnid, "error opening cwd: %s", strerror(errno));
-        return -1;
-    }
-
-    /* chdir to db_envhome */
-    if ((chdir(dbd->db_envhome)) != 0) {
-        LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));        
-        return -1;
-    }
-
-    if ((rc = stat(dbd->db_table[DBIF_CNID].name, &st)) < 0) {
-        LOG(log_error, logtype_cnid, "error stating database %s: %s", dbd->db_table[DBIF_CNID].name, db_strerror(errno));
-        return -1;
-    }
-
-    LOG(log_maxdebug, logtype_cnid,"stamp: %s", asctime(localtime(&st.st_ctime)));
-
-    memset(buffer, 0, size);
-    memcpy(buffer, &st.st_ctime, sizeof(st.st_ctime));
-
-    if ((fchdir(cwd)) != 0) {
-        LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));        
-        return -1;
-    }
-
-    return 0;
-}
-
 /* --------------- */
 DBD *dbif_init(const char *envhome, const char *filename)
 {
@@ -290,7 +356,7 @@ DBD *dbif_init(const char *envhome, const char *filename)
 /* 
    We must open the db_env with an absolute pathname, as `dbd` keeps chdir'ing, which
    breaks e.g. bdb logfile-rotation with relative pathnames.
-   But still we use relative paths with upgrade_required() and the DB_ERRLOGFILE
+   But still we use relative paths with DB_ERRLOGFILE
    in order to avoid creating absolute paths by copying. Both have no problem with
    a relative path.
 */
@@ -298,12 +364,6 @@ int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
 {
     int ret;
 
-    /* Refuse to do anything if this is an old version of the CNID database */
-    if (upgrade_required(dbd)) {
-        LOG(log_error, logtype_cnid, "Found version 1 of the CNID database. Please upgrade to version 2");
-        return -1;
-    }
-
     if ((ret = db_env_create(&dbd->db_env, 0))) {
         LOG(log_error, logtype_cnid, "error creating DB environment: %s",
             db_strerror(ret));
@@ -552,9 +612,9 @@ int dbif_open(DBD *dbd, struct db_param *dbp, int reindex)
     if (reindex)
         LOG(log_info, logtype_cnid, "Reindexing name index...");
 
-    int version = CNID_VERSION;
-    if (dbd->db_envhome) {
-        if ((version = dbif_getversion(dbd)) == -1)
+    uint32_t version = CNID_VERSION;
+    if (dbd->db_envhome && !reindex) {
+        if (dbif_getversion(dbd, &version) == -1)
             return -1;
     }
 
@@ -808,122 +868,6 @@ int dbif_del(DBD *dbd, const int dbi, DBT *key, u_int32_t flags)
         return 1;
 }
 
-/*!
- * Inititialize rootinfo key (which has CNID 0 as key)
- *
- * This also "stamps" the database, which means storing st.st_ctime of the
- * "cnid2.db" file in the rootinfo data at the DEV offset
- *
- * @param dbd      (rw) database handle
- * @param version  (r)  database version number
- *
- * @returns -1 on error, 0 on success
- */
-static int dbif_init_rootinfo(DBD *dbd, int version)
-{
-    DBT key, data;
-    uint32_t v;
-    char buf[ROOTINFO_DATALEN];
-
-    LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
-
-    v = version;
-    v = htonl(v);
-
-    memset(&key, 0, sizeof(key));
-    memset(&data, 0, sizeof(data));
-    key.data = ROOTINFO_KEY;
-    key.size = ROOTINFO_KEYLEN;
-    data.data = buf;
-    data.size = ROOTINFO_DATALEN;
-
-    memcpy(buf, ROOTINFO_DATA, ROOTINFO_DATALEN);
-    memcpy(buf + CNID_DID_OFS, &v, sizeof(v));
-    if (dbif_stamp(dbd, buf + CNID_DEV_OFS, CNID_DEV_LEN) < 0)
-        return -1;
-
-    if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
-        return -1;
-
-    return 0;
-}
-
-/*!
- * Initialize or return CNID database version number
- *
- * Calls dbif_init_rootinfo if the rootinfo key does not exist yet
- *
- * @returns -1 on error, version number otherwise
- */
-int dbif_getversion(DBD *dbd)
-{
-    DBT key, data;
-    uint32_t version;
-    int ret;
-
-    memset(&key, 0, sizeof(key));
-    memset(&data, 0, sizeof(data));
-    key.data = ROOTINFO_KEY;
-    key.size = ROOTINFO_KEYLEN;
-
-    switch (dbif_get(dbd, DBIF_CNID, &key, &data, 0)) {
-    case 1: /* found */
-        memcpy(&version, (char *)data.data + CNID_DID_OFS, sizeof(version));
-        version = ntohl(version);
-        LOG(log_debug, logtype_cnid, "CNID database version %u", version);
-        ret = version;
-        break;
-    case 0: /* not found */
-        if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
-            return -1;
-        ret = CNID_VERSION;
-        break;
-    default:
-        return -1;
-    }
-    return ret;
-}
-
-/*!
- * Set CNID database version number
- *
- * Initializes rootinfo key as neccessary, as does dbif_getversion
- * @returns -1 on error, version number otherwise
- */
-int dbif_setversion(DBD *dbd, int version)
-{
-    int ret;
-    DBT key, data;
-    uint32_t v;
-
-    LOG(log_debug, logtype_cnid, "Setting CNID database version to %u", version);
-
-    v = version;
-    v = htonl(v);
-
-    memset(&key, 0, sizeof(key));
-    memset(&data, 0, sizeof(data));
-    key.data = ROOTINFO_KEY;
-    key.size = ROOTINFO_KEYLEN;
-
-    if ((ret = dbif_get(dbd, DBIF_CNID, &key, &data, 0)) == -1)
-        return -1;
-    if (ret == 0) {
-        /* No rootinfo key yet, init it */
-        if (dbif_init_rootinfo(dbd, CNID_VERSION) != 0)
-            return -1;
-        /* Now try again */
-        if (dbif_get(dbd, DBIF_CNID, &key, &data, 0) == -1)
-            return -1;
-    }
-    memcpy((char *)data.data + CNID_DID_OFS, &v, sizeof(v));
-    data.size = ROOTINFO_DATALEN;
-    if (dbif_put(dbd, DBIF_CNID, &key, &data, 0) < 0)
-        return -1;
-
-    return 0;
-}
-
 /*!
  * Search the database by name
  *
index 033fc72ea16875d298fdf2ca0ee385119d745c3d..9c886fb1f9d60e960c099cb0b5c4920ab2af575c 100644 (file)
@@ -90,15 +90,12 @@ extern int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags);
 extern int dbif_open(DBD *dbd, struct db_param *dbp, int reindex);
 extern int dbif_close(DBD *dbd);
 extern int dbif_env_remove(const char *path);
-extern int dbif_getversion(DBD *dbd);
-extern int dbif_setversion(DBD *dbd, int);
 
 extern int dbif_get(DBD *, const int, DBT *, DBT *, u_int32_t);
 extern int dbif_pget(DBD *, const int, DBT *, DBT *, DBT *, u_int32_t);
 extern int dbif_put(DBD *, const int, DBT *, DBT *, u_int32_t);
 extern int dbif_del(DBD *, const int, DBT *, u_int32_t);
 extern int dbif_count(DBD *, const int, u_int32_t *);
-extern int dbif_stamp(DBD *, void *, int);
 extern int dbif_search(DBD *dbd, DBT *key, char *resbuf);
 extern int dbif_copy_rootinfokey(DBD *srcdbd, DBD *destdbd);
 extern int dbif_txn_begin(DBD *);
index 48b1d5075f34ccbea2a2153fd68770a0f59e92c9..ec0793cb9ceb2beebe4c1c350408fe19eb97ee38 100644 (file)
@@ -47,7 +47,7 @@
  */
 #define DBOPTIONS (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER)
 
-/* Global */
+/* Global, needed by pack.c:idxname() */
 struct volinfo volinfo;
 
 static DBD *dbd;
index 159e62b8c6e14cb502bc0e59b0c78464b7439b33..2612469415eaa5582d71712bca82dc5b63c33770 100644 (file)
@@ -78,10 +78,9 @@ int devino(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
 /* --------------- */
 int idxname(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
 {
-    char buffer[MAXPATHLEN +2];
+    static char buffer[MAXPATHLEN +2];
     uint16_t flags = CONV_TOLOWER;
     memset(skey, 0, sizeof(DBT));
-    skey->data = (char *)pdata->data + CNID_NAME_OFS;
 
     if (convert_charset(volinfo.v_volcharset,
                         volinfo.v_volcharset,