diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp index 93e0de294c..2a1196c6b6 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.cpp @@ -84,9 +84,9 @@ Attribute::WriteAt(off_t offset, const void *buffer, size_t size, fIndex->Changed(this, oldKey, oldLength); // update live queries - const uint8* newKey; + uint8 newKey[kMaxIndexKeyLength]; size_t newLength; - GetKey(&newKey, &newLength); + GetKey(newKey, &newLength); GetVolume()->UpdateLiveQueries(NULL, fNode, GetName(), fType, oldKey, oldLength, newKey, newLength); @@ -105,26 +105,12 @@ Attribute::SetIndex(AttributeIndex *index, bool inIndex) fInIndex = inIndex; } -// GetKey -void -Attribute::GetKey(const uint8 **key, size_t *length) -{ - if (key && length) { - GetFirstDataBlock(key, length); - *length = min(*length, kMaxIndexKeyLength); - } -} - // GetKey void Attribute::GetKey(uint8 *key, size_t *length) { - if (key && length) { - const uint8 *originalKey = NULL; - GetKey(&originalKey, length); - if (length > 0) - memcpy(key, originalKey, *length); - } + *length = min(*length, kMaxIndexKeyLength); + ReadAt(0, key, *length, length); } // AttachAttributeIterator diff --git a/src/add-ons/kernel/file_systems/ramfs/Attribute.h b/src/add-ons/kernel/file_systems/ramfs/Attribute.h index b87440dd0b..630e55f39c 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Attribute.h +++ b/src/add-ons/kernel/file_systems/ramfs/Attribute.h @@ -42,7 +42,6 @@ public: void SetIndex(AttributeIndex *index, bool inIndex); AttributeIndex *GetIndex() const { return fIndex; } bool IsInIndex() const { return fInIndex; } - void GetKey(const uint8 **key, size_t *length); void GetKey(uint8 *key, size_t *length); // iterator management diff --git a/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp b/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp index c85642f135..8a77a6baec 100644 --- a/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/AttributeIndexImpl.cpp @@ -66,16 +66,18 @@ compare_keys(const uint8 *key1, size_t length1, const uint8 *key2, // PrimaryKey class AttributeIndexImpl::PrimaryKey { public: - PrimaryKey(Attribute *attribute, const uint8 *key, + PrimaryKey(Attribute *attribute, const uint8 *theKey, size_t length) - : attribute(attribute), key(key), length(length) {} + : attribute(attribute), length(length) + { memcpy(key, theKey, length); } PrimaryKey(Attribute *attribute) - : attribute(attribute) { attribute->GetKey(&key, &length); } - PrimaryKey(const uint8 *key, size_t length) - : attribute(NULL), key(key), length(length) {} + : attribute(attribute) { attribute->GetKey(key, &length); } + PrimaryKey(const uint8 *theKey, size_t length) + : attribute(NULL), length(length) + { memcpy(key, theKey, length); } Attribute *attribute; - const uint8 *key; + uint8 key[kMaxIndexKeyLength]; size_t length; }; @@ -466,9 +468,9 @@ AttributeIndexImpl::Iterator::SetTo(AttributeIndexImpl *index, if (!fEntry) BaseClass::GetNext(); if (Attribute **attribute = fIterator.fIterator.GetCurrent()) { - const uint8 *attrKey; + uint8 attrKey[kMaxIndexKeyLength]; size_t attrKeyLength; - (*attribute)->GetKey(&attrKey, &attrKeyLength); + (*attribute)->GetKey(attrKey, &attrKeyLength); if (!ignoreValue && compare_keys(attrKey, attrKeyLength, key, length, fIndex->GetType()) != 0) { diff --git a/src/add-ons/kernel/file_systems/ramfs/Query.cpp b/src/add-ons/kernel/file_systems/ramfs/Query.cpp index 9398f3bfa2..0b4e721904 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Query.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Query.cpp @@ -1009,9 +1009,10 @@ Equation::Match(Entry *entry, Node* node, const char *attributeName, int32 type, } else { // then for attributes Attribute *attribute = NULL; + buffer = (const uint8*)alloca(kMaxIndexKeyLength); if (node->FindAttribute(fAttribute, &attribute) == B_OK) { - attribute->GetKey(&buffer, &size); + attribute->GetKey((uint8*)buffer, &size); type = attribute->GetType(); } else return MatchEmptyString(); diff --git a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp index 781ff7f950..002b51cbb9 100644 --- a/src/add-ons/kernel/file_systems/ramfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/Volume.cpp @@ -670,9 +670,9 @@ Volume::NodeAttributeRemoved(ino_t id, Attribute *attribute) // update live queries if (error == B_OK && attribute->GetNode()) { - const uint8* oldKey; + uint8 oldKey[kMaxIndexKeyLength]; size_t oldLength; - attribute->GetKey(&oldKey, &oldLength); + attribute->GetKey(oldKey, &oldLength); UpdateLiveQueries(NULL, attribute->GetNode(), attribute->GetName(), attribute->GetType(), oldKey, oldLength, NULL, 0); }