From 0f05d40f25e6b391f08a8e70e2cb110b5d32ad3d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 3 Oct 2014 21:24:19 +0200 Subject: [PATCH] Adds the --test-force-scan-winfind option to use the legacy dir listing. --- cmdline/mingw.c | 15 +++++++++++---- cmdline/snapraid.c | 27 +++++++++++++++++++++------ cmdline/state.h | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index fe1c4826..c741a5d9 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -119,10 +119,17 @@ static char* last_error; */ static int is_wine; -void os_init(void) +/** + * If we should use the legacy FindFirst/Next way to list directories. + */ +static int is_scan_winfind; + +void os_init(int opt) { HMODULE kernel32, ntdll; + is_scan_winfind = opt != 0; + kernel32 = GetModuleHandle("KERNEL32.DLL"); if (!kernel32) { fprintf(stderr, "Error loading the KERNEL32 module.\n"); @@ -1174,7 +1181,7 @@ windows_dir* windows_opendir(const char* dir) { /* if we have GetFileInformationByHandleEx() we can read */ /* the directory using a stream */ - if (ptr_GetFileInformationByHandleEx != 0) + if (!is_scan_winfind && ptr_GetFileInformationByHandleEx != 0) return windows_opendir_stream(dir); else return windows_opendir_find(dir); @@ -1182,7 +1189,7 @@ windows_dir* windows_opendir(const char* dir) struct windows_dirent* windows_readdir(windows_dir* dirstream) { - if (ptr_GetFileInformationByHandleEx != 0) + if (!is_scan_winfind && ptr_GetFileInformationByHandleEx != 0) return windows_readdir_stream(dirstream); else return windows_readdir_find(dirstream); @@ -1190,7 +1197,7 @@ struct windows_dirent* windows_readdir(windows_dir* dirstream) int windows_closedir(windows_dir* dirstream) { - if (ptr_GetFileInformationByHandleEx != 0) + if (!is_scan_winfind && ptr_GetFileInformationByHandleEx != 0) return windows_closedir_stream(dirstream); else return windows_closedir_find(dirstream); diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 3b2c46df..468ee2ee 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -233,6 +233,7 @@ void config(char* conf, size_t conf_size, const char* argv0) #define OPT_TEST_SKIP_PARITY_ACCESS 276 #define OPT_TEST_EXPECT_FAILURE 277 #define OPT_TEST_RUN 278 +#define OPT_TEST_FORCE_SCAN_WINFIND 279 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -328,6 +329,9 @@ struct option long_options[] = { /* Run some command after loading the state and before the command */ { "test-run", 1, 0, OPT_TEST_RUN }, + /* Use the FindFirst/Next approach in Windows to list files */ + { "test-force-scan-winfind", 0, 0, OPT_TEST_FORCE_SCAN_WINFIND }, + { 0, 0, 0, 0 } }; #endif @@ -384,15 +388,12 @@ int main(int argc, char* argv[]) int lock; const char* gen_conf; const char* run; + int speedtest; int period; time_t t; struct tm* tm; int i; - os_init(); - raid_init(); - crc32c_init(); - /* always different random numbers */ srand(time(0)); @@ -412,6 +413,7 @@ int main(int argc, char* argv[]) log = 0; lock = 0; gen_conf = 0; + speedtest = 0; run = 0; opterr = 0; @@ -546,8 +548,8 @@ int main(int argc, char* argv[]) version(); exit(EXIT_SUCCESS); case 'T' : - speed(period); - exit(EXIT_SUCCESS); + speedtest = 1; + break; case 'C' : gen_conf = optarg; break; @@ -623,6 +625,9 @@ int main(int argc, char* argv[]) case OPT_TEST_RUN : run = optarg; break; + case OPT_TEST_FORCE_SCAN_WINFIND : + opt.force_scan_winfind = 1; + break; default : /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); @@ -631,6 +636,16 @@ int main(int argc, char* argv[]) } } + os_init(opt.force_scan_winfind); + raid_init(); + crc32c_init(); + + if (speedtest != 0) { + speed(period); + os_done(); + exit(EXIT_SUCCESS); + } + if (gen_conf != 0) { generate_configuration(gen_conf); os_done(); diff --git a/cmdline/state.h b/cmdline/state.h index 71921428..3816866f 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -90,6 +90,7 @@ struct snapraid_option { int force_scrub_even; /**< Force scrub of all the even blocks. */ int force_content_write; /**< Force the update of the content file. */ int force_content_text; /**< Force the use of text version of content file. */ + int force_scan_winfind; /**< Force the use of FindFirst/Next in Windows to list directories. */ }; /**