* Backported r20809 to the R5 version of BFS.

* Note that r20809 also fixes a bug in Inode::GetAttribute() - it could clobber
  the attribute parameter and still fail (which could create problems in WriteAttribute()).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20810 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-04-25 10:53:14 +00:00
parent cb0572cac5
commit a72b83c06e
@@ -786,10 +786,12 @@ Inode::WriteAttribute(Transaction *transaction, const char *name, int32 type, of
small_data *smallData = FindSmallData(name); small_data *smallData = FindSmallData(name);
if (smallData != NULL) { if (smallData != NULL) {
oldLength = smallData->DataSize(); oldLength = smallData->DataSize();
if (oldLength > 0) {
if (oldLength > BPLUSTREE_MAX_KEY_LENGTH) if (oldLength > BPLUSTREE_MAX_KEY_LENGTH)
oldLength = BPLUSTREE_MAX_KEY_LENGTH; oldLength = BPLUSTREE_MAX_KEY_LENGTH;
memcpy(oldData = oldBuffer, smallData->Data(), oldLength); memcpy(oldData = oldBuffer, smallData->Data(), oldLength);
} }
}
fSmallDataLock.Unlock(); fSmallDataLock.Unlock();
// if the attribute doesn't exist yet (as a file), try to put it in the // if the attribute doesn't exist yet (as a file), try to put it in the
@@ -807,7 +809,7 @@ Inode::WriteAttribute(Transaction *transaction, const char *name, int32 type, of
if (attribute != NULL) { if (attribute != NULL) {
if (attribute->Lock().LockWrite() == B_OK) { if (attribute->Lock().LockWrite() == B_OK) {
// save the old attribute data (if this fails, oldLength will reflect it) // save the old attribute data (if this fails, oldLength will reflect it)
if (fVolume->CheckForLiveQuery(name)) { if (fVolume->CheckForLiveQuery(name) && attribute->Size() > 0) {
oldLength = BPLUSTREE_MAX_KEY_LENGTH; oldLength = BPLUSTREE_MAX_KEY_LENGTH;
if (attribute->ReadAt(0, oldBuffer, &oldLength) == B_OK) if (attribute->ReadAt(0, oldBuffer, &oldLength) == B_OK)
oldData = oldBuffer; oldData = oldBuffer;
@@ -913,7 +915,7 @@ Inode::RemoveAttribute(Transaction *transaction, const char *name)
status_t status_t
Inode::GetAttribute(const char *name, Inode **attribute) Inode::GetAttribute(const char *name, Inode **_attribute)
{ {
// does this inode even have attributes? // does this inode even have attributes?
if (Attributes().IsZero()) if (Attributes().IsZero())
@@ -932,11 +934,12 @@ Inode::GetAttribute(const char *name, Inode **attribute)
vnode_id id; vnode_id id;
if ((status = tree->Find((uint8 *)name, (uint16)strlen(name), &id)) == B_OK) { if ((status = tree->Find((uint8 *)name, (uint16)strlen(name), &id)) == B_OK) {
Vnode vnode(fVolume, id); Vnode vnode(fVolume, id);
Inode *inode;
// Check if the attribute is really an attribute // Check if the attribute is really an attribute
if (vnode.Get(attribute) < B_OK if (vnode.Get(&inode) < B_OK || !inode->IsAttribute())
|| !(*attribute)->IsAttribute())
return B_ERROR; return B_ERROR;
*_attribute = inode;
vnode.Keep(); vnode.Keep();
return B_OK; return B_OK;
} }