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(-)
@@ -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;
}
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)
{
uint8 oldKey[kMaxIndexKeyLength];
size_t oldLength = kMaxIndexKeyLength;
GetKey(oldKey, &oldLength);
status_t error = DataContainer::WriteAt(offset, buffer, size, bytesWritten);
if (error != B_OK)
return error;
_Changed(oldKey, oldLength, offset, size);
return B_OK;
}
void
Attribute::_Changed(uint8* oldKey, size_t oldLength, off_t changeOffset, ssize_t changeSize)
{
if (offset < (off_t)kMaxIndexKeyLength && size > 0 && fIndex)
if (fIndex != NULL && changeOffset < (off_t)kMaxIndexKeyLength && changeSize != 0)
fIndex->Changed(this, oldKey, oldLength);
@@ -92,10 +108,8 @@
oldLength, newKey, newLength);
if (fNode && size > 0)
if (fNode != NULL && changeSize != 0)
fNode->MarkModified(B_STAT_MODIFICATION_TIME);
return error;
}
@@ -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;