From e62e8e246a9866ad230d35f7272c9e79fd3162d1 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Mon, 21 Aug 2023 01:47:21 +0200 Subject: [PATCH] ufs2: Add access() support Change-Id: I4c2fa12a623f0893c976430893f448f734794548 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6858 Reviewed-by: waddlesplash --- src/add-ons/kernel/file_systems/ufs2/Inode.cpp | 12 ++++++++++++ src/add-ons/kernel/file_systems/ufs2/Inode.h | 1 + .../kernel/file_systems/ufs2/kernel_interface.cpp | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/file_systems/ufs2/Inode.cpp b/src/add-ons/kernel/file_systems/ufs2/Inode.cpp index 9c5bcfce0f..d2dbf758b9 100644 --- a/src/add-ons/kernel/file_systems/ufs2/Inode.cpp +++ b/src/add-ons/kernel/file_systems/ufs2/Inode.cpp @@ -232,3 +232,15 @@ Inode::ReadLink(char* buffer, size_t *_bufferSize) strlcpy(buffer, fNode.symlinkpath, *_bufferSize); return B_OK; } + + +status_t +Inode::CheckPermissions(int accessMode) const +{ + // you never have write access to a read-only volume + if ((accessMode & W_OK) != 0/* && fVolume->IsReadOnly()*/) + return B_READ_ONLY_DEVICE; + + return check_access_permissions(accessMode, Mode(), (gid_t)GroupID(), + (uid_t)UserID()); +} diff --git a/src/add-ons/kernel/file_systems/ufs2/Inode.h b/src/add-ons/kernel/file_systems/ufs2/Inode.h index b105bba035..cded024b19 100644 --- a/src/add-ons/kernel/file_systems/ufs2/Inode.h +++ b/src/add-ons/kernel/file_systems/ufs2/Inode.h @@ -109,6 +109,7 @@ class Inode { { fNode.GetCreationTime(timespec); } void GetAccessTime(struct timespec& timespec) const { fNode.GetAccessTime(timespec); } + status_t CheckPermissions(int accessMode) const; Volume* GetVolume() const { return fVolume; } diff --git a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp index 9eaf41b4ab..8605c2b04f 100644 --- a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp @@ -320,7 +320,8 @@ ufs2_free_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) static status_t ufs2_access(fs_volume *_volume, fs_vnode *_node, int accessMode) { - return B_OK; + Inode* inode = (Inode*)_node->private_node; + return inode->CheckPermissions(accessMode); }