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

This commit is contained in:
ksherlock 2010-05-20 22:30:00 +00:00
parent d9bc18bdee
commit e7b4c96984
8 changed files with 43 additions and 3 deletions

View File

@ -58,3 +58,18 @@ BlockCache *BlockCache::Create(BlockDevice *device)
return device->createBlockCache();
}
void BlockCache::zeroBlock(unsigned block)
{
/*
void *address = acquire(block);
std::memset(address, 0, 512);
release(block, true);
*/
uint8_t buffer[512];
std::memset(buffer, 0, 512);
write(block, buffer);
}

View File

@ -36,6 +36,9 @@ public:
virtual void release(unsigned block, int flags) = 0 ;
virtual void markDirty(unsigned block) = 0;
virtual void zeroBlock(unsigned block);
void release(unsigned block) { release(block, 0); }
void release(unsigned block, bool dirty)
{

View File

@ -148,6 +148,8 @@ void ConcreteBlockCache::write(unsigned block, const void *bp)
setLast(e);
}
void ConcreteBlockCache::markDirty(unsigned block)
{
Entry *e = findEntry(block);

View File

@ -20,6 +20,7 @@ public:
virtual void release(unsigned block, int flags);
virtual void markDirty(unsigned block);
private:
struct Entry {

View File

@ -69,6 +69,14 @@ void MappedBlockCache::write(unsigned block, const void *vp)
}
void MappedBlockCache::zeroBlock(unsigned block)
{
_dirty = true;
std::memset(_data + block * 512, 0, 512);
}
// sync everything.
void MappedBlockCache::sync()
{

View File

@ -14,6 +14,8 @@ class MappedBlockCache : public BlockCache {
virtual void sync();
virtual void write(unsigned block, const void *vp);
virtual void zeroBlock(unsigned block);
virtual void *acquire(unsigned block);
virtual void release(unsigned block, int flags);

View File

@ -78,6 +78,9 @@ class VolumeEntry : public Entry {
public:
static unsigned ValidName(const char *);
// create new
VolumeEntry(const char *name, Device::BlockDevice *);
@ -103,8 +106,8 @@ public:
void readBlock(unsigned block, void *);
void writeBlock(unsigned block, void *);
unsigned static ValidName(const char *);
void sync();
protected:
virtual void writeDirectoryEntry(LittleEndian::IOBuffer *);

View File

@ -77,9 +77,10 @@ VolumeEntry::VolumeEntry(const char *name, Device::BlockDevice *device)
_cache = BlockCache::Create(device);
_device = device;
for (unsigned i = 2; i < 6; ++i)
{
device->zeroBlock(i);
_cache->zeroBlock(i);
}
void *vp = _cache->acquire(2);
@ -89,6 +90,7 @@ VolumeEntry::VolumeEntry(const char *name, Device::BlockDevice *device)
_cache->release(2, true);
_cache->sync();
}
@ -216,6 +218,10 @@ void VolumeEntry::writeBlock(unsigned block, void *buffer)
}
void VolumeEntry::sync()
{
_cache->sync();
}
void VolumeEntry::writeDirectoryEntry(IOBuffer *b)
{