From 48bfa9ee2f08d41752a1096238884d0c9e40094e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 16 Jan 2025 23:21:04 -0500 Subject: [PATCH] ramfs: Add some WriteLocked assertions. These would have caught the problem in #19360. --- src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp | 2 ++ src/add-ons/kernel/file_systems/ramfs/LastModifiedIndex.cpp | 2 ++ src/add-ons/kernel/file_systems/ramfs/SizeIndex.cpp | 2 ++ src/add-ons/kernel/file_systems/ramfs/Volume.h | 1 + 4 files changed, 7 insertions(+) diff --git a/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp b/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp index 35df934a7c..3d0ac20b6c 100644 --- a/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp @@ -237,6 +237,8 @@ status_t AttributeIndexImpl::Changed(Attribute *attribute, const uint8 *oldKey, size_t oldLength) { + fVolume->AssertWriteLocked(); + status_t error = B_BAD_VALUE; if (attribute && attribute->GetIndex() == this) { // update the iterators and remove the attribute from the tree diff --git a/src/add-ons/kernel/file_systems/ramfs/LastModifiedIndex.cpp b/src/add-ons/kernel/file_systems/ramfs/LastModifiedIndex.cpp index 030ba96a55..d6a5886e04 100644 --- a/src/add-ons/kernel/file_systems/ramfs/LastModifiedIndex.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/LastModifiedIndex.cpp @@ -147,6 +147,8 @@ LastModifiedIndex::CountEntries() const status_t LastModifiedIndex::Changed(Node *node, time_t oldModified) { + fVolume->AssertWriteLocked(); + status_t error = B_BAD_VALUE; if (node) { NodeTree::Iterator it; diff --git a/src/add-ons/kernel/file_systems/ramfs/SizeIndex.cpp b/src/add-ons/kernel/file_systems/ramfs/SizeIndex.cpp index 469adf024a..bd67eb7045 100644 --- a/src/add-ons/kernel/file_systems/ramfs/SizeIndex.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/SizeIndex.cpp @@ -145,6 +145,8 @@ SizeIndex::CountEntries() const status_t SizeIndex::Changed(Node *node, off_t oldSize) { + fVolume->AssertWriteLocked(); + status_t error = B_BAD_VALUE; if (node) { NodeTree::Iterator it; diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.h b/src/add-ons/kernel/file_systems/ramfs/Volume.h index 0c4f63fbdb..93ffb36814 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.h +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.h @@ -163,6 +163,7 @@ public: void ReadUnlock(); bool WriteLock(); void WriteUnlock(); + inline void AssertWriteLocked() { ASSERT_WRITE_LOCKED_RW_LOCK(&fLocker); } bool IteratorLock(); void IteratorUnlock();