diff --git a/libfloppy/Makefile b/libfloppy/Makefile index 0917a78..215929a 100644 --- a/libfloppy/Makefile +++ b/libfloppy/Makefile @@ -9,7 +9,7 @@ CPPFLAGS = -I$(TOP)/../libmacos -DARCH_M68K LIBRARY = libfloppy.a -SOURCES = floppy_lseek.c floppy_read.c floppy_read_sector.c +SOURCES = floppy_read_sector.c floppy_close.c floppy_open.c HEADERS = libfloppy.h diff --git a/libfloppy/floppy_lseek.c b/libfloppy/floppy_lseek.c deleted file mode 100644 index b323759..0000000 --- a/libfloppy/floppy_lseek.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * (c) 2005 Laurent Vivier - * - */ - -#include "libfloppy.h" - -int floppy_lseek(floppy_FILE *file, off_t offset, int whence) -{ - long new_offset; - - switch(whence) - { - case SEEK_SET: - new_offset = offset; - break; - case SEEK_CUR: - new_offset = file->offset + offset; - break; - default: - return -1; - } - - if (new_offset < 0) - return -1; - - file->offset = new_offset; - - return new_offset; -} diff --git a/libfloppy/floppy_read.c b/libfloppy/floppy_read.c deleted file mode 100644 index ef3ad2f..0000000 --- a/libfloppy/floppy_read.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * (c) 2005 Laurent Vivier - * - */ - -#include - -#include "libfloppy.h" - -size_t floppy_read(floppy_FILE *file, void *ptr, size_t size) -{ - int read = 0; - int ret; - - while (size != 0) - { - int part; - int cylinder_nb = file->offset / CYLINDER_SIZE; - int cylinder_offset = file->offset % CYLINDER_SIZE; - - if (cylinder_nb != file->current_cylinder) - { - ret = floppy_read_sector((cylinder_nb * CYLINDER_SIZE) >> SECTOR_SIZE_BITS, - file->cylinder, - CYLINDER_SIZE); - if (ret == -1) - return read; - file->current_cylinder = cylinder_nb; - } - - part = CYLINDER_SIZE - cylinder_offset; - if (part > size) - part = size; - memcpy(ptr, file->cylinder + cylinder_offset, part); - - size -= part; - ptr = (char*)ptr + part; - file->offset += part; - read += part; - } - - return read; -} diff --git a/libfloppy/floppy_read_sector.c b/libfloppy/floppy_read_sector.c index cb4369a..6ce7f18 100644 --- a/libfloppy/floppy_read_sector.c +++ b/libfloppy/floppy_read_sector.c @@ -15,7 +15,8 @@ * size is the number of bytes to read */ -int floppy_read_sector(off_t offset, void* buffer, size_t size) +int floppy_read_sector(floppy_device_t *device, + off_t offset, void* buffer, size_t size) { OSErr err; ParamBlockRec_t param_block; @@ -28,7 +29,7 @@ int floppy_read_sector(off_t offset, void* buffer, size_t size) memset(¶m_block, 0, sizeof(param_block)); param_block.ioBuffer = (unsigned long)buffer; - param_block.ioVRefNum = 1; + param_block.ioVRefNum = device->unit + 1; param_block.ioRefNum = -5; param_block.ioReqCount = size; param_block.ioPosMode = fsFromStart; diff --git a/libfloppy/libfloppy.h b/libfloppy/libfloppy.h index 1e6856c..cbd0ef4 100644 --- a/libfloppy/libfloppy.h +++ b/libfloppy/libfloppy.h @@ -11,14 +11,11 @@ #define SECTOR_SIZE (1 << (SECTOR_SIZE_BITS)) #define SECTOR_PER_TRACK 18 #define SIDE_NB 2 -#define CYLINDER_SIZE (SIDE_NB*SECTOR_PER_TRACK*SECTOR_SIZE) typedef struct { - int offset; - int current_cylinder; - unsigned char cylinder[CYLINDER_SIZE]; -} floppy_FILE; + int unit; +} floppy_device_t; -extern int floppy_read_sector(off_t offset, void* buffer, size_t size); -extern size_t floppy_read(floppy_FILE *file, void *ptr, size_t size); -extern int floppy_lseek(floppy_FILE *file, off_t offset, int whence); +extern floppy_device_t *floppy_open(int unit); +extern int floppy_close(floppy_device_t* device); +extern int floppy_read_sector(floppy_device_t *device,off_t offset, void* buffer, size_t size);