Switched to the new DoublyLinkedList implementation.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5008 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -13,27 +13,16 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
struct file_system_entry {
|
|
||||||
list_link link;
|
|
||||||
Directory *root;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dir_cookie {
|
|
||||||
file_system_entry *current;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
RootFileSystem::RootFileSystem()
|
RootFileSystem::RootFileSystem()
|
||||||
{
|
{
|
||||||
list_init(&fList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RootFileSystem::~RootFileSystem()
|
RootFileSystem::~RootFileSystem()
|
||||||
{
|
{
|
||||||
file_system_entry *entry = NULL;
|
struct entry *entry = NULL;
|
||||||
|
|
||||||
while ((entry = (file_system_entry *)list_remove_head_item(&fList)) != NULL) {
|
while ((entry = fList.RemoveHead()) != NULL) {
|
||||||
entry->root->Release();
|
entry->root->Release();
|
||||||
delete entry;
|
delete entry;
|
||||||
}
|
}
|
||||||
@@ -43,12 +32,11 @@ RootFileSystem::~RootFileSystem()
|
|||||||
status_t
|
status_t
|
||||||
RootFileSystem::Open(void **_cookie, int mode)
|
RootFileSystem::Open(void **_cookie, int mode)
|
||||||
{
|
{
|
||||||
dir_cookie *cookie = new dir_cookie();
|
EntryIterator *iterator = new EntryIterator(fList.Iterator());
|
||||||
if (cookie == NULL)
|
if (iterator == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
cookie->current = NULL;
|
*_cookie = iterator;
|
||||||
*_cookie = cookie;
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -57,7 +45,7 @@ RootFileSystem::Open(void **_cookie, int mode)
|
|||||||
status_t
|
status_t
|
||||||
RootFileSystem::Close(void *cookie)
|
RootFileSystem::Close(void *cookie)
|
||||||
{
|
{
|
||||||
delete (dir_cookie *)cookie;
|
delete (EntryIterator *)cookie;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,9 +53,10 @@ RootFileSystem::Close(void *cookie)
|
|||||||
Node *
|
Node *
|
||||||
RootFileSystem::Lookup(const char *name, bool /*traverseLinks*/)
|
RootFileSystem::Lookup(const char *name, bool /*traverseLinks*/)
|
||||||
{
|
{
|
||||||
file_system_entry *entry = NULL;
|
EntryIterator iterator = fList.Iterator();
|
||||||
|
struct entry *entry = NULL;
|
||||||
|
|
||||||
while ((entry = (file_system_entry *)list_get_next_item(&fList, entry)) != NULL) {
|
while ((entry = iterator.Next()) != NULL) {
|
||||||
char entryName[B_OS_NAME_LENGTH];
|
char entryName[B_OS_NAME_LENGTH];
|
||||||
if (entry->root->GetName(entryName, sizeof(entryName)) != B_OK)
|
if (entry->root->GetName(entryName, sizeof(entryName)) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
@@ -85,10 +74,10 @@ RootFileSystem::Lookup(const char *name, bool /*traverseLinks*/)
|
|||||||
status_t
|
status_t
|
||||||
RootFileSystem::GetNextEntry(void *_cookie, char *name, size_t size)
|
RootFileSystem::GetNextEntry(void *_cookie, char *name, size_t size)
|
||||||
{
|
{
|
||||||
dir_cookie *cookie = (dir_cookie *)_cookie;
|
EntryIterator *iterator = (EntryIterator *)_cookie;
|
||||||
file_system_entry *entry;
|
struct entry *entry;
|
||||||
|
|
||||||
entry = cookie->current = (file_system_entry *)list_get_next_item(&fList, cookie->current);
|
entry = iterator->Next();
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
return entry->root->GetName(name, size);
|
return entry->root->GetName(name, size);
|
||||||
|
|
||||||
@@ -99,10 +88,10 @@ RootFileSystem::GetNextEntry(void *_cookie, char *name, size_t size)
|
|||||||
status_t
|
status_t
|
||||||
RootFileSystem::GetNextNode(void *_cookie, Node **_node)
|
RootFileSystem::GetNextNode(void *_cookie, Node **_node)
|
||||||
{
|
{
|
||||||
dir_cookie *cookie = (dir_cookie *)_cookie;
|
EntryIterator *iterator = (EntryIterator *)_cookie;
|
||||||
file_system_entry *entry;
|
struct entry *entry;
|
||||||
|
|
||||||
entry = cookie->current = (file_system_entry *)list_get_next_item(&fList, cookie->current);
|
entry = iterator->Next();
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
*_node = entry->root;
|
*_node = entry->root;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -114,9 +103,7 @@ RootFileSystem::GetNextNode(void *_cookie, Node **_node)
|
|||||||
status_t
|
status_t
|
||||||
RootFileSystem::Rewind(void *_cookie)
|
RootFileSystem::Rewind(void *_cookie)
|
||||||
{
|
{
|
||||||
dir_cookie *cookie = (dir_cookie *)_cookie;
|
// ToDo: implement
|
||||||
|
|
||||||
cookie->current = NULL;
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +111,7 @@ RootFileSystem::Rewind(void *_cookie)
|
|||||||
bool
|
bool
|
||||||
RootFileSystem::IsEmpty()
|
RootFileSystem::IsEmpty()
|
||||||
{
|
{
|
||||||
return list_is_empty(&fList);
|
return fList.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,14 +122,14 @@ RootFileSystem::AddNode(Node *node)
|
|||||||
if (node->Type() != S_IFDIR)
|
if (node->Type() != S_IFDIR)
|
||||||
return B_BAD_TYPE;
|
return B_BAD_TYPE;
|
||||||
|
|
||||||
file_system_entry *entry = new file_system_entry();
|
struct entry *entry = new RootFileSystem::entry();
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
node->Acquire();
|
node->Acquire();
|
||||||
entry->root = (Directory *)node;
|
entry->root = (Directory *)node;
|
||||||
|
|
||||||
list_add_item(&fList, entry);
|
fList.Add(entry);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,14 @@ class RootFileSystem : public Directory {
|
|||||||
virtual status_t AddNode(Node *node);
|
virtual status_t AddNode(Node *node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
list fList;
|
struct entry {
|
||||||
|
DoublyLinked::Link link;
|
||||||
|
Directory *root;
|
||||||
|
};
|
||||||
|
typedef DoublyLinked::Iterator<entry, &entry::link> EntryIterator;
|
||||||
|
typedef DoublyLinked::List<entry, &entry::link> EntryList;
|
||||||
|
|
||||||
|
EntryList fList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user