move all specific structure to block.h and stream_* generic structures in interface

This commit is contained in:
Laurent Vivier 2008-04-20 16:16:53 +00:00
parent 5caae75dc2
commit c346e2b01d
10 changed files with 86 additions and 28 deletions

View File

@ -10,9 +10,10 @@ CPPFLAGS = -I$(TOP)/../libmacos -DARCH_M68K -I$(TOP)/../libstream
LIBRARY = libblock.a 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) all: $(LIBRARY)

22
libblock/block.h Normal file
View File

@ -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;

View File

@ -8,12 +8,10 @@
#include "libblock.h" #include "libblock.h"
int block_close(block_FILE *file) void block_close(stream_FILE *file)
{ {
if (file == NULL) if (file == NULL)
return -1; return;
free(file); free(file);
return 0;
} }

View File

@ -5,9 +5,11 @@
*/ */
#include "libblock.h" #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) if (buf == NULL)
return -1; return -1;
if (file->size == -1) if (file->size == -1)

20
libblock/block_init.c Normal file
View File

@ -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;
}

View File

@ -5,9 +5,11 @@
*/ */
#include "libblock.h" #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; long new_offset;
switch(whence) switch(whence)

17
libblock/block_mount.c Normal file
View File

@ -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;
}

View File

@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "libblock.h" #include "libblock.h"
#include "block.h"
#define NB_SECTORS (18*2) #define NB_SECTORS (18*2)
@ -16,10 +17,10 @@
* and <size> is the number of bytes to read then. * 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; 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; int first, size;
first = strtol(path, &path, 0); first = strtol(path, &path, 0);
@ -44,9 +45,9 @@ block_FILE *block_open(device_io_t *device, char *path)
block->base = first; block->base = first;
block->offset = 0; block->offset = 0;
block->size = size; block->size = size;
block->device = device; block->device = (device_io_t*)volume;
block->current = -1; block->current = -1;
block->buffer_size = NB_SECTORS; block->buffer_size = NB_SECTORS;
return block; return (stream_FILE*)block;
} }

View File

@ -7,9 +7,11 @@
#include <string.h> #include <string.h>
#include "libblock.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 part;
int block_nb; int block_nb;
int block_offset; int block_offset;

View File

@ -9,18 +9,11 @@
#include <libstream.h> #include <libstream.h>
typedef struct { extern int block_init(device_io_t *device, filesystem_io_t *fs);
int base; extern stream_VOLUME *block_mount(device_io_t *device);
int offset; extern int block_umount(stream_VOLUME *volume);
int size; extern stream_FILE *block_open(stream_VOLUME *volume, char *path);
device_io_t *device; extern void block_close(stream_FILE *file);
int current; extern size_t block_read(stream_FILE *file, void *ptr, size_t size);
int buffer_size; extern int block_lseek(stream_FILE *file, off_t offset, int whence);
unsigned char buffer[0]; extern int block_fstat(stream_FILE *file, struct stream_stat *buf);
} 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);