block cache support.

git-svn-id: https://profuse.googlecode.com/svn/branches/v2@220 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2010-05-18 19:59:18 +00:00
parent be7a7bafc1
commit 629efe6da5
11 changed files with 92 additions and 14 deletions

View File

@ -18,8 +18,8 @@ namespace Device {
{
public:
POAdaptor(void *address);
void readBlock(unsigned block, void *bp);
void writeBlock(unsigned block, const void *bp);
virtual void readBlock(unsigned block, void *bp);
virtual void writeBlock(unsigned block, const void *bp);
private:
uint8_t *_address;
};
@ -28,8 +28,8 @@ namespace Device {
{
public:
DOAdaptor(void *address);
void readBlock(unsigned block, void *bp);
void writeBlock(unsigned block, const void *bp);
virtual void readBlock(unsigned block, void *bp);
virtual void writeBlock(unsigned block, const void *bp);
private:
uint8_t *_address;

View File

@ -9,7 +9,7 @@
#include <Device/BlockDevice.h>
#include <Cache/ConcreteBlockCache.h>
#include <ProFUSE/Exception.h>
@ -54,3 +54,8 @@ void BlockDevice::sync(TrackSector ts)
sync();
}
BlockCache *BlockDevice::createBlockCache(unsigned size)
{
return new ConcreteBlockCache(this, size);
}

View File

@ -8,6 +8,8 @@
#include <Device/TrackSector.h>
#include <Cache/BlockCache.h>
namespace Device {
class BlockDevice {
@ -15,6 +17,9 @@ public:
virtual ~BlockDevice();
virtual BlockCache *createBlockCache(unsigned size);
virtual void read(unsigned block, void *bp) = 0;
virtual void read(TrackSector ts, void *bp);

View File

@ -14,6 +14,7 @@
#include <Endian/Endian.h>
#include <Endian/IOBuffer.h>
#include <Cache/MappedBlockCache.h>
using namespace Device;
using namespace LittleEndian;
@ -159,3 +160,10 @@ DavexDiskImage *DavexDiskImage::Create(const char *name, size_t blocks, const ch
return new DavexDiskImage(file);
}
BlockCache *DavexDiskImage::createBlockCache(unsigned size)
{
return new MappedBlockCache(this, 512 + (uint8_t *)address());
}

View File

@ -20,6 +20,7 @@ public:
static DavexDiskImage *Create(const char *name, size_t blocks, const char *vname);
static DavexDiskImage *Open(MappedFile *);
virtual BlockCache *createBlockCache(unsigned size);
private:

View File

@ -9,6 +9,9 @@
#include <Endian/Endian.h>
#include <Endian/IOBuffer.h>
#include <Cache/MappedBlockCache.h>
using namespace Device;
using namespace BigEndian;
@ -17,6 +20,7 @@ using ProFUSE::Exception;
using ProFUSE::POSIXException;
enum {
oDataSize = 64,
oDataChecksum = 72,
@ -219,4 +223,14 @@ void DiskCopy42Image::write(unsigned block, const void *bp)
{
DiskImage::write(block, bp);
_changed = true;
}
BlockCache *DiskCopy42Image::createBlockCache(unsigned size)
{
// if not readonly, mark changed so crc will be updated at close.
if (!readOnly()) _changed = true;
return new MappedBlockCache(this, address());
}

View File

@ -21,7 +21,9 @@ public:
virtual void write(unsigned block, const void *bp);
virtual BlockCache *createBlockCache(unsigned size);
private:
DiskCopy42Image(const char *name, bool readOnly);

View File

@ -11,6 +11,8 @@
#include <Device/DiskImage.h>
#include <File/MappedFile.h>
#include <Cache/MappedBlockCache.h>
#include <ProFUSE/Exception.h>
@ -190,6 +192,15 @@ void ProDOSOrderDiskImage::Validate(MappedFile *f)
}
BlockCache *ProDOSOrderDiskImage::createBlockCache(unsigned size)
{
return new MappedBlockCache(this, address());
}
#pragma mark -
#pragma mark DOS Order Disk Image
/*
DOSOrderDiskImage::DOSOrderDiskImage(const char *name, bool readOnly) :
DiskImage(name, readOnly)

View File

@ -59,6 +59,9 @@ public:
static ProDOSOrderDiskImage *Create(const char *name, size_t blocks);
static ProDOSOrderDiskImage *Open(MappedFile *);
virtual BlockCache *createBlockCache(unsigned size);
private:
ProDOSOrderDiskImage(const char *name, bool readOnly);

View File

@ -5,12 +5,17 @@
#include <ProFUSE/Exception.h>
#include <Cache/MappedBlockCache.h>
#include <Cache/ConcreteBlockCache.h>
using namespace Device;
using namespace LittleEndian;
using ProFUSE::Exception;
using ProFUSE::POSIXException;
/*
UniversalDiskImage::UniversalDiskImage(const char *name, bool readOnly) :
DiskImage(name, readOnly)
@ -26,21 +31,23 @@ UniversalDiskImage::UniversalDiskImage(const char *name, bool readOnly) :
UniversalDiskImage::UniversalDiskImage(MappedFile *file) :
DiskImage(file)
{
unsigned blocks;
unsigned offset;
uint8_t * data = (uint8_t *)file->address();
_format = Read32(data, 0x0c);
_flags = Read32(data, 0x10);
_blocks = Read32(data, 0x14);
offset = Read32(data, 0x20);
blocks = Read32(data, 0x14);
_dataOffset = Read32(data, 0x18);
_dataLength = Read32(data, 0x1c);
setBlocks(blocks);
setBlocks(_blocks);
// TODO -- DO, Nibble support.
setAdaptor(new POAdaptor(offset + data));
setAdaptor(new POAdaptor(_dataOffset + data));
}
UniversalDiskImage *UniversalDiskImage::Create(const char *name, size_t blocks)
@ -119,8 +126,8 @@ void UniversalDiskImage::Validate(MappedFile *file)
// TODO -- Dos Order, Nibble support.
if (Read32(data, 0x0c) != 1) break;
offset = Read32(data, 0x20);
blocks = Read32(data, 0x14);
offset = Read32(data, 0x18);
// file size == blocks * 512
if (Read32(data, 0x1c) != blocks * 512) break;
@ -140,4 +147,17 @@ void UniversalDiskImage::Validate(MappedFile *file)
bool UniversalDiskImage::readOnly()
{
return (_flags & 0x8000000) || DiskImage::readOnly();
}
}
BlockCache *UniversalDiskImage::createBlockCache(unsigned size)
{
if (_format == 1)
{
return new MappedBlockCache(this, _dataOffset + (uint8_t *)address());
}
return DiskImage::createBlockCache(size);
}

View File

@ -12,11 +12,16 @@ namespace Device {
class UniversalDiskImage : public DiskImage {
public:
static UniversalDiskImage *Create(const char *name, size_t blocks);
static UniversalDiskImage *Open(MappedFile *);
virtual bool readOnly();
BlockCache *createBlockCache(unsigned size);
private:
UniversalDiskImage(const char *name, bool readOnly);
@ -24,7 +29,11 @@ private:
UniversalDiskImage(MappedFile *);
static void Validate(MappedFile *);
uint32_t _format;
uint32_t _flags;
uint32_t _blocks;
uint32_t _dataOffset;
uint32_t _dataLength;
};
}