2 * Copyright 2003-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 #include "RootFileSystem.h"
15 RootFileSystem::RootFileSystem()
20 RootFileSystem::~RootFileSystem()
22 struct entry
*entry
= NULL
;
24 while ((entry
= fList
.RemoveHead()) != NULL
) {
25 entry
->root
->Release();
32 RootFileSystem::Open(void **_cookie
, int mode
)
34 EntryIterator
*iterator
= new (std::nothrow
) EntryIterator(&fList
);
45 RootFileSystem::Close(void *cookie
)
47 delete (EntryIterator
*)cookie
;
53 RootFileSystem::LookupDontTraverse(const char* name
)
55 EntryIterator iterator
= fLinks
.GetIterator();
58 // first check the links
60 while ((entry
= iterator
.Next()) != NULL
) {
61 if (!strcmp(name
, entry
->name
)) {
62 entry
->root
->Acquire();
67 // then all mounted file systems
69 iterator
= fList
.GetIterator();
71 while ((entry
= iterator
.Next()) != NULL
) {
72 char entryName
[B_OS_NAME_LENGTH
];
73 if (entry
->root
->GetName(entryName
, sizeof(entryName
)) != B_OK
)
76 if (!strcmp(entryName
, name
)) {
77 entry
->root
->Acquire();
87 RootFileSystem::GetNextEntry(void *_cookie
, char *name
, size_t size
)
89 EntryIterator
*iterator
= (EntryIterator
*)_cookie
;
92 entry
= iterator
->Next();
94 return entry
->root
->GetName(name
, size
);
96 return B_ENTRY_NOT_FOUND
;
101 RootFileSystem::GetNextNode(void *_cookie
, Node
**_node
)
103 EntryIterator
*iterator
= (EntryIterator
*)_cookie
;
106 entry
= iterator
->Next();
108 *_node
= entry
->root
;
111 return B_ENTRY_NOT_FOUND
;
116 RootFileSystem::Rewind(void *_cookie
)
118 EntryIterator
*iterator
= (EntryIterator
*)_cookie
;
126 RootFileSystem::IsEmpty()
128 return fList
.IsEmpty();
133 RootFileSystem::AddVolume(Directory
*volume
, Partition
*partition
)
135 struct entry
*entry
= new (std::nothrow
) RootFileSystem::entry();
141 entry
->root
= volume
;
142 entry
->partition
= partition
;
151 RootFileSystem::AddLink(const char *name
, Directory
*target
)
153 struct entry
*entry
= new (std::nothrow
) RootFileSystem::entry();
159 entry
->root
= target
;
168 RootFileSystem::GetPartitionFor(Directory
*volume
, Partition
**_partition
)
170 EntryIterator iterator
= fList
.GetIterator();
173 while ((entry
= iterator
.Next()) != NULL
) {
174 if (entry
->root
== volume
) {
175 *_partition
= entry
->partition
;
180 return B_ENTRY_NOT_FOUND
;