[Kernel/IO] Return error creating dir as non-dir.

[Kernel/IO] Return error when creating directory with non-directory
flag in NtCreateFile.
This commit is contained in:
Gliniak 2020-08-02 17:09:32 +02:00 committed by Rick Gibbed
parent cadc31c93f
commit 06ab8589b4
5 changed files with 14 additions and 4 deletions

View File

@ -142,7 +142,8 @@ dword_result_t NtCreateFile(lpdword_t handle_out, dword_t desired_access,
X_STATUS result = kernel_state()->file_system()->OpenFile(
root_entry, target_path,
vfs::FileDisposition((uint32_t)creation_disposition), desired_access,
(create_options & CreateOptions::FILE_DIRECTORY_FILE) != 0, &vfs_file,
(create_options & CreateOptions::FILE_DIRECTORY_FILE) != 0,
(create_options & CreateOptions::FILE_NON_DIRECTORY_FILE) != 0, &vfs_file,
&file_action);
object_ref<XFile> file = nullptr;

View File

@ -266,7 +266,7 @@ object_ref<XFile> XFile::Restore(KernelState* kernel_state,
vfs::FileAction action;
auto res = kernel_state->file_system()->OpenFile(
nullptr, abs_path, vfs::FileDisposition::kOpen, access, is_directory,
&vfs_file, &action);
false, &vfs_file, &action);
if (XFAILED(res)) {
XELOGE("Failed to open XFile: error {:08X}", res);
return object_ref<XFile>(file);

View File

@ -172,7 +172,8 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry,
const std::string_view path,
FileDisposition creation_disposition,
uint32_t desired_access, bool is_directory,
File** out_file, FileAction* out_action) {
bool is_non_directory, File** out_file,
FileAction* out_action) {
// TODO(gibbed): should 'is_directory' remain as a bool or should it be
// flipped to a generic FileAttributeFlags?
@ -207,6 +208,12 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry,
entry = !root_entry ? ResolvePath(path) : root_entry->GetChild(path);
}
if (entry) {
if (entry->attributes() & kFileAttributeDirectory && is_non_directory) {
return X_STATUS_FILE_IS_A_DIRECTORY;
}
}
// Check if exists (if we need it to), or that it doesn't (if it shouldn't).
switch (creation_disposition) {
case FileDisposition::kOpen:

View File

@ -43,7 +43,8 @@ class VirtualFileSystem {
X_STATUS OpenFile(Entry* root_entry, const std::string_view path,
FileDisposition creation_disposition,
uint32_t desired_access, bool is_directory, File** out_file,
uint32_t desired_access, bool is_directory,
bool is_non_directory, File** out_file,
FileAction* out_action);
private:

View File

@ -64,6 +64,7 @@ typedef uint32_t X_STATUS;
#define X_STATUS_PROCEDURE_NOT_FOUND ((X_STATUS)0xC000007AL)
#define X_STATUS_INSUFFICIENT_RESOURCES ((X_STATUS)0xC000009AL)
#define X_STATUS_MEMORY_NOT_ALLOCATED ((X_STATUS)0xC00000A0L)
#define X_STATUS_FILE_IS_A_DIRECTORY ((X_STATUS)0xC00000BAL)
#define X_STATUS_NOT_SUPPORTED ((X_STATUS)0xC00000BBL)
#define X_STATUS_INVALID_PARAMETER_1 ((X_STATUS)0xC00000EFL)
#define X_STATUS_INVALID_PARAMETER_2 ((X_STATUS)0xC00000F0L)