File: floppy_read_sector.c

package info (click to toggle)
emile 0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,716 kB
  • ctags: 2,737
  • sloc: ansic: 18,908; makefile: 726; asm: 622; sh: 2
file content (43 lines) | stat: -rw-r--r-- 849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 *
 * (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

#include <sys/types.h>
#include <string.h>

#include <macos/devices.h>

#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(&param_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(&param_block);
	if (err != noErr)
		return -1;

	return 0;
}