mirror of
https://github.com/ksherlock/profuse.git
synced 2025-01-09 15:30:57 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@223 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
22afe5d128
commit
77fda944ae
@ -14,7 +14,7 @@ enum BlockReleaseFlags {
|
||||
kBlockDirty = 1,
|
||||
kBlockCommitNow = 2,
|
||||
kBlockReuse = 3
|
||||
} BlockReleaseFlags;
|
||||
};
|
||||
|
||||
class BlockCache {
|
||||
public:
|
||||
|
@ -203,6 +203,25 @@ unsigned ConcreteBlockCache::hashFunction(unsigned block)
|
||||
return block % HashTableSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ConcreteBlockCache::Entry *ConcreteBlockCache::findEntry(unsigned block)
|
||||
{
|
||||
Entry *e;
|
||||
unsigned hash = hashFunction(block);
|
||||
|
||||
e = _hashTable[hash];
|
||||
|
||||
if (e)
|
||||
{
|
||||
while ((e) && (e->block != block)) e = e->nextHash;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* remove a block from the hashtable
|
||||
* and write to dick if dirty.
|
||||
|
@ -59,6 +59,15 @@ void MappedBlockCache::release(unsigned block, int flags)
|
||||
if (flags & kBlockDirty) _dirty = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MappedBlockCache::write(unsigned block, const void *vp)
|
||||
{
|
||||
_dirty = true;
|
||||
std::memcpy(_data + block * 512, vp, 512);
|
||||
}
|
||||
|
||||
|
||||
// sync everything.
|
||||
void MappedBlockCache::sync()
|
||||
{
|
||||
|
@ -49,11 +49,12 @@ void BlockDevice::sync(unsigned block)
|
||||
sync();
|
||||
}
|
||||
|
||||
/*
|
||||
void BlockDevice::sync(TrackSector ts)
|
||||
{
|
||||
sync();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
BlockCache *BlockDevice::createBlockCache()
|
||||
{
|
||||
|
@ -21,10 +21,10 @@ public:
|
||||
|
||||
|
||||
virtual void read(unsigned block, void *bp) = 0;
|
||||
virtual void read(TrackSector ts, void *bp);
|
||||
//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);
|
||||
//virtual void write(TrackSector ts, const void *bp) = 0;
|
||||
|
||||
|
||||
virtual unsigned blocks() = 0;
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
virtual void sync() = 0;
|
||||
virtual void sync(unsigned block);
|
||||
virtual void sync(TrackSector ts);
|
||||
//virtual void sync(TrackSector ts);
|
||||
|
||||
|
||||
void zeroBlock(unsigned block);
|
||||
|
@ -9,6 +9,11 @@
|
||||
|
||||
|
||||
#include <Device/DiskImage.h>
|
||||
#include <Device/UniversalDiskImage.h>
|
||||
#include <Device/DiskCopy42Image.h>
|
||||
#include <Device/DavexDiskImage.h>
|
||||
|
||||
|
||||
#include <File/MappedFile.h>
|
||||
|
||||
#include <Cache/MappedBlockCache.h>
|
||||
@ -71,6 +76,41 @@ unsigned DiskImage::ImageType(const char *type, unsigned defv)
|
||||
return defv;
|
||||
}
|
||||
|
||||
BlockDevice *DiskImage::Open(const char *name, bool readOnly, unsigned imageType)
|
||||
{
|
||||
if (!imageType) imageType = ImageType(name, 'PO__');
|
||||
|
||||
// TODO -- if no image type, guess based on file size?
|
||||
// TODO -- check for /dev/* ?
|
||||
|
||||
MappedFile file(name, readOnly);
|
||||
|
||||
|
||||
switch (imageType)
|
||||
{
|
||||
case '2IMG':
|
||||
return UniversalDiskImage::Open(&file);
|
||||
|
||||
case 'DC42':
|
||||
return DiskCopy42Image::Open(&file);
|
||||
|
||||
case 'DO__':
|
||||
return DOSOrderDiskImage::Open(&file);
|
||||
|
||||
case 'PO__':
|
||||
return ProDOSOrderDiskImage::Open(&file);
|
||||
|
||||
case 'DVX_':
|
||||
return DavexDiskImage::Open(&file);
|
||||
|
||||
}
|
||||
|
||||
// throw an error?
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DiskImage::DiskImage(const char *name, bool readOnly)
|
||||
|
@ -20,6 +20,9 @@ public:
|
||||
|
||||
static unsigned ImageType(const char *type, unsigned defv = 0);
|
||||
|
||||
|
||||
static BlockDevice *Open(const char *name, bool readOnly, unsigned imageType = 0);
|
||||
|
||||
virtual ~DiskImage();
|
||||
|
||||
virtual void read(unsigned block, void *bp);
|
||||
|
@ -145,7 +145,7 @@ void MappedFile::swap(MappedFile &mf)
|
||||
}
|
||||
|
||||
|
||||
static MappedFile *Create(const char *name, size_t size)
|
||||
MappedFile *MappedFile::Create(const char *name, size_t size)
|
||||
{
|
||||
#undef __METHOD__
|
||||
#define __METHOD__ "MappedFile::Create"
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <File/File.h>
|
||||
|
||||
class File;
|
||||
|
||||
class MappedFile {
|
||||
public:
|
||||
|
28
apfm.cpp
28
apfm.cpp
@ -115,7 +115,7 @@ int action_ls(int argc, char **argv, Pascal::VolumeEntry *volume)
|
||||
|
||||
std::fprintf(stdout, "%s:\n", volume->name());
|
||||
|
||||
argv[0] = "afpm ls";
|
||||
//argv[0] = "afpm ls";
|
||||
|
||||
while ((ch = ::getopt(argc, argv, "l")) != -1)
|
||||
{
|
||||
@ -179,7 +179,7 @@ int action_ls(int argc, char **argv, Pascal::VolumeEntry *volume)
|
||||
int action_cat(unsigned argc, char **argv, Pascal::VolumeEntry *volume)
|
||||
{
|
||||
// cat file1, file2...
|
||||
argv[0] = "afpm cat";
|
||||
//argv[0] = "afpm cat";
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
@ -318,28 +318,16 @@ int main(int argc, char **argv)
|
||||
const char *file = argv[0];
|
||||
const char *action = argv[1];
|
||||
|
||||
if (!fmt) fmt = Device::DiskImage::ImageType(optarg, 'PO__');
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
device.reset( Device::DiskImage::Open(file, true, fmt) );
|
||||
|
||||
switch(fmt)
|
||||
{
|
||||
case 'DO__':
|
||||
device.reset( new Device::DOSOrderDiskImage(file, true) );
|
||||
break;
|
||||
case 'PO__':
|
||||
device.reset( new Device::ProDOSOrderDiskImage(file, true) );
|
||||
break;
|
||||
case 'DC42':
|
||||
device.reset( new Device::DiskCopy42Image(file, true) );
|
||||
break;
|
||||
|
||||
default:
|
||||
std::fprintf(stderr, "Unable to determine format. Please use -f flag.\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
volume.reset( new Pascal::VolumeEntry(device.get()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user