From a72b83c06ef27bf95713eb8c28cd720319f1e8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 25 Apr 2007 10:53:14 +0000 Subject: [PATCH] * 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 --- .../kernel/file_systems/bfs/r5/Inode.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tests/add-ons/kernel/file_systems/bfs/r5/Inode.cpp b/src/tests/add-ons/kernel/file_systems/bfs/r5/Inode.cpp index 64f77e0a24..fcbb50ee11 100644 --- a/src/tests/add-ons/kernel/file_systems/bfs/r5/Inode.cpp +++ b/src/tests/add-ons/kernel/file_systems/bfs/r5/Inode.cpp @@ -786,9 +786,11 @@ Inode::WriteAttribute(Transaction *transaction, const char *name, int32 type, of small_data *smallData = FindSmallData(name); if (smallData != NULL) { oldLength = smallData->DataSize(); - if (oldLength > BPLUSTREE_MAX_KEY_LENGTH) - oldLength = BPLUSTREE_MAX_KEY_LENGTH; - memcpy(oldData = oldBuffer, smallData->Data(), oldLength); + if (oldLength > 0) { + if (oldLength > BPLUSTREE_MAX_KEY_LENGTH) + oldLength = BPLUSTREE_MAX_KEY_LENGTH; + memcpy(oldData = oldBuffer, smallData->Data(), oldLength); + } } fSmallDataLock.Unlock(); @@ -807,7 +809,7 @@ Inode::WriteAttribute(Transaction *transaction, const char *name, int32 type, of if (attribute != NULL) { if (attribute->Lock().LockWrite() == B_OK) { // 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; if (attribute->ReadAt(0, oldBuffer, &oldLength) == B_OK) oldData = oldBuffer; @@ -913,7 +915,7 @@ Inode::RemoveAttribute(Transaction *transaction, const char *name) status_t -Inode::GetAttribute(const char *name, Inode **attribute) +Inode::GetAttribute(const char *name, Inode **_attribute) { // does this inode even have attributes? if (Attributes().IsZero()) @@ -932,11 +934,12 @@ Inode::GetAttribute(const char *name, Inode **attribute) vnode_id id; if ((status = tree->Find((uint8 *)name, (uint16)strlen(name), &id)) == B_OK) { Vnode vnode(fVolume, id); + Inode *inode; // Check if the attribute is really an attribute - if (vnode.Get(attribute) < B_OK - || !(*attribute)->IsAttribute()) + if (vnode.Get(&inode) < B_OK || !inode->IsAttribute()) return B_ERROR; + *_attribute = inode; vnode.Keep(); return B_OK; }