]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/cmd_dbd.c
Set cachesize for rebuild db
[netatalk.git] / etc / cnid_dbd / cmd_dbd.c
index 62df7c019389dc094aa112c5c4a4595c740d7ee8..78e5cd4763493312c741f8068bca091d7529a136 100644 (file)
@@ -1,5 +1,5 @@
 /* 
-   $Id: cmd_dbd.c,v 1.13 2009-10-14 01:38:28 didg Exp $
+   $Id: cmd_dbd.c,v 1.21 2009-12-21 06:41:09 franklahm Exp $
 
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
@@ -91,7 +91,7 @@ static int exclusive;           /* Exclusive volume access */
 static struct db_param db_param = {
     NULL,                       /* Volume dirpath */
     1,                          /* bdb logfile autoremove */
-    16384,                      /* bdb cachesize */
+    64 * 1024 * 1024,           /* bdb cachesize */
     -1,                         /* not used ... */
     -1,
     "",
@@ -266,9 +266,8 @@ static void usage (void)
            "   -x rebuild indexes (just for completeness, mostly useless!)\n"
            "   -v verbose\n\n"
            "WARNING:\n"
-           "If you want/need to run an -r -f rebuild after adding 'cachecnid' to a volume configuration,\n"
-           "you must run a rebuild with -r alone at first in order to sync all existing CNIDs from the db\n"
-           "to the AppleDouble files!\n"
+           "For -r -f restore of the CNID database from the adouble files, the CNID must of course\n"
+           "be synched to them files first with a plain -r rebuild !\n"
         );
 }
 
@@ -285,6 +284,8 @@ int main(int argc, char **argv)
         usage();
         exit(EXIT_FAILURE);
     }
+    /* Inhereting perms in ad_mkdir etc requires this */
+    ad_setfuid(0);
 
     while ((c = getopt(argc, argv, ":dsnruvxife")) != -1) {
         switch(c) {
@@ -352,9 +353,9 @@ int main(int argc, char **argv)
 
     /* Setup logging. Should be portable among *NIXes */
     if (!verbose)
-        setuplog("default log_info /dev/tty");
+        setuplog("console log_info /dev/tty");
     else
-        setuplog("default log_debug /dev/tty");
+        setuplog("console log_debug /dev/tty");
 
     /* Load .volinfo file */
     if (loadvolinfo(volpath, &volinfo) == -1) {
@@ -366,6 +367,12 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
+    /* Sanity checks to ensure we can touch this volume */
+    if (volinfo.v_vfs_ea != AFPVOL_EA_AD && volinfo.v_vfs_ea != AFPVOL_EA_SYS) {
+        dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", volinfo.v_vfs_ea);
+        exit(EXIT_FAILURE);        
+    }
+
     /* Put "/.AppleDB" at end of volpath, get path from volinfo file */
     if ( (strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > (PATH_MAX - 1) ) {
         dbd_log( LOGSTD, "Volume pathname too long");
@@ -374,6 +381,22 @@ int main(int argc, char **argv)
     strncpy(dbpath, volinfo.v_dbpath, PATH_MAX - 9 - 1);
     strcat(dbpath, "/.AppleDB");
 
+    /* Check or create dbpath */
+    int dbdirfd = open(dbpath, O_RDONLY);
+    if (dbdirfd == -1 && errno == ENOENT) {
+        if (errno == ENOENT) {
+            if ((mkdir(dbpath, 0755)) != 0) {
+                dbd_log( LOGSTD, "Can't create .AppleDB for \"%s\": %s", dbpath, strerror(errno));
+                exit(EXIT_FAILURE);
+            }
+        } else {
+            dbd_log( LOGSTD, "Somethings wrong with .AppleDB for \"%s\", giving up: %s", dbpath, strerror(errno));
+            exit(EXIT_FAILURE);
+        }
+    } else {
+        close(dbdirfd);
+    }
+
     /* 
        Before we do anything else, check if there is an instance of cnid_dbd
        running already and silently exit if yes.
@@ -411,7 +434,7 @@ int main(int argc, char **argv)
         if (exclusive)
             dbd_log( LOGDEBUG, "Finished recovery.");
 
-        if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
+        if (dbif_open(dbd, NULL, rebuildindexes) < 0) {
             dbif_close(dbd);
             goto exit_failure;
         }
@@ -427,7 +450,7 @@ int main(int argc, char **argv)
         if (dbif_dump(dbd, dumpindexes) < 0) {
             dbd_log( LOGSTD, "Error dumping database");
         }
-    } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) {
+    } else if ((rebuild && ! nocniddb) || scan) {
         if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) {
             dbd_log( LOGSTD, "Error repairing database.");
         }