EMILE/tools/device.c

36 lines
638 B
C
Raw Normal View History

2005-11-13 19:43:28 +00:00
/*
*
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
2005-11-12 22:28:50 +00:00
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#define SECTOR_SIZE (2048)
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
static const char *filename = "/dev/cdrom";
static FILE *infile = NULL;
2005-11-13 19:43:28 +00:00
int device_open(void)
2005-11-12 22:28:50 +00:00
{
infile = fopen(filename, "rb");
if (infile == NULL)
return -1;
return 0;
}
2005-11-13 19:43:28 +00:00
void device_close(void)
2005-11-12 22:28:50 +00:00
{
if (infile)
fclose(infile);
}
2005-11-13 19:43:28 +00:00
void device_read(off_t offset, void* buffer, size_t size)
2005-11-12 22:28:50 +00:00
{
lseek(fileno(infile), offset << 11, SEEK_SET);
read(fileno(infile), buffer, ISO_BLOCKS(size) << 11);
}