mirror of
https://github.com/ksherlock/profuse.git
synced 2025-01-17 21:30:51 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@125 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
b660593d25
commit
dcd31997ed
@ -5,7 +5,7 @@
|
||||
#include "Entry.h"
|
||||
#include "Buffer.h"
|
||||
#include "Endian.h"
|
||||
|
||||
#include "BlockDevice.h"
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
@ -69,3 +69,39 @@ void Directory::setAccess(unsigned access)
|
||||
// todo -- mark dirty? update block?
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Directory::loadChildren(BlockDevice *device, unsigned block)
|
||||
{
|
||||
uint8_t buffer[512];
|
||||
unsigned next;
|
||||
bool first = true;
|
||||
unsigned offset;
|
||||
|
||||
// set of already-visited blocks?
|
||||
|
||||
while(block)
|
||||
{
|
||||
device->read(block, buffer);
|
||||
|
||||
next = Read16(buffer, 2);
|
||||
|
||||
_entryBlocks.push_back(block);
|
||||
|
||||
offset = 4;
|
||||
if (!first)
|
||||
{
|
||||
// storage type 0 is deleted, don't load...
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
first = false;
|
||||
block = next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
12
Entry.h
12
Entry.h
@ -131,6 +131,8 @@ protected:
|
||||
|
||||
std::vector<FileEntry *> _children;
|
||||
std::vector<unsigned> _entryBlocks;
|
||||
|
||||
void loadChildren(BlockDevice *, unsigned block);
|
||||
|
||||
private:
|
||||
|
||||
@ -149,7 +151,10 @@ private:
|
||||
class VolumeDirectory: public Directory {
|
||||
public:
|
||||
|
||||
VolumeDirectory(const char *name, BlockDevice *device);
|
||||
static VolumeDirectory *Create(const char *name, BlockDevice *device);
|
||||
static VolumeDirectory *Create(BlockDevice *);
|
||||
|
||||
|
||||
virtual ~VolumeDirectory();
|
||||
|
||||
unsigned bitmapPointer() const { return _bitmapPointer; }
|
||||
@ -162,7 +167,12 @@ public:
|
||||
virtual void write(Buffer *);
|
||||
|
||||
BlockDevice *device() const { return _device; }
|
||||
|
||||
private:
|
||||
|
||||
VolumeDirectory(const char *name, BlockDevice *device);
|
||||
VolumeDirectory(BlockDevice *device, const void *bp);
|
||||
|
||||
Bitmap *_bitmap;
|
||||
BlockDevice *_device;
|
||||
|
||||
|
@ -15,6 +15,25 @@ using namespace LittleEndian;
|
||||
|
||||
#pragma mark VolumeDirectory
|
||||
|
||||
|
||||
VolumeDirectory *VolumeDirectory::Create(const char *name, BlockDevice *device)
|
||||
{
|
||||
return new VolumeDirectory(name, device);
|
||||
}
|
||||
|
||||
VolumeDirectory *VolumeDirectory::Create(BlockDevice *device)
|
||||
{
|
||||
uint8_t block[512];
|
||||
// always block 2.
|
||||
|
||||
device->read(2, block);
|
||||
|
||||
return new VolumeDirectory(device, block);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
VolumeDirectory::VolumeDirectory(const char *name, BlockDevice *device) :
|
||||
Directory(VolumeHeader, name)
|
||||
{
|
||||
@ -75,6 +94,46 @@ VolumeDirectory::VolumeDirectory(const char *name, BlockDevice *device) :
|
||||
_bitmap = bitmap.release();
|
||||
}
|
||||
|
||||
|
||||
VolumeDirectory::VolumeDirectory(BlockDevice *device, const void *bp) :
|
||||
Directory(bp),
|
||||
_modification(0,0)
|
||||
{
|
||||
#undef __METHOD__
|
||||
#define __METHOD__ "VolumeDirectory::VolumeDirectory"
|
||||
|
||||
// + 4 to skip over the block poitners.
|
||||
std::auto_ptr<Bitmap> bitmap;
|
||||
const void *vp = 4 + (const uint8_t *)bp;
|
||||
|
||||
|
||||
if (storageType() != VolumeHeader)
|
||||
throw ProDOSException(__METHOD__ ": Invalid storage type.", 0x4b);
|
||||
|
||||
|
||||
|
||||
_modification = DateTime(Read16(vp, 0x12), Read16(vp, 0x14));
|
||||
|
||||
_bitmapPointer = Read16(vp, 0x23);
|
||||
|
||||
_totalBlocks = Read16(vp, 0x25);
|
||||
|
||||
|
||||
// verify totalBlocks <= device->blocks() ?
|
||||
|
||||
if (_bitmapPointer >= _totalBlocks)
|
||||
throw ProDOSException(__METHOD__ ": Invalid bitmap pointer.", 0x5a);
|
||||
|
||||
|
||||
// bitmap pointer...
|
||||
bitmap.reset(new Bitmap(device, _bitmapPointer, _totalBlocks));
|
||||
|
||||
|
||||
// parse the directory header....
|
||||
|
||||
_bitmap = bitmap.release();
|
||||
}
|
||||
|
||||
VolumeDirectory::~VolumeDirectory()
|
||||
{
|
||||
if (_device)
|
||||
|
@ -275,7 +275,7 @@ int main(int argc, char **argv)
|
||||
|
||||
// VolumeDirectory assumes ownership of device,
|
||||
// but doesn't release it on exception.
|
||||
volume.reset(new VolumeDirectory(volumeName.c_str(), device.get()));
|
||||
volume.reset(VolumeDirectory::Create(volumeName.c_str(), device.get()));
|
||||
device.release();
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user