2005-11-13 19:43:28 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
2005-11-13 19:43:28 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-11-21 22:09:16 +00:00
|
|
|
#include "device.h"
|
|
|
|
|
2005-11-12 22:28:50 +00:00
|
|
|
#define SECTOR_SIZE (2048)
|
|
|
|
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
|
|
|
|
|
2005-11-21 22:09:16 +00:00
|
|
|
int device_read_sector(void *data,off_t offset, void* buffer, size_t size)
|
2005-11-12 22:28:50 +00:00
|
|
|
{
|
2005-11-21 22:09:16 +00:00
|
|
|
FILE* file = (FILE*)data;
|
|
|
|
|
|
|
|
lseek(fileno(file), offset << 11, SEEK_SET);
|
|
|
|
return read(fileno(file), buffer, ISO_BLOCKS(size) << 11);
|
2005-11-12 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
2005-11-21 22:09:16 +00:00
|
|
|
void device_close(void *data)
|
2005-11-12 22:28:50 +00:00
|
|
|
{
|
2005-11-21 22:09:16 +00:00
|
|
|
FILE* file = (FILE*)data;
|
|
|
|
if (file)
|
|
|
|
fclose(file);
|
2005-11-12 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
2006-09-08 22:57:36 +00:00
|
|
|
FILE *device_open(char *device)
|
2005-11-12 22:28:50 +00:00
|
|
|
{
|
2005-11-21 22:09:16 +00:00
|
|
|
FILE* file;
|
|
|
|
|
2006-09-08 22:57:36 +00:00
|
|
|
if (device == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
file = fopen(device, "rb");
|
2005-11-21 22:09:16 +00:00
|
|
|
if (file == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return file;
|
2005-11-12 22:28:50 +00:00
|
|
|
}
|