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