diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index ecd2c37a20c..e41f83275f1 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -303,7 +303,6 @@ set(AK_SOURCES ../AK/FlyString.cpp ../AK/GenericLexer.cpp ../AK/Hex.cpp - ../AK/LexicalPath.cpp ../AK/String.cpp ../AK/StringBuilder.cpp ../AK/StringImpl.cpp diff --git a/Kernel/CoreDump.cpp b/Kernel/CoreDump.cpp index b81f5b3b5a1..b6e2cab79f1 100644 --- a/Kernel/CoreDump.cpp +++ b/Kernel/CoreDump.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -44,8 +45,7 @@ CoreDump::CoreDump(NonnullRefPtr process, NonnullRefPtr CoreDump::create_target_file(const Process& process, const String& output_path) { - LexicalPath lexical_path(output_path); - const auto& output_directory = lexical_path.dirname(); + auto output_directory = KLexicalPath::dirname(output_path); auto dump_directory = VFS::the().open_directory(output_directory, VFS::the().root_custody()); if (dump_directory.is_error()) { dbgln("Can't find directory '{}' for core dump", output_directory); @@ -57,7 +57,7 @@ RefPtr CoreDump::create_target_file(const Process& process, con return nullptr; } auto fd_or_error = VFS::the().open( - lexical_path.basename(), + KLexicalPath::basename(output_path), O_CREAT | O_WRONLY | O_EXCL, S_IFREG, // We will enable reading from userspace when we finish generating the coredump file *dump_directory.value(), diff --git a/Kernel/CoreDump.h b/Kernel/CoreDump.h index f09a78735f5..76b4ab111b8 100644 --- a/Kernel/CoreDump.h +++ b/Kernel/CoreDump.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 68894047bf9..c67a38a6dc8 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -353,14 +353,14 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base) if (parent_custody->is_readonly()) return EROFS; - auto basename = LexicalPath::basename(path); + auto basename = KLexicalPath::basename(path); dbgln("VFS::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier()); return parent_inode.create_child(basename, mode, dev, current_process->euid(), current_process->egid()).result(); } KResultOr> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional owner) { - auto basename = LexicalPath::basename(path); + auto basename = KLexicalPath::basename(path); if (auto result = validate_path_against_process_veil(String::formatted("{}/{}", parent_custody.absolute_path(), basename), options); result.is_error()) return result; @@ -418,7 +418,7 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base) if (parent_custody->is_readonly()) return EROFS; - auto basename = LexicalPath::basename(path); + auto basename = KLexicalPath::basename(path); dbgln_if(VFS_DEBUG, "VFS::mkdir: '{}' in {}", basename, parent_inode.identifier()); return parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process->euid(), current_process->egid()).result(); } @@ -533,7 +533,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) if (old_parent_custody->is_readonly() || new_parent_custody->is_readonly()) return EROFS; - auto new_basename = LexicalPath::basename(new_path); + auto new_basename = KLexicalPath::basename(new_path); if (!new_custody_or_error.is_error()) { auto& new_custody = *new_custody_or_error.value(); @@ -554,7 +554,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) if (auto result = new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()); result.is_error()) return result; - if (auto result = old_parent_inode.remove_child(LexicalPath::basename(old_path)); result.is_error()) + if (auto result = old_parent_inode.remove_child(KLexicalPath::basename(old_path)); result.is_error()) return result; return KSuccess; @@ -656,7 +656,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base) if (!hard_link_allowed(old_inode)) return EPERM; - return parent_inode.add_child(old_inode, LexicalPath::basename(new_path), old_inode.mode()); + return parent_inode.add_child(old_inode, KLexicalPath::basename(new_path), old_inode.mode()); } KResult VFS::unlink(StringView path, Custody& base) @@ -689,7 +689,7 @@ KResult VFS::unlink(StringView path, Custody& base) if (parent_custody->is_readonly()) return EROFS; - if (auto result = parent_inode.remove_child(LexicalPath::basename(path)); result.is_error()) + if (auto result = parent_inode.remove_child(KLexicalPath::basename(path)); result.is_error()) return result; return KSuccess; @@ -712,7 +712,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base) if (parent_custody->is_readonly()) return EROFS; - auto basename = LexicalPath::basename(linkpath); + auto basename = KLexicalPath::basename(linkpath); dbgln_if(VFS_DEBUG, "VFS::symlink: '{}' (-> '{}') in {}", basename, target, parent_inode.identifier()); auto inode_or_error = parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process->euid(), current_process->egid()); if (inode_or_error.is_error()) @@ -771,7 +771,7 @@ KResult VFS::rmdir(StringView path, Custody& base) if (auto result = inode.remove_child(".."); result.is_error()) return result; - return parent_inode.remove_child(LexicalPath::basename(path)); + return parent_inode.remove_child(KLexicalPath::basename(path)); } VFS::Mount::Mount(FS& guest_fs, Custody* host_custody, int flags) @@ -833,8 +833,7 @@ UnveilNode const& VFS::find_matching_unveiled_path(StringView path) VERIFY(Process::current()->veil_state() != VeilState::None); auto& unveil_root = Process::current()->unveiled_paths(); - LexicalPath lexical_path { path }; - auto& path_parts = lexical_path.parts_view(); + auto path_parts = KLexicalPath::parts(path); return unveil_root.traverse_until_last_accessible_node(path_parts.begin(), path_parts.end()); } diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 663fd956e20..2e72df23e5a 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp index 0a9248b823b..39099be3a01 100644 --- a/Kernel/Syscalls/unveil.cpp +++ b/Kernel/Syscalls/unveil.cpp @@ -5,10 +5,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include #include namespace Kernel { @@ -91,16 +91,16 @@ KResultOr Process::sys$unveil(Userspaceabsolute_path(); } else if (custody_or_error.error() == -ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) { - String basename = LexicalPath::basename(path.view()); + auto basename = KLexicalPath::basename(path.view()); new_unveiled_path = String::formatted("{}/{}", parent_custody->absolute_path(), basename); } else { // FIXME Should this be EINVAL? return custody_or_error.error(); } - LexicalPath lexical_path(new_unveiled_path); - auto it = lexical_path.parts_view().begin(); - auto& matching_node = m_unveiled_paths.traverse_until_last_accessible_node(it, lexical_path.parts_view().end()); + auto path_parts = KLexicalPath::parts(new_unveiled_path); + auto it = path_parts.begin(); + auto& matching_node = m_unveiled_paths.traverse_until_last_accessible_node(it, path_parts.end()); if (it.is_end()) { // If the path has already been explicitly unveiled, do not allow elevating its permissions. if (matching_node.was_explicitly_unveiled()) { @@ -122,10 +122,10 @@ KResultOr Process::sys$unveil(Userspace Optional { - auto path = LexicalPath::join(parent.path(), *it).string(); + auto path = String::formatted("{}/{}", parent.path(), *it); return UnveilMetadata { path, parent.permissions(), false }; });