BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / add-ons / kernel / file_systems / btrfs / AttributeIterator.cpp
blobf453a11468e43a4ba23ce610ae00c15a1274afa7
1 /*
2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3 * This file may be used under the terms of the MIT License.
4 */
7 #include "AttributeIterator.h"
10 //#define TRACE_BTRFS
11 #ifdef TRACE_BTRFS
12 # define TRACE(x...) dprintf("\33[34mbtrfs:\33[0m " x)
13 #else
14 # define TRACE(x...) ;
15 #endif
16 # define ERROR(x...) dprintf("\33[34mbtrfs:\33[0m " x)
19 AttributeIterator::AttributeIterator(Inode* inode)
21 fOffset(-1ULL),
22 fInode(inode),
23 fIterator(NULL)
25 struct btrfs_key key;
26 key.SetType(BTRFS_KEY_TYPE_XATTR_ITEM);
27 key.SetObjectID(inode->ID());
28 fIterator = new(std::nothrow) TreeIterator(inode->GetVolume()->FSTree(),
29 key);
33 AttributeIterator::~AttributeIterator()
35 delete fIterator;
39 status_t
40 AttributeIterator::InitCheck()
42 return fIterator != NULL ? B_OK : B_NO_MEMORY;
46 status_t
47 AttributeIterator::GetNext(char* name, size_t* _nameLength)
49 btrfs_key key;
50 btrfs_dir_entry* entries;
51 uint32 entries_length;
52 status_t status = fIterator->GetPreviousEntry(key, (void**)&entries,
53 &entries_length);
54 if (status != B_OK)
55 return status;
57 btrfs_dir_entry* entry = entries;
58 uint16 current = 0;
59 while (current < entries_length) {
60 current += entry->Length();
61 break;
62 // TODO there could be several entries with the same name hash
63 entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length());
66 TRACE("DirectoryIterator::GetNext() entries_length %ld name_length %d\n",
67 entries_length, entry->NameLength());
69 memcpy(name, entry + 1, entry->NameLength());
70 name[entry->NameLength()] = '\0';
71 *_nameLength = entry->NameLength();
72 free(entries);
74 return B_OK;
78 status_t
79 AttributeIterator::Rewind()
81 fIterator->Rewind();
82 fOffset = -1ULL;
83 return B_OK;