1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:17:45 +00:00

Kernel: Only allow looking up Mounts by InodeIdentifier

Let's simplify the interface by not allowing lookup by Inode&.
This commit is contained in:
Andreas Kling 2021-07-11 00:50:08 +02:00
parent 6a27de2d94
commit 4238e2e9be
2 changed files with 3 additions and 23 deletions

View file

@ -82,7 +82,7 @@ KResult VirtualFileSystem::remount(Custody& mount_point, int new_flags)
dbgln("VirtualFileSystem: Remounting {}", mount_point.try_create_absolute_path()); dbgln("VirtualFileSystem: Remounting {}", mount_point.try_create_absolute_path());
Mount* mount = find_mount_for_guest(mount_point.inode()); Mount* mount = find_mount_for_guest(mount_point.inode().identifier());
if (!mount) if (!mount)
return ENODEV; return ENODEV;
@ -139,15 +139,6 @@ bool VirtualFileSystem::mount_root(FileSystem& fs)
return true; return true;
} }
auto VirtualFileSystem::find_mount_for_host(Inode& inode) -> Mount*
{
for (auto& mount : m_mounts) {
if (mount.host() == &inode)
return &mount;
}
return nullptr;
}
auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount* auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount*
{ {
for (auto& mount : m_mounts) { for (auto& mount : m_mounts) {
@ -157,15 +148,6 @@ auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount*
return nullptr; return nullptr;
} }
auto VirtualFileSystem::find_mount_for_guest(Inode& inode) -> Mount*
{
for (auto& mount : m_mounts) {
if (&mount.guest() == &inode)
return &mount;
}
return nullptr;
}
auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount* auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount*
{ {
for (auto& mount : m_mounts) { for (auto& mount : m_mounts) {
@ -192,7 +174,7 @@ KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<b
// FIXME: This is now broken considering chroot and bind mounts. // FIXME: This is now broken considering chroot and bind mounts.
bool is_root_inode = dir_inode.identifier() == dir_inode.fs().root_inode()->identifier(); bool is_root_inode = dir_inode.identifier() == dir_inode.fs().root_inode()->identifier();
if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && entry.name == "..") { if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && entry.name == "..") {
auto mount = find_mount_for_guest(dir_inode); auto mount = find_mount_for_guest(dir_inode.identifier());
VERIFY(mount); VERIFY(mount);
VERIFY(mount->host()); VERIFY(mount->host());
resolved_inode = mount->host()->identifier(); resolved_inode = mount->host()->identifier();
@ -965,7 +947,7 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(S
// See if there's something mounted on the child; in that case // See if there's something mounted on the child; in that case
// we would need to return the guest inode, not the host inode. // we would need to return the guest inode, not the host inode.
if (auto mount = find_mount_for_host(*child_inode)) { if (auto mount = find_mount_for_host(child_inode->identifier())) {
child_inode = mount->guest(); child_inode = mount->guest();
mount_flags_for_child = mount->flags(); mount_flags_for_child = mount->flags();
} }

View file

@ -86,9 +86,7 @@ private:
KResult traverse_directory_inode(Inode&, Function<bool(FileSystem::DirectoryEntryView const&)>); KResult traverse_directory_inode(Inode&, Function<bool(FileSystem::DirectoryEntryView const&)>);
Mount* find_mount_for_host(Inode&);
Mount* find_mount_for_host(InodeIdentifier); Mount* find_mount_for_host(InodeIdentifier);
Mount* find_mount_for_guest(Inode&);
Mount* find_mount_for_guest(InodeIdentifier); Mount* find_mount_for_guest(InodeIdentifier);
Lock m_lock { "VFSLock" }; Lock m_lock { "VFSLock" };