فهرست منبع

Kernel: Replace usage of LexicalPath with KLexicalPath

This replaces all uses of LexicalPath in the Kernel with the functions
from KLexicalPath. This also allows the Kernel to stop including
AK::LexicalPath.
Max Wipfli 4 سال پیش
والد
کامیت
ee342f5ec3
6فایلهای تغییر یافته به همراه21 افزوده شده و 25 حذف شده
  1. 0 1
      Kernel/CMakeLists.txt
  2. 3 3
      Kernel/CoreDump.cpp
  3. 0 1
      Kernel/CoreDump.h
  4. 11 12
      Kernel/FileSystem/VirtualFileSystem.cpp
  5. 0 1
      Kernel/Syscalls/execve.cpp
  6. 7 7
      Kernel/Syscalls/unveil.cpp

+ 0 - 1
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

+ 3 - 3
Kernel/CoreDump.cpp

@@ -13,6 +13,7 @@
 #include <Kernel/FileSystem/Custody.h>
 #include <Kernel/FileSystem/FileDescription.h>
 #include <Kernel/FileSystem/VirtualFileSystem.h>
+#include <Kernel/KLexicalPath.h>
 #include <Kernel/Process.h>
 #include <Kernel/RTC.h>
 #include <Kernel/SpinLock.h>
@@ -44,8 +45,7 @@ CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription
 
 RefPtr<FileDescription> 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<FileDescription> 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(),

+ 0 - 1
Kernel/CoreDump.h

@@ -7,7 +7,6 @@
 
 #pragma once
 
-#include <AK/LexicalPath.h>
 #include <AK/NonnullRefPtr.h>
 #include <AK/OwnPtr.h>
 #include <Kernel/Forward.h>

+ 11 - 12
Kernel/FileSystem/VirtualFileSystem.cpp

@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <AK/LexicalPath.h>
 #include <AK/Singleton.h>
 #include <AK/StringBuilder.h>
 #include <Kernel/Debug.h>
@@ -14,6 +13,7 @@
 #include <Kernel/FileSystem/FileDescription.h>
 #include <Kernel/FileSystem/FileSystem.h>
 #include <Kernel/FileSystem/VirtualFileSystem.h>
+#include <Kernel/KLexicalPath.h>
 #include <Kernel/KSyms.h>
 #include <Kernel/Process.h>
 #include <Kernel/Sections.h>
@@ -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<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> 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());
 }
 

+ 0 - 1
Kernel/Syscalls/execve.cpp

@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <AK/LexicalPath.h>
 #include <AK/ScopeGuard.h>
 #include <AK/TemporaryChange.h>
 #include <AK/WeakPtr.h>

+ 7 - 7
Kernel/Syscalls/unveil.cpp

@@ -5,10 +5,10 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include <AK/LexicalPath.h>
 #include <AK/StringView.h>
 #include <Kernel/FileSystem/Custody.h>
 #include <Kernel/FileSystem/VirtualFileSystem.h>
+#include <Kernel/KLexicalPath.h>
 #include <Kernel/Process.h>
 
 namespace Kernel {
@@ -91,16 +91,16 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
     if (!custody_or_error.is_error()) {
         new_unveiled_path = custody_or_error.value()->absolute_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<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
 
     matching_node.insert(
         it,
-        lexical_path.parts_view().end(),
+        path_parts.end(),
         { new_unveiled_path, (UnveilAccess)new_permissions, true },
         [](auto& parent, auto& it) -> Optional<UnveilMetadata> {
-            auto path = LexicalPath::join(parent.path(), *it).string();
+            auto path = String::formatted("{}/{}", parent.path(), *it);
             return UnveilMetadata { path, parent.permissions(), false };
         });