From e91faca1c44790b26410084c43bead9ef2edd3f0 Mon Sep 17 00:00:00 2001 From: Gliniak <153369+Gliniak@users.noreply.github.com> Date: Tue, 21 Apr 2026 21:58:49 +0200 Subject: [PATCH] [VFS] Return more proper error codes in OpenFile - Added handling for opening file with directory flag --- src/xenia/vfs/virtual_file_system.cc | 14 +++++++++----- src/xenia/xbox.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/xenia/vfs/virtual_file_system.cc b/src/xenia/vfs/virtual_file_system.cc index 01ca0dd8c..248e9a9a2 100644 --- a/src/xenia/vfs/virtual_file_system.cc +++ b/src/xenia/vfs/virtual_file_system.cc @@ -230,7 +230,7 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry, : root_entry->ResolvePath(base_path); if (!parent_entry) { *out_action = FileAction::kDoesNotExist; - return X_STATUS_NO_SUCH_FILE; + return X_STATUS_OBJECT_PATH_NOT_FOUND; } auto file_name = xe::utf8::find_name_from_guest_path(path); @@ -244,13 +244,17 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry, return X_STATUS_FILE_IS_A_DIRECTORY; } + if (!(entry->attributes() & kFileAttributeDirectory) && is_directory) { + return X_STATUS_NOT_A_DIRECTORY; + } + // If the entry does not exist on the host then remove the cached entry if (parent_entry) { - const xe::vfs::HostPathEntry* host_Path = + const xe::vfs::HostPathEntry* host_path = dynamic_cast(parent_entry); - if (host_Path) { - auto const file_path = host_Path->host_path() / entry->name(); + if (host_path) { + auto const file_path = host_path->host_path() / entry->name(); if (!std::filesystem::exists(file_path)) { // Remove cached entry @@ -268,7 +272,7 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry, // Must exist. if (!entry) { *out_action = FileAction::kDoesNotExist; - return X_STATUS_NO_SUCH_FILE; + return X_STATUS_OBJECT_NAME_NOT_FOUND; } break; case FileDisposition::kCreate: diff --git a/src/xenia/xbox.h b/src/xenia/xbox.h index 2565380d6..334578599 100644 --- a/src/xenia/xbox.h +++ b/src/xenia/xbox.h @@ -58,6 +58,7 @@ typedef uint32_t X_STATUS; #define X_STATUS_OBJECT_NAME_INVALID ((X_STATUS)0xC0000033L) #define X_STATUS_OBJECT_NAME_NOT_FOUND ((X_STATUS)0xC0000034L) #define X_STATUS_OBJECT_NAME_COLLISION ((X_STATUS)0xC0000035L) +#define X_STATUS_OBJECT_PATH_NOT_FOUND ((X_STATUS)0xC000003AL) #define X_STATUS_INVALID_PAGE_PROTECTION ((X_STATUS)0xC0000045L) #define X_STATUS_MUTANT_NOT_OWNED ((X_STATUS)0xC0000046L) #define X_STATUS_SEMAPHORE_LIMIT_EXCEEDED ((X_STATUS)0xC0000047L) @@ -72,6 +73,7 @@ typedef uint32_t X_STATUS; #define X_STATUS_INVALID_PARAMETER_1 ((X_STATUS)0xC00000EFL) #define X_STATUS_INVALID_PARAMETER_2 ((X_STATUS)0xC00000F0L) #define X_STATUS_INVALID_PARAMETER_3 ((X_STATUS)0xC00000F1L) +#define X_STATUS_NOT_A_DIRECTORY ((X_STATUS)0xC0000103L) #define X_STATUS_PROCESS_IS_TERMINATING ((X_STATUS)0xC000010AL) #define X_STATUS_DLL_NOT_FOUND ((X_STATUS)0xC0000135L) #define X_STATUS_ENTRYPOINT_NOT_FOUND ((X_STATUS)0xC0000139L)