From a9428730b0d0baf136d2c45c1dc9709a2d7a84b5 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 18 Mar 2014 00:00:53 +0100 Subject: [PATCH] Changes default Windows .conf location to the .exe dir. --- HISTORY | 10 ++++++---- TODO | 4 ++++ snapraid.c | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/HISTORY b/HISTORY index db168569..5f2b492e 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,8 @@ SnapRAID HISTORY ================ -6.0 2014/3 (BETA) -================= +6.0 2014/3 +========== * In "sync", even if a silent error is found, continue to update the parity if it's possible to correct the error. Note that the block will be marked bad, and the data @@ -24,9 +24,11 @@ SnapRAID HISTORY * The options -p, --percentage and -o, --older-than now keep their default value even if the other one is specified. * Moved the .lock file in the same dir of the first specified content - file. This avoid to spin the parity disks in all commands. + file. This avoid to spin-up the parity disks in all commands. * The "diff", "list", "dup", "status" and "pool" commands don't access - anymore the parity disks that can stay powered down. + anymore the parity disks that can now stay powered down. + * The default configuration file in Windows is now searched in the same + directory where the snapraid.exe file resides. * New source code organization. The RAID engine is now an external component usable also in other projects. diff --git a/TODO b/TODO index b063e974..57788805 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,10 @@ This is the list of TODO items for SnapRAID. - Next +* Measures the time waited in blocking syscall for each disk, +and prints stats of the disk speeds when the command finish, +or when it's running. + * In status prints the allocated parity in each data disk. In case, also takes into account the extra available space in the parity disks. diff --git a/snapraid.c b/snapraid.c index 0faa6afa..4b5a8536 100644 --- a/snapraid.c +++ b/snapraid.c @@ -27,15 +27,6 @@ /****************************************************************************/ /* main */ -/** - * Default configuration file. - */ -#ifdef _WIN32 -#define CONF PACKAGE ".conf" -#else -#define CONF "/etc/" PACKAGE ".conf" -#endif - void version(void) { printf(PACKAGE " v" VERSION " by Andrea Mazzoleni, " PACKAGE_URL "\n"); @@ -58,7 +49,7 @@ void usage(void) printf(" fix Fix the array of disks\n"); printf("\n"); printf("Options:\n"); - printf(" " SWITCH_GETOPT_LONG("-c, --conf FILE ", "-c") " Configuration file (default " CONF ")\n"); + printf(" " SWITCH_GETOPT_LONG("-c, --conf FILE ", "-c") " Configuration file\n"); printf(" " SWITCH_GETOPT_LONG("-f, --filter PATTERN ", "-f") " Process only files matching the pattern\n"); printf(" " SWITCH_GETOPT_LONG("-d, --filter-dist NAME", "-f") " Process only files in the specified disk\n"); printf(" " SWITCH_GETOPT_LONG("-m, --filter-missing ", "-m") " Process only missing/deleted files\n"); @@ -188,6 +179,30 @@ void log_close(const char* log) } } +/****************************************************************************/ +/* config */ + +void config(char* conf, size_t conf_size, const char* argv0) +{ +#ifdef _WIN32 + char* slash; + + pathimport(conf, conf_size, argv0); + + slash = strrchr(conf, '/'); + if (slash) { + slash[1] = 0; + pathcat(conf, conf_size, PACKAGE ".conf"); + } else { + pathcpy(conf, conf_size, PACKAGE ".conf"); + } +#else + (void)argv0; + + pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf"); +#endif +} + /****************************************************************************/ /* main */ @@ -336,7 +351,7 @@ int main(int argc, char* argv[]) { int c; struct snapraid_option opt; - const char* conf; + char conf[PATH_MAX]; struct snapraid_state state; int operation; block_off_t blockstart; @@ -361,7 +376,7 @@ int main(int argc, char* argv[]) crc32c_init(); /* defaults */ - conf = CONF; + config(conf, sizeof(conf), argv[0]); memset(&opt, 0, sizeof(opt)); blockstart = 0; blockcount = 0; @@ -387,7 +402,7 @@ int main(int argc, char* argv[]) != EOF) { switch (c) { case 'c' : - conf = optarg; + pathimport(conf, sizeof(conf), optarg); break; case 'f' : { struct snapraid_filter* filter = filter_alloc_file(1, optarg);