From e1d9b813843e529b0a1ed8df5c3fdd3de4b6d1c3 Mon Sep 17 00:00:00 2001 From: "Bruno G. Albuquerque" Date: Mon, 25 Aug 2008 12:25:15 +0000 Subject: [PATCH] - AttributeIterator::Update() now take into account differences between its view of the small data section and the outside view. Long version: AttributeIterator is a higher level class designed to make it easy to iterate through attributes in the small data section. The first attribute in the small data section is the special "name" attribute that is used to reconstruct the node path when you only have a node handy. As this attribute is not user visible nor user modifiable (except by changing a node name of course), it is considered a special attribute so the AttributeIterator class ignores it and starts iterating from the second attribute on. As opposed to this, internally the Inode class accesses the small data section directly without using the AttributeIterator class so whenever it indexes items in the small data section, it takes into account the special "name" attribute. This creates a off-by-one relationship between those 2 representations and this was a problem because whenever the small data section changed, all iterators had to be updated (through a call to AttributeIterator::Update() having an index parameter that represented the outside view and not the AttributeIterator view, so iterators would not be adjusted correctly and the end result is that every other attribute was not removed from the index. This would cause all types of havoc with indexes, the simplest one being that entries in indexes would point to non-existing nodes. Ingo, pleased now? ;) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27196 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index aa70c6f559..7b12ece3fa 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -633,11 +633,7 @@ Inode::_RemoveSmallData(Transaction& transaction, NodeGetter& nodeGetter, nodeGetter.MakeWritable(transaction); - // TODO(bga): It seems that the first item in the small data section is not - // a nomela attribute (for example, it does not have a name). We take this - // into account and decrement index before passing it along. Although this - // fix one bug, it may be as well just masking out a different bug. - status_t status = _RemoveSmallData(node, item, index - 1); + status_t status = _RemoveSmallData(node, item, index); if (status == B_OK) status = WriteBack(transaction); @@ -2680,8 +2676,11 @@ AttributeIterator::GetNext(char* name, size_t* _length, uint32* _type, void AttributeIterator::Update(uint16 index, int8 change) { - // fCurrentSmallData points already to the next item - if (index < fCurrentSmallData) + // fCurrentSmallData points already to the next item. OTOH, index is always + // the position when considering the special name attribute while the + // attribute iterators do ignore that (they always start at the second + // position in the small data section, not the first). + if (index <= fCurrentSmallData) fCurrentSmallData += change; }