2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3 * This file may be used under the terms of the MIT License.
7 #include "AttributeIterator.h"
12 # define TRACE(x...) dprintf("\33[34mbtrfs:\33[0m " x)
14 # define TRACE(x...) ;
16 # define ERROR(x...) dprintf("\33[34mbtrfs:\33[0m " x)
19 AttributeIterator::AttributeIterator(Inode
* inode
)
26 key
.SetType(BTRFS_KEY_TYPE_XATTR_ITEM
);
27 key
.SetObjectID(inode
->ID());
28 fIterator
= new(std::nothrow
) TreeIterator(inode
->GetVolume()->FSTree(),
33 AttributeIterator::~AttributeIterator()
40 AttributeIterator::InitCheck()
42 return fIterator
!= NULL
? B_OK
: B_NO_MEMORY
;
47 AttributeIterator::GetNext(char* name
, size_t* _nameLength
)
50 btrfs_dir_entry
* entries
;
51 uint32 entries_length
;
52 status_t status
= fIterator
->GetPreviousEntry(key
, (void**)&entries
,
57 btrfs_dir_entry
* entry
= entries
;
59 while (current
< entries_length
) {
60 current
+= entry
->Length();
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();
79 AttributeIterator::Rewind()