Fix NtCreateFile's create_disposition behavior

This commit is contained in:
Igor Pissolati
2026-01-11 17:07:34 -03:00
parent d70ab2607e
commit ffd7058bec
2 changed files with 25 additions and 2 deletions

View File

@@ -43,6 +43,7 @@ using NTSTATUS = std::uint32_t;
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L)
#define STATUS_OBJECT_NAME_NOT_FOUND ((NTSTATUS)0xC0000034L)
#define STATUS_OBJECT_NAME_COLLISION ((NTSTATUS)0xC0000035L)
#define STATUS_INVALID_PAGE_PROTECTION ((NTSTATUS)0xC0000045L)
#define STATUS_MUTANT_NOT_OWNED ((NTSTATUS)0xC0000046L)
#define STATUS_SEMAPHORE_LIMIT_EXCEEDED ((NTSTATUS)0xC0000047L)

View File

@@ -1020,7 +1020,8 @@ namespace syscalls
return STATUS_OBJECT_NAME_NOT_FOUND;
}
const bool is_directory = std::filesystem::is_directory(c.win_emu.file_sys.translate(path), ec);
const auto host_path = c.win_emu.file_sys.translate(path);
const bool is_directory = std::filesystem::is_directory(host_path, ec);
if (is_directory || create_options & FILE_DIRECTORY_FILE)
{
@@ -1028,7 +1029,7 @@ namespace syscalls
if (create_disposition & FILE_CREATE)
{
create_directory(c.win_emu.file_sys.translate(path), ec);
create_directory(host_path, ec);
if (ec)
{
@@ -1048,6 +1049,27 @@ namespace syscalls
c.win_emu.callbacks.on_generic_access("Opening file", f.name);
const bool file_exists = std::filesystem::exists(host_path, ec);
if (create_disposition == FILE_CREATE && file_exists)
{
return STATUS_OBJECT_NAME_COLLISION;
}
if ((create_disposition == FILE_OVERWRITE || create_disposition == FILE_OPEN) && !file_exists)
{
return STATUS_OBJECT_NAME_NOT_FOUND;
}
if (create_disposition == FILE_OPEN_IF && !file_exists)
{
std::ofstream touch(host_path, std::ios::binary | std::ios::app);
if (!touch)
{
return STATUS_ACCESS_DENIED;
}
}
std::u16string mode = map_mode(desired_access, create_disposition);
if (mode.empty() || path.is_relative())