mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-21 18:30:20 +00:00
move all specific structure to ext2.h and stream_* generic structures in interface
This commit is contained in:
parent
c017df52ba
commit
0b40281c38
@ -19,12 +19,12 @@ LIBRARY = libext2.a
|
||||
|
||||
SOURCES = ext2_mount.c ext2_opendir.c \
|
||||
ext2_closedir.c \
|
||||
ext2_open.c \
|
||||
ext2_open.c ext2_init.c \
|
||||
ext2_read.c ext2_close.c \
|
||||
ext2_lseek.c ext2_fstat.c \
|
||||
ext2_utils.c ext2_readdir.c
|
||||
|
||||
HEADERS = libext2.h ext2_utils.h
|
||||
HEADERS = libext2.h ext2_utils.h ext2.h
|
||||
|
||||
all:
|
||||
test -d $(TARGET) || mkdir $(TARGET)
|
||||
|
33
libext2/ext2.h
Normal file
33
libext2/ext2.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __EXT2_H__
|
||||
#define __EXT2_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/ext2_fs.h>
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
typedef struct ext2_VOLUME {
|
||||
device_io_t *device;
|
||||
struct ext2_super_block *super;
|
||||
unsigned int current;
|
||||
char *buffer;
|
||||
} ext2_VOLUME;
|
||||
|
||||
typedef struct ext2_DIR {
|
||||
ext2_VOLUME *volume;
|
||||
struct ext2_inode *inode;
|
||||
off_t index;
|
||||
} ext2_DIR;
|
||||
|
||||
typedef struct ext2_FILE {
|
||||
ext2_VOLUME *volume;
|
||||
struct ext2_inode *inode;
|
||||
off_t offset;
|
||||
} ext2_FILE;
|
||||
#endif /* __LIBEXT2_H__ */
|
@ -6,11 +6,12 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
|
||||
void ext2_close(ext2_FILE *file)
|
||||
void ext2_close(stream_FILE *file)
|
||||
{
|
||||
if (file == NULL)
|
||||
return;
|
||||
free(file->inode);
|
||||
free(((ext2_FILE*)file)->inode);
|
||||
free(file);
|
||||
}
|
||||
|
@ -6,11 +6,12 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
|
||||
void ext2_closedir(ext2_DIR *dir)
|
||||
void ext2_closedir(stream_DIR *dir)
|
||||
{
|
||||
if (dir == NULL)
|
||||
return;
|
||||
free(dir->inode);
|
||||
free(((ext2_DIR*)dir)->inode);
|
||||
free(dir);
|
||||
}
|
||||
|
@ -5,9 +5,10 @@
|
||||
*/
|
||||
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
|
||||
int ext2_fstat(ext2_FILE *file, struct stream_stat *buf)
|
||||
int ext2_fstat(stream_FILE *file, struct stream_stat *buf)
|
||||
{
|
||||
buf->st_size = file->inode->i_size;
|
||||
buf->st_size = ((ext2_FILE*)file)->inode->i_size;
|
||||
return 0;
|
||||
}
|
||||
|
20
libext2/ext2_init.c
Normal file
20
libext2/ext2_init.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libext2.h"
|
||||
|
||||
int ext2_init(device_io_t *device, filesystem_io_t *fs)
|
||||
{
|
||||
fs->mount = ext2_mount;
|
||||
fs->open = ext2_open;
|
||||
fs->read = ext2_read;
|
||||
fs->lseek = ext2_lseek;
|
||||
fs->close = ext2_close;
|
||||
fs->umount = ext2_umount;
|
||||
fs->fstat = ext2_fstat;
|
||||
|
||||
return 0;
|
||||
}
|
@ -5,9 +5,11 @@
|
||||
*/
|
||||
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
|
||||
int ext2_lseek(ext2_FILE *file, long offset, int whence)
|
||||
int ext2_lseek(stream_FILE *_file, long offset, int whence)
|
||||
{
|
||||
ext2_FILE *file = (ext2_FILE*)_file;
|
||||
long new_offset;
|
||||
|
||||
switch(whence)
|
||||
|
@ -5,12 +5,14 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libstream.h>
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
#include "ext2_utils.h"
|
||||
|
||||
#define SB_OFFSET (2)
|
||||
|
||||
ext2_VOLUME* ext2_mount(device_io_t *device)
|
||||
stream_VOLUME* ext2_mount(device_io_t *device)
|
||||
{
|
||||
ext2_VOLUME *volume;
|
||||
struct ext2_super_block *super;
|
||||
@ -46,11 +48,12 @@ ext2_VOLUME* ext2_mount(device_io_t *device)
|
||||
volume->current = -1;
|
||||
ext2_read_block(volume, 0);
|
||||
|
||||
return volume;
|
||||
return (stream_VOLUME*)volume;
|
||||
}
|
||||
|
||||
int ext2_umount(ext2_VOLUME* volume)
|
||||
int ext2_umount(stream_VOLUME* _volume)
|
||||
{
|
||||
ext2_VOLUME *volume = (ext2_VOLUME*)_volume;
|
||||
if (volume == NULL)
|
||||
return -1;
|
||||
free(volume->super);
|
||||
|
@ -7,16 +7,17 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
#include "ext2_utils.h"
|
||||
|
||||
ext2_FILE* ext2_open(ext2_VOLUME *volume, char* pathname)
|
||||
stream_FILE* ext2_open(stream_VOLUME *volume, char* pathname)
|
||||
{
|
||||
ext2_FILE *file;
|
||||
struct ext2_inode *inode;
|
||||
int ino;
|
||||
int ret;
|
||||
|
||||
ino = ext2_seek_name(volume, pathname);
|
||||
ino = ext2_seek_name((ext2_VOLUME*)volume, pathname);
|
||||
if (ino == 0)
|
||||
return NULL;
|
||||
|
||||
@ -24,7 +25,7 @@ ext2_FILE* ext2_open(ext2_VOLUME *volume, char* pathname)
|
||||
if (inode == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = ext2_get_inode(volume, ino, inode);
|
||||
ret = ext2_get_inode((ext2_VOLUME*)volume, ino, inode);
|
||||
if (ret == -1) {
|
||||
free(inode);
|
||||
return NULL;
|
||||
@ -35,9 +36,9 @@ ext2_FILE* ext2_open(ext2_VOLUME *volume, char* pathname)
|
||||
free(inode);
|
||||
return NULL;
|
||||
}
|
||||
file->volume = volume;
|
||||
file->volume = (ext2_VOLUME*)volume;
|
||||
file->inode = inode;
|
||||
file->offset = 0;
|
||||
|
||||
return file;
|
||||
return (stream_FILE*)file;
|
||||
}
|
||||
|
@ -8,16 +8,17 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
#include "ext2_utils.h"
|
||||
|
||||
ext2_DIR* ext2_opendir(ext2_VOLUME *volume, char *name)
|
||||
stream_DIR* ext2_opendir(stream_VOLUME *volume, char *name)
|
||||
{
|
||||
ext2_DIR* dir;
|
||||
int ino;
|
||||
struct ext2_inode *inode;
|
||||
int ret;
|
||||
|
||||
ino = ext2_seek_name(volume, name);
|
||||
ino = ext2_seek_name((ext2_VOLUME*)volume, name);
|
||||
if (ino == 0)
|
||||
return NULL;
|
||||
|
||||
@ -25,7 +26,7 @@ ext2_DIR* ext2_opendir(ext2_VOLUME *volume, char *name)
|
||||
if (inode == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = ext2_get_inode(volume, ino, inode);
|
||||
ret = ext2_get_inode((ext2_VOLUME*)volume, ino, inode);
|
||||
if (ret == -1) {
|
||||
free(inode);
|
||||
return NULL;
|
||||
@ -41,9 +42,9 @@ ext2_DIR* ext2_opendir(ext2_VOLUME *volume, char *name)
|
||||
free(inode);
|
||||
return NULL;
|
||||
}
|
||||
dir->volume = volume;
|
||||
dir->volume = (ext2_VOLUME*)volume;
|
||||
dir->inode = inode;
|
||||
dir->index = 0;
|
||||
|
||||
return dir;
|
||||
return (stream_DIR*)dir;
|
||||
}
|
||||
|
@ -5,10 +5,12 @@
|
||||
*/
|
||||
|
||||
#include "libext2.h"
|
||||
#include "ext2.h"
|
||||
#include "ext2_utils.h"
|
||||
|
||||
ssize_t ext2_read(ext2_FILE *file, void *buf, size_t count)
|
||||
size_t ext2_read(stream_FILE *_file, void *buf, size_t count)
|
||||
{
|
||||
ext2_FILE *file = (ext2_FILE*)_file;
|
||||
int ret;
|
||||
|
||||
ret = ext2_read_data(file->volume, file->inode, file->offset,
|
||||
|
@ -9,8 +9,9 @@
|
||||
|
||||
static struct ext2_dir_entry_2 entry;
|
||||
|
||||
struct ext2_dir_entry_2 *ext2_readdir(ext2_DIR *dir)
|
||||
struct ext2_dir_entry_2 *ext2_readdir(stream_DIR *_dir)
|
||||
{
|
||||
ext2_DIR *dir = (ext2_DIR*)_dir;
|
||||
int ret;
|
||||
|
||||
ret = ext2_dir_entry(dir->volume, dir->inode, dir->index, &entry);
|
||||
|
@ -7,6 +7,10 @@
|
||||
#ifndef __EXT2_UTILS_H__
|
||||
#define __EXT2_UTILS_H__
|
||||
|
||||
#include <linux/ext2_fs.h>
|
||||
#include <libstream.h>
|
||||
#include "ext2.h"
|
||||
|
||||
extern void ext2_get_super(device_io_t *device, struct ext2_super_block *super);
|
||||
extern void ext2_read_block(ext2_VOLUME* volume, unsigned int fsblock);
|
||||
extern void ext2_get_group_desc(ext2_VOLUME* volume,
|
||||
|
@ -7,39 +7,18 @@
|
||||
#ifndef __LIBEXT2_H__
|
||||
#define __LIBEXT2_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/ext2_fs.h>
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
typedef struct ext2_VOLUME {
|
||||
device_io_t *device;
|
||||
struct ext2_super_block *super;
|
||||
unsigned int current;
|
||||
char *buffer;
|
||||
} ext2_VOLUME;
|
||||
|
||||
typedef struct ext2_DIR {
|
||||
ext2_VOLUME *volume;
|
||||
struct ext2_inode *inode;
|
||||
off_t index;
|
||||
} ext2_DIR;
|
||||
|
||||
typedef struct ext2_FILE {
|
||||
ext2_VOLUME *volume;
|
||||
struct ext2_inode *inode;
|
||||
off_t offset;
|
||||
} ext2_FILE;
|
||||
|
||||
extern ext2_VOLUME* ext2_mount(device_io_t *device);
|
||||
extern int ext2_umount(ext2_VOLUME *volume);
|
||||
extern ext2_DIR* ext2_opendir(ext2_VOLUME *, char *name);
|
||||
extern struct ext2_dir_entry_2* ext2_readdir(ext2_DIR* dir);
|
||||
extern void ext2_closedir(ext2_DIR *dir);
|
||||
extern ext2_FILE* ext2_open(ext2_VOLUME *, char* pathname);
|
||||
extern ssize_t ext2_read(ext2_FILE *file, void *buf, size_t count);
|
||||
extern void ext2_close(ext2_FILE *file);
|
||||
extern int ext2_lseek(ext2_FILE *file, long offset, int whence);
|
||||
extern int ext2_fstat(ext2_FILE *file, struct stream_stat *buf);
|
||||
extern int ext2_init(device_io_t *device, filesystem_io_t *fs);
|
||||
extern stream_VOLUME* ext2_mount(device_io_t *device);
|
||||
extern int ext2_umount(stream_VOLUME *volume);
|
||||
extern stream_DIR* ext2_opendir(stream_VOLUME *, char *name);
|
||||
extern struct ext2_dir_entry_2* ext2_readdir(stream_DIR* dir);
|
||||
extern void ext2_closedir(stream_DIR *dir);
|
||||
extern stream_FILE* ext2_open(stream_VOLUME *, char* pathname);
|
||||
extern size_t ext2_read(stream_FILE *file, void *buf, size_t count);
|
||||
extern void ext2_close(stream_FILE *file);
|
||||
extern int ext2_lseek(stream_FILE *file, long offset, int whence);
|
||||
extern int ext2_fstat(stream_FILE *file, struct stream_stat *buf);
|
||||
|
||||
#endif /* __LIBEXT2_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user