]> arthur.barton.de Git - netatalk.git/commitdiff
Add conversion option to dbd
authorFrank Lahm <franklahm@googlemail.com>
Tue, 21 Feb 2012 14:15:44 +0000 (15:15 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 21 Feb 2012 14:15:44 +0000 (15:15 +0100)
etc/cnid_dbd/cmd_dbd.c
etc/cnid_dbd/cmd_dbd.h
etc/cnid_dbd/cmd_dbd_scanvol.c
etc/cnid_dbd/main.c
include/atalk/netatalk_conf.h
libatalk/adouble/ad_open.c
libatalk/util/netatalk_conf.c

index 8eb9c57672006d1544ac7fdd1c0b96688e2d94ba..d197efd5d76d98cda8df018fd967e8619747b6d6 100644 (file)
@@ -129,48 +129,29 @@ static void set_signal(void)
 static void usage (void)
 {
     printf("dbd (Netatalk %s)\n"
-           "Usage: dbd [-etvxF] -d [-i] | -s [-c|-n]| -r [-c|-f] | -u <path to netatalk volume>\n"
+           "Usage: dbd [-CeFtvx] -d [-i] | -s [-c|-n]| -r [-c|-f] | -u <path to netatalk volume>\n"
            "dbd can dump, scan, reindex and rebuild Netatalk dbd CNID databases.\n"
            "dbd must be run with appropiate permissions i.e. as root.\n\n"
            "Main commands are:\n"
            "   -d Dump CNID database\n"
            "      Option: -i dump indexes too\n\n"
            "   -s Scan volume:\n"
-           "      1. Compare CNIDs in database with volume\n"
-           "      2. Check if .AppleDouble dirs exist\n"
-           "      3. Check if  AppleDouble file exist\n"
-           "      4. Report orphaned AppleDouble files\n"
-           "      5. Check for directories inside AppleDouble directories\n"
-           "      6. Check name encoding by roundtripping, log on error\n"
-           "      7. Check for orphaned CNIDs in database (requires -e)\n"
-           "      8. Open and close adouble files\n"
            "      Options: -c Don't check .AppleDouble stuff, only ckeck orphaned.\n"
            "               -n Don't open CNID database, skip CNID checks.\n\n"
            "   -r Rebuild volume:\n"
-           "      1. Sync CNIDSs in database with volume\n"
-           "      2. Make sure .AppleDouble dir exist, create if missing\n"
-           "      3. Make sure AppleDouble file exists, create if missing\n"
-           "      4. Delete orphaned AppleDouble files\n"
-           "      5. Check for directories inside AppleDouble directories\n"
-           "      6. Check name encoding by roundtripping, log on error\n"
-           "      7. Check for orphaned CNIDs in database (requires -e)\n"
-           "      8. Open and close adouble files\n"
            "      Options: -c Don't create .AppleDouble stuff, only cleanup orphaned.\n"
            "               -f wipe database and rebuild from IDs stored in AppleDouble\n"
-           "                  files, only available for volumes without 'nocnidcache'\n"
-           "                  option. Implies -e.\n\n"
+           "                  metadata file or EA. Implies -e.\n\n"
            "   -u Upgrade:\n"
            "      Opens the database which triggers any necessary upgrades,\n"
            "      then closes and exits.\n\n"
            "General options:\n"
+           "   -C convert from adouble:v2 to adouble:ea (use with -r)\n"
            "   -F location of the afp.conf config file\n"
            "   -e only work on inactive volumes and lock them (exclusive)\n"
            "   -x rebuild indexes (just for completeness, mostly useless!)\n"
            "   -t show statistics while running\n"
            "   -v verbose\n\n"
-           "WARNING:\n"
-           "For -r -f restore of the CNID database from the adouble files,\n"
-           "the CNID must of course be synched to them files first with a plain -r rebuild!\n"
            , VERSION
         );
 }
@@ -192,11 +173,14 @@ int main(int argc, char **argv)
     /* Inhereting perms in ad_mkdir etc requires this */
     ad_setfuid(0);
 
-    while ((c = getopt(argc, argv, ":cdefFinrstuvx")) != -1) {
+    while ((c = getopt(argc, argv, ":cCdefFinrstuvx")) != -1) {
         switch(c) {
         case 'c':
             flags |= DBD_FLAGS_CLEANUP;
             break;
+        case 'C':
+            flags |= DBD_FLAGS_V2TOEA;
+            break;
         case 'd':
             dump = 1;
             break;
@@ -288,6 +272,12 @@ int main(int argc, char **argv)
         dbd_log( LOGSTD, "Couldn't find volume for '%s'", volpath);
         exit(EXIT_FAILURE);
     }
+
+    if (load_charset(vol) != 0) {
+        dbd_log( LOGSTD, "Couldn't load charsets for '%s'", volpath);
+        exit(EXIT_FAILURE);
+    }
+
     pack_setvol(vol);
 
     if (vol->v_adouble == AD_VERSION_EA)
@@ -299,6 +289,12 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
+    /* -C v2 to ea conversion only on adouble:ea volumes */
+    if ((flags & DBD_FLAGS_V2TOEA) && (vol->v_adouble!= AD_VERSION_EA)) {
+        dbd_log( LOGSTD, "Can't run adouble:v2 to adouble:ea conversion because not an adouble:ea volume");
+        exit(EXIT_FAILURE);
+    }
+
     /* Sanity checks to ensure we can touch this volume */
     if (vol->v_vfs_ea != AFPVOL_EA_AD && vol->v_vfs_ea != AFPVOL_EA_SYS) {
         dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", vol->v_vfs_ea);
index e94c861873bdd2acdb9f77041211838d5ab22555..efec636b482e464f40a1bda7ebc469dd420acb70 100644 (file)
@@ -15,6 +15,7 @@ typedef unsigned int dbd_flags_t;
 #define DBD_FLAGS_EXCL     (1 << 2)
 #define DBD_FLAGS_CLEANUP  (1 << 3) /* Dont create AD stuff, but cleanup orphaned */
 #define DBD_FLAGS_STATS    (1 << 4)
+#define DBD_FLAGS_V2TOEA   (1 << 5) /* Convert adouble:v2 to adouble:ea */
 
 #define ADv2_DIRNAME ".AppleDouble"
 
index 90421a9395f143da845abd58c820e724d493822d..9685c3d219c341a81aa48de436abd2e3f3bb4ca0 100644 (file)
@@ -218,13 +218,25 @@ static int check_adfile(const char *fname, const struct stat *st)
     struct adouble ad;
     const char *adname;
 
-    if (myvol->v_adouble == AD_VERSION_EA)
+    if (myvol->v_adouble == AD_VERSION_EA) {
+        if (!(dbd_flags & DBD_FLAGS_V2TOEA))
+            return 0;
+        if (ad_convert(fname, st, myvol) != 0) {
+            switch (errno) {
+            case ENOENT:
+                break;
+            default:
+                dbd_log(LOGSTD, "Conversion error for \"%s/%s\": %s", cwdbuf, fname, strerror(errno));
+                break;
+            }
+        }
         return 0;
-
+    }
+    
     if (dbd_flags & DBD_FLAGS_CLEANUP)
         return 0;
 
-    if (S_ISREG(st->st_mode))
+    if (S_ISDIR(st->st_mode))
         adflags |= ADFLAGS_DIR;
 
     adname = myvol->ad_path(fname, adflags);
@@ -521,10 +533,10 @@ static int read_addir(void)
     struct dirent *ep;
     struct stat st;
 
-    if (myvol->v_adouble == AD_VERSION_EA)
-        return 0;
-
     if ((chdir(ADv2_DIRNAME)) != 0) {
+        if (myvol->v_adouble == AD_VERSION_EA) {
+            return 0;
+        }
         dbd_log(LOGSTD, "Couldn't chdir to '%s/%s': %s",
                 cwdbuf, ADv2_DIRNAME, strerror(errno));
         return -1;
@@ -803,7 +815,7 @@ static int dbd_readdir(int volroot, cnid_t did)
             return -1;
 
     /* Check AppleDouble files in AppleDouble folder, but only if it exists or could be created */
-    if (myvol->v_adouble == AD_VERSION2 && ADDIR_OK)
+    if (ADDIR_OK)
         if ((read_addir()) != 0)
             if ( ! (dbd_flags & DBD_FLAGS_SCAN))
                 /* Fatal on rebuild run, continue if only scanning ! */
@@ -958,13 +970,25 @@ static int dbd_readdir(int volroot, cnid_t did)
     /*
       Use results of previous checks
     */
-
+    if ((myvol->v_adouble == AD_VERSION_EA) && (dbd_flags & DBD_FLAGS_V2TOEA)) {
+        if (rmdir(ADv2_DIRNAME) != 0) {
+            switch (errno) {
+            case ENOENT:
+                break;
+            default:
+                dbd_log(LOGSTD, "Error removing adouble dir \"%s/%s\": %s", cwdbuf, ADv2_DIRNAME, strerror(errno));
+                break;
+            }
+        }
+    }
     closedir(dp);
     return ret;
 }
 
 static int scanvol(struct vol *vol, dbd_flags_t flags)
 {
+    struct stat st;
+
     /* Make this stuff accessible from all funcs easily */
     myvol = vol;
     dbd_flags = flags;
@@ -975,6 +999,20 @@ static int scanvol(struct vol *vol, dbd_flags_t flags)
     strcpy(cwdbuf, myvol->v_path);
     chdir(myvol->v_path);
 
+    if ((myvol->v_adouble == AD_VERSION_EA) && (dbd_flags & DBD_FLAGS_V2TOEA)) {
+        if (lstat(".", &st) != 0)
+            return -1;
+        if (ad_convert(".", &st, vol) != 0) {
+            switch (errno) {
+            case ENOENT:
+                break;
+            default:
+                dbd_log(LOGSTD, "Conversion error for \"%s\": %s", myvol->v_path, strerror(errno));
+                break;
+            }
+        }
+    }
+
     /* Start recursion */
     if (dbd_readdir(1, htonl(2)) < 0)  /* 2 = volumeroot CNID */
         return -1;
index 9b5fd7856a0e79565842c27fb83e08e03f046564..fea36b81317376e2ba931b1c307bcd618c290ced 100644 (file)
@@ -319,7 +319,7 @@ int main(int argc, char *argv[])
 
     EC_ZERO( load_volumes(&obj, NULL) );
     EC_NULL( vol = getvolbypath(volpath) );
-
+    EC_ZERO( load_charset(vol) );
     pack_setvol(vol);
 
     EC_NULL( dbpath = bfromcstr(vol->v_dbpath) );
index a8d525f5726874d290e470f03556c8276ba03f38..9c189e6385b3b934407f2df6bb254c11d2643185 100644 (file)
@@ -22,6 +22,7 @@
 
 extern int        afp_config_parse(AFPObj *obj);
 
+extern int        load_charset(struct vol *vol);
 extern int        load_volumes(AFPObj *obj, void (*delvol_fn)(struct vol *));
 extern void       unload_volumes(AFPObj *obj);
 extern struct vol *getvolumes(void);
index 8d0e6f4b3e942d13acbdf87302a34f9288a84b66..c6aa776da7244bf83de2b8749450f0b499aa606a 100644 (file)
@@ -806,6 +806,7 @@ static int ad_conv_v22ea_hf(const char *path, const struct stat *sp, const struc
 EC_CLEANUP:
     EC_ZERO_LOG( ad_close(&adv2, ADFLAGS_HF | ADFLAGS_SETSHRMD) );
     EC_ZERO_LOG( ad_close(&adea, ADFLAGS_HF | ADFLAGS_SETSHRMD) );
+    LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): END: %d", fullpathname(path), ret);
     EC_EXIT;
 }
 
@@ -839,6 +840,7 @@ static int ad_conv_v22ea_rf(const char *path, const struct stat *sp, const struc
 EC_CLEANUP:
     EC_ZERO_LOG( ad_close(&adv2, ADFLAGS_HF | ADFLAGS_RF) );
     EC_ZERO_LOG( ad_close(&adea, ADFLAGS_HF | ADFLAGS_RF) );
+    LOG(log_debug, logtype_default,"ad_conv_v22ea_rf(\"%s\"): END: %d", fullpathname(path), ret);
     EC_EXIT;
 }
 
@@ -1862,6 +1864,8 @@ int ad_convert(const char *path, const struct stat *sp, const struct vol *vol)
     const char *adpath;
     int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0;
 
+    LOG(log_debug, logtype_default,"ad_convert(\"%s\"): BEGIN", fullpathname(path));
+
     if (!(vol->v_adouble == AD_VERSION_EA) || (vol->v_flags & AFPVOL_NOV2TOEACONV))
         goto EC_CLEANUP;
 
@@ -1877,6 +1881,7 @@ int ad_convert(const char *path, const struct stat *sp, const struct vol *vol)
     unbecome_root();
 
 EC_CLEANUP:
+    LOG(log_debug, logtype_default,"ad_convert(\"%s\"): END: %d", fullpathname(path), ret);
     EC_EXIT;
 }
 
index ab5e8787ec7e3eb7914e4257758bf48ab866a040..38ba664358e42fcdca23d5d8edf9859bcf0003dc 100644 (file)
@@ -606,9 +606,13 @@ static int creatvol(AFPObj *obj,
 
     if (val = getoption(obj->iniconfig, name, "volcharset", preset))
         EC_NULL( volume->v_volcodepage = strdup(val) );
+    else
+        EC_NULL( volume->v_volcodepage = strdup("UTF8") );
 
     if (val = getoption(obj->iniconfig, name, "maccharset", preset))
         EC_NULL( volume->v_maccodepage = strdup(val) );
+    else
+        EC_NULL( volume->v_maccodepage = strdup(obj->options.maccodepage) );
 
     if (val = getoption(obj->iniconfig, name, "dbpath", preset))
         EC_NULL( volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
@@ -1035,6 +1039,24 @@ void volume_free(struct vol *vol)
     LOG(log_debug, logtype_afpd, "volume_free: END");
 }
 
+/*!
+ * Load charsets for a volume
+ */
+int load_charset(struct vol *vol)
+{
+    if ((vol->v_maccharset = add_charset(vol->v_maccodepage)) == (charset_t)-1) {
+        LOG(log_error, logtype_default, "Setting Mac codepage '%s' failed", vol->v_maccodepage);
+        return -1;
+    }
+
+    if ((vol->v_volcharset = add_charset(vol->v_volcodepage)) == (charset_t)-1) {
+        LOG(log_error, logtype_default, "Setting volume codepage '%s' failed", vol->v_volcodepage);
+        return -1;
+    }
+
+    return 0;
+}
+
 /*!
  * Initialize volumes and load ini configfile
  *