From 629efe6da57cb577d83e997b5095be15bdaeffb5 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Tue, 18 May 2010 19:59:18 +0000 Subject: [PATCH] block cache support. git-svn-id: https://profuse.googlecode.com/svn/branches/v2@220 aa027e90-d47c-11dd-86d7-074df07e0730 --- Device/Adaptor.h | 8 ++++---- Device/BlockDevice.cpp | 7 ++++++- Device/BlockDevice.h | 5 +++++ Device/DavexDiskImage.cpp | 8 ++++++++ Device/DavexDiskImage.h | 1 + Device/DiskCopy42Image.cpp | 14 ++++++++++++++ Device/DiskCopy42Image.h | 4 +++- Device/DiskImage.cpp | 11 +++++++++++ Device/DiskImage.h | 3 +++ Device/UniversalDiskImage.cpp | 36 +++++++++++++++++++++++++++-------- Device/UniversalDiskImage.h | 9 +++++++++ 11 files changed, 92 insertions(+), 14 deletions(-) diff --git a/Device/Adaptor.h b/Device/Adaptor.h index 0e945db..311077f 100644 --- a/Device/Adaptor.h +++ b/Device/Adaptor.h @@ -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; diff --git a/Device/BlockDevice.cpp b/Device/BlockDevice.cpp index a9a12ba..c17ddf3 100644 --- a/Device/BlockDevice.cpp +++ b/Device/BlockDevice.cpp @@ -9,7 +9,7 @@ #include - +#include #include @@ -54,3 +54,8 @@ void BlockDevice::sync(TrackSector ts) sync(); } + +BlockCache *BlockDevice::createBlockCache(unsigned size) +{ + return new ConcreteBlockCache(this, size); +} diff --git a/Device/BlockDevice.h b/Device/BlockDevice.h index 97cd438..d5e13dd 100644 --- a/Device/BlockDevice.h +++ b/Device/BlockDevice.h @@ -8,6 +8,8 @@ #include +#include + 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); diff --git a/Device/DavexDiskImage.cpp b/Device/DavexDiskImage.cpp index 3ac452b..30fafc4 100644 --- a/Device/DavexDiskImage.cpp +++ b/Device/DavexDiskImage.cpp @@ -14,6 +14,7 @@ #include #include +#include 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()); + +} diff --git a/Device/DavexDiskImage.h b/Device/DavexDiskImage.h index 9246ada..9977dee 100644 --- a/Device/DavexDiskImage.h +++ b/Device/DavexDiskImage.h @@ -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: diff --git a/Device/DiskCopy42Image.cpp b/Device/DiskCopy42Image.cpp index 967af2b..1a7d0cd 100644 --- a/Device/DiskCopy42Image.cpp +++ b/Device/DiskCopy42Image.cpp @@ -9,6 +9,9 @@ #include #include +#include + + 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()); } \ No newline at end of file diff --git a/Device/DiskCopy42Image.h b/Device/DiskCopy42Image.h index bdc7b0a..ba14b9e 100644 --- a/Device/DiskCopy42Image.h +++ b/Device/DiskCopy42Image.h @@ -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); diff --git a/Device/DiskImage.cpp b/Device/DiskImage.cpp index 8a2a032..fc515a1 100644 --- a/Device/DiskImage.cpp +++ b/Device/DiskImage.cpp @@ -11,6 +11,8 @@ #include #include +#include + #include @@ -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) diff --git a/Device/DiskImage.h b/Device/DiskImage.h index 6234c74..de891d6 100644 --- a/Device/DiskImage.h +++ b/Device/DiskImage.h @@ -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); diff --git a/Device/UniversalDiskImage.cpp b/Device/UniversalDiskImage.cpp index c9487ab..c23267f 100644 --- a/Device/UniversalDiskImage.cpp +++ b/Device/UniversalDiskImage.cpp @@ -5,12 +5,17 @@ #include +#include +#include + 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(); -} \ No newline at end of file +} + + +BlockCache *UniversalDiskImage::createBlockCache(unsigned size) +{ + if (_format == 1) + { + return new MappedBlockCache(this, _dataOffset + (uint8_t *)address()); + } + + return DiskImage::createBlockCache(size); +} + + diff --git a/Device/UniversalDiskImage.h b/Device/UniversalDiskImage.h index 42f7cfe..b70d0ed 100644 --- a/Device/UniversalDiskImage.h +++ b/Device/UniversalDiskImage.h @@ -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; }; }