mirror of
https://github.com/ksherlock/profuse.git
synced 2024-06-16 10:29:32 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@216 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
56ff80afcc
commit
f13263d5ad
|
@ -9,8 +9,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <Device/BlockDevice.h>
|
#include <Device/BlockDevice.h>
|
||||||
#include <Device/BlockCache.h>
|
|
||||||
#include <Device/MappedFile.h>
|
|
||||||
|
|
||||||
#include <ProFUSE/Exception.h>
|
#include <ProFUSE/Exception.h>
|
||||||
|
|
||||||
|
@ -38,19 +37,7 @@ void BlockDevice::zeroBlock(unsigned block)
|
||||||
write(block, bp);
|
write(block, bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractBlockCache *BlockDevice::blockCache()
|
|
||||||
{
|
|
||||||
if (!_cache)
|
|
||||||
{
|
|
||||||
_cache = createBlockCache();
|
|
||||||
}
|
|
||||||
return _cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractBlockCache *BlockDevice::createBlockCache()
|
|
||||||
{
|
|
||||||
return new BlockCache(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BlockDevice::mapped()
|
bool BlockDevice::mapped()
|
||||||
{
|
{
|
||||||
|
@ -67,13 +54,3 @@ void BlockDevice::sync(TrackSector ts)
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *BlockDevice::read(unsigned block)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *BlockDevice::read(TrackSector ts)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
namespace Device {
|
namespace Device {
|
||||||
|
|
||||||
class BlockCache;
|
|
||||||
|
|
||||||
class BlockDevice {
|
class BlockDevice {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -40,8 +38,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
BlockDevice();
|
BlockDevice();
|
||||||
|
|
||||||
friend class BlockCache;
|
|
||||||
virtual BlockCache *createBlockCache();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,204 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
#include <Device/DeviceReader.h>
|
|
||||||
|
|
||||||
using namespace Device;
|
|
||||||
|
|
||||||
DeviceReader::~DeviceReader()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void *DeviceReader::read(unsigned block)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceReader::read(TrackSector ts)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceReader::mapped()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark ProDOS Order
|
|
||||||
|
|
||||||
void ProDOSOrderDeviceReader::read(unsigned block, void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(bp, read(block), 512);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProDOSOrderDeviceReader::read(TrackSector ts, void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(bp, read(ts), 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *ProDOSOrderDeviceReader::read(unsigned block)
|
|
||||||
{
|
|
||||||
if (block > _blocks)
|
|
||||||
{
|
|
||||||
throw ProFUSE::Exception("Invalid block.");
|
|
||||||
}
|
|
||||||
return block * 512 + (uint8_t *)_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *ProDOSOrderDeviceReader::read(TrackSector ts)
|
|
||||||
{
|
|
||||||
unsigned block = (ts.track * 16 + ts.sector) / 2;
|
|
||||||
|
|
||||||
if (block > _blocks)
|
|
||||||
{
|
|
||||||
throw ProFUSE::Exception("Invalid track/sector.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ts.track * 16 + ts.sector) * 256 + (uint8_t *)_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ProDOSOrderDeviceReader::write(unsigned block, const void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(read(block), bp, 512);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProDOSOrderDeviceReader::write(TrackSector ts, const void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(read(ts), bp, 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark DOS Order
|
|
||||||
|
|
||||||
const unsigned DOSMap[] = {
|
|
||||||
0x00, 0x0e, 0x0d, 0x0c,
|
|
||||||
0x0b, 0x0a, 0x09, 0x08,
|
|
||||||
0x07, 0x06, 0x05, 0x04,
|
|
||||||
0x03, 0x02, 0x01, 0x0f
|
|
||||||
};
|
|
||||||
|
|
||||||
void *DOSOrderDeviceReader::read(TrackSector ts)
|
|
||||||
{
|
|
||||||
if (ts.track > _tracks || ts.sector > 16)
|
|
||||||
{
|
|
||||||
throw ProFUSE::Exception("Invalid track/sector.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ts.track * 16 + ts.sector) * 256 + (uint8_t *)_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DOSOrderDeviceReader::read(unsigned block, void *bp)
|
|
||||||
{
|
|
||||||
TrackSector ts(block >> 3, 0);
|
|
||||||
unsigned sector = (block & 0x07) << 1;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < 2; ++i)
|
|
||||||
{
|
|
||||||
ts.sector = DOSMap[sector];
|
|
||||||
std::memcpy(bp, read(ts), 256);
|
|
||||||
bp = 256 + (uint8_t *)bp;
|
|
||||||
++sector;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DOSOrderDeviceReader::read(TrackSector ts, void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(bp, read(ts), 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DOSOrderDeviceReader::write(unsigned block, const void *bp)
|
|
||||||
{
|
|
||||||
TrackSector ts(block >> 3, 0);
|
|
||||||
unsigned sector = (block & 0x07) << 1;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < 2; ++i)
|
|
||||||
{
|
|
||||||
ts.sector = DOSMap[sector];
|
|
||||||
std::memcpy(read(ts), bp, 256);
|
|
||||||
bp = 256 + (const uint8_t *)bp;
|
|
||||||
++sector;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DOSOrderDeviceReader::write(TrackSector ts, const void *bp)
|
|
||||||
{
|
|
||||||
std::memcpy(read(ts), bp, 256);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark FileDeviceReader
|
|
||||||
|
|
||||||
FileDeviceReader::FileDeviceReader(int fd, unsigned blocks, bool readOnly)
|
|
||||||
{
|
|
||||||
_fd = fd;
|
|
||||||
_readOnly = readOnly;
|
|
||||||
_blocks = blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileDeviceReader::readOnly()
|
|
||||||
{
|
|
||||||
return _readOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileDeviceReader::write(unsigned block, const void *bp)
|
|
||||||
{
|
|
||||||
|
|
||||||
off_t offset = block * 512;
|
|
||||||
|
|
||||||
size_t ok = ::pwrite(_fd, bp, 512, offset);
|
|
||||||
|
|
||||||
if (ok != 512)
|
|
||||||
throw ok < 0
|
|
||||||
? POSIXException(__METHOD__ ": Error writing block.", errno)
|
|
||||||
: Exception(__METHOD__ ": Error writing block.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FileDeviceReader::write(TrackSector ts, const void *bp)
|
|
||||||
{
|
|
||||||
off_t offset = (ts.track * 16 + ts.sector) * 256;
|
|
||||||
size_t ok = ::pwrite(_fd, bp, 256, offset);
|
|
||||||
|
|
||||||
if (ok != 256)
|
|
||||||
throw ok < 0
|
|
||||||
? POSIXException(__METHOD__ ": Error writing block.", errno)
|
|
||||||
: Exception(__METHOD__ ": Error writing block.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FileDeviceReader::read(unsigned block, void *bp)
|
|
||||||
{
|
|
||||||
|
|
||||||
off_t offset = block * 512;
|
|
||||||
|
|
||||||
size_t ok = ::pread(_fd, bp, 512, offset);
|
|
||||||
|
|
||||||
if (ok != 512)
|
|
||||||
throw ok < 0
|
|
||||||
? POSIXException(__METHOD__ ": Error reading block.", errno)
|
|
||||||
: Exception(__METHOD__ ": Error reading block.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileDeviceReader::read(TrackSector ts, void *bp)
|
|
||||||
{
|
|
||||||
off_t offset = (ts.track * 16 + ts.sector) * 256;
|
|
||||||
size_t ok = ::pread(_fd, bp, 256, offset);
|
|
||||||
|
|
||||||
if (ok != 256)
|
|
||||||
throw ok < 0
|
|
||||||
? POSIXException(__METHOD__ ": Error reading block.", errno)
|
|
||||||
: Exception(__METHOD__ ": Error reading block.");
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
#ifndef __DEVICEREADER_H__
|
|
||||||
#define __DEVICEREADER_H__
|
|
||||||
|
|
||||||
#include <Device/TrackSector.h>
|
|
||||||
|
|
||||||
namespace Device {
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceReader {
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~DeviceReader();
|
|
||||||
|
|
||||||
virtual void read(unsigned block, void *bp) = 0;
|
|
||||||
virtual void read(TrackSector ts, void *bp) = 0;
|
|
||||||
|
|
||||||
virtual void write(unsigned block, const void *bp) = 0;
|
|
||||||
virtual void write(TrackSector ts, const void *bp) = 0;
|
|
||||||
|
|
||||||
// direct access -- not always available.
|
|
||||||
|
|
||||||
virtual void *read(unsigned block);
|
|
||||||
virtual void *read(TrackSector ts);
|
|
||||||
|
|
||||||
virtual bool readOnly() = 0;
|
|
||||||
virtual bool mapped();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileDeviceReader : public DeviceReader {
|
|
||||||
|
|
||||||
// does not assume ownership of fd.
|
|
||||||
FileDeviceReader(int fd, unsigned blocks, bool readOnly);
|
|
||||||
//virtual ~FileDeviceReader();
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual bool readOnly();
|
|
||||||
|
|
||||||
|
|
||||||
virtual void read(unsigned block, void *bp);
|
|
||||||
virtual void read(TrackSector ts, void *bp);
|
|
||||||
|
|
||||||
virtual void write(unsigned block, const void *bp);
|
|
||||||
virtual void write(TrackSector ts, const void *bp);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int _fd;
|
|
||||||
unsigned _blocks;
|
|
||||||
bool _readOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MappedFileDeviceReader : public DeviceReader {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
MappedFileDeviceReader(MappedFile *f, unsigned offset);
|
|
||||||
|
|
||||||
void *_data;
|
|
||||||
|
|
||||||
private:
|
|
||||||
MappedFile *_file
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProDOSOrderDeviceReader : public MappedFileDeviceReader {
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void read(unsigned block, void *bp);
|
|
||||||
virtual void read(TrackSector ts, void *bp);
|
|
||||||
|
|
||||||
virtual void write(unsigned block, const void *bp);
|
|
||||||
virtual void write(TrackSector ts, const void *bp);
|
|
||||||
|
|
||||||
virtual void *read(unsigned block);
|
|
||||||
virtual void *read(TrackSector ts);
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned blocks;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 16 sectors only.
|
|
||||||
class DOSOrderDeviceReader : public MappedFileDeviceReader {
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void read(unsigned block, void *bp);
|
|
||||||
virtual void read(TrackSector ts, void *bp);
|
|
||||||
|
|
||||||
virtual void write(unsigned block, const void *bp);
|
|
||||||
virtual void write(TrackSector ts, const void *bp);
|
|
||||||
|
|
||||||
virtual void *read(TrackSector ts);
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned _tracks;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NibbleDeviceReader : public MappedFileDeviceReader {
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<unsigned> _map;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user