3 #include "AllocationInfo.h"
11 Attribute::Attribute(Volume
*volume
, Node
*node
, const char *name
,
13 : DataContainer(volume
),
24 Attribute::~Attribute()
30 Attribute::InitCheck() const
32 return (fName
.GetString() ? B_OK
: B_NO_INIT
);
37 Attribute::SetType(uint32 type
)
41 fIndex
->Removed(this);
43 if (AttributeIndex
*index
= GetVolume()->FindAttributeIndex(GetName(),
52 Attribute::SetSize(off_t newSize
)
54 status_t error
= B_OK
;
55 off_t oldSize
= DataContainer::GetSize();
56 if (newSize
!= oldSize
) {
58 fNode
->MarkModified(B_STAT_MODIFICATION_TIME
);
60 error
= DataContainer::Resize(newSize
);
67 Attribute::WriteAt(off_t offset
, const void *buffer
, size_t size
,
70 // get the current key for the attribute
71 uint8 oldKey
[kMaxIndexKeyLength
];
73 GetKey(oldKey
, &oldLength
);
75 // write the new value
76 status_t error
= DataContainer::WriteAt(offset
, buffer
, size
, bytesWritten
);
78 // If there is an index and a change has been made within the key, notify
80 if (offset
< kMaxIndexKeyLength
&& size
> 0 && fIndex
)
81 fIndex
->Changed(this, oldKey
, oldLength
);
83 // update live queries
86 GetKey(&newKey
, &newLength
);
87 GetVolume()->UpdateLiveQueries(NULL
, fNode
, GetName(), fType
, oldKey
,
88 oldLength
, newKey
, newLength
);
90 // node has been changed
91 if (fNode
&& size
> 0)
92 fNode
->MarkModified(B_STAT_MODIFICATION_TIME
);
99 Attribute::SetIndex(AttributeIndex
*index
, bool inIndex
)
107 Attribute::GetKey(const uint8
**key
, size_t *length
)
110 GetFirstDataBlock(key
, length
);
111 *length
= min(*length
, kMaxIndexKeyLength
);
117 Attribute::GetKey(uint8
*key
, size_t *length
)
120 const uint8
*originalKey
= NULL
;
121 GetKey(&originalKey
, length
);
123 memcpy(key
, originalKey
, *length
);
127 // AttachAttributeIterator
129 Attribute::AttachAttributeIterator(AttributeIterator
*iterator
)
131 if (iterator
&& iterator
->GetCurrent() == this && !iterator
->IsSuspended())
132 fIterators
.Insert(iterator
);
135 // DetachAttributeIterator
137 Attribute::DetachAttributeIterator(AttributeIterator
*iterator
)
139 if (iterator
&& iterator
->GetCurrent() == this && iterator
->IsSuspended())
140 fIterators
.Remove(iterator
);
145 Attribute::GetAllocationInfo(AllocationInfo
&info
)
147 DataContainer::GetAllocationInfo(info
);
148 info
.AddAttributeAllocation(GetSize());
149 info
.AddStringAllocation(fName
.GetLength());