File: device.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 (42 lines) | stat: -rw-r--r-- 726 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
/*
 *
 * (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

#include "device.h"

#define SECTOR_SIZE     (2048)
#define ISO_BLOCKS(X)   (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))

static const char *filename = "/dev/cdrom";

int device_read_sector(void *data,off_t offset, void* buffer, size_t size)
{
	FILE* file = (FILE*)data;

	lseek(fileno(file), offset << 11, SEEK_SET);
	return read(fileno(file), buffer, ISO_BLOCKS(size) << 11);
}

void device_close(void *data)
{
	FILE* file = (FILE*)data;
	if (file)
		fclose(file);
}

FILE *device_open(void)
{
	FILE* file;

	file = fopen(filename, "rb");
	if (file == NULL)
		return NULL;

	return file;
}