ramfs: Remove the Attribute::GetKey overload that accepts a ptr-ptr.

This only works because DataCollector stores its data in blocks
which are mapped into the kernel's address space. After the
next series of commits, it won't, so we can't depend on that.

This required some changes to the indexes to keep a copy of the
keys.
This commit is contained in:
Augustin Cavalier 2019-08-31 17:44:00 -04:00
parent 6d244f23b8
commit 677fca26d7
5 changed files with 18 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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();

View File

@ -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);
}