diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 5a36839244..d91f558878 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -205,6 +205,9 @@ KResultOr> VFS::open(StringView path, int options auto& inode = custody.inode(); auto metadata = inode.metadata(); + if ((options & O_DIRECTORY) && !metadata.is_directory()) + return KResult(-ENOTDIR); + bool should_truncate_file = false; // NOTE: Read permission is a bit weird, since O_RDONLY == 0, diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index cd7f62c0d4..e66f93ea1b 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1589,8 +1589,6 @@ int Process::sys$open(const Syscall::SC_open_params* params) if (result.is_error()) return result.error(); auto description = result.value(); - if (options & O_DIRECTORY && !description->is_directory()) - return -ENOTDIR; // FIXME: This should be handled by VFS::open. description->set_file_flags(options); u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0; m_fds[fd].set(move(description), fd_flags); @@ -1629,8 +1627,6 @@ int Process::sys$openat(const Syscall::SC_openat_params* params) if (result.is_error()) return result.error(); auto description = result.value(); - if (options & O_DIRECTORY && !description->is_directory()) - return -ENOTDIR; // FIXME: This should be handled by VFS::open. description->set_file_flags(options); u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0; m_fds[fd].set(move(description), fd_flags);