Added Type(), IsFile(), IsDirectory(), and GetDirectoryIterator()

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3941 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2003-07-10 19:43:57 +00:00
parent 267fd7e7d1
commit b8f1212a91
2 changed files with 40 additions and 1 deletions

View File

@ -1,5 +1,7 @@
#include "Icb.h"
#include "DirectoryIterator.h"
#include "Utils.h"
#include "Volume.h"
using namespace Udf;
@ -8,7 +10,7 @@ Icb::Icb(Volume *volume, udf_long_address address)
: fVolume(NULL)
, fIcbData(volume ? volume->BlockSize() : 0)
, fInitStatus(B_NO_INIT)
, fId((address.block() << 16) & (address.partition()))
, fId(to_vnode_id(address))
{
DEBUG_INIT_ETC(CF_PUBLIC, "Icb", ("Volume*(%p), long_address(block: %ld, partition: %d, length: %ld)", volume, address.block(), address.partition(), address.length()));
status_t err = volume ? B_OK : B_BAD_VALUE;
@ -31,3 +33,22 @@ Icb::InitCheck()
{
return fInitStatus;
}
status_t
Icb::GetDirectoryIterator(DirectoryIterator **iterator)
{
status_t err = iterator ? B_OK : B_BAD_VALUE;
if (!err) {
*iterator = new DirectoryIterator(this);
if (*iterator) {
err = fIteratorList.PushBack(*iterator);
} else {
err = B_NO_MEMORY;
}
}
return err;
}

View File

@ -23,9 +23,11 @@ extern "C" {
#include "DiskStructures.h"
#include "MemoryChunk.h"
#include "SinglyLinkedList.h"
namespace Udf {
class DirectoryIterator;
class Volume;
class Icb {
@ -33,13 +35,29 @@ public:
Icb(Volume *volume, udf_long_address address);
status_t InitCheck();
vnode_id Id() { return fId; }
// categorization
uint8 Type() { return IcbTag().file_type(); }
bool IsFile() { return InitCheck() == B_OK && Type() == ICB_TYPE_REGULAR_FILE; }
bool IsDirectory() { return InitCheck() == B_OK
&& (Type() == ICB_TYPE_DIRECTORY || Type() == ICB_TYPE_STREAM_DIRECTORY); }
// directories
status_t GetDirectoryIterator(DirectoryIterator **iterator);
private:
Icb(); // unimplemented
udf_icb_entry_tag& IcbTag() { return (reinterpret_cast<udf_icb_header*>(fIcbData.Data()))->icb_tag(); }
private:
Volume *fVolume;
MemoryChunk fIcbData;
status_t fInitStatus;
vnode_id fId;
SinglyLinkedList<Strategy::SinglyLinkedList::Auto<DirectoryIterator*> > fIteratorList;
};
}; // namespace Udf