mirror of
https://github.com/vivier/EMILE.git
synced 2024-05-29 04:41:27 +00:00
move all specific structure to container.h and stream_* generic structures in interface
This commit is contained in:
parent
c346e2b01d
commit
c017df52ba
|
@ -12,9 +12,10 @@ CPPFLAGS = -I$(TOP)/../libstream
|
|||
LIBRARY = libcontainer.a
|
||||
|
||||
SOURCES = container_close.c container_lseek.c container_open.c \
|
||||
container_read.c container_fstat.c
|
||||
container_read.c container_fstat.c container_init.c \
|
||||
container_mount.c
|
||||
|
||||
HEADERS = libcontainer.h
|
||||
HEADERS = libcontainer.h container.h
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
|
|
24
libcontainer/container.h
Normal file
24
libcontainer/container.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONTAINER_H_
|
||||
#define _CONTAINER_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned long offset;
|
||||
device_io_t *device;
|
||||
struct emile_container* container;
|
||||
unsigned long current_block;
|
||||
char *buffer[0];
|
||||
} container_FILE;
|
||||
|
||||
typedef device_io_t container_VOLUME;
|
||||
|
||||
#endif /* _CONTAINER_H_ */
|
|
@ -7,16 +7,17 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
int container_close(container_FILE *file)
|
||||
void container_close(stream_FILE *file)
|
||||
{
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
return;
|
||||
|
||||
if (file->container)
|
||||
free(file->container);
|
||||
if (((container_FILE*)file)->container)
|
||||
free(((container_FILE*)file)->container);
|
||||
|
||||
free(file);
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||
* (c) 2005-2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
int container_fstat(container_FILE *file, struct stream_stat *buf)
|
||||
int container_fstat(stream_FILE *_file, struct stream_stat *buf)
|
||||
{
|
||||
container_FILE *file = (container_FILE*)_file;
|
||||
if (buf == NULL)
|
||||
return -1;
|
||||
if (file->container->size == -1)
|
||||
|
|
19
libcontainer/container_init.c
Normal file
19
libcontainer/container_init.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libcontainer.h"
|
||||
|
||||
int container_init(device_io_t *device, filesystem_io_t *fs)
|
||||
{
|
||||
fs->umount = container_umount;
|
||||
fs->open = container_open;
|
||||
fs->read = container_read;
|
||||
fs->lseek = container_lseek;
|
||||
fs->close = container_close;
|
||||
fs->fstat = container_fstat;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -8,9 +8,11 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
int container_lseek(container_FILE *file, off_t offset, int whence)
|
||||
int container_lseek(stream_FILE *_file, off_t offset, int whence)
|
||||
{
|
||||
container_FILE *file = (container_FILE*)_file;
|
||||
long new_offset;
|
||||
|
||||
switch(whence)
|
||||
|
|
19
libcontainer/container_mount.c
Normal file
19
libcontainer/container_mount.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <libstream.h>
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
stream_VOLUME *container_mount(device_io_t *device)
|
||||
{
|
||||
return (stream_VOLUME*)device;
|
||||
}
|
||||
|
||||
int container_umount(stream_VOLUME *volume)
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -9,10 +9,12 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
container_FILE *container_open(device_io_t *device, char *path)
|
||||
stream_FILE *container_open(stream_VOLUME *volume, char *path)
|
||||
{
|
||||
container_FILE *file;
|
||||
device_io_t *device = (device_io_t*)volume;
|
||||
int block_size = device->get_blocksize(device->data);
|
||||
unsigned long first, nbblocs;
|
||||
int ret;
|
||||
|
@ -45,5 +47,5 @@ container_FILE *container_open(device_io_t *device, char *path)
|
|||
file->offset = 0;
|
||||
file->device = device;
|
||||
file->current_block = 0;
|
||||
return file;
|
||||
return (stream_FILE*)file;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "libcontainer.h"
|
||||
#include "container.h"
|
||||
|
||||
extern void error(char *x) __attribute__ ((noreturn));
|
||||
|
||||
static unsigned long seek_block(container_FILE *file)
|
||||
static unsigned long seek_block(stream_FILE *_file)
|
||||
{
|
||||
container_FILE *file = (container_FILE*)_file;
|
||||
struct emile_container *container = file->container;
|
||||
ssize_t current;
|
||||
int i;
|
||||
|
@ -38,8 +40,9 @@ static unsigned long seek_block(container_FILE *file)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ssize_t container_read(container_FILE *file, void *ptr, size_t size)
|
||||
size_t container_read(stream_FILE *_file, void *ptr, size_t size)
|
||||
{
|
||||
container_FILE *file = (container_FILE*)_file;
|
||||
int err;
|
||||
ssize_t read = 0;
|
||||
int part;
|
||||
|
@ -53,7 +56,7 @@ ssize_t container_read(container_FILE *file, void *ptr, size_t size)
|
|||
if (file->offset >= file->container->size)
|
||||
return read;
|
||||
|
||||
block_nb = seek_block(file);
|
||||
block_nb = seek_block(_file);
|
||||
block_offset = file->offset % block_size;
|
||||
|
||||
if (block_nb == 0)
|
||||
|
|
|
@ -21,18 +21,13 @@ struct emile_container {
|
|||
struct emile_block blocks[0];
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct {
|
||||
unsigned long offset;
|
||||
device_io_t *device;
|
||||
struct emile_container* container;
|
||||
unsigned long current_block;
|
||||
char *buffer[0];
|
||||
} container_FILE;
|
||||
|
||||
extern container_FILE *container_open(device_io_t *device, char *current);
|
||||
extern int container_close(container_FILE *file);
|
||||
extern int container_lseek(container_FILE *file, off_t offset, int whence);
|
||||
extern ssize_t container_read(container_FILE *file, void *ptr, size_t size);
|
||||
extern int container_fstat(container_FILE *file, struct stream_stat *buf);
|
||||
extern stream_VOLUME *container_mount(device_io_t *device);
|
||||
extern int container_umount(stream_VOLUME *volume);
|
||||
extern int container_init(device_io_t *device, filesystem_io_t *fs);
|
||||
extern stream_FILE *container_open(stream_VOLUME *volume, char *current);
|
||||
extern void container_close(stream_FILE *file);
|
||||
extern int container_lseek(stream_FILE *file, off_t offset, int whence);
|
||||
extern size_t container_read(stream_FILE *file, void *ptr, size_t size);
|
||||
extern int container_fstat(stream_FILE *file, struct stream_stat *buf);
|
||||
|
||||
#endif /* _LIBCONTAINER_H_ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user