From 545dd02842749b4e4c98b18690a2167f6846e43e Mon Sep 17 00:00:00 2001 From: ksherlock Date: Wed, 19 May 2010 17:50:18 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@225 aa027e90-d47c-11dd-86d7-074df07e0730 --- Cache/BlockCache.cpp | 2 +- Device/DavexDiskImage.cpp | 7 +++++-- Device/DiskImage.cpp | 12 ++++++++---- Device/DiskImage.h | 2 ++ Device/UniversalDiskImage.cpp | 4 +++- Pascal/VolumeEntry.cpp | 5 ++--- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cache/BlockCache.cpp b/Cache/BlockCache.cpp index c56e5eb..24f80d7 100644 --- a/Cache/BlockCache.cpp +++ b/Cache/BlockCache.cpp @@ -27,7 +27,7 @@ using ProFUSE::POSIXException; BlockCache::BlockCache(BlockDevice *device) { - _device = _device; + _device = device; _blocks = device->blocks(); _readOnly = device->readOnly(); } diff --git a/Device/DavexDiskImage.cpp b/Device/DavexDiskImage.cpp index f388567..c2e11d6 100644 --- a/Device/DavexDiskImage.cpp +++ b/Device/DavexDiskImage.cpp @@ -40,9 +40,12 @@ DavexDiskImage::DavexDiskImage(const char *name, bool readOnly) : DavexDiskImage::DavexDiskImage(MappedFile *file) : DiskImage(file) { + // at this point, file is no longer valid. + + // 512-bytes header - setBlocks((file->length() / 512) - 1); - setAdaptor(new POAdaptor(512 + (uint8_t *)file->address())); + setBlocks((length() / 512) - 1); + setAdaptor(new POAdaptor(512 + (uint8_t *)address())); } diff --git a/Device/DiskImage.cpp b/Device/DiskImage.cpp index 0bdd365..156cb36 100644 --- a/Device/DiskImage.cpp +++ b/Device/DiskImage.cpp @@ -202,8 +202,10 @@ ProDOSOrderDiskImage::ProDOSOrderDiskImage(const char *name, bool readOnly) : ProDOSOrderDiskImage::ProDOSOrderDiskImage(MappedFile *file) : DiskImage(file) { - setBlocks(file->length() / 512); - setAdaptor(new POAdaptor(file->address())); + // at this point, file is no longer valid. + + setBlocks(length() / 512); + setAdaptor(new POAdaptor(address())); } ProDOSOrderDiskImage *ProDOSOrderDiskImage::Create(const char *name, size_t blocks) @@ -252,8 +254,10 @@ DOSOrderDiskImage::DOSOrderDiskImage(const char *name, bool readOnly) : DOSOrderDiskImage::DOSOrderDiskImage(MappedFile *file) : DiskImage(file) { - setBlocks(file->length() / 512); - setAdaptor(new DOAdaptor(file->address())); + // at this point, file is no longer valid. + + setBlocks(length() / 512); + setAdaptor(new DOAdaptor(address())); } diff --git a/Device/DiskImage.h b/Device/DiskImage.h index 2f1a909..e5b9b55 100644 --- a/Device/DiskImage.h +++ b/Device/DiskImage.h @@ -44,6 +44,8 @@ protected: void setAdaptor(Adaptor *); void *address() const { return _file.address(); } + size_t length() const { return _file.length(); } + MappedFile *file() { return &_file; } private: diff --git a/Device/UniversalDiskImage.cpp b/Device/UniversalDiskImage.cpp index 227f5f3..b1162f0 100644 --- a/Device/UniversalDiskImage.cpp +++ b/Device/UniversalDiskImage.cpp @@ -32,7 +32,9 @@ UniversalDiskImage::UniversalDiskImage(MappedFile *file) : DiskImage(file) { - uint8_t * data = (uint8_t *)file->address(); + // at this point, file is no longer valid. + + uint8_t * data = (uint8_t *)address(); diff --git a/Pascal/VolumeEntry.cpp b/Pascal/VolumeEntry.cpp index c5924fe..524271f 100644 --- a/Pascal/VolumeEntry.cpp +++ b/Pascal/VolumeEntry.cpp @@ -100,7 +100,7 @@ VolumeEntry::VolumeEntry(Device::BlockDevice *device) _device = device; _cache = BlockCache::Create(device); - device->read(2, buffer.get()); + _cache->read(2, buffer.get()); init(buffer.get()); @@ -108,7 +108,6 @@ VolumeEntry::VolumeEntry(Device::BlockDevice *device) //printf("%u %u\n", blocks(), _lastBlock - _firstBlock); - // why the fuck didn't this work???? blockCount = blocks(); if (blockCount > 1) @@ -117,7 +116,7 @@ VolumeEntry::VolumeEntry(Device::BlockDevice *device) for (unsigned i = 0; i < blockCount; ++i) { - device->read(2 + i, buffer.get() + 512 * i); + _cache->read(2 + i, buffer.get() + 512 * i); } }