Implemented actual iteration.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4155 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -10,22 +10,71 @@
|
|||||||
|
|
||||||
#include "DirectoryIterator.h"
|
#include "DirectoryIterator.h"
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "Icb.h"
|
||||||
|
|
||||||
|
#include "CS0String.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
using namespace Udf;
|
using namespace Udf;
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DirectoryIterator::GetNextEntry(vnode_id *id, char *name, uint32 *length)
|
DirectoryIterator::GetNextEntry(char *name, uint32 *length, vnode_id *id)
|
||||||
{
|
{
|
||||||
|
DEBUG_INIT_ETC(CF_PUBLIC | CF_DIRECTORY_OPS, "DirectoryIterator",
|
||||||
|
("name: %p, length: %p, id: %p", name, length, id));
|
||||||
|
|
||||||
if (!id || !name || !length)
|
if (!id || !name || !length)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (fCount < 5)
|
status_t err = B_OK;
|
||||||
sprintf(name, "entry #%ld", fCount++);
|
if (fAtBeginning) {
|
||||||
else
|
sprintf(name, ".");
|
||||||
|
*length = 2;
|
||||||
|
*id = Parent()->Id();
|
||||||
|
fAtBeginning = false;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (uint64(fPosition) >= Parent()->Length())
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
uint8 data[kMaxFileIdSize];
|
||||||
|
udf_file_id_descriptor *entry = reinterpret_cast<udf_file_id_descriptor*>(data);
|
||||||
|
|
||||||
|
uint32 block = 0;
|
||||||
|
off_t offset = fPosition;
|
||||||
|
|
||||||
|
size_t entryLength = kMaxFileIdSize;
|
||||||
|
// First read in the static portion of the file id descriptor,
|
||||||
|
// then, based on the information therein, read in the variable
|
||||||
|
// length tail portion as well.
|
||||||
|
err = Parent()->Read(offset, entry, &entryLength, &block);
|
||||||
|
if (!err && entryLength >= sizeof(udf_file_id_descriptor) && entry->tag().init_check(block) == B_OK) {
|
||||||
|
PDUMP(entry);
|
||||||
|
offset += entry->total_length();
|
||||||
|
|
||||||
return B_OK;
|
if (entry->is_parent()) {
|
||||||
|
sprintf(name, "..");
|
||||||
|
*length = 3;
|
||||||
|
} else {
|
||||||
|
CS0String string(entry->id(), entry->id_length());
|
||||||
|
PRINT(("id == `%s'\n", string.String()));
|
||||||
|
PRINT(("vnode_id: %lld\n", to_vnode_id(entry->icb())));
|
||||||
|
DUMP(entry->icb());
|
||||||
|
sprintf(name, "%s", string.String());
|
||||||
|
*length = string.Length();
|
||||||
|
}
|
||||||
|
*id = to_vnode_id(entry->icb());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!err)
|
||||||
|
fPosition = offset;
|
||||||
|
}
|
||||||
|
// size_t dynamicLength = sizeof(udf_file_id_descriptor);
|
||||||
|
|
||||||
|
RETURN(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \brief Rewinds the iterator to point to the first
|
/* \brief Rewinds the iterator to point to the first
|
||||||
@@ -34,12 +83,14 @@ DirectoryIterator::GetNextEntry(vnode_id *id, char *name, uint32 *length)
|
|||||||
void
|
void
|
||||||
DirectoryIterator::Rewind()
|
DirectoryIterator::Rewind()
|
||||||
{
|
{
|
||||||
fCount = 0;
|
fPosition = 0;
|
||||||
|
fAtBeginning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectoryIterator::DirectoryIterator(Icb *parent)
|
DirectoryIterator::DirectoryIterator(Icb *parent)
|
||||||
: fParent(parent)
|
: fParent(parent)
|
||||||
, fCount(0)
|
, fPosition(0)
|
||||||
|
, fAtBeginning(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ class Icb;
|
|||||||
class DirectoryIterator {
|
class DirectoryIterator {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
status_t GetNextEntry(vnode_id *id, char *name, uint32 *length);
|
status_t GetNextEntry(char *name, uint32 *length, vnode_id *id);
|
||||||
void Rewind();
|
void Rewind();
|
||||||
|
|
||||||
Icb* Parent() const { return fParent; }
|
Icb* Parent() { return fParent; }
|
||||||
|
const Icb* Parent() const { return fParent; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Icb;
|
friend class Icb;
|
||||||
@@ -41,7 +42,8 @@ private:
|
|||||||
void Invalidate(); // called by Icb::~Icb()
|
void Invalidate(); // called by Icb::~Icb()
|
||||||
|
|
||||||
Icb *fParent;
|
Icb *fParent;
|
||||||
uint32 fCount; // Used to implement fake iteration until file reading is implemented
|
off_t fPosition;
|
||||||
|
bool fAtBeginning;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace Udf
|
}; // namespace Udf
|
||||||
|
|||||||
Reference in New Issue
Block a user