git-svn-id: https://profuse.googlecode.com/svn/branches/v2@183 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2009-12-16 01:33:28 +00:00
parent 70dfd5b485
commit bd063227e2
14 changed files with 136 additions and 94 deletions

View File

@ -6,10 +6,11 @@
#include <sys/mman.h>
#include <unistd.h>
#include "BlockDevice.h"
#include "BlockCache.h"
#include "Exception.h"
#include "auto.h"
#include <Device/BlockDevice.h>
#include <Device/BlockCache.h>
#include <ProFUSE/Exception.h>
#include <ProFUSE/auto.h>
/*
@ -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<uint8_t> buffer(new uint8_t[512]);
ProFUSE::auto_array<uint8_t> buffer(new uint8_t[512]);
BlockDescriptor bd = { block, 1, _ts, false, buffer.get() };
_device->read(block, buffer.get());

View File

@ -4,7 +4,7 @@
#include <stdint.h>
#include <vector>
namespace ProFUSE {
namespace Device {
class BlockDevice;

View File

@ -1,7 +1,3 @@
#include "BlockDevice.h"
#include "BlockCache.h"
#include "Exception.h"
#include "MappedFile.h"
#include <cerrno>
#include <cstdlib>
@ -11,7 +7,18 @@
#include <fcntl.h>
#include <sys/mman.h>
using namespace ProFUSE;
#include <Device/BlockDevice.h>
#include <Device/BlockCache.h>
#include <Device/MappedFile.h>
#include <ProFUSE/Exception.h>
using namespace Device;
using ProFUSE::Exception;
using ProFUSE::POSIXException;
#pragma mark -
#pragma mark BlockDevice

View File

@ -4,9 +4,9 @@
#include <stdint.h>
#include <sys/types.h>
#include "Exception.h"
#include <ProFUSE/Exception.h>
namespace ProFUSE {
namespace Device {
class MappedFile;
class AbstractBlockCache;

View File

@ -1,7 +1,3 @@
#include "DavexDiskImage.h"
#include "MappedFile.h"
#include "Buffer.h"
#include "Endian.h"
#include <cerrno>
#include <cstdlib>
@ -11,9 +7,19 @@
#include <cstdio>
#include <algorithm>
using namespace ProFUSE;
#include <Device/DavexDiskImage.h>
#include <Device/MappedFile.h>
#include <Endian/Endian.h>
#include <Endian/IOBuffer.h>
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);

View File

@ -1,9 +1,11 @@
#ifndef __DAVEXDISKIMAGE_H__
#define __DAVEXDISKIMAGE_H__
#include "BlockDevice.h"
#include <string>
namespace ProFUSE {
#include <Device/BlockDevice.h>
namespace Device {
// only supports 1 file; may be split over multiple files.
@ -28,4 +30,6 @@ private:
};
}
}
#endif

View File

@ -1,15 +1,22 @@
#include "DiskCopy42Image.h"
#include "MappedFile.h"
#include "Buffer.h"
#include "Endian.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace ProFUSE;
#include <Device/DiskCopy42Image.h>
#include <Device/MappedFile.h>
#include <Endian/Endian.h>
#include <Endian/IOBuffer.h>
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();

View File

@ -1,11 +1,11 @@
#ifndef __DISKCOPY42IMAGE_H__
#define __DISKCOPY42IMAGE_H__
#include "BlockDevice.h"
#include <Device/BlockDevice.h>
#include <stdint.h>
namespace ProFUSE {
namespace Device {
class DiskCopy42Image : public DiskImage {
public:

View File

@ -1,6 +1,3 @@
#include "MappedFile.h"
#include "Exception.h"
#include <cerrno>
#include <cstdlib>
#include <cstring>
@ -9,10 +6,14 @@
#include <fcntl.h>
#include <sys/mman.h>
#include "auto.h"
#include <Device/MappedFile.h>
using namespace ProFUSE;
#include <ProFUSE/Exception.h>
#include <ProFUSE/auto.h>
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,

View File

@ -5,7 +5,7 @@
#include <stdint.h>
#include <cstdlib>
namespace ProFUSE {
namespace Device {
class MappedFile {

View File

@ -20,12 +20,15 @@
#include <sys/dkio.h>
#endif
#include <Device/RawDevice.h>
#include "RawDevice.h"
#include "auto.h"
#include "Exception.h"
#include <ProFUSE/auto.h>
#include <ProFUSE/Exception.h>
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)

View File

@ -3,9 +3,9 @@
#include <stdint.h>
#include "BlockDevice.h"
#include <Device/BlockDevice.h>
namespace ProFUSE {
namespace Device {
// /dev/xxx

View File

@ -1,11 +1,17 @@
#include "UniversalDiskImage.h"
#include "MappedFile.h"
#include "Buffer.h"
#include "Endian.h"
#include <Device/UniversalDiskImage.h>
#include <Device/MappedFile.h>
using namespace ProFUSE;
#include <Endian/Endian.h>
#include <Endian/IOBuffer.h>
#include <ProFUSE/Exception.h>
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);

View File

@ -2,10 +2,10 @@
#define __UNIVERSALDISKIMAGE_H__
#include "BlockDevice.h"
#include <Device/BlockDevice.h>
#include <stdint.h>
namespace ProFUSE {
namespace Device {
class UniversalDiskImage : public DiskImage {
public: