summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/Bus/USB/SysFSUSB.cpp8
-rw-r--r--Kernel/Bus/USB/SysFSUSB.h2
-rw-r--r--Kernel/Devices/Device.cpp27
-rw-r--r--Kernel/FileSystem/DevPtsFS.cpp13
-rw-r--r--Kernel/FileSystem/DevPtsFS.h2
-rw-r--r--Kernel/FileSystem/DevTmpFS.cpp10
-rw-r--r--Kernel/FileSystem/DevTmpFS.h4
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp29
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h2
-rw-r--r--Kernel/FileSystem/ISO9660FileSystem.cpp7
-rw-r--r--Kernel/FileSystem/ISO9660FileSystem.h2
-rw-r--r--Kernel/FileSystem/Inode.h2
-rw-r--r--Kernel/FileSystem/OpenFileDescription.cpp9
-rw-r--r--Kernel/FileSystem/Plan9FileSystem.cpp9
-rw-r--r--Kernel/FileSystem/Plan9FileSystem.h2
-rw-r--r--Kernel/FileSystem/ProcFS.cpp10
-rw-r--r--Kernel/FileSystem/ProcFS.h10
-rw-r--r--Kernel/FileSystem/SysFS.cpp12
-rw-r--r--Kernel/FileSystem/SysFS.h10
-rw-r--r--Kernel/FileSystem/SysFSComponent.cpp8
-rw-r--r--Kernel/FileSystem/SysFSComponent.h4
-rw-r--r--Kernel/FileSystem/TmpFS.cpp8
-rw-r--r--Kernel/FileSystem/TmpFS.h2
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp16
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.h2
-rw-r--r--Kernel/GlobalProcessExposed.cpp24
-rw-r--r--Kernel/Process.h6
-rw-r--r--Kernel/ProcessExposed.cpp8
-rw-r--r--Kernel/ProcessExposed.h6
-rw-r--r--Kernel/ProcessProcFSTraits.cpp24
-rw-r--r--Kernel/ProcessSpecificExposed.cpp27
31 files changed, 154 insertions, 151 deletions
diff --git a/Kernel/Bus/USB/SysFSUSB.cpp b/Kernel/Bus/USB/SysFSUSB.cpp
index d242c8cb85..ecb64f352e 100644
--- a/Kernel/Bus/USB/SysFSUSB.cpp
+++ b/Kernel/Bus/USB/SysFSUSB.cpp
@@ -91,17 +91,17 @@ ErrorOr<size_t> SysFSUSBDeviceInformation::read_bytes(off_t offset, size_t count
return nread;
}
-ErrorOr<void> SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> SysFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
SpinlockLocker lock(m_lock);
// Note: if the parent directory is null, it means something bad happened as this should not happen for the USB directory.
VERIFY(m_parent_directory);
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, m_parent_directory->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, m_parent_directory->component_index() }, 0 }));
for (auto& device_node : m_device_nodes) {
InodeIdentifier identifier = { fsid, device_node.component_index() };
- callback({ device_node.name(), identifier, 0 });
+ TRY(callback({ device_node.name(), identifier, 0 }));
}
return {};
}
diff --git a/Kernel/Bus/USB/SysFSUSB.h b/Kernel/Bus/USB/SysFSUSB.h
index 9891c87b13..ffb14a3740 100644
--- a/Kernel/Bus/USB/SysFSUSB.h
+++ b/Kernel/Bus/USB/SysFSUSB.h
@@ -46,7 +46,7 @@ public:
void plug(USB::Device&);
void unplug(USB::Device&);
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:
diff --git a/Kernel/Devices/Device.cpp b/Kernel/Devices/Device.cpp
index ccd46b1881..ea4063117d 100644
--- a/Kernel/Devices/Device.cpp
+++ b/Kernel/Devices/Device.cpp
@@ -44,21 +44,23 @@ SysFSBlockDevicesDirectory::SysFSBlockDevicesDirectory(SysFSDevicesDirectory con
: SysFSDirectory("block"sv, devices_directory)
{
}
-ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+
+ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(m_parent_directory);
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, m_parent_directory->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, m_parent_directory->component_index() }, 0 }));
- SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
+ return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> ErrorOr<void> {
for (auto& exposed_device : list) {
if (!exposed_device.is_block_device())
continue;
- callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
+ TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 }));
}
+ return {};
});
- return {};
}
+
RefPtr<SysFSComponent> SysFSBlockDevicesDirectory::lookup(StringView name)
{
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
@@ -80,21 +82,22 @@ SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDevicesDirec
: SysFSDirectory("char"sv, devices_directory)
{
}
-ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(m_parent_directory);
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, m_parent_directory->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, m_parent_directory->component_index() }, 0 }));
- SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
+ return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> ErrorOr<void> {
for (auto& exposed_device : list) {
if (exposed_device.is_block_device())
continue;
- callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
+ TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 }));
}
+ return {};
});
- return {};
}
+
RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
{
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp
index ef49e6b4c0..422430d126 100644
--- a/Kernel/FileSystem/DevPtsFS.cpp
+++ b/Kernel/FileSystem/DevPtsFS.cpp
@@ -105,23 +105,22 @@ InodeMetadata DevPtsFSInode::metadata() const
return m_metadata;
}
-ErrorOr<void> DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> DevPtsFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
if (identifier().index() > 1)
return ENOTDIR;
- callback({ ".", identifier(), 0 });
- callback({ "..", identifier(), 0 });
+ TRY(callback({ ".", identifier(), 0 }));
+ TRY(callback({ "..", identifier(), 0 }));
- SlavePTY::all_instances().with([&](auto& list) {
+ return SlavePTY::all_instances().with([&](auto& list) -> ErrorOr<void> {
for (SlavePTY& slave_pty : list) {
StringBuilder builder;
builder.appendff("{}", slave_pty.index());
- callback({ builder.string_view(), { fsid(), pty_index_to_inode_index(slave_pty.index()) }, 0 });
+ TRY(callback({ builder.string_view(), { fsid(), pty_index_to_inode_index(slave_pty.index()) }, 0 }));
}
+ return {};
});
-
- return {};
}
ErrorOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS.h
index 9b2f6a0229..65a6e92c1f 100644
--- a/Kernel/FileSystem/DevPtsFS.h
+++ b/Kernel/FileSystem/DevPtsFS.h
@@ -49,7 +49,7 @@ private:
// ^Inode
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
diff --git a/Kernel/FileSystem/DevTmpFS.cpp b/Kernel/FileSystem/DevTmpFS.cpp
index 2a12915312..2ce31042fb 100644
--- a/Kernel/FileSystem/DevTmpFS.cpp
+++ b/Kernel/FileSystem/DevTmpFS.cpp
@@ -60,7 +60,7 @@ ErrorOr<size_t> DevTmpFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, Op
VERIFY_NOT_REACHED();
}
-ErrorOr<void> DevTmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
+ErrorOr<void> DevTmpFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
@@ -210,14 +210,14 @@ DevTmpFSDirectoryInode::~DevTmpFSDirectoryInode()
{
}
-ErrorOr<void> DevTmpFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> DevTmpFSDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(m_inode_lock);
- callback({ ".", identifier(), 0 });
- callback({ "..", identifier(), 0 });
+ TRY(callback({ ".", identifier(), 0 }));
+ TRY(callback({ "..", identifier(), 0 }));
for (auto& node : m_nodes) {
InodeIdentifier identifier = { fsid(), node.index() };
- callback({ node.name(), identifier, 0 });
+ TRY(callback({ node.name(), identifier, 0 }));
}
return {};
}
diff --git a/Kernel/FileSystem/DevTmpFS.h b/Kernel/FileSystem/DevTmpFS.h
index 9a203d83a8..837ecb25df 100644
--- a/Kernel/FileSystem/DevTmpFS.h
+++ b/Kernel/FileSystem/DevTmpFS.h
@@ -49,7 +49,7 @@ protected:
explicit DevTmpFSInode(DevTmpFS&);
DevTmpFSInode(DevTmpFS&, unsigned, unsigned);
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual InodeMetadata metadata() const override final;
@@ -138,7 +138,7 @@ protected:
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> remove_child(const StringView& name) override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
DevTmpFSDirectoryInode(DevTmpFS&, NonnullOwnPtr<KString> name);
// ^Inode
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 673ff7558d..b6b1a49514 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -1058,7 +1058,7 @@ Ext2FS::FeaturesReadOnly Ext2FS::get_features_readonly() const
return Ext2FS::FeaturesReadOnly::None;
}
-ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(is_directory());
@@ -1079,8 +1079,7 @@ ErrorOr<void> Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::Direc
while (entry < entries_end) {
if (entry->inode != 0) {
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::traverse_as_directory(): inode {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", identifier(), entry->inode, entry->name_len, entry->rec_len, entry->file_type, StringView(entry->name, entry->name_len));
- if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }))
- return {};
+ TRY(callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }));
}
entry = (ext2_dir_entry_2*)((char*)entry + entry->rec_len);
}
@@ -1167,21 +1166,13 @@ ErrorOr<void> Ext2FSInode::add_child(Inode& child, const StringView& name, mode_
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::add_child(): Adding inode {} with name '{}' and mode {:o} to directory {}", identifier(), child.index(), name, mode, index());
Vector<Ext2FSDirectoryEntry> entries;
- bool name_already_exists = false;
- TRY(traverse_as_directory([&](auto& entry) {
- if (name == entry.name) {
- name_already_exists = true;
- return false;
- }
+ TRY(traverse_as_directory([&](auto& entry) -> ErrorOr<void> {
+ if (name == entry.name)
+ return EEXIST;
entries.append({ entry.name, entry.inode.index(), entry.file_type });
- return true;
+ return {};
}));
- if (name_already_exists) {
- dbgln("Ext2FSInode[{}]::add_child(): Name '{}' already exists", identifier(), name);
- return EEXIST;
- }
-
TRY(child.increment_link_count());
entries.empend(name, child.index(), to_ext2_file_type(mode));
@@ -1210,10 +1201,10 @@ ErrorOr<void> Ext2FSInode::remove_child(const StringView& name)
InodeIdentifier child_id { fsid(), child_inode_index };
Vector<Ext2FSDirectoryEntry> entries;
- TRY(traverse_as_directory([&](auto& entry) {
+ TRY(traverse_as_directory([&](auto& entry) -> ErrorOr<void> {
if (name != entry.name)
entries.append({ entry.name, entry.inode.index(), entry.file_type });
- return true;
+ return {};
}));
TRY(write_directory(entries));
@@ -1540,9 +1531,9 @@ ErrorOr<void> Ext2FSInode::populate_lookup_cache() const
return {};
HashMap<String, InodeIndex> children;
- TRY(traverse_as_directory([&children](auto& entry) {
+ TRY(traverse_as_directory([&children](auto& entry) -> ErrorOr<void> {
children.set(entry.name, entry.inode.index());
- return true;
+ return {};
}));
VERIFY(m_lookup_cache.is_empty());
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index c252b463b9..7e6733a20a 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -40,7 +40,7 @@ private:
// ^Inode
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
diff --git a/Kernel/FileSystem/ISO9660FileSystem.cpp b/Kernel/FileSystem/ISO9660FileSystem.cpp
index fb53518945..aec85af922 100644
--- a/Kernel/FileSystem/ISO9660FileSystem.cpp
+++ b/Kernel/FileSystem/ISO9660FileSystem.cpp
@@ -447,9 +447,10 @@ InodeMetadata ISO9660Inode::metadata() const
return m_metadata;
}
-ErrorOr<void> ISO9660Inode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> visitor) const
+ErrorOr<void> ISO9660Inode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> visitor) const
{
Array<u8, max_file_identifier_length> file_identifier_buffer;
+ ErrorOr<void> result;
return fs().visit_directory_record(m_record, [&](ISO::DirectoryRecordHeader const* record) {
StringView filename = get_normalized_filename(*record, file_identifier_buffer);
@@ -458,9 +459,9 @@ ErrorOr<void> ISO9660Inode::traverse_as_directory(Function<bool(FileSystem::Dire
InodeIdentifier id { fsid(), get_inode_index(*record, filename) };
auto entry = FileSystem::DirectoryEntryView(filename, id, static_cast<u8>(record->file_flags));
- if (!visitor(entry)) {
+ result = visitor(entry);
+ if (result.is_error())
return RecursionDecision::Break;
- }
return RecursionDecision::Continue;
});
diff --git a/Kernel/FileSystem/ISO9660FileSystem.h b/Kernel/FileSystem/ISO9660FileSystem.h
index d578966117..70b17b0e2d 100644
--- a/Kernel/FileSystem/ISO9660FileSystem.h
+++ b/Kernel/FileSystem/ISO9660FileSystem.h
@@ -349,7 +349,7 @@ public:
// ^Inode
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index e0ede5b092..68ca3ce824 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -53,7 +53,7 @@ public:
virtual void detach(OpenFileDescription&) { }
virtual void did_seek(OpenFileDescription&, off_t) { }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const = 0;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const = 0;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) = 0;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) = 0;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0;
diff --git a/Kernel/FileSystem/OpenFileDescription.cpp b/Kernel/FileSystem/OpenFileDescription.cpp
index a408e085e5..06ff77418a 100644
--- a/Kernel/FileSystem/OpenFileDescription.cpp
+++ b/Kernel/FileSystem/OpenFileDescription.cpp
@@ -238,18 +238,17 @@ ErrorOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& output_
return true;
};
- ErrorOr<void> result = VirtualFileSystem::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &stream, this](auto& entry) {
+ ErrorOr<void> result = VirtualFileSystem::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &error, &stream, this](auto& entry) -> ErrorOr<void> {
size_t serialized_size = sizeof(ino_t) + sizeof(u8) + sizeof(size_t) + sizeof(char) * entry.name.length();
if (serialized_size > stream.remaining()) {
- if (!flush_stream_to_output_buffer()) {
- return false;
- }
+ if (!flush_stream_to_output_buffer())
+ return error;
}
stream << (u64)entry.inode.index().value();
stream << m_inode->fs().internal_file_type_to_directory_entry_type(entry);
stream << (u32)entry.name.length();
stream << entry.name.bytes();
- return true;
+ return {};
});
flush_stream_to_output_buffer();
diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp
index 95439a9356..c543ada187 100644
--- a/Kernel/FileSystem/Plan9FileSystem.cpp
+++ b/Kernel/FileSystem/Plan9FileSystem.cpp
@@ -828,7 +828,7 @@ ErrorOr<void> Plan9FSInode::flush_metadata()
return {};
}
-ErrorOr<void> Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> Plan9FSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
// TODO: Should we synthesize "." and ".." here?
@@ -873,8 +873,13 @@ ErrorOr<void> Plan9FSInode::traverse_as_directory(Function<bool(FileSystem::Dire
u8 type;
StringView name;
decoder >> qid >> offset >> type >> name;
- callback({ name, { fsid(), fs().allocate_fid() }, 0 });
+ result = callback({ name, { fsid(), fs().allocate_fid() }, 0 });
+ if (result.is_error())
+ break;
}
+
+ if (result.is_error())
+ break;
}
Plan9FS::Message close_message { fs(), Plan9FS::Message::Type::Tclunk };
diff --git a/Kernel/FileSystem/Plan9FileSystem.h b/Kernel/FileSystem/Plan9FileSystem.h
index bf21e3f672..13c7b4fd3b 100644
--- a/Kernel/FileSystem/Plan9FileSystem.h
+++ b/Kernel/FileSystem/Plan9FileSystem.h
@@ -158,7 +158,7 @@ public:
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override;
virtual ErrorOr<void> add_child(Inode&, const StringView& name, mode_t) override;
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index 675541e4b8..bcd5e50371 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -137,7 +137,7 @@ StringView ProcFSGlobalInode::name() const
return m_associated_component->name();
}
-ErrorOr<void> ProcFSGlobalInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
+ErrorOr<void> ProcFSGlobalInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
@@ -200,7 +200,7 @@ InodeMetadata ProcFSDirectoryInode::metadata() const
metadata.mtime = m_associated_component->modified_time();
return metadata;
}
-ErrorOr<void> ProcFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> ProcFSDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
return m_associated_component->traverse_as_directory(procfs().fsid(), move(callback));
@@ -285,7 +285,7 @@ ErrorOr<size_t> ProcFSProcessDirectoryInode::read_bytes(off_t, size_t, UserOrKer
VERIFY_NOT_REACHED();
}
-ErrorOr<void> ProcFSProcessDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> ProcFSProcessDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@@ -365,7 +365,7 @@ InodeMetadata ProcFSProcessSubDirectoryInode::metadata() const
return metadata;
}
-ErrorOr<void> ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(procfs().m_lock);
auto process = Process::from_pid(associated_pid());
@@ -474,7 +474,7 @@ InodeMetadata ProcFSProcessPropertyInode::metadata() const
metadata.mtime = traits->modified_time();
return metadata;
}
-ErrorOr<void> ProcFSProcessPropertyInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
+ErrorOr<void> ProcFSProcessPropertyInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h
index 7801ddbf72..6ed723cf8a 100644
--- a/Kernel/FileSystem/ProcFS.h
+++ b/Kernel/FileSystem/ProcFS.h
@@ -81,7 +81,7 @@ protected:
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
virtual void did_seek(OpenFileDescription&, off_t) override final;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView) override;
virtual ErrorOr<void> truncate(u64) override final;
virtual ErrorOr<void> set_mtime(time_t) override final;
@@ -111,7 +111,7 @@ protected:
ProcFSDirectoryInode(const ProcFS&, const ProcFSExposedComponent&);
// ^Inode
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
@@ -141,7 +141,7 @@ private:
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override { }
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
@@ -158,7 +158,7 @@ private:
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
@@ -181,7 +181,7 @@ private:
virtual ErrorOr<void> attach(OpenFileDescription& description) override;
virtual void did_seek(OpenFileDescription&, off_t) override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override final;
diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp
index b4a9614822..3ae80d3a31 100644
--- a/Kernel/FileSystem/SysFS.cpp
+++ b/Kernel/FileSystem/SysFS.cpp
@@ -46,15 +46,15 @@ NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create()
return adopt_ref(*new (nothrow) SysFSRootDirectory);
}
-ErrorOr<void> SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, 0 }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, 0 }, 0 }));
for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() };
- callback({ component.name(), identifier, 0 });
+ TRY(callback({ component.name(), identifier, 0 }));
}
return {};
}
@@ -125,7 +125,7 @@ ErrorOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelB
return m_associated_component->read_bytes(offset, count, buffer, fd);
}
-ErrorOr<void> SysFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const
+ErrorOr<void> SysFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const
{
VERIFY_NOT_REACHED();
}
@@ -219,7 +219,7 @@ InodeMetadata SysFSDirectoryInode::metadata() const
metadata.mtime = mepoch;
return metadata;
}
-ErrorOr<void> SysFSDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> SysFSDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(fs().m_lock);
return m_associated_component->traverse_as_directory(fs().fsid(), move(callback));
diff --git a/Kernel/FileSystem/SysFS.h b/Kernel/FileSystem/SysFS.h
index 2a8a8a4518..2a021a4890 100644
--- a/Kernel/FileSystem/SysFS.h
+++ b/Kernel/FileSystem/SysFS.h
@@ -19,7 +19,7 @@ class SysFSRootDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSRootDirectory> create();
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
private:
SysFSRootDirectory();
@@ -53,7 +53,7 @@ private:
class SysFSBlockDevicesDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSBlockDevicesDirectory> must_create(SysFSDevicesDirectory const&);
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:
@@ -63,7 +63,7 @@ private:
class SysFSCharacterDevicesDirectory final : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSCharacterDevicesDirectory> must_create(SysFSDevicesDirectory const&);
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
private:
@@ -135,7 +135,7 @@ public:
protected:
SysFSInode(SysFS const&, SysFSComponent const&);
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual InodeMetadata metadata() const override;
@@ -168,7 +168,7 @@ protected:
SysFSDirectoryInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
};
diff --git a/Kernel/FileSystem/SysFSComponent.cpp b/Kernel/FileSystem/SysFSComponent.cpp
index 807a129ab7..f3818f0cc2 100644
--- a/Kernel/FileSystem/SysFSComponent.cpp
+++ b/Kernel/FileSystem/SysFSComponent.cpp
@@ -31,16 +31,16 @@ mode_t SysFSComponent::permissions() const
return S_IRUSR | S_IRGRP | S_IROTH;
}
-ErrorOr<void> SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> SysFSDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
VERIFY(m_parent_directory);
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, m_parent_directory->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, m_parent_directory->component_index() }, 0 }));
for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() };
- callback({ component.name(), identifier, 0 });
+ TRY(callback({ component.name(), identifier, 0 }));
}
return {};
}
diff --git a/Kernel/FileSystem/SysFSComponent.h b/Kernel/FileSystem/SysFSComponent.h
index e42620d419..d5b52e983e 100644
--- a/Kernel/FileSystem/SysFSComponent.h
+++ b/Kernel/FileSystem/SysFSComponent.h
@@ -27,7 +27,7 @@ class SysFSComponent : public RefCounted<SysFSComponent> {
public:
virtual StringView name() const { return m_name->view(); }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
virtual mode_t permissions() const;
virtual ErrorOr<void> truncate(u64) { return EPERM; }
@@ -51,7 +51,7 @@ private:
class SysFSDirectory : public SysFSComponent {
public:
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index 824c04a106..cdff254276 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -107,18 +107,18 @@ InodeMetadata TmpFSInode::metadata() const
return m_metadata;
}
-ErrorOr<void> TmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> TmpFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(m_inode_lock, Mutex::Mode::Shared);
if (!is_directory())
return ENOTDIR;
- callback({ ".", identifier(), 0 });
- callback({ "..", m_parent, 0 });
+ TRY(callback({ ".", identifier(), 0 }));
+ TRY(callback({ "..", m_parent, 0 }));
for (auto& child : m_children) {
- callback({ child.name->view(), child.inode->identifier(), 0 });
+ TRY(callback({ child.name->view(), child.inode->identifier(), 0 }));
}
return {};
}
diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h
index 9152964729..43f83ef3a5 100644
--- a/Kernel/FileSystem/TmpFS.h
+++ b/Kernel/FileSystem/TmpFS.h
@@ -54,7 +54,7 @@ public:
// ^Inode
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
virtual InodeMetadata metadata() const override;
- virtual ErrorOr<void> traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
virtual ErrorOr<void> flush_metadata() override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override;
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index 319cb91d9c..f3b524d7b2 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -162,9 +162,9 @@ bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const
return inode == root_inode_id();
}
-ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
+ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback)
{
- return dir_inode.traverse_as_directory([&](auto& entry) {
+ return dir_inode.traverse_as_directory([&](auto& entry) -> ErrorOr<void> {
InodeIdentifier resolved_inode;
if (auto mount = find_mount_for_host(entry.inode))
resolved_inode = mount->guest().identifier();
@@ -179,8 +179,8 @@ ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Func
VERIFY(mount->host());
resolved_inode = mount->host()->identifier();
}
- callback({ entry.name, resolved_inode, entry.file_type });
- return true;
+ TRY(callback({ entry.name, resolved_inode, entry.file_type }));
+ return {};
});
}
@@ -467,9 +467,9 @@ ErrorOr<void> VirtualFileSystem::rename(StringView old_path, StringView new_path
if (old_inode.index() != new_inode.index() && old_inode.is_directory() && new_inode.is_directory()) {
size_t child_count = 0;
- TRY(new_inode.traverse_as_directory([&child_count](auto&) {
+ TRY(new_inode.traverse_as_directory([&child_count](auto&) -> ErrorOr<void> {
++child_count;
- return child_count <= 2;
+ return {};
}));
if (child_count > 2)
return ENOTEMPTY;
@@ -710,9 +710,9 @@ ErrorOr<void> VirtualFileSystem::rmdir(StringView path, Custody& base)
}
size_t child_count = 0;
- TRY(inode.traverse_as_directory([&child_count](auto&) {
+ TRY(inode.traverse_as_directory([&child_count](auto&) -> ErrorOr<void> {
++child_count;
- return true;
+ return {};
}));
if (child_count != 2)
diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h
index bbf2d77ec0..a57721e7ad 100644
--- a/Kernel/FileSystem/VirtualFileSystem.h
+++ b/Kernel/FileSystem/VirtualFileSystem.h
@@ -85,7 +85,7 @@ private:
bool is_vfs_root(InodeIdentifier) const;
- ErrorOr<void> traverse_directory_inode(Inode&, Function<bool(FileSystem::DirectoryEntryView const&)>);
+ ErrorOr<void> traverse_directory_inode(Inode&, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>);
Mount* find_mount_for_host(InodeIdentifier);
Mount* find_mount_for_guest(InodeIdentifier);
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index 782a940579..3efb3d3a7c 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -936,24 +936,26 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRootDirectory> ProcFSRootDirectory::must_cr
return directory;
}
-ErrorOr<void> ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(ProcFSComponentRegistry::the().get_lock());
- callback({ ".", { fsid, component_index() }, 0 });
- callback({ "..", { fsid, 0 }, 0 });
+ TRY(callback({ ".", { fsid, component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, 0 }, 0 }));
for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() };
- callback({ component.name(), identifier, 0 });
+ TRY(callback({ component.name(), identifier, 0 }));
}
- processes().for_each([&](Process& process) {
- VERIFY(!(process.pid() < 0));
- u64 process_id = (u64)process.pid().value();
- InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
- callback({ String::formatted("{:d}", process.pid().value()), identifier, 0 });
- return IterationDecision::Continue;
+
+ return processes().with([&](auto& list) -> ErrorOr<void> {
+ for (auto& process : list) {
+ VERIFY(!(process.pid() < 0));
+ u64 process_id = (u64)process.pid().value();
+ InodeIdentifier identifier = { fsid, static_cast<InodeIndex>(process_id << 36) };
+ TRY(callback({ String::formatted("{:d}", process.pid().value()), identifier, 0 }));
+ }
+ return {};
});
- return {};
}
ErrorOr<NonnullRefPtr<ProcFSExposedComponent>> ProcFSRootDirectory::lookup(StringView name)
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 498e66e7ce..f212074fc2 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -566,10 +566,10 @@ public:
ErrorOr<void> procfs_get_current_work_directory_link(KBufferBuilder& builder) const;
mode_t binary_link_required_mode() const;
ErrorOr<size_t> procfs_get_thread_stack(ThreadID thread_id, KBufferBuilder& builder) const;
- ErrorOr<void> traverse_stacks_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const;
+ ErrorOr<void> traverse_stacks_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const;
ErrorOr<NonnullRefPtr<Inode>> lookup_stacks_directory(const ProcFS&, StringView name) const;
ErrorOr<size_t> procfs_get_file_description_link(unsigned fd, KBufferBuilder& builder) const;
- ErrorOr<void> traverse_file_descriptions_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const;
+ ErrorOr<void> traverse_file_descriptions_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const;
ErrorOr<NonnullRefPtr<Inode>> lookup_file_descriptions_directory(const ProcFS&, StringView name) const;
private:
@@ -723,7 +723,7 @@ public:
virtual InodeIndex component_index() const override;
virtual ErrorOr<NonnullRefPtr<Inode>> to_inode(const ProcFS& procfs_instance) const override;
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual mode_t required_mode() const override { return 0555; }
virtual UserID owner_user() const override;
diff --git a/Kernel/ProcessExposed.cpp b/Kernel/ProcessExposed.cpp
index d3d188bc9a..f4aa24d627 100644
--- a/Kernel/ProcessExposed.cpp
+++ b/Kernel/ProcessExposed.cpp
@@ -232,18 +232,18 @@ ErrorOr<NonnullRefPtr<ProcFSExposedComponent>> ProcFSExposedDirectory::lookup(St
return ENOENT;
}
-ErrorOr<void> ProcFSExposedDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> ProcFSExposedDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(ProcFSComponentRegistry::the().get_lock());
auto parent_directory = m_parent_directory.strong_ref();
if (parent_directory.is_null())
return Error::from_errno(EINVAL);
- callback({ ".", { fsid, component_index() }, DT_DIR });
- callback({ "..", { fsid, parent_directory->component_index() }, DT_DIR });
+ TRY(callback({ ".", { fsid, component_index() }, DT_DIR }));
+ TRY(callback({ "..", { fsid, parent_directory->component_index() }, DT_DIR }));
for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() };
- callback({ component.name(), identifier, 0 });
+ TRY(callback({ component.name(), identifier, 0 }));
}
return {};
}
diff --git a/Kernel/ProcessExposed.h b/Kernel/ProcessExposed.h
index d46579e035..552f1c528e 100644
--- a/Kernel/ProcessExposed.h
+++ b/Kernel/ProcessExposed.h
@@ -67,7 +67,7 @@ class ProcFSExposedComponent : public RefCounted<ProcFSExposedComponent> {
public:
StringView name() const { return m_name->view(); }
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); }
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual ErrorOr<NonnullRefPtr<ProcFSExposedComponent>> lookup(StringView) { VERIFY_NOT_REACHED(); };
virtual ErrorOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { return EROFS; }
virtual ErrorOr<void> truncate(u64) { return EPERM; }
@@ -105,7 +105,7 @@ class ProcFSExposedDirectory
friend class ProcFSComponentRegistry;
public:
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullRefPtr<ProcFSExposedComponent>> lookup(StringView name) override;
void add_component(const ProcFSExposedComponent&);
@@ -147,7 +147,7 @@ public:
virtual ~ProcFSRootDirectory();
private:
- virtual ErrorOr<void> traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
+ virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
ProcFSRootDirectory();
};
diff --git a/Kernel/ProcessProcFSTraits.cpp b/Kernel/ProcessProcFSTraits.cpp
index d9592f4744..320bd8746d 100644
--- a/Kernel/ProcessProcFSTraits.cpp
+++ b/Kernel/ProcessProcFSTraits.cpp
@@ -45,23 +45,23 @@ ErrorOr<NonnullRefPtr<Inode>> Process::ProcessProcFSTraits::to_inode(const ProcF
return TRY(ProcFSProcessDirectoryInode::try_create(procfs_instance, process->pid()));
}
-ErrorOr<void> Process::ProcessProcFSTraits::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> Process::ProcessProcFSTraits::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
auto process = m_process.strong_ref();
if (!process)
return ESRCH;
- callback({ ".", { fsid, SegmentedProcFSIndex::build_segmented_index_for_pid_directory(process->pid()) }, DT_DIR });
- callback({ "..", { fsid, ProcFSComponentRegistry::the().root_directory().component_index() }, DT_DIR });
- callback({ "fd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) }, DT_DIR });
- callback({ "stacks", { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks) }, DT_DIR });
- callback({ "unveil", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Unveil) }, DT_REG });
- callback({ "pledge", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Pledge) }, DT_REG });
- callback({ "fds", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::OpenFileDescriptions) }, DT_DIR });
- callback({ "exe", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::BinaryLink) }, DT_LNK });
- callback({ "cwd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) }, DT_LNK });
- callback({ "perf_events", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents) }, DT_REG });
- callback({ "vm", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats) }, DT_REG });
+ TRY(callback({ ".", { fsid, SegmentedProcFSIndex::build_segmented_index_for_pid_directory(process->pid()) }, DT_DIR }));
+ TRY(callback({ "..", { fsid, ProcFSComponentRegistry::the().root_directory().component_index() }, DT_DIR }));
+ TRY(callback({ "fd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) }, DT_DIR }));
+ TRY(callback({ "stacks", { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks) }, DT_DIR }));
+ TRY(callback({ "unveil", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Unveil) }, DT_REG }));
+ TRY(callback({ "pledge", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Pledge) }, DT_REG }));
+ TRY(callback({ "fds", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::OpenFileDescriptions) }, DT_DIR }));
+ TRY(callback({ "exe", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::BinaryLink) }, DT_LNK }));
+ TRY(callback({ "cwd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) }, DT_LNK }));
+ TRY(callback({ "perf_events", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents) }, DT_REG }));
+ TRY(callback({ "vm", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats) }, DT_REG }));
return {};
}
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp
index 2c3a27b8d6..58823770d2 100644
--- a/Kernel/ProcessSpecificExposed.cpp
+++ b/Kernel/ProcessSpecificExposed.cpp
@@ -41,17 +41,19 @@ ErrorOr<size_t> Process::procfs_get_thread_stack(ThreadID thread_id, KBufferBuil
return 0;
}
-ErrorOr<void> Process::traverse_stacks_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> Process::traverse_stacks_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
- callback({ ".", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property(pid(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks, SegmentedProcFSIndex::MainProcessProperty::Reserved) }, 0 });
- callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property(pid(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks, SegmentedProcFSIndex::MainProcessProperty::Reserved) }, 0 }));
+ TRY(callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 }));
- for_each_thread([&](const Thread& thread) {
- int tid = thread.tid().value();
- InodeIdentifier identifier = { fsid, SegmentedProcFSIndex::build_segmented_index_for_thread_stack(pid(), thread.tid()) };
- callback({ String::number(tid), identifier, 0 });
+ return thread_list().with([&](auto& list) -> ErrorOr<void> {
+ for (auto const& thread : list) {
+ int tid = thread.tid().value();
+ InodeIdentifier identifier = { fsid, SegmentedProcFSIndex::build_segmented_index_for_thread_stack(pid(), thread.tid()) };
+ TRY(callback({ String::number(tid), identifier, 0 }));
+ }
+ return {};
});
- return {};
}
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& procfs, StringView name) const
@@ -87,10 +89,10 @@ ErrorOr<size_t> Process::procfs_get_file_description_link(unsigned fd, KBufferBu
return data->length();
}
-ErrorOr<void> Process::traverse_file_descriptions_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
+ErrorOr<void> Process::traverse_file_descriptions_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
- callback({ ".", { fsid, m_procfs_traits->component_index() }, 0 });
- callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 });
+ TRY(callback({ ".", { fsid, m_procfs_traits->component_index() }, 0 }));
+ TRY(callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 }));
size_t count = 0;
fds().enumerate([&](auto& file_description_metadata) {
if (!file_description_metadata.is_valid()) {
@@ -99,7 +101,8 @@ ErrorOr<void> Process::traverse_file_descriptions_directory(unsigned fsid, Funct
}
StringBuilder builder;
builder.appendff("{}", count);
- callback({ builder.string_view(), { fsid, SegmentedProcFSIndex::build_segmented_index_for_file_description(pid(), count) }, DT_LNK });
+ // FIXME: Propagate errors from callback.
+ (void)callback({ builder.string_view(), { fsid, SegmentedProcFSIndex::build_segmented_index_for_file_description(pid(), count) }, DT_LNK });
count++;
});
return {};