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

Kernel: Deemphasize inode identifiers

These APIs were clearly modeled after Ext2FS internals, and make perfect sense
in Ext2FS context. The new APIs are more generic, and map better to the
semantics exported to the userspace, where inode identifiers only appear in
stat() and readdir() output, but never in any input.

This will also hopefully reduce the potential for races (see commit c44b4d61f3).

Lastly, this makes it way more viable to implement a filesystem that only
synthesizes its inodes lazily when queried, and destroys them when they are no
longer in use. With inode identifiers being used to reference inodes, the only
choice for such a filesystem is to persist any inode it has given out the
identifier for, because it might be queried at any later time. With direct
references to inodes, the filesystem will know when the last reference is
dropped and the inode can be safely destroyed.
This commit is contained in:
Sergey Bugaev 2020-06-24 23:35:56 +03:00 committed by Andreas Kling
parent c689be0dbc
commit df66c28479
12 changed files with 133 additions and 160 deletions

View file

@ -75,19 +75,9 @@ static unsigned pty_index_to_inode_index(unsigned pty_index)
return pty_index + 2;
}
InodeIdentifier DevPtsFS::root_inode() const
NonnullRefPtr<Inode> DevPtsFS::root_inode() const
{
return { fsid(), 1 };
}
KResultOr<NonnullRefPtr<Inode>> DevPtsFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, uid_t, gid_t)
{
return KResult(-EROFS);
}
KResult DevPtsFS::create_directory(InodeIdentifier, const String&, mode_t, uid_t, gid_t)
{
return KResult(-EROFS);
return *m_root_inode;
}
RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
@ -175,11 +165,13 @@ RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
ASSERT(identifier().index() == 1);
if (name == "." || name == "..")
return fs().get_inode(identifier());
return this;
auto& fs = static_cast<DevPtsFS&>(this->fs());
auto pty_index = name.to_uint();
if (pty_index.has_value() && ptys->contains(pty_index.value())) {
return fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
}
return {};
@ -189,7 +181,12 @@ void DevPtsFSInode::flush_metadata()
{
}
KResult DevPtsFSInode::add_child(InodeIdentifier, const StringView&, mode_t)
KResult DevPtsFSInode::add_child(Inode&, const StringView&, mode_t)
{
return KResult(-EROFS);
}
KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t)
{
return KResult(-EROFS);
}