From 525fe7810af975f648b9c134e6c70bd74a735201 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Sat, 29 May 2010 01:03:20 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@291 aa027e90-d47c-11dd-86d7-074df07e0730 --- Pascal/VolumeEntry.cpp | 37 +++++++++++++++++++++++++++++++++++++ Pascal/VolumeEntry.h | 10 +++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Pascal/VolumeEntry.cpp b/Pascal/VolumeEntry.cpp index 46637d8..5ee5031 100644 --- a/Pascal/VolumeEntry.cpp +++ b/Pascal/VolumeEntry.cpp @@ -339,6 +339,7 @@ unsigned VolumeEntry::unlink(const char *name) } +// TODO -- if newName exists, atomically remove it. unsigned VolumeEntry::rename(const char *oldName, const char *newName) { FileEntry *e; @@ -561,6 +562,42 @@ unsigned VolumeEntry::krunch() +/* + * return the number of free blocks. + * if krunched is true, returns sum of all free blocks + * if krunched is false, returns free blocks at end. + * + */ +unsigned VolumeEntry::freeBlocks(bool krunched) const +{ + unsigned freeBlocks = 0; + unsigned lastBlock = 0; + + if (krunched) + { + std::vector::const_iterator iter; + + lastBlock = _lastBlock; + + for (iter = _files.begin(); iter != _files.end(); ++iter) + { + const FileEntry *e = *iter; + freeBlocks += e->_firstBlock - lastBlock; + lastBlock = e->_lastBlock; + } + } + else + { + lastBlock = _fileCount ? _files.back()->_lastBlock : _lastBlock; + } + + + freeBlocks += _lastVolumeBlock - lastBlock; + return freeBlocks; +} + + + void *VolumeEntry::loadBlock(unsigned block) diff --git a/Pascal/VolumeEntry.h b/Pascal/VolumeEntry.h index 5bf52dd..fd40240 100644 --- a/Pascal/VolumeEntry.h +++ b/Pascal/VolumeEntry.h @@ -31,12 +31,12 @@ namespace Pascal { Pascal::Date lastBoot() const { return _lastBoot; } + unsigned freeBlocks(bool krunched = false) const; + + FileEntry *fileAtIndex(unsigned i) const; FileEntry *fileByName(const char *name) const; - void addChild(FileEntry *child, unsigned blocks); - - void *loadBlock(unsigned block); void unloadBlock(unsigned block, bool dirty = false); @@ -50,11 +50,11 @@ namespace Pascal { unsigned unlink(const char *name); unsigned rename(const char *oldName, const char *newName); - - FileEntry *create(const char *name, unsigned blocks); + + unsigned krunch();