From 6af2418de71ad71b16eca1aea7b1528ab8cfa44d Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 28 May 2020 17:41:04 +0300 Subject: [PATCH] Kernel: Pass a Custody instead of Inode to VFS methods VFS no longer deals with inodes in public API, only with custodies and file descriptions. Talk directly to the file system if you need to operate on a inode. In most cases you actually want to go though VFS, to get proper permission check and other niceties. For this to work, you have to provide a custody, which describes *how* you have opened the inode, not just what the inode is. --- Kernel/FileSystem/InodeFile.cpp | 6 ++++-- Kernel/FileSystem/VirtualFileSystem.cpp | 12 ++++++------ Kernel/FileSystem/VirtualFileSystem.h | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 3e244345060..4e286cc3da2 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -100,13 +100,15 @@ KResult InodeFile::truncate(u64 size) KResult InodeFile::chown(FileDescription& description, uid_t uid, gid_t gid) { ASSERT(description.inode() == m_inode); - return VFS::the().chown(*m_inode, uid, gid); + ASSERT(description.custody()); + return VFS::the().chown(*description.custody(), uid, gid); } KResult InodeFile::chmod(FileDescription& description, mode_t mode) { ASSERT(description.inode() == m_inode); - return VFS::the().chmod(*m_inode, mode); + ASSERT(description.custody()); + return VFS::the().chmod(*description.custody(), mode); } } diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index e4d97772fc9..112dece57e8 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -393,8 +393,9 @@ KResultOr> VFS::open_directory(StringView path, Custody& return custody; } -KResult VFS::chmod(Inode& inode, mode_t mode) +KResult VFS::chmod(Custody& custody, mode_t mode) { + auto& inode = custody.inode(); if (inode.fs().is_readonly()) return KResult(-EROFS); @@ -412,8 +413,7 @@ KResult VFS::chmod(StringView path, mode_t mode, Custody& base) if (custody_or_error.is_error()) return custody_or_error.error(); auto& custody = *custody_or_error.value(); - auto& inode = custody.inode(); - return chmod(inode, mode); + return chmod(custody, mode); } KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) @@ -479,8 +479,9 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) return KSuccess; } -KResult VFS::chown(Inode& inode, uid_t a_uid, gid_t a_gid) +KResult VFS::chown(Custody& custody, uid_t a_uid, gid_t a_gid) { + auto& inode = custody.inode(); if (inode.fs().is_readonly()) return KResult(-EROFS); @@ -521,8 +522,7 @@ KResult VFS::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base) if (custody_or_error.is_error()) return custody_or_error.error(); auto& custody = *custody_or_error.value(); - auto& inode = custody.inode(); - return chown(inode, a_uid, a_gid); + return chown(custody, a_uid, a_gid); } KResult VFS::link(StringView old_path, StringView new_path, Custody& base) diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index ff390a2df0b..d4c70c3e383 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -118,9 +118,9 @@ public: KResult symlink(StringView target, StringView linkpath, Custody& base); KResult rmdir(StringView path, Custody& base); KResult chmod(StringView path, mode_t, Custody& base); - KResult chmod(Inode&, mode_t); + KResult chmod(Custody&, mode_t); KResult chown(StringView path, uid_t, gid_t, Custody& base); - KResult chown(Inode&, uid_t, gid_t); + KResult chown(Custody&, uid_t, gid_t); KResult access(StringView path, int mode, Custody& base); KResultOr lookup_metadata(StringView path, Custody& base, int options = 0); KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);