add support for dos-order sectoring.

git-svn-id: https://profuse.googlecode.com/svn/trunk@25 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2009-01-24 04:14:45 +00:00
parent b510ef3ec4
commit 0b5ef674f2
3 changed files with 42 additions and 5 deletions

View File

@ -50,7 +50,7 @@ Disk::~Disk()
} }
Disk *Disk::OpenFile(const char *file) Disk *Disk::OpenFile(const char *file, bool dos_order)
{ {
int fd; int fd;
struct stat st; struct stat st;
@ -59,8 +59,11 @@ Disk *Disk::OpenFile(const char *file)
unsigned offset; unsigned offset;
void *map; void *map;
Disk *d = NULL; Disk *d = NULL;
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (fd >= 0) if (fd >= 0)
@ -119,7 +122,7 @@ Disk *Disk::OpenFile(const char *file)
break; break;
} }
} while (false); } while (false);
if (!ok) if (!ok)
{ {
@ -138,6 +141,7 @@ Disk *Disk::OpenFile(const char *file)
d->_data = (uint8_t *)map; d->_data = (uint8_t *)map;
d->_blocks = blocks; d->_blocks = blocks;
d->_offset = offset; d->_offset = offset;
d->_dosorder = dos_order;
} }
} }
@ -191,6 +195,29 @@ int Disk::Normalize(FileEntry &f, unsigned fork, ExtendedEntry *ee)
int Disk::Read(unsigned block, void *buffer) int Disk::Read(unsigned block, void *buffer)
{ {
if (block > _blocks) return -P8_INVALID_BLOCK; if (block > _blocks) return -P8_INVALID_BLOCK;
if (_dosorder)
{
static unsigned do_map[] = {0x00, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x0f };
unsigned track = (block & ~0x07) << 9;
unsigned sector = (block & 0x07) << 1;
for (unsigned i = 0; i < 2; i++)
{
unsigned offset = track | (do_map[sector+i] << 8);
memcpy(buffer, _data + _offset + offset, 256);
buffer = (char *)buffer + 256;
}
return 1;
}
memcpy(buffer, _data + _offset + (block << 9), BLOCK_SIZE); memcpy(buffer, _data + _offset + (block << 9), BLOCK_SIZE);
return 1; return 1;
} }

4
Disk.h
View File

@ -39,7 +39,7 @@ public:
~Disk(); ~Disk();
//static Disk *Open2MG(const char *file); //static Disk *Open2MG(const char *file);
static Disk *OpenFile(const char *file); static Disk *OpenFile(const char *file, bool dos_order);
int Normalize(FileEntry &f, unsigned fork, ExtendedEntry *ee = NULL); int Normalize(FileEntry &f, unsigned fork, ExtendedEntry *ee = NULL);
@ -61,6 +61,8 @@ private:
unsigned _offset; unsigned _offset;
unsigned _blocks; unsigned _blocks;
size_t _size; size_t _size;
bool _dosorder;
}; };
#endif #endif

View File

@ -33,6 +33,8 @@ Disk *disk = NULL;
char *dfile = NULL; char *dfile = NULL;
VolumeEntry volume; VolumeEntry volume;
bool dos_order = false;
bool validProdosName(const char *name) bool validProdosName(const char *name)
@ -67,7 +69,8 @@ static struct fuse_lowlevel_ops prodos_oper;
enum { enum {
PRODOS_OPT_HELP, PRODOS_OPT_HELP,
PRODOS_OPT_VERSION PRODOS_OPT_VERSION,
PRODOS_OPT_DOS_ORDER
}; };
static struct fuse_opt prodos_opts[] = { static struct fuse_opt prodos_opts[] = {
@ -75,6 +78,7 @@ static struct fuse_opt prodos_opts[] = {
FUSE_OPT_KEY("--help", PRODOS_OPT_HELP), FUSE_OPT_KEY("--help", PRODOS_OPT_HELP),
FUSE_OPT_KEY("-V", PRODOS_OPT_VERSION), FUSE_OPT_KEY("-V", PRODOS_OPT_VERSION),
FUSE_OPT_KEY("--version", PRODOS_OPT_VERSION), FUSE_OPT_KEY("--version", PRODOS_OPT_VERSION),
FUSE_OPT_KEY("--dos-order", PRODOS_OPT_DOS_ORDER),
{0, 0, 0} {0, 0, 0}
}; };
@ -97,6 +101,10 @@ static int prodos_opt_proc(void *data, const char *arg, int key, struct fuse_arg
// TODO // TODO
exit(1); exit(1);
break; break;
case PRODOS_OPT_DOS_ORDER:
dos_order = true;
return 0;
break;
case FUSE_OPT_KEY_NONOPT: case FUSE_OPT_KEY_NONOPT:
if (dfile == NULL) if (dfile == NULL)
@ -186,7 +194,7 @@ int main(int argc, char *argv[])
exit(0); exit(0);
} }
disk = Disk::OpenFile(dfile); disk = Disk::OpenFile(dfile, dos_order);
if (!disk) if (!disk)
{ {