git-svn-id: https://profuse.googlecode.com/svn/branches/v2@222 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2010-05-18 21:26:07 +00:00
parent 699a6e02fb
commit 22afe5d128
12 changed files with 30 additions and 25 deletions

View File

@ -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();
}

View File

@ -19,7 +19,7 @@ enum BlockReleaseFlags {
class BlockCache {
public:
BlockCache *Create(BlockDevice *device, unsigned size = 16);
static BlockCache *Create(BlockDevice *device);
virtual ~BlockCache();

View File

@ -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);
}

View File

@ -17,7 +17,7 @@ public:
virtual ~BlockDevice();
virtual BlockCache *createBlockCache(unsigned size);
virtual BlockCache *createBlockCache();
virtual void read(unsigned block, void *bp) = 0;

View File

@ -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());

View File

@ -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:

View File

@ -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.

View File

@ -22,7 +22,7 @@ public:
virtual void write(unsigned block, const void *bp);
virtual BlockCache *createBlockCache(unsigned size);
virtual BlockCache *createBlockCache();
private:

View File

@ -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();
}

View File

@ -19,7 +19,7 @@ public:
virtual bool readOnly();
BlockCache *createBlockCache(unsigned size);
virtual BlockCache *createBlockCache();
private:

View File

@ -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;
};

View File

@ -7,7 +7,7 @@
#include <Endian/IOBuffer.h>
#include <Device/BlockDevice.h>
#include <Device/BlockCache.h>
#include <Cache/BlockCache.h>
#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);
}