From 0b5ef674f2307c882807cff3ef46f4b6fd4b5bcf Mon Sep 17 00:00:00 2001 From: ksherlock Date: Sat, 24 Jan 2009 04:14:45 +0000 Subject: [PATCH] add support for dos-order sectoring. git-svn-id: https://profuse.googlecode.com/svn/trunk@25 aa027e90-d47c-11dd-86d7-074df07e0730 --- Disk.cpp | 31 +++++++++++++++++++++++++++++-- Disk.h | 4 +++- main.cpp | 12 ++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Disk.cpp b/Disk.cpp index bc41601..4f9fa45 100644 --- a/Disk.cpp +++ b/Disk.cpp @@ -50,7 +50,7 @@ Disk::~Disk() } -Disk *Disk::OpenFile(const char *file) +Disk *Disk::OpenFile(const char *file, bool dos_order) { int fd; struct stat st; @@ -59,8 +59,11 @@ Disk *Disk::OpenFile(const char *file) unsigned offset; + void *map; Disk *d = NULL; + + fd = open(file, O_RDONLY); if (fd >= 0) @@ -119,7 +122,7 @@ Disk *Disk::OpenFile(const char *file) break; } - } while (false); + } while (false); if (!ok) { @@ -138,6 +141,7 @@ Disk *Disk::OpenFile(const char *file) d->_data = (uint8_t *)map; d->_blocks = blocks; 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) { 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); return 1; } diff --git a/Disk.h b/Disk.h index 49c20cb..dbda672 100644 --- a/Disk.h +++ b/Disk.h @@ -39,7 +39,7 @@ public: ~Disk(); //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); @@ -61,6 +61,8 @@ private: unsigned _offset; unsigned _blocks; size_t _size; + + bool _dosorder; }; #endif diff --git a/main.cpp b/main.cpp index ec7cc83..a55211e 100644 --- a/main.cpp +++ b/main.cpp @@ -33,6 +33,8 @@ Disk *disk = NULL; char *dfile = NULL; VolumeEntry volume; +bool dos_order = false; + bool validProdosName(const char *name) @@ -67,7 +69,8 @@ static struct fuse_lowlevel_ops prodos_oper; enum { PRODOS_OPT_HELP, - PRODOS_OPT_VERSION + PRODOS_OPT_VERSION, + PRODOS_OPT_DOS_ORDER }; 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("-V", PRODOS_OPT_VERSION), FUSE_OPT_KEY("--version", PRODOS_OPT_VERSION), + FUSE_OPT_KEY("--dos-order", PRODOS_OPT_DOS_ORDER), {0, 0, 0} }; @@ -97,6 +101,10 @@ static int prodos_opt_proc(void *data, const char *arg, int key, struct fuse_arg // TODO exit(1); break; + case PRODOS_OPT_DOS_ORDER: + dos_order = true; + return 0; + break; case FUSE_OPT_KEY_NONOPT: if (dfile == NULL) @@ -186,7 +194,7 @@ int main(int argc, char *argv[]) exit(0); } - disk = Disk::OpenFile(dfile); + disk = Disk::OpenFile(dfile, dos_order); if (!disk) {