/* * * (c) 2005 Laurent Vivier * */ #include #include #include #include "libfloppy.h" /* offset is a block number * size is the number of bytes to read */ int floppy_read_sector(floppy_device_t *device, off_t offset, void* buffer, size_t size) { OSErr err; ParamBlockRec_t param_block; /* check size to read is multiple of sector size */ if (size & (SECTOR_SIZE - 1)) return -1; memset(¶m_block, 0, sizeof(param_block)); param_block.ioBuffer = (unsigned long)buffer; param_block.ioVRefNum = device->unit + 1; param_block.ioRefNum = -5; param_block.ioReqCount = size; param_block.ioPosMode = fsFromStart; param_block.ioPosOffset = offset << SECTOR_SIZE_BITS; err = PBReadSync(¶m_block); if (err != noErr) return -1; return 0; }