ramfs: Code cleanup to EntryIterator.

No functional change intended.
This commit is contained in:
Augustin Cavalier 2025-01-14 21:17:43 -05:00
parent 0f63c097ac
commit 3f73e6e934

View File

@ -8,9 +8,10 @@
#include "EntryIterator.h"
#include "Volume.h"
// constructor
EntryIterator::EntryIterator(Directory *directory)
: fDirectory(directory),
:
fDirectory(directory),
fEntry(NULL),
fSuspended(false),
fIsNext(false),
@ -18,34 +19,37 @@ EntryIterator::EntryIterator(Directory *directory)
{
}
// destructor
EntryIterator::~EntryIterator()
{
Unset();
}
// SetTo
status_t
EntryIterator::SetTo(Directory *directory)
{
Unset();
status_t error = (directory ? B_OK : B_BAD_VALUE);
if (error == B_OK) {
if (directory == NULL)
return B_BAD_VALUE;
fDirectory = directory;
fEntry = NULL;
fSuspended = false;
fIsNext = false;
fDone = false;
}
return error;
return B_OK;
}
// Unset
void
EntryIterator::Unset()
{
if (fDirectory && fSuspended)
if (fDirectory != NULL && fSuspended)
Resume();
fDirectory = NULL;
fEntry = NULL;
fSuspended = false;
@ -53,51 +57,51 @@ EntryIterator::Unset()
fDone = false;
}
// Suspend
status_t
EntryIterator::Suspend()
{
status_t error = (fDirectory ? B_OK : B_ERROR);
if (error == B_OK) {
if (fDirectory->GetVolume()->IteratorLock()) {
if (!fSuspended) {
if (fEntry)
if (fDirectory == NULL || fSuspended)
return B_ERROR;
if (!fDirectory->GetVolume()->IteratorLock())
return B_ERROR;
if (fEntry != NULL)
fEntry->AttachEntryIterator(this);
fDirectory->GetVolume()->IteratorUnlock();
fSuspended = true;
} else
error = B_ERROR;
} else
error = B_ERROR;
}
return error;
return B_OK;
}
// Resume
status_t
EntryIterator::Resume()
{
status_t error = (fDirectory ? B_OK : B_ERROR);
if (error == B_OK) {
if (fDirectory->GetVolume()->IteratorLock()) {
if (fSuspended) {
if (fEntry)
if (fDirectory == NULL)
return B_ERROR;
if (!fDirectory->GetVolume()->IteratorLock())
return B_ERROR;
if (fSuspended && fEntry != NULL)
fEntry->DetachEntryIterator(this);
fSuspended = false;
}
fDirectory->GetVolume()->IteratorUnlock();
} else
error = B_ERROR;
}
return error;
return B_OK;
}
// GetNext
status_t
EntryIterator::GetNext(Entry **entry)
{
if (fDirectory == NULL || entry == NULL)
return B_BAD_VALUE;
status_t error = B_ENTRY_NOT_FOUND;
if (!fDone && fDirectory && entry) {
if (!fDone) {
if (fIsNext) {
fIsNext = false;
if (fEntry)
@ -110,26 +114,28 @@ EntryIterator::GetNext(Entry **entry)
return error;
}
// Rewind
status_t
EntryIterator::Rewind()
{
status_t error = (fDirectory ? B_OK : B_ERROR);
if (error == B_OK) {
if (fDirectory->GetVolume()->IteratorLock()) {
if (fSuspended && fEntry)
if (fDirectory == NULL)
return B_ERROR;
if (!fDirectory->GetVolume()->IteratorLock())
return B_ERROR;
if (fSuspended && fEntry != NULL)
fEntry->DetachEntryIterator(this);
fEntry = NULL;
fIsNext = false;
fDone = false;
fDirectory->GetVolume()->IteratorUnlock();
} else
error = B_ERROR;
}
return error;
return B_OK;
}
// SetCurrent
void
EntryIterator::SetCurrent(Entry *entry, bool isNext)
{
@ -137,4 +143,3 @@ EntryIterator::SetCurrent(Entry *entry, bool isNext)
fEntry = entry;
fDone = !fEntry;
}