From a55aa395c79a83a72037444bef363a58eba73822 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 23 Nov 2005 00:09:00 +0000 Subject: [PATCH] Add stream_fstat() --- libstream/Makefile | 2 +- libstream/libstream.h | 7 +++++++ libstream/stream_fstat.c | 15 +++++++++++++++ libstream/stream_open.c | 17 +++++++++++------ 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 libstream/stream_fstat.c diff --git a/libstream/Makefile b/libstream/Makefile index b782fed..4b425e4 100644 --- a/libstream/Makefile +++ b/libstream/Makefile @@ -13,7 +13,7 @@ CPPFLAGS = -I$(TOP)/../libfloppy -I$(TOP)/../libscsi -I$(TOP)/../libblock \ LIBRARY = libstream.a SOURCES = stream_close.c stream_open.c stream_read.c stream_lseek.c \ - stream_uncompress.c gzio.c + stream_uncompress.c gzio.c stream_fstat.c HEADERS = libstream.h diff --git a/libstream/libstream.h b/libstream/libstream.h index e84cc35..98a01b9 100644 --- a/libstream/libstream.h +++ b/libstream/libstream.h @@ -9,11 +9,16 @@ #include #include +struct stream_stat { + off_t st_size; +}; + typedef int (*stream_read_sector_t)(void *data,off_t offset, void* buffer, size_t size); typedef ssize_t (*stream_read_t)(void *data, void *buf, size_t count); typedef int (*stream_lseek_t)(void *data, long offset, int whence); typedef int (*stream_close_t)(void *data); typedef int (*stream_umount_t)(void *data); +typedef int (*stream_fstat_t)(void *data, struct stream_stat *buf); typedef struct { void *data; @@ -28,6 +33,7 @@ typedef struct { stream_lseek_t lseek; stream_close_t close; stream_umount_t umount; + stream_fstat_t fstat; } filesystem_io_t; typedef struct { @@ -47,4 +53,5 @@ extern int stream_read(stream_t *stream, void *buf, size_t count); extern int stream_lseek(stream_t *stream, long offset, int whence); extern int stream_close(stream_t *stream); extern int stream_uncompress(stream_t *stream); +extern int stream_fstat(stream_t *stream, struct stream_stat *buf); #endif /* __LIBSTREAM_H__ */ diff --git a/libstream/stream_fstat.c b/libstream/stream_fstat.c new file mode 100644 index 0000000..59a1f6a --- /dev/null +++ b/libstream/stream_fstat.c @@ -0,0 +1,15 @@ +/* + * + * (c) 2005 Laurent Vivier + * + */ + +#include "libstream.h" + +int stream_fstat(stream_t *stream, struct stream_stat *buf) +{ + if (stream->fs.fstat == NULL) + return -1; + + return stream->fs.fstat(stream->fs.file, buf); +} diff --git a/libstream/stream_open.c b/libstream/stream_open.c index 0256c06..c6a191e 100644 --- a/libstream/stream_open.c +++ b/libstream/stream_open.c @@ -160,17 +160,21 @@ stream_t *stream_open(char *dev) case fs_BLOCK: if (stream->fs.data == NULL) goto outfs; - stream->fs.read = block_read; - stream->fs.seek = block_seek; - stream->fs.close = block_close; + stream->fs.read = (stream_read_t)block_read; + stream->fs.seek = (stream_lseek_t)block_seek; + stream->fs.close = (stream_close_t)block_close; + stream->fs.umount = (stream_umount_t)block_umount; + stream->fs.fstat = (stream_fstat_t)block_fstat; break; case fs_CONTAINER: stream->fs.data = container_open(&stream->device, current); if (stream->fs.data == NULL) goto outfs; - stream->fs.read = container_read; - stream->fs.seek = container_seek; - stream->fs.close = container_close; + stream->fs.read = (stream_read_t)container_read; + stream->fs.seek = (stream_lseek_t)container_seek; + stream->fs.close = (stream_close_t)container_close; + stream->fs.umount = (stream_umount_t)container_umount; + stream->fs.fstat = (stream_fstat_t)container_fstat; break; #endif case fs_ISO9660: @@ -190,6 +194,7 @@ stream_t *stream_open(char *dev) stream->fs.lseek = (stream_lseek_t)iso9660_lseek; stream->fs.close = (stream_close_t)iso9660_close; stream->fs.umount = (stream_umount_t)iso9660_umount; + stream->fs.fstat = (stream_fstat_t)iso9660_fstat; break; default: outfs: