⛏️ index : haiku.git

author Augustin Cavalier <waddlesplash@gmail.com> 2025-08-28 16:58:38.0 -04:00:00
committer Augustin Cavalier <waddlesplash@gmail.com> 2025-08-28 19:35:06.0 -04:00:00
commit
8f7bb51e2067d47c9901bcecd0dbfdbf34ef25d9 [patch]
tree
938288f8f07576bd14bb3c5e697363d03fe204f4
parent
4e09216c77766395aa028932721837a568357e0d
download
8f7bb51e2067d47c9901bcecd0dbfdbf34ef25d9.tar.gz

ramfs: Properly update indexes when attribute sizes change.

Otherwise we'll have incorrect data in the index.

Part of #19252.

Diff

 src/add-ons/kernel/file_systems/ramfs/Attribute.cpp | 44 +++++++++++++++++++++++++++++++-------------
 src/add-ons/kernel/file_systems/ramfs/Attribute.h   |  4 ++++
 2 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp
index f5f5896..dc83f45 100644
--- a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp
+++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp
@@ -55,33 +55,49 @@
status_t
Attribute::SetSize(off_t newSize)
{
	status_t error = B_OK;
	off_t oldSize = DataContainer::GetSize();
	if (newSize != oldSize) {
		if (fNode)
			fNode->MarkModified(B_STAT_MODIFICATION_TIME);

		error = DataContainer::Resize(newSize);
	}
	return error;
	if (newSize == oldSize)
		return B_OK;

	uint8 oldKey[kMaxIndexKeyLength];
	size_t oldLength = kMaxIndexKeyLength;
	GetKey(oldKey, &oldLength);

	status_t error = DataContainer::Resize(newSize);
	if (error != B_OK)
		return error;

	off_t changeOffset = (newSize < oldSize) ? newSize : oldSize;
	_Changed(oldKey, oldLength, changeOffset, newSize - oldSize);
	return B_OK;
}

// WriteAt
status_t
Attribute::WriteAt(off_t offset, const void *buffer, size_t size,
				   size_t *bytesWritten)
Attribute::WriteAt(off_t offset, const void *buffer, size_t size, size_t *bytesWritten)
{
	// get the current key for the attribute
	// store the current key for the attribute
	uint8 oldKey[kMaxIndexKeyLength];
	size_t oldLength = kMaxIndexKeyLength;
	GetKey(oldKey, &oldLength);

	// write the new value
	status_t error = DataContainer::WriteAt(offset, buffer, size, bytesWritten);
	if (error != B_OK)
		return error;

	// update index and live queries
	_Changed(oldKey, oldLength, offset, size);
	return B_OK;
}

// _Changed
void
Attribute::_Changed(uint8* oldKey, size_t oldLength, off_t changeOffset, ssize_t changeSize)
{
	// If there is an index and a change has been made within the key, notify
	// the index.
	if (offset < (off_t)kMaxIndexKeyLength && size > 0 && fIndex)
	if (fIndex != NULL && changeOffset < (off_t)kMaxIndexKeyLength && changeSize != 0)
		fIndex->Changed(this, oldKey, oldLength);

	// update live queries
@@ -92,10 +108,8 @@
		oldLength, newKey, newLength);

	// node has been changed
	if (fNode && size > 0)
	if (fNode != NULL && changeSize != 0)
		fNode->MarkModified(B_STAT_MODIFICATION_TIME);

	return error;
}

// SetIndex
diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.h b/src/add-ons/kernel/file_systems/ramfs/Attribute.h
index 630e55f..5cf007c 100644
--- a/src/add-ons/kernel/file_systems/ramfs/Attribute.h
+++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.h
@@ -54,6 +54,10 @@
	void GetAllocationInfo(AllocationInfo &info);

private:
	void _Changed(uint8* oldKey, size_t oldLength,
		off_t changeOffset, ssize_t changeSize);

private:
	Node						*fNode;
	String						fName;
	uint32						fType;