Adds the --test-force-scan-winfind option to use the legacy dir listing.

This commit is contained in:
Andrea Mazzoleni 2014-10-03 21:24:19 +02:00
parent be24f82cfd
commit 0f05d40f25
3 changed files with 33 additions and 10 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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. */
};
/**