Kernel: Make Inode::directory_entry_count errors observable.

Certain implementations of Inode::directory_entry_count were calling
functions which returned errors, but had no way of surfacing them.
Switch the return type to KResultOr<size_t> and start observing these
error paths.
This commit is contained in:
Brian Gianforcaro 2020-08-05 01:00:18 -07:00 committed by Andreas Kling
parent 7490ea9449
commit e8c9b5e870
Notes: sideshowbarker 2024-07-19 04:17:38 +09:00
12 changed files with 29 additions and 17 deletions

View file

@ -153,7 +153,7 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEn
return KSuccess;
}
size_t DevPtsFSInode::directory_entry_count() const
KResultOr<size_t> DevPtsFSInode::directory_entry_count() const
{
ASSERT(identifier().index() == 1);

View file

@ -76,7 +76,7 @@ private:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;

View file

@ -1562,7 +1562,7 @@ void Ext2FS::uncache_inode(InodeIndex index)
m_inode_cache.remove(index);
}
size_t Ext2FSInode::directory_entry_count() const
KResultOr<size_t> Ext2FSInode::directory_entry_count() const
{
ASSERT(is_directory());
LOCKER(m_lock);

View file

@ -71,7 +71,7 @@ private:
virtual int set_mtime(time_t) override;
virtual KResult increment_link_count() override;
virtual KResult decrement_link_count() override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(u64) override;

View file

@ -76,7 +76,7 @@ public:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) = 0;
virtual KResult add_child(Inode&, const StringView& name, mode_t) = 0;
virtual KResult remove_child(const StringView& name) = 0;
virtual size_t directory_entry_count() const = 0;
virtual KResultOr<size_t> directory_entry_count() const = 0;
virtual KResult chmod(mode_t) = 0;
virtual KResult chown(uid_t, gid_t) = 0;
virtual KResult truncate(u64) { return KSuccess; }

View file

@ -794,13 +794,17 @@ void Plan9FSInode::flush_metadata()
// Do nothing.
}
size_t Plan9FSInode::directory_entry_count() const
KResultOr<size_t> Plan9FSInode::directory_entry_count() const
{
size_t count = 0;
traverse_as_directory([&count](const FS::DirectoryEntry&) {
KResult result = traverse_as_directory([&count](const FS::DirectoryEntry&) {
count++;
return true;
});
if (result.is_error())
return result;
return count;
}

View file

@ -131,7 +131,7 @@ public:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(u64) override;

View file

@ -1515,10 +1515,10 @@ RefPtr<Inode> ProcFSProxyInode::lookup(StringView name)
return m_fd->inode()->lookup(name);
}
size_t ProcFSProxyInode::directory_entry_count() const
KResultOr<size_t> ProcFSProxyInode::directory_entry_count() const
{
if (!m_fd->inode())
return 0;
return KResult(-EINVAL);
return m_fd->inode()->directory_entry_count();
}
@ -1538,14 +1538,18 @@ KResult ProcFSInode::remove_child(const StringView& name)
return KResult(-EPERM);
}
size_t ProcFSInode::directory_entry_count() const
KResultOr<size_t> ProcFSInode::directory_entry_count() const
{
ASSERT(is_directory());
size_t count = 0;
traverse_as_directory([&count](const FS::DirectoryEntry&) {
KResult result = traverse_as_directory([&count](const FS::DirectoryEntry&) {
++count;
return true;
});
if (result.is_error())
return result;
return count;
}

View file

@ -105,7 +105,7 @@ private:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResultOr<NonnullRefPtr<Custody>> resolve_as_link(Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0) const override;
@ -132,7 +132,7 @@ private:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override { return KResult(-EINVAL); }
virtual KResult chown(uid_t, gid_t) override { return KResult(-EINVAL); }
virtual KResultOr<NonnullRefPtr<Custody>> resolve_as_link(Custody&, RefPtr<Custody>*, int, int) const override { ASSERT_NOT_REACHED(); }

View file

@ -219,7 +219,7 @@ RefPtr<Inode> TmpFSInode::lookup(StringView name)
return fs().get_inode(it->value.entry.inode);
}
size_t TmpFSInode::directory_entry_count() const
KResultOr<size_t> TmpFSInode::directory_entry_count() const
{
LOCKER(m_lock, Lock::Mode::Shared);
ASSERT(is_directory());

View file

@ -83,7 +83,7 @@ public:
virtual KResultOr<NonnullRefPtr<Inode>> create_child(const String& name, mode_t, dev_t, uid_t, gid_t) override;
virtual KResult add_child(Inode&, const StringView& name, mode_t) override;
virtual KResult remove_child(const StringView& name) override;
virtual size_t directory_entry_count() const override;
virtual KResultOr<size_t> directory_entry_count() const override;
virtual KResult chmod(mode_t) override;
virtual KResult chown(uid_t, gid_t) override;
virtual KResult truncate(u64) override;

View file

@ -731,7 +731,11 @@ KResult VFS::rmdir(StringView path, Custody& base)
if (!parent_inode.metadata().may_write(*Process::current()))
return KResult(-EACCES);
if (inode.directory_entry_count() != 2)
KResultOr<size_t> dir_count_result = inode.directory_entry_count();
if (dir_count_result.is_error())
return dir_count_result.result();
if (dir_count_result.value() != 2)
return KResult(-ENOTEMPTY);
if (custody.is_readonly())