diff --git a/Device/BlockCache.cpp b/Device/BlockCache.cpp index 8971383..75f8b44 100644 --- a/Device/BlockCache.cpp +++ b/Device/BlockCache.cpp @@ -6,10 +6,11 @@ #include #include -#include "BlockDevice.h" -#include "BlockCache.h" -#include "Exception.h" -#include "auto.h" +#include +#include + +#include +#include /* @@ -19,7 +20,10 @@ -using namespace ProFUSE; +using namespace Device; + +using ProFUSE::Exception; +using ProFUSE::POSIXException; #pragma mark - #pragma mark AbstractBlockCache @@ -162,7 +166,7 @@ void *BlockCache::load(unsigned block) } - auto_array buffer(new uint8_t[512]); + ProFUSE::auto_array buffer(new uint8_t[512]); BlockDescriptor bd = { block, 1, _ts, false, buffer.get() }; _device->read(block, buffer.get()); diff --git a/Device/BlockCache.h b/Device/BlockCache.h index 36b4066..3983f1c 100644 --- a/Device/BlockCache.h +++ b/Device/BlockCache.h @@ -4,7 +4,7 @@ #include #include -namespace ProFUSE { +namespace Device { class BlockDevice; diff --git a/Device/BlockDevice.cpp b/Device/BlockDevice.cpp index df17519..1c556d6 100644 --- a/Device/BlockDevice.cpp +++ b/Device/BlockDevice.cpp @@ -1,7 +1,3 @@ -#include "BlockDevice.h" -#include "BlockCache.h" -#include "Exception.h" -#include "MappedFile.h" #include #include @@ -11,7 +7,18 @@ #include #include -using namespace ProFUSE; + +#include +#include +#include + +#include + + +using namespace Device; + +using ProFUSE::Exception; +using ProFUSE::POSIXException; #pragma mark - #pragma mark BlockDevice diff --git a/Device/BlockDevice.h b/Device/BlockDevice.h index c76a713..41d899e 100644 --- a/Device/BlockDevice.h +++ b/Device/BlockDevice.h @@ -4,9 +4,9 @@ #include #include -#include "Exception.h" +#include -namespace ProFUSE { +namespace Device { class MappedFile; class AbstractBlockCache; diff --git a/Device/DavexDiskImage.cpp b/Device/DavexDiskImage.cpp index fafb8a9..1e02e4b 100644 --- a/Device/DavexDiskImage.cpp +++ b/Device/DavexDiskImage.cpp @@ -1,7 +1,3 @@ -#include "DavexDiskImage.h" -#include "MappedFile.h" -#include "Buffer.h" -#include "Endian.h" #include #include @@ -11,9 +7,19 @@ #include #include -using namespace ProFUSE; +#include +#include + +#include +#include + + +using namespace Device; using namespace LittleEndian; +using ProFUSE::Exception; +using ProFUSE::POSIXException; + /* http://www.umich.edu/~archive/apple2/technotes/ftn/FTN.E0.8004 */ @@ -99,50 +105,51 @@ DavexDiskImage *DavexDiskImage::Create(const char *name, size_t blocks, const ch #define __METHOD__ "DavexDiskImage::Create" uint8_t *data; + uint8_t tmp[512]; + IOBuffer header(tmp,512); + MappedFile *file = new MappedFile(name, blocks * 512 + 512); data = (uint8_t *)file->fileData(); - - Buffer header(512); - - header.pushBytes(IdentityCheck, 16); + + header.writeBytes(IdentityCheck, 16); // file Format - header.push8(0); + header.write8(0); //version - header.push8(0); + header.write8(0); // version - header.push8(0x10); + header.write8(0x10); // reserved. - header.resize(32); + header.setOffset(32, true); //deviceNum - header.push8(1); + header.write8(1); // total blocks - header.push32le(blocks); + header.write32(blocks); // unused blocks - header.push32le(0); + header.write32(0); // volume Name if (!vname || !*vname) vname = "Untitled"; unsigned l = std::strlen(vname); - header.push8(std::min(l, 15u)); - header.pushBytes(vname, std::min(l, 15u)); + header.write8(std::min(l, 15u)); + header.writeBytes(vname, std::min(l, 15u)); // name + reserved. - header.resize(64); + header.setOffset(64, true); // file number - header.push8(1); + header.write8(1); //starting block - header.push32le(0); + header.write32(0); // reserved - header.resize(512); + header.setOffset(512, true); std::memcpy(file->fileData(), header.buffer(), 512); diff --git a/Device/DavexDiskImage.h b/Device/DavexDiskImage.h index 5f75934..1f7122b 100644 --- a/Device/DavexDiskImage.h +++ b/Device/DavexDiskImage.h @@ -1,9 +1,11 @@ +#ifndef __DAVEXDISKIMAGE_H__ +#define __DAVEXDISKIMAGE_H__ - -#include "BlockDevice.h" #include -namespace ProFUSE { +#include + +namespace Device { // only supports 1 file; may be split over multiple files. @@ -28,4 +30,6 @@ private: }; -} \ No newline at end of file +} + +#endif diff --git a/Device/DiskCopy42Image.cpp b/Device/DiskCopy42Image.cpp index 5502130..a3b441c 100644 --- a/Device/DiskCopy42Image.cpp +++ b/Device/DiskCopy42Image.cpp @@ -1,15 +1,22 @@ -#include "DiskCopy42Image.h" -#include "MappedFile.h" -#include "Buffer.h" -#include "Endian.h" + #include #include #include -using namespace ProFUSE; +#include +#include + +#include +#include + +using namespace Device; using namespace BigEndian; + +using ProFUSE::Exception; +using ProFUSE::POSIXException; + DiskCopy42Image::DiskCopy42Image(MappedFile *f) : DiskImage(f), _changed(false) @@ -97,30 +104,32 @@ DiskCopy42Image *DiskCopy42Image::Create(const char *name, size_t blocks, const file->setOffset(84); file->setBlocks(blocks); - Buffer header(84); + uint8_t tmp[84]; + IOBuffer header(tmp, 84); // name -- 64byte pstring. if (vname == NULL) vname = "Untitled"; unsigned l = std::strlen(vname); - header.push8(std::min(l, 63u)); - header.pushBytes(vname, std::min(l, 63u)); + header.write8(std::min(l, 63u)); + header.writeBytes(vname, std::min(l, 63u)); - header.resize(64); + //header.resize(64); + header.setOffset(64, true); // data size -- number of bytes - header.push32be(blocks * 512); + header.write32(blocks * 512); // tag size - header.push32be(0); + header.write32(0); // data checksum // if data is 0, will be 0. //header.push32be(Checksum(file->fileData(), blocks * 512)); - header.push32be(0); + header.write32(0); // tag checksum - header.push32be(0); + header.write32(0); // disk format. /* @@ -130,7 +139,7 @@ DiskCopy42Image *DiskCopy42Image::Create(const char *name, size_t blocks, const * 3 = 1440k * 0xff = other */ - header.push8(DiskFormat(blocks)); + header.write8(DiskFormat(blocks)); // formatbyte /* @@ -138,10 +147,10 @@ DiskCopy42Image *DiskCopy42Image::Create(const char *name, size_t blocks, const * 0x22 = >400k mac * 0x24 = 800k appleII */ - header.push8(FormatByte(blocks)); + header.write8(FormatByte(blocks)); // private - header.push16be(0x100); + header.write16(0x100); std::memcpy(file->fileData(), header.buffer(), 84); file->sync(); diff --git a/Device/DiskCopy42Image.h b/Device/DiskCopy42Image.h index 7a80f87..8511c16 100644 --- a/Device/DiskCopy42Image.h +++ b/Device/DiskCopy42Image.h @@ -1,11 +1,11 @@ #ifndef __DISKCOPY42IMAGE_H__ #define __DISKCOPY42IMAGE_H__ -#include "BlockDevice.h" +#include #include -namespace ProFUSE { +namespace Device { class DiskCopy42Image : public DiskImage { public: diff --git a/Device/MappedFile.cpp b/Device/MappedFile.cpp index 3c16710..c0029da 100644 --- a/Device/MappedFile.cpp +++ b/Device/MappedFile.cpp @@ -1,6 +1,3 @@ -#include "MappedFile.h" -#include "Exception.h" - #include #include #include @@ -9,10 +6,14 @@ #include #include -#include "auto.h" +#include -using namespace ProFUSE; +#include +#include +using namespace Device; +using ProFUSE::POSIXException; +using ProFUSE::Exception; MappedFile::MappedFile(const char *name, bool readOnly) @@ -23,7 +24,7 @@ MappedFile::MappedFile(const char *name, bool readOnly) // if unable to open as read/write, open as read-only. - auto_fd fd; + ProFUSE::auto_fd fd; if (!readOnly) { @@ -61,7 +62,7 @@ MappedFile::MappedFile(const char *name, size_t size) _readOnly = false; _encoding = ProDOSOrder; - auto_fd fd(::open(name, O_CREAT | O_TRUNC | O_RDWR, 0644)); + ProFUSE::auto_fd fd(::open(name, O_CREAT | O_TRUNC | O_RDWR, 0644)); if (fd < 0) throw POSIXException(__METHOD__ ": Unable to create file.", errno); @@ -74,7 +75,7 @@ MappedFile::MappedFile(const char *name, size_t size) //_map = ::mmap(NULL, _size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, _fd, 0); - auto_map map( + ProFUSE::auto_map map( NULL, _size, PROT_READ | PROT_WRITE, @@ -101,8 +102,7 @@ void MappedFile::init(int f, bool readOnly) #undef __METHOD__ #define __METHOD__ "MappedFile::init" - //auto_fd fd(f); - + _fd = -1; _map = MAP_FAILED; _offset = 0; @@ -122,7 +122,7 @@ void MappedFile::init(int f, bool readOnly) ::lseek(f, 0, SEEK_SET); - auto_map map( + ProFUSE::auto_map map( NULL, _size, readOnly ? PROT_READ : PROT_READ | PROT_WRITE, diff --git a/Device/MappedFile.h b/Device/MappedFile.h index ce2c768..5f10984 100644 --- a/Device/MappedFile.h +++ b/Device/MappedFile.h @@ -5,7 +5,7 @@ #include #include -namespace ProFUSE { +namespace Device { class MappedFile { diff --git a/Device/RawDevice.cpp b/Device/RawDevice.cpp index bc19ce5..9047f17 100644 --- a/Device/RawDevice.cpp +++ b/Device/RawDevice.cpp @@ -20,12 +20,15 @@ #include #endif +#include -#include "RawDevice.h" -#include "auto.h" -#include "Exception.h" +#include +#include -using namespace ProFUSE; +using namespace Device; + +using ProFUSE::Exception; +using ProFUSE::POSIXException; #ifdef __SUN__ void RawDevice::devSize(int fd) @@ -100,7 +103,7 @@ RawDevice::RawDevice(const char *name, bool readOnly) // open read-only, verify if device is readable, and then try to upgrade to read/write? - auto_fd fd; + ProFUSE::auto_fd fd; if (!readOnly) fd.reset(::open(name, O_RDWR)); if (fd < 0) diff --git a/Device/RawDevice.h b/Device/RawDevice.h index b2bafe9..dfbeb8f 100644 --- a/Device/RawDevice.h +++ b/Device/RawDevice.h @@ -3,9 +3,9 @@ #include -#include "BlockDevice.h" +#include -namespace ProFUSE { +namespace Device { // /dev/xxx diff --git a/Device/UniversalDiskImage.cpp b/Device/UniversalDiskImage.cpp index 0e077c7..f624960 100644 --- a/Device/UniversalDiskImage.cpp +++ b/Device/UniversalDiskImage.cpp @@ -1,11 +1,17 @@ -#include "UniversalDiskImage.h" -#include "MappedFile.h" -#include "Buffer.h" -#include "Endian.h" +#include +#include -using namespace ProFUSE; +#include +#include + +#include + +using namespace Device; using namespace LittleEndian; +using ProFUSE::Exception; +using ProFUSE::POSIXException; + UniversalDiskImage::UniversalDiskImage(const char *name, bool readOnly) : DiskImage(name, readOnly) { @@ -27,35 +33,37 @@ UniversalDiskImage *UniversalDiskImage::Create(const char *name, size_t blocks) // 64-byte header. MappedFile *file = new MappedFile(name, blocks * 512 + 64); - Buffer header(64); + uint8_t tmp[64]; + + IOBuffer header(tmp, 64); // magic + creator - header.pushBytes("2IMGPRFS", 8); + header.writeBytes("2IMGPRFS", 8); // header size. - header.push16le(64); + header.write16(64); // version - header.push16le(1); + header.write16(1); //image format -- ProDOS order - header.push32le(1); + header.write32(1); // flags - header.push32le(0); + header.write32(0); // # blocks. s/b 0 unless prodos-order - header.push32le(blocks); + header.write32(blocks); // offset to disk data - header.push32le(64); + header.write32(64); // data length - header.push32le(512 * blocks); + header.write32(512 * blocks); // comment offset, creator, reserved -- 0. - header.resize(64); + header.setOffset(64, true); std::memcpy(file->fileData(), header.buffer(), 64); diff --git a/Device/UniversalDiskImage.h b/Device/UniversalDiskImage.h index 1bcac1b..875105b 100644 --- a/Device/UniversalDiskImage.h +++ b/Device/UniversalDiskImage.h @@ -2,10 +2,10 @@ #define __UNIVERSALDISKIMAGE_H__ -#include "BlockDevice.h" +#include #include -namespace ProFUSE { +namespace Device { class UniversalDiskImage : public DiskImage { public: