ramfs: Remove open-mode checks in read and write hooks.

The VFS already does this for us, other filesystems don't
check this either.
This commit is contained in:
Augustin Cavalier
2025-09-03 18:57:02 -04:00
parent f7c3fa972c
commit 64322ea7d0
@@ -1036,7 +1036,6 @@ ramfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
// FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
FileCookie *cookie = (FileCookie*)_cookie;
// FUNCTION(("((%lu, %lu), %lld, %p, %lu)\n", node->GetDirID(),
// node->GetObjectID(), pos, buffer, *bufferSize));
@@ -1050,11 +1049,6 @@ ramfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
if (!node->IsFile())
SET_ERROR(error, B_BAD_VALUE);
// check, if reading is allowed
int rwMode = cookie->GetOpenMode() & O_RWMASK;
if (error == B_OK && rwMode != O_RDONLY && rwMode != O_RDWR)
SET_ERROR(error, B_FILE_ERROR);
// read
if (error == B_OK) {
if (File *file = dynamic_cast<File*>(node)) {
@@ -1091,23 +1085,17 @@ ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
if (!node->IsFile())
SET_ERROR(error, B_BAD_VALUE);
if (error == B_OK) {
// check, if reading is allowed
int rwMode = cookie->GetOpenMode() & O_RWMASK;
if (error == B_OK && rwMode != O_WRONLY && rwMode != O_RDWR)
SET_ERROR(error, B_FILE_ERROR);
if (error == B_OK) {
// reset the position, if opened in append mode
if (cookie->GetOpenMode() & O_APPEND)
pos = node->GetSize();
// write
if (File *file = dynamic_cast<File*>(node)) {
error = file->WriteAt(pos, buffer, *bufferSize,
bufferSize);
} else {
FATAL("Node %" B_PRIdINO " pretends to be a File, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
// reset the position, if opened in append mode
if (cookie->GetOpenMode() & O_APPEND)
pos = node->GetSize();
// write
if (File *file = dynamic_cast<File*>(node)) {
error = file->WriteAt(pos, buffer, *bufferSize,
bufferSize);
} else {
FATAL("Node %" B_PRIdINO " pretends to be a File, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
}
// notify listeners