mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-02 21:30:29 +00:00
Add device_write_sector() and device_sector_size, use int fd instead FILE*
This commit is contained in:
parent
2fe3ca34e7
commit
7ba120c6c5
@ -6,38 +6,53 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#define SECTOR_SIZE (2048)
|
||||
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
|
||||
int device_sector_size = 2048;
|
||||
|
||||
#define BLOCKS(X) (((X)/device_sector_size)+(((X)%device_sector_size)?1:0))
|
||||
|
||||
int device_read_sector(void *data,off_t offset, void* buffer, size_t size)
|
||||
{
|
||||
FILE* file = (FILE*)data;
|
||||
int fd = (int)data;
|
||||
int ret;
|
||||
|
||||
lseek(fileno(file), offset << 11, SEEK_SET);
|
||||
return read(fileno(file), buffer, ISO_BLOCKS(size) << 11);
|
||||
lseek(fd, offset << 11, SEEK_SET);
|
||||
ret = read(fd, buffer, BLOCKS(size) << 11);
|
||||
if (ret != BLOCKS(size) << 11)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_write_sector(void *data,off_t offset, void* buffer, size_t size)
|
||||
{
|
||||
int fd = (int)data;
|
||||
int ret;
|
||||
|
||||
lseek(fd, offset << 11, SEEK_SET);
|
||||
ret = write(fd, buffer, BLOCKS(size) << 11);
|
||||
if (ret != BLOCKS(size) << 11)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void device_close(void *data)
|
||||
{
|
||||
FILE* file = (FILE*)data;
|
||||
if (file)
|
||||
fclose(file);
|
||||
close((int)data);
|
||||
}
|
||||
|
||||
FILE *device_open(char *device)
|
||||
int device_open(char *device, int flags)
|
||||
{
|
||||
FILE* file;
|
||||
int fd;
|
||||
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
return -1;
|
||||
|
||||
file = fopen(device, "rb");
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
fd = open(device, flags);
|
||||
|
||||
return file;
|
||||
return fd;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
* (c) 2005-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
@ -10,6 +10,9 @@
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
extern FILE *device_open(char *device);
|
||||
extern int device_sector_size;
|
||||
|
||||
extern int device_open(char *device, int flags);
|
||||
extern void device_close(void *data);
|
||||
extern int device_write_sector(void *data,off_t offset, void* buffer, size_t size);
|
||||
extern int device_read_sector(void *data, off_t offset, void* buffer, size_t size);
|
||||
|
Loading…
Reference in New Issue
Block a user