mirror of
https://github.com/ksherlock/profuse.git
synced 2024-06-10 02:29:33 +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 "Entry.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Endian.h"
|
#include "Endian.h"
|
||||||
|
#include "BlockDevice.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,3 +69,39 @@ void Directory::setAccess(unsigned access)
|
||||||
// todo -- mark dirty? update block?
|
// 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
|
@ -132,6 +132,8 @@ protected:
|
||||||
std::vector<FileEntry *> _children;
|
std::vector<FileEntry *> _children;
|
||||||
std::vector<unsigned> _entryBlocks;
|
std::vector<unsigned> _entryBlocks;
|
||||||
|
|
||||||
|
void loadChildren(BlockDevice *, unsigned block);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DateTime _creation;
|
DateTime _creation;
|
||||||
|
@ -149,7 +151,10 @@ private:
|
||||||
class VolumeDirectory: public Directory {
|
class VolumeDirectory: public Directory {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VolumeDirectory(const char *name, BlockDevice *device);
|
static VolumeDirectory *Create(const char *name, BlockDevice *device);
|
||||||
|
static VolumeDirectory *Create(BlockDevice *);
|
||||||
|
|
||||||
|
|
||||||
virtual ~VolumeDirectory();
|
virtual ~VolumeDirectory();
|
||||||
|
|
||||||
unsigned bitmapPointer() const { return _bitmapPointer; }
|
unsigned bitmapPointer() const { return _bitmapPointer; }
|
||||||
|
@ -162,7 +167,12 @@ public:
|
||||||
virtual void write(Buffer *);
|
virtual void write(Buffer *);
|
||||||
|
|
||||||
BlockDevice *device() const { return _device; }
|
BlockDevice *device() const { return _device; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
VolumeDirectory(const char *name, BlockDevice *device);
|
||||||
|
VolumeDirectory(BlockDevice *device, const void *bp);
|
||||||
|
|
||||||
Bitmap *_bitmap;
|
Bitmap *_bitmap;
|
||||||
BlockDevice *_device;
|
BlockDevice *_device;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,25 @@ using namespace LittleEndian;
|
||||||
|
|
||||||
#pragma mark VolumeDirectory
|
#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) :
|
VolumeDirectory::VolumeDirectory(const char *name, BlockDevice *device) :
|
||||||
Directory(VolumeHeader, name)
|
Directory(VolumeHeader, name)
|
||||||
{
|
{
|
||||||
|
@ -75,6 +94,46 @@ VolumeDirectory::VolumeDirectory(const char *name, BlockDevice *device) :
|
||||||
_bitmap = bitmap.release();
|
_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()
|
VolumeDirectory::~VolumeDirectory()
|
||||||
{
|
{
|
||||||
if (_device)
|
if (_device)
|
||||||
|
|
|
@ -275,7 +275,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// VolumeDirectory assumes ownership of device,
|
// VolumeDirectory assumes ownership of device,
|
||||||
// but doesn't release it on exception.
|
// 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();
|
device.release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user