From 393e48362c7c856bcb4a9e1c3c58dca1250913b3 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Fri, 3 Oct 2014 21:00:22 +0200 Subject: kernel32: Implement FindFirstFileExW level FindExInfoBasic. --- dlls/kernel32/file.c | 14 +++++++++++--- dlls/kernel32/tests/file.c | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c index 4a6fc13..006db1c 100644 --- a/dlls/kernel32/file.c +++ b/dlls/kernel32/file.c @@ -57,6 +57,7 @@ typedef struct HANDLE handle; /* handle to directory */ CRITICAL_SECTION cs; /* crit section protecting this structure */ FINDEX_SEARCH_OPS search_op; /* Flags passed to FindFirst. */ + FINDEX_INFO_LEVELS level; /* Level passed to FindFirst */ UNICODE_STRING mask; /* file mask */ UNICODE_STRING path; /* NT path used to open the directory */ BOOL is_root; /* is directory the root of the drive? */ @@ -1875,7 +1876,7 @@ HANDLE WINAPI FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_LEVELS level, SetLastError( ERROR_INVALID_PARAMETER ); return INVALID_HANDLE_VALUE; } - if (level != FindExInfoStandard) + if (level != FindExInfoStandard && level != FindExInfoBasic) { FIXME("info level %d not implemented\n", level ); SetLastError( ERROR_INVALID_PARAMETER ); @@ -1979,6 +1980,7 @@ HANDLE WINAPI FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_LEVELS level, info->data_size = 0; info->data = NULL; info->search_op = search_op; + info->level = level; if (device) { @@ -2141,8 +2143,14 @@ BOOL WINAPI FindNextFileW( HANDLE handle, WIN32_FIND_DATAW *data ) memcpy( data->cFileName, dir_info->FileName, dir_info->FileNameLength ); data->cFileName[dir_info->FileNameLength/sizeof(WCHAR)] = 0; - memcpy( data->cAlternateFileName, dir_info->ShortName, dir_info->ShortNameLength ); - data->cAlternateFileName[dir_info->ShortNameLength/sizeof(WCHAR)] = 0; + + if (info->level != FindExInfoBasic) + { + memcpy( data->cAlternateFileName, dir_info->ShortName, dir_info->ShortNameLength ); + data->cAlternateFileName[dir_info->ShortNameLength/sizeof(WCHAR)] = 0; + } + else + data->cAlternateFileName[0] = 0; TRACE("returning %s (%s)\n", debugstr_w(data->cFileName), debugstr_w(data->cAlternateFileName) ); diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 0973efe..dd9cf06 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -2562,7 +2562,7 @@ static void test_FindNextFileA(void) ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n"); } -static void test_FindFirstFileExA(FINDEX_SEARCH_OPS search_ops, DWORD flags) +static void test_FindFirstFileExA(FINDEX_INFO_LEVELS level, FINDEX_SEARCH_OPS search_ops, DWORD flags) { WIN32_FIND_DATAA search_results; HANDLE handle; @@ -2574,12 +2574,15 @@ static void test_FindFirstFileExA(FINDEX_SEARCH_OPS search_ops, DWORD flags) return; } + trace("Running FindFirstFileExA tests with level=%d, search_ops=%d, flags=%d\n", + level, search_ops, flags); + CreateDirectoryA("test-dir", NULL); _lclose(_lcreat("test-dir\\file1", 0)); _lclose(_lcreat("test-dir\\file2", 0)); CreateDirectoryA("test-dir\\dir1", NULL); SetLastError(0xdeadbeef); - handle = pFindFirstFileExA("test-dir\\*", FindExInfoStandard, &search_results, search_ops, NULL, flags); + handle = pFindFirstFileExA("test-dir\\*", level, &search_results, search_ops, NULL, flags); if (handle == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("FindFirstFileExA is not implemented\n"); @@ -2590,16 +2593,26 @@ static void test_FindFirstFileExA(FINDEX_SEARCH_OPS search_ops, DWORD flags) win_skip("FindFirstFileExA flag FIND_FIRST_EX_LARGE_FETCH not supported, skipping test\n"); goto cleanup; } - ok(handle != INVALID_HANDLE_VALUE, "FindFirstFile failed (err=%u)\n", GetLastError()); - ok(strcmp(search_results.cFileName, ".") == 0, "First entry should be '.', is %s\n", search_results.cFileName); + if ((level == FindExInfoBasic) && handle == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_PARAMETER) + { + win_skip("FindFirstFileExA level FindExInfoBasic not supported, skipping test\n"); + goto cleanup; + } #define CHECK_NAME(fn) (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0) +#define CHECK_LEVEL(fn) (level != FindExInfoBasic || !(fn)[0]) + + ok(handle != INVALID_HANDLE_VALUE, "FindFirstFile failed (err=%u)\n", GetLastError()); + ok(strcmp(search_results.cFileName, ".") == 0, "First entry should be '.', is %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); ok(FindNextFileA(handle, &search_results), "Fetching second file failed\n"); ok(strcmp(search_results.cFileName, "..") == 0, "Second entry should be '..' is %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); ok(FindNextFileA(handle, &search_results), "Fetching third file failed\n"); ok(CHECK_NAME(search_results.cFileName), "Invalid third entry - %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); SetLastError(0xdeadbeef); ret = FindNextFileA(handle, &search_results); @@ -2608,26 +2621,31 @@ static void test_FindFirstFileExA(FINDEX_SEARCH_OPS search_ops, DWORD flags) skip("File system supports directory filtering\n"); /* Results from the previous call are not cleared */ ok(strcmp(search_results.cFileName, "dir1") == 0, "Third entry should be 'dir1' is %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); + } else { ok(ret, "Fetching fourth file failed\n"); ok(CHECK_NAME(search_results.cFileName), "Invalid fourth entry - %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); ok(FindNextFileA(handle, &search_results), "Fetching fifth file failed\n"); ok(CHECK_NAME(search_results.cFileName), "Invalid fifth entry - %s\n", search_results.cFileName); + ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n"); ok(FindNextFileA(handle, &search_results) == FALSE, "Fetching sixth file should fail\n"); } #undef CHECK_NAME +#undef CHECK_LEVEL FindClose( handle ); /* Most Windows systems seem to ignore the FIND_FIRST_EX_CASE_SENSITIVE flag. Unofficial documentation * suggests that there are registry keys and that it might depend on the used filesystem. */ SetLastError(0xdeadbeef); - handle = pFindFirstFileExA("TEST-DIR\\*", FindExInfoStandard, &search_results, search_ops, NULL, flags); + handle = pFindFirstFileExA("TEST-DIR\\*", level, &search_results, search_ops, NULL, flags); if (flags & FIND_FIRST_EX_CASE_SENSITIVE) { ok(handle != INVALID_HANDLE_VALUE || GetLastError() == ERROR_PATH_NOT_FOUND, @@ -4192,13 +4210,19 @@ START_TEST(file) test_MoveFileW(); test_FindFirstFileA(); test_FindNextFileA(); - test_FindFirstFileExA(0, 0); - test_FindFirstFileExA(0, FIND_FIRST_EX_CASE_SENSITIVE); - test_FindFirstFileExA(0, FIND_FIRST_EX_LARGE_FETCH); + test_FindFirstFileExA(FindExInfoStandard, 0, 0); + test_FindFirstFileExA(FindExInfoStandard, 0, FIND_FIRST_EX_CASE_SENSITIVE); + test_FindFirstFileExA(FindExInfoStandard, 0, FIND_FIRST_EX_LARGE_FETCH); + test_FindFirstFileExA(FindExInfoBasic, 0, 0); + test_FindFirstFileExA(FindExInfoBasic, 0, FIND_FIRST_EX_CASE_SENSITIVE); + test_FindFirstFileExA(FindExInfoBasic, 0, FIND_FIRST_EX_LARGE_FETCH); /* FindExLimitToDirectories is ignored if the file system doesn't support directory filtering */ - test_FindFirstFileExA(FindExSearchLimitToDirectories, 0); - test_FindFirstFileExA(FindExSearchLimitToDirectories, FIND_FIRST_EX_CASE_SENSITIVE); - test_FindFirstFileExA(FindExSearchLimitToDirectories, FIND_FIRST_EX_LARGE_FETCH); + test_FindFirstFileExA(FindExInfoStandard, FindExSearchLimitToDirectories, 0); + test_FindFirstFileExA(FindExInfoStandard, FindExSearchLimitToDirectories, FIND_FIRST_EX_CASE_SENSITIVE); + test_FindFirstFileExA(FindExInfoStandard, FindExSearchLimitToDirectories, FIND_FIRST_EX_LARGE_FETCH); + test_FindFirstFileExA(FindExInfoBasic, FindExSearchLimitToDirectories, 0); + test_FindFirstFileExA(FindExInfoBasic, FindExSearchLimitToDirectories, FIND_FIRST_EX_CASE_SENSITIVE); + test_FindFirstFileExA(FindExInfoBasic, FindExSearchLimitToDirectories, FIND_FIRST_EX_LARGE_FETCH); test_LockFile(); test_file_sharing(); test_offset_in_overlapped_structure(); -- 2.1.1