From 895bab385c302ef68e2e32e5bc5a1041abfeb61b Mon Sep 17 00:00:00 2001 From: ksherlock Date: Fri, 21 May 2010 23:35:12 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@254 aa027e90-d47c-11dd-86d7-074df07e0730 --- Pascal/File.h | 5 +++ Pascal/VolumeEntry.cpp | 69 ++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Pascal/File.h b/Pascal/File.h index 14e69e0..b093b3c 100644 --- a/Pascal/File.h +++ b/Pascal/File.h @@ -127,6 +127,11 @@ private: void init(void *); + + uint8_t *readDirectoryHeader(); + void writeDirectoryHeader(uint8_t *); + + unsigned _fileNameLength; char _fileName[8]; unsigned _lastVolumeBlock; diff --git a/Pascal/VolumeEntry.cpp b/Pascal/VolumeEntry.cpp index dab8c39..afe9f7c 100644 --- a/Pascal/VolumeEntry.cpp +++ b/Pascal/VolumeEntry.cpp @@ -96,8 +96,9 @@ VolumeEntry::VolumeEntry(const char *name, Device::BlockDevice *device) VolumeEntry::VolumeEntry(Device::BlockDevice *device) { - ProFUSE::auto_array buffer(new uint8_t[512]); unsigned blockCount; + ProFUSE::auto_array buffer(new uint8_t[512]); + // read the header block, then load up all the header // blocks. @@ -117,12 +118,7 @@ VolumeEntry::VolumeEntry(Device::BlockDevice *device) if (blockCount > 1) { - buffer.reset(new uint8_t[512 * blockCount]); - - for (unsigned i = 0; i < blockCount; ++i) - { - _cache->read(2 + i, buffer.get() + 512 * i); - } + buffer.reset(readDirectoryHeader()); } // now load up all the children. @@ -214,7 +210,7 @@ unsigned VolumeEntry::unlink(const char *name) unsigned index; - if (_device->readOnly()) return 0x2b; // WRITE-PROTECTED DISK + if (_device->readOnly()) return ProFUSE::drvrWrtProt; // WRITE-PROTECTED DISK for(index = 0; index < _fileCount; ++index) { @@ -226,23 +222,17 @@ unsigned VolumeEntry::unlink(const char *name) break; } } - if (index == _fileCount) return 0x46; // FILE NOT FOUND + if (index == _fileCount) return ProFUSE::fileNotFound; // FILE NOT FOUND _files.erase(_files.begin() + index); _fileCount--; // need to update the header blocks. - unsigned blockCount = blocks(); - ProFUSE::auto_array buffer(new uint8_t[512 * blockCount]); + ProFUSE::auto_array buffer(readDirectoryHeader()); + - // load up blocks. - // since entries span blocks, we can't do this via pointer. - for (unsigned i = 0; i < blockCount; ++i) - { - _cache->read(2 + i, buffer.get() + 512 * i); - } // update the filecount. - IOBuffer b(buffer.get(), 512 * blockCount); + IOBuffer b(buffer.get(), 512 * blocks()); writeDirectoryEntry(&b); // move up all the entries. @@ -252,10 +242,7 @@ unsigned VolumeEntry::unlink(const char *name) std::memset(buffer.get() + 0x1a + _fileCount * 0x1a, 0, 0x1a); // now write to disk. - for (unsigned i = 0; i < blockCount; ++i) - { - _cache->write(2 + i, buffer.get() + 512 * i); - } + writeDirectoryHeader(buffer.get()); _cache->sync(); return 0; @@ -303,17 +290,10 @@ unsigned VolumeEntry::krunch() // need to update the header blocks. - unsigned blockCount = blocks(); - ProFUSE::auto_array buffer(new uint8_t[512 * blockCount]); - IOBuffer b(buffer.get(), 512 * blockCount); - - // load up the directory blocks. - for (unsigned i = 0; i < blocks(); ++i) - { - _cache->read(2 + i, buffer.get() + 512 * i); - } - + ProFUSE::auto_array buffer(readDirectoryHeader()); + IOBuffer b(buffer.get(), 512 * blocks()); + prevBlock = lastBlock(); unsigned offset = 0; @@ -353,10 +333,7 @@ unsigned VolumeEntry::krunch() // now save the directory entries. // load up the directory blocks. - for (unsigned i = 0; i < blocks(); ++i) - { - _cache->write(2 + i, buffer.get() + 512 * i); - } + writeDirectoryHeader(buffer.get()); _cache->sync(); @@ -418,3 +395,23 @@ void VolumeEntry::writeDirectoryEntry(IOBuffer *b) } + +uint8_t *VolumeEntry::readDirectoryHeader() +{ + ProFUSE::auto_array buffer(new uint8_t[512 * blocks()]); + + for (unsigned i = 0; i < blocks(); ++i) + { + _cache->read(2 + i, buffer.get() + i * 512); + } + + return buffer.release(); +} + +void VolumeEntry::writeDirectoryHeader(uint8_t *buffer) +{ + for (unsigned i = 0; i < blocks(); ++i) + { + _cache->write(2 + i, buffer + 512 * i); + } +}