summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2020-05-28 17:41:04 +0300
committerAndreas Kling <kling@serenityos.org>2020-05-29 07:53:30 +0200
commit6af2418de71ad71b16eca1aea7b1528ab8cfa44d (patch)
tree58885a1eb75d6a2df7f4e526af96fbfa3fd463b8 /Kernel/FileSystem
parenta9946a99f24e17644b2b7796ec8be10c8913f38b (diff)
downloadserenity-6af2418de71ad71b16eca1aea7b1528ab8cfa44d.zip
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.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/InodeFile.cpp6
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp12
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.h4
3 files changed, 12 insertions, 10 deletions
diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp
index 3e24434506..4e286cc3da 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 e4d97772fc..112dece57e 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -393,8 +393,9 @@ KResultOr<NonnullRefPtr<Custody>> 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 ff390a2df0..d4c70c3e38 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<InodeMetadata> lookup_metadata(StringView path, Custody& base, int options = 0);
KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);