-- v5: kernelbase: For FILE_FLAG_BACKUP_SEMANTICS also handle FILE_ATTRIBUTE_DIRECTORY in CreateFile. kernel32/tests: Test FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY.
From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/kernel32/tests/file.c | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index d3cd0fbcd9f..5fb15c8b01f 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -6813,6 +6813,65 @@ static void test_symbolic_link(void) ok( ret == TRUE, "got error %lu\n", GetLastError() ); }
+static void test_posix_semantics(void) +{ + static const DWORD flags[] = { FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY, + FILE_FLAG_POSIX_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY }; + static const struct + { + DWORD disposition, cleanup; + } td[] = + { + { CREATE_NEW, 1 }, + { OPEN_ALWAYS, 0 }, + { TRUNCATE_EXISTING, 0 }, + { CREATE_ALWAYS, 1 } + }; + HANDLE hFile, hFile2; + WCHAR temp_path[MAX_PATH]; + WCHAR filename[MAX_PATH]; + DWORD ret, i, j; + BY_HANDLE_FILE_INFORMATION info; + + GetTempPathW(MAX_PATH, temp_path); + GetTempFileNameW(temp_path, L"psx", 0, filename); + DeleteFileW(filename); + + for (i = 0; i < ARRAY_SIZE(td); i++) + { + for (j = 0; j < ARRAY_SIZE(flags); j++) + { + winetest_push_context("%lu/%lu", i, j); + + hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, td[i].disposition, flags[j], NULL); + ok(hFile != INVALID_HANDLE_VALUE, "CreateFileW error %lu\n", GetLastError()); + ret = GetFileInformationByHandle(hFile, &info); + ok(ret, "GetFileInformationByHandle error %lu\n", GetLastError()); + if (td[i].disposition == CREATE_NEW && flags[j] == (FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY)) + todo_wine + ok(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY, "created file is not a directory\n"); + else + ok(!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY), "created file is a directory\n"); + + hFile2 = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, flags[j], NULL); + ok(hFile2 != INVALID_HANDLE_VALUE, "CreateFileW error %lu\n", GetLastError()); + CloseHandle(hFile2); + CloseHandle(hFile); + + if (td[i].cleanup) + { + if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + RemoveDirectoryW(filename); + else + DeleteFileW(filename); + } + + winetest_pop_context(); + } + } +} + START_TEST(file) { char temp_path[MAX_PATH]; @@ -6892,4 +6951,5 @@ START_TEST(file) test_move_file(); test_eof(); test_symbolic_link(); + test_posix_semantics(); }
From: Dmitry Timoshkov dmitry@baikal.ru
Looks like this behaviour depends on FILE_FLAG_POSIX_SEMANTICS and activated when a file is being created.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58636 Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/kernel32/tests/file.c | 1 - dlls/kernelbase/file.c | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 5fb15c8b01f..47b8307aeda 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -6849,7 +6849,6 @@ static void test_posix_semantics(void) ret = GetFileInformationByHandle(hFile, &info); ok(ret, "GetFileInformationByHandle error %lu\n", GetLastError()); if (td[i].disposition == CREATE_NEW && flags[j] == (FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY)) - todo_wine ok(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY, "created file is not a directory\n"); else ok(!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY), "created file is a directory\n"); diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index b34a3bb25b8..b3ebbe2321c 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -758,12 +758,16 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateFileA( LPCSTR name, DWORD access, DWORD sh return CreateFileW( nameW, access, sharing, sa, creation, attributes, template ); }
-static UINT get_nt_file_options( DWORD attributes ) +static UINT get_nt_file_options( DWORD attributes, BOOL create ) { UINT options = 0;
if (attributes & FILE_FLAG_BACKUP_SEMANTICS) + { options |= FILE_OPEN_FOR_BACKUP_INTENT; + if ((attributes & FILE_FLAG_POSIX_SEMANTICS) && create) + options |= (attributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0; + } else options |= FILE_NON_DIRECTORY_FILE; if (attributes & FILE_FLAG_DELETE_ON_CLOSE) @@ -864,7 +868,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateFileW( LPCWSTR filename, DWORD access, DWO status = NtCreateFile( &ret, access | SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attr, &io, NULL, attributes & FILE_ATTRIBUTE_VALID_FLAGS, sharing, nt_disposition[creation - CREATE_NEW], - get_nt_file_options( attributes ), NULL, 0 ); + get_nt_file_options( attributes, creation == CREATE_NEW ), NULL, 0 ); if (status) { if (vxd_name && vxd_name[0]) @@ -3423,7 +3427,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH ReOpenFile( HANDLE handle, DWORD access, DWORD s }
status = NtCreateFile( &file, access | SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attr, &io, NULL, - 0, sharing, FILE_OPEN, FILE_NON_DIRECTORY_FILE | get_nt_file_options( attributes ), NULL, 0 ); + 0, sharing, FILE_OPEN, FILE_NON_DIRECTORY_FILE | get_nt_file_options( attributes, FALSE ), NULL, 0 ); if (!set_ntstatus( status )) return INVALID_HANDLE_VALUE; return file;
On Fri Aug 29 14:40:58 2025 +0000, Alexandre Julliard wrote:
Now you are going to need tests for the other creation types (CREATE_ALWAYS, OPEN_ALWAYS, etc.)...
Does new version of the tests look better?
On Fri Aug 29 14:40:58 2025 +0000, Dmitry Timoshkov wrote:
Does new version of the tests look better?
Yes, looks good, thanks!