diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-10-29 23:28:25 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-31 12:06:28 +0100 |
commit | 88ca12f037ffd9aedc884331c927f08d57e047cd (patch) | |
tree | ef64d03e51c2b62d4d53c0416e58fe7cc8a0a192 | |
parent | 735da58d44383389b9aacfdb03f4fa945ce8d665 (diff) | |
download | serenity-88ca12f037ffd9aedc884331c927f08d57e047cd.zip |
Kernel: Enable early-returns from VFS::for_each_mount
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 5 | ||||
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.h | 2 | ||||
-rw-r--r-- | Kernel/GlobalProcessExposed.cpp | 5 | ||||
-rw-r--r-- | Kernel/Syscalls/statvfs.cpp | 24 |
4 files changed, 20 insertions, 16 deletions
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 886c4cf7d3..61546fecc7 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -724,11 +724,12 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base) return parent_inode.remove_child(KLexicalPath::basename(path)); } -void VirtualFileSystem::for_each_mount(Function<void(Mount const&)> callback) const +void VirtualFileSystem::for_each_mount(Function<IterationDecision(Mount const&)> callback) const { m_mounts.with_shared([&](auto& mounts) { for (auto& mount : mounts) { - callback(mount); + if (callback(mount) == IterationDecision::Break) + break; } }); } diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 8c9655ba44..09b4fd05de 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -66,7 +66,7 @@ public: KResult mknod(StringView path, mode_t, dev_t, Custody& base); KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base); - void for_each_mount(Function<void(const Mount&)>) const; + void for_each_mount(Function<IterationDecision(const Mount&)>) const; InodeIdentifier root_inode_id() const; diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp index 6e17f8052b..8e05187f88 100644 --- a/Kernel/GlobalProcessExposed.cpp +++ b/Kernel/GlobalProcessExposed.cpp @@ -351,7 +351,8 @@ private: virtual KResult try_generate(KBufferBuilder& builder) override { JsonArraySerializer array { builder }; - VirtualFileSystem::the().for_each_mount([&array](auto& mount) { + KResult result = KSuccess; + VirtualFileSystem::the().for_each_mount([&array, &result](auto& mount) { auto& fs = mount.guest_fs(); auto fs_object = array.add_object(); fs_object.add("class_name", fs.class_name()); @@ -368,6 +369,8 @@ private: fs_object.add("source", static_cast<const FileBackedFileSystem&>(fs).file_description().absolute_path()); else fs_object.add("source", "none"); + + return IterationDecision::Continue; }); array.finish(); return KSuccess; diff --git a/Kernel/Syscalls/statvfs.cpp b/Kernel/Syscalls/statvfs.cpp index ed2a70dfa9..8764f98a9b 100644 --- a/Kernel/Syscalls/statvfs.cpp +++ b/Kernel/Syscalls/statvfs.cpp @@ -38,19 +38,19 @@ KResultOr<FlatPtr> Process::do_statvfs(StringView path, statvfs* buf) while (current_custody) { VirtualFileSystem::the().for_each_mount([&kernelbuf, ¤t_custody](auto& mount) { - if (current_custody) { - if (¤t_custody->inode() == &mount.guest()) { - int mountflags = mount.flags(); - int flags = 0; - if (mountflags & MS_RDONLY) - flags = flags | ST_RDONLY; - if (mountflags & MS_NOSUID) - flags = flags | ST_NOSUID; - - kernelbuf.f_flag = flags; - current_custody = nullptr; - } + if (¤t_custody->inode() == &mount.guest()) { + int mountflags = mount.flags(); + int flags = 0; + if (mountflags & MS_RDONLY) + flags = flags | ST_RDONLY; + if (mountflags & MS_NOSUID) + flags = flags | ST_NOSUID; + + kernelbuf.f_flag = flags; + current_custody = nullptr; + return IterationDecision::Break; } + return IterationDecision::Continue; }); if (current_custody) { |