From 22afe5d128ca6369bc8f18959b032f9d2cf03b2b Mon Sep 17 00:00:00 2001 From: ksherlock Date: Tue, 18 May 2010 21:26:07 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@222 aa027e90-d47c-11dd-86d7-074df07e0730 --- Cache/BlockCache.cpp | 4 ++-- Cache/BlockCache.h | 2 +- Device/BlockDevice.cpp | 4 +++- Device/BlockDevice.h | 2 +- Device/DavexDiskImage.cpp | 2 +- Device/DavexDiskImage.h | 2 +- Device/DiskCopy42Image.cpp | 2 +- Device/DiskCopy42Image.h | 2 +- Device/UniversalDiskImage.cpp | 4 ++-- Device/UniversalDiskImage.h | 2 +- Pascal/File.h | 4 ++-- Pascal/VolumeEntry.cpp | 25 ++++++++++++++----------- 12 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Cache/BlockCache.cpp b/Cache/BlockCache.cpp index 4b51fc1..c56e5eb 100644 --- a/Cache/BlockCache.cpp +++ b/Cache/BlockCache.cpp @@ -52,9 +52,9 @@ void BlockCache::read(unsigned block, void *bp) } -BlockCache *BlockCache::Create(BlockDevice *device, unsigned size = 16) +BlockCache *BlockCache::Create(BlockDevice *device) { if (!device) return NULL; - return device->createBlockCache(size); + return device->createBlockCache(); } diff --git a/Cache/BlockCache.h b/Cache/BlockCache.h index acaa46e..75fabef 100644 --- a/Cache/BlockCache.h +++ b/Cache/BlockCache.h @@ -19,7 +19,7 @@ enum BlockReleaseFlags { class BlockCache { public: - BlockCache *Create(BlockDevice *device, unsigned size = 16); + static BlockCache *Create(BlockDevice *device); virtual ~BlockCache(); diff --git a/Device/BlockDevice.cpp b/Device/BlockDevice.cpp index c17ddf3..77cb671 100644 --- a/Device/BlockDevice.cpp +++ b/Device/BlockDevice.cpp @@ -55,7 +55,9 @@ void BlockDevice::sync(TrackSector ts) } -BlockCache *BlockDevice::createBlockCache(unsigned size) +BlockCache *BlockDevice::createBlockCache() { + unsigned b = blocks(); + unsigned size = std::max(16u, b / 16); return new ConcreteBlockCache(this, size); } diff --git a/Device/BlockDevice.h b/Device/BlockDevice.h index d5e13dd..6775da1 100644 --- a/Device/BlockDevice.h +++ b/Device/BlockDevice.h @@ -17,7 +17,7 @@ public: virtual ~BlockDevice(); - virtual BlockCache *createBlockCache(unsigned size); + virtual BlockCache *createBlockCache(); virtual void read(unsigned block, void *bp) = 0; diff --git a/Device/DavexDiskImage.cpp b/Device/DavexDiskImage.cpp index 30fafc4..f388567 100644 --- a/Device/DavexDiskImage.cpp +++ b/Device/DavexDiskImage.cpp @@ -162,7 +162,7 @@ DavexDiskImage *DavexDiskImage::Create(const char *name, size_t blocks, const ch } -BlockCache *DavexDiskImage::createBlockCache(unsigned size) +BlockCache *DavexDiskImage::createBlockCache() { return new MappedBlockCache(this, 512 + (uint8_t *)address()); diff --git a/Device/DavexDiskImage.h b/Device/DavexDiskImage.h index 9977dee..fa9a432 100644 --- a/Device/DavexDiskImage.h +++ b/Device/DavexDiskImage.h @@ -20,7 +20,7 @@ public: static DavexDiskImage *Create(const char *name, size_t blocks, const char *vname); static DavexDiskImage *Open(MappedFile *); - virtual BlockCache *createBlockCache(unsigned size); + virtual BlockCache *createBlockCache(); private: diff --git a/Device/DiskCopy42Image.cpp b/Device/DiskCopy42Image.cpp index 1a7d0cd..c8e22bb 100644 --- a/Device/DiskCopy42Image.cpp +++ b/Device/DiskCopy42Image.cpp @@ -226,7 +226,7 @@ void DiskCopy42Image::write(unsigned block, const void *bp) } -BlockCache *DiskCopy42Image::createBlockCache(unsigned size) +BlockCache *DiskCopy42Image::createBlockCache() { // if not readonly, mark changed so crc will be updated at close. diff --git a/Device/DiskCopy42Image.h b/Device/DiskCopy42Image.h index ba14b9e..2c43da8 100644 --- a/Device/DiskCopy42Image.h +++ b/Device/DiskCopy42Image.h @@ -22,7 +22,7 @@ public: virtual void write(unsigned block, const void *bp); - virtual BlockCache *createBlockCache(unsigned size); + virtual BlockCache *createBlockCache(); private: diff --git a/Device/UniversalDiskImage.cpp b/Device/UniversalDiskImage.cpp index c23267f..227f5f3 100644 --- a/Device/UniversalDiskImage.cpp +++ b/Device/UniversalDiskImage.cpp @@ -150,14 +150,14 @@ bool UniversalDiskImage::readOnly() } -BlockCache *UniversalDiskImage::createBlockCache(unsigned size) +BlockCache *UniversalDiskImage::createBlockCache() { if (_format == 1) { return new MappedBlockCache(this, _dataOffset + (uint8_t *)address()); } - return DiskImage::createBlockCache(size); + return DiskImage::createBlockCache(); } diff --git a/Device/UniversalDiskImage.h b/Device/UniversalDiskImage.h index b70d0ed..fbaccba 100644 --- a/Device/UniversalDiskImage.h +++ b/Device/UniversalDiskImage.h @@ -19,7 +19,7 @@ public: virtual bool readOnly(); - BlockCache *createBlockCache(unsigned size); + virtual BlockCache *createBlockCache(); private: diff --git a/Pascal/File.h b/Pascal/File.h index 8d34eca..39e408b 100644 --- a/Pascal/File.h +++ b/Pascal/File.h @@ -7,7 +7,7 @@ namespace Device { class BlockDevice; - class AbstractBlockCache; + class BlockCache; } namespace LittleEndian { @@ -125,7 +125,7 @@ private: unsigned _inodeGenerator; Device::BlockDevice *_device; - Device::AbstractBlockCache *_cache; + Device::BlockCache *_cache; }; diff --git a/Pascal/VolumeEntry.cpp b/Pascal/VolumeEntry.cpp index c666eef..c5924fe 100644 --- a/Pascal/VolumeEntry.cpp +++ b/Pascal/VolumeEntry.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #pragma mark - #pragma mark VolumeEntry @@ -15,6 +15,8 @@ using namespace LittleEndian; using namespace Pascal; +using namespace Device; + unsigned VolumeEntry::ValidName(const char *cp) { // 7 chars max. Legal values: ascii, printable, @@ -69,7 +71,7 @@ VolumeEntry::VolumeEntry(const char *name, Device::BlockDevice *device) _accessTime = 0; _lastBoot = Date::Today(); - _cache = device->blockCache(); + _cache = BlockCache::Create(device); _device = device; for (unsigned i = 2; i < 6; ++i) @@ -77,12 +79,12 @@ VolumeEntry::VolumeEntry(const char *name, Device::BlockDevice *device) device->zeroBlock(i); } - void *vp = _cache->load(2); + void *vp = _cache->acquire(2); IOBuffer b(vp, 0x1a); writeDirectoryEntry(&b); - _cache->unload(2, true); + _cache->release(2, true); } @@ -96,7 +98,7 @@ VolumeEntry::VolumeEntry(Device::BlockDevice *device) // blocks. _device = device; - _cache = device->blockCache(); + _cache = BlockCache::Create(device); device->read(2, buffer.get()); @@ -160,8 +162,9 @@ VolumeEntry::~VolumeEntry() if (*iter) delete *iter; } - // _blockCache does not need deleting. - delete _device; + delete _cache; + // _device is deleted by _cache. + //delete _device; } @@ -194,20 +197,20 @@ FileEntry *VolumeEntry::fileAtIndex(unsigned i) const void *VolumeEntry::loadBlock(unsigned block) { - return _cache->load(block); + return _cache->acquire(block); } void VolumeEntry::unloadBlock(unsigned block, bool dirty) { - return _cache->unload(block, dirty); + return _cache->release(block, dirty); } void VolumeEntry::readBlock(unsigned block, void *buffer) { - _device->read(block, buffer); + _cache->read(block, buffer); } void VolumeEntry::writeBlock(unsigned block, void *buffer) { - _device->write(block, buffer); + _cache->write(block, buffer); }