diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp index f5f58964a5..dc83f45c11 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 @@ Attribute::SetType(uint32 type) 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); + if (newSize == oldSize) + return B_OK; - error = DataContainer::Resize(newSize); - } - return error; + 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 @@ Attribute::WriteAt(off_t offset, const void *buffer, size_t size, 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 630e55f39c..5cf007c673 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.h +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.h @@ -53,6 +53,10 @@ public: // debugging void GetAllocationInfo(AllocationInfo &info); +private: + void _Changed(uint8* oldKey, size_t oldLength, + off_t changeOffset, ssize_t changeSize); + private: Node *fNode; String fName;