1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

Kernel: Enable early-returns from VFS::for_each_mount

This commit is contained in:
Ben Wiederhake 2021-10-29 23:28:25 +02:00 committed by Andreas Kling
parent 735da58d44
commit 88ca12f037
4 changed files with 19 additions and 15 deletions

View file

@ -724,11 +724,12 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
return parent_inode.remove_child(KLexicalPath::basename(path)); 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) { m_mounts.with_shared([&](auto& mounts) {
for (auto& mount : mounts) { for (auto& mount : mounts) {
callback(mount); if (callback(mount) == IterationDecision::Break)
break;
} }
}); });
} }

View file

@ -66,7 +66,7 @@ public:
KResult mknod(StringView path, mode_t, dev_t, Custody& base); KResult mknod(StringView path, mode_t, dev_t, Custody& base);
KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, 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; InodeIdentifier root_inode_id() const;

View file

@ -351,7 +351,8 @@ private:
virtual KResult try_generate(KBufferBuilder& builder) override virtual KResult try_generate(KBufferBuilder& builder) override
{ {
JsonArraySerializer array { builder }; 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 = mount.guest_fs();
auto fs_object = array.add_object(); auto fs_object = array.add_object();
fs_object.add("class_name", fs.class_name()); 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()); fs_object.add("source", static_cast<const FileBackedFileSystem&>(fs).file_description().absolute_path());
else else
fs_object.add("source", "none"); fs_object.add("source", "none");
return IterationDecision::Continue;
}); });
array.finish(); array.finish();
return KSuccess; return KSuccess;

View file

@ -38,19 +38,19 @@ KResultOr<FlatPtr> Process::do_statvfs(StringView path, statvfs* buf)
while (current_custody) { while (current_custody) {
VirtualFileSystem::the().for_each_mount([&kernelbuf, &current_custody](auto& mount) { VirtualFileSystem::the().for_each_mount([&kernelbuf, &current_custody](auto& mount) {
if (current_custody) { if (&current_custody->inode() == &mount.guest()) {
if (&current_custody->inode() == &mount.guest()) { int mountflags = mount.flags();
int mountflags = mount.flags(); int flags = 0;
int flags = 0; if (mountflags & MS_RDONLY)
if (mountflags & MS_RDONLY) flags = flags | ST_RDONLY;
flags = flags | ST_RDONLY; if (mountflags & MS_NOSUID)
if (mountflags & MS_NOSUID) flags = flags | ST_NOSUID;
flags = flags | ST_NOSUID;
kernelbuf.f_flag = flags; kernelbuf.f_flag = flags;
current_custody = nullptr; current_custody = nullptr;
} return IterationDecision::Break;
} }
return IterationDecision::Continue;
}); });
if (current_custody) { if (current_custody) {