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
);
}
/* 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;
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)
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);
#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"
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);
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;
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 ! */
/*
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;
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;
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) );
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);
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;
}
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;
}
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;
unbecome_root();
EC_CLEANUP:
+ LOG(log_debug, logtype_default,"ad_convert(\"%s\"): END: %d", fullpathname(path), ret);
EC_EXIT;
}
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) );
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
*