mirror of
https://github.com/vivier/EMILE.git
synced 2026-10-22 04:02:33 +00:00
move all specific structure to block.h and stream_* generic structures in interface
This commit is contained in:
1 parent
5caae75dc2
commit
c346e2b01d
10 files changed
+86
-28
No files matched your search
+3
-2
@@ -10,9 +10,10 @@ CPPFLAGS = -I$(TOP)/../libmacos -DARCH_M68K -I$(TOP)/../libstream
|
||||
|
||||
LIBRARY = libblock.a
|
||||
|
||||
SOURCES = block_close.c block_fstat.c block_lseek.c block_open.c block_read.c
|
||||
SOURCES = block_close.c block_fstat.c block_lseek.c block_open.c block_read.c \
|
||||
block_init.c block_mount.c
|
||||
|
||||
HEADERS = libblock.h
|
||||
HEADERS = libblock.h block.h
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
typedef struct {
|
||||
int base;
|
||||
int offset;
|
||||
int size;
|
||||
device_io_t *device;
|
||||
int current;
|
||||
int buffer_size;
|
||||
unsigned char buffer[0];
|
||||
} block_FILE;
|
||||
|
||||
typedef device_io_t block_VOLUME;
|
||||
@@ -8,12 +8,10 @@
|
||||
|
||||
#include "libblock.h"
|
||||
|
||||
int block_close(block_FILE *file)
|
||||
void block_close(stream_FILE *file)
|
||||
{
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
return;
|
||||
|
||||
free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -5,9 +5,11 @@
|
||||
*/
|
||||
|
||||
#include "libblock.h"
|
||||
#include "block.h"
|
||||
|
||||
int block_fstat(block_FILE *file, struct stream_stat *buf)
|
||||
int block_fstat(stream_FILE *_file, struct stream_stat *buf)
|
||||
{
|
||||
block_FILE *file = (block_FILE*)_file;
|
||||
if (buf == NULL)
|
||||
return -1;
|
||||
if (file->size == -1)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libblock.h"
|
||||
|
||||
int block_init(device_io_t *device, filesystem_io_t *fs)
|
||||
{
|
||||
fs->mount = block_mount;
|
||||
fs->umount = block_umount;
|
||||
fs->open = block_open;
|
||||
fs->read = block_read;
|
||||
fs->lseek = block_lseek;
|
||||
fs->close = block_close;
|
||||
fs->fstat = block_fstat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -5,9 +5,11 @@
|
||||
*/
|
||||
|
||||
#include "libblock.h"
|
||||
#include "block.h"
|
||||
|
||||
int block_lseek(block_FILE *file, off_t offset, int whence)
|
||||
int block_lseek(stream_FILE *_file, off_t offset, int whence)
|
||||
{
|
||||
block_FILE *file = (block_FILE*)_file;
|
||||
long new_offset;
|
||||
|
||||
switch(whence)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libblock.h"
|
||||
|
||||
stream_VOLUME *block_mount(device_io_t *device)
|
||||
{
|
||||
return (stream_VOLUME*)device;
|
||||
}
|
||||
|
||||
int block_umount(stream_VOLUME *volume)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libblock.h"
|
||||
#include "block.h"
|
||||
|
||||
#define NB_SECTORS (18*2)
|
||||
|
||||
@@ -16,10 +17,10 @@
|
||||
* and <size> is the number of bytes to read then.
|
||||
*/
|
||||
|
||||
block_FILE *block_open(device_io_t *device, char *path)
|
||||
stream_FILE *block_open(stream_VOLUME *volume, char *path)
|
||||
{
|
||||
block_FILE *block;
|
||||
int blocksize = device->get_blocksize(device->data);
|
||||
int blocksize = ((device_io_t*)volume)->get_blocksize(((device_io_t*)volume)->data);
|
||||
int first, size;
|
||||
|
||||
first = strtol(path, &path, 0);
|
||||
@@ -44,9 +45,9 @@ block_FILE *block_open(device_io_t *device, char *path)
|
||||
block->base = first;
|
||||
block->offset = 0;
|
||||
block->size = size;
|
||||
block->device = device;
|
||||
block->device = (device_io_t*)volume;
|
||||
block->current = -1;
|
||||
block->buffer_size = NB_SECTORS;
|
||||
|
||||
return block;
|
||||
return (stream_FILE*)block;
|
||||
}
|
||||
@@ -7,9 +7,11 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "libblock.h"
|
||||
#include "block.h"
|
||||
|
||||
size_t block_read(block_FILE *file, void *ptr, size_t size)
|
||||
size_t block_read(stream_FILE *_file, void *ptr, size_t size)
|
||||
{
|
||||
block_FILE *file = (block_FILE*)_file;
|
||||
int part;
|
||||
int block_nb;
|
||||
int block_offset;
|
||||
|
||||
+8
-15
@@ -9,18 +9,11 @@
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
typedef struct {
|
||||
int base;
|
||||
int offset;
|
||||
int size;
|
||||
device_io_t *device;
|
||||
int current;
|
||||
int buffer_size;
|
||||
unsigned char buffer[0];
|
||||
} block_FILE;
|
||||
|
||||
extern block_FILE *block_open(device_io_t *device, char *path);
|
||||
extern int block_close(block_FILE *file);
|
||||
extern size_t block_read(block_FILE *file, void *ptr, size_t size);
|
||||
extern int block_lseek(block_FILE *file, off_t offset, int whence);
|
||||
extern int block_fstat(block_FILE *file, struct stream_stat *buf);
|
||||
extern int block_init(device_io_t *device, filesystem_io_t *fs);
|
||||
extern stream_VOLUME *block_mount(device_io_t *device);
|
||||
extern int block_umount(stream_VOLUME *volume);
|
||||
extern stream_FILE *block_open(stream_VOLUME *volume, char *path);
|
||||
extern void block_close(stream_FILE *file);
|
||||
extern size_t block_read(stream_FILE *file, void *ptr, size_t size);
|
||||
extern int block_lseek(stream_FILE *file, off_t offset, int whence);
|
||||
extern int block_fstat(stream_FILE *file, struct stream_stat *buf);
|
||||
Reference in new issue
Block a user