mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-22 00:32:15 +00:00
move all specific structure to iso9660.h and stream_* generic structures in interface
This commit is contained in:
parent
0b40281c38
commit
2c64fafc4f
@ -21,9 +21,10 @@ SOURCES = iso9660_mount.c iso9660_opendir.c \
|
||||
iso9660_closedir.c iso9660_readdir.c \
|
||||
iso9660_is_directory.c iso9660_open.c \
|
||||
iso9660_read.c iso9660_close.c \
|
||||
iso9660_lseek.c iso9660_fstat.c
|
||||
iso9660_lseek.c iso9660_fstat.c \
|
||||
iso9660_init.c
|
||||
|
||||
HEADERS = libiso9660.h
|
||||
HEADERS = libiso9660.h iso9660.h
|
||||
|
||||
all:
|
||||
test -d $(TARGET) || mkdir $(TARGET)
|
||||
|
58
libiso9660/iso9660.h
Normal file
58
libiso9660/iso9660.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005-2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ISO9660_H__
|
||||
#define __ISO9660_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/iso_fs.h>
|
||||
|
||||
#define ISO9660_EXTENT_SIZE (2048)
|
||||
|
||||
typedef struct iso9660_VOLUME {
|
||||
int ucs_level;
|
||||
struct iso_primary_descriptor *descriptor;
|
||||
device_io_t *device;
|
||||
} iso9660_VOLUME;
|
||||
|
||||
typedef struct iso9660_DIR {
|
||||
iso9660_VOLUME *volume;
|
||||
int extent;
|
||||
int len;
|
||||
int index;
|
||||
unsigned char buffer[ISO9660_EXTENT_SIZE];
|
||||
} iso9660_DIR;
|
||||
|
||||
typedef struct iso9660_FILE {
|
||||
iso9660_VOLUME *volume;
|
||||
int base; /* first extent of the file */
|
||||
int size; /* size of the file */
|
||||
int offset;
|
||||
int current;
|
||||
unsigned char buffer[ISO9660_EXTENT_SIZE];
|
||||
} iso9660_FILE;
|
||||
|
||||
static inline int isonum_721(char *p)
|
||||
{
|
||||
return ((p[0] & 0xff)
|
||||
| ((p[1] & 0xff) << 8));
|
||||
}
|
||||
|
||||
static inline int isonum_723(char *p)
|
||||
{
|
||||
return (isonum_721(p));
|
||||
}
|
||||
|
||||
static inline int isonum_733(char *p)
|
||||
{
|
||||
return ((p[0] & 0xff) | ((p[1] & 0xff) << 8) |
|
||||
((p[2] & 0xff) << 16) | ((p[3] & 0xff) << 24));
|
||||
}
|
||||
|
||||
extern struct iso_directory_record *iso9660_get_root_node(iso9660_VOLUME* volume);
|
||||
extern struct iso_directory_record* iso9660_get_node(iso9660_VOLUME *volume, struct iso_directory_record *dirnode, char *path);
|
||||
|
||||
#endif /* __ISO9660_H__ */
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
void iso9660_close(iso9660_FILE *file)
|
||||
void iso9660_close(stream_FILE *file)
|
||||
{
|
||||
free(file);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
int iso9660_closedir(iso9660_DIR *dir)
|
||||
int iso9660_closedir(stream_DIR *dir)
|
||||
{
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
|
@ -5,10 +5,12 @@
|
||||
*/
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
int iso9660_fstat(iso9660_FILE *file, struct stream_stat *buf)
|
||||
int iso9660_fstat(stream_FILE *file, struct stream_stat *buf)
|
||||
{
|
||||
buf->st_size = file->size;
|
||||
buf->st_size = ((iso9660_FILE*)file)->size;
|
||||
buf->st_base = ((iso9660_FILE*)file)->base;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
20
libiso9660/iso9660_init.c
Normal file
20
libiso9660/iso9660_init.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
int iso9660_init(device_io_t *device, filesystem_io_t *fs)
|
||||
{
|
||||
fs->mount = iso9660_mount;
|
||||
fs->open = iso9660_open;
|
||||
fs->read = iso9660_read;
|
||||
fs->lseek = iso9660_lseek;
|
||||
fs->close = iso9660_close;
|
||||
fs->umount = iso9660_umount;
|
||||
fs->fstat = iso9660_fstat;
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,9 +7,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
int iso9660_lseek(iso9660_FILE *file, long offset, int whence)
|
||||
int iso9660_lseek(stream_FILE *_file, long offset, int whence)
|
||||
{
|
||||
iso9660_FILE *file = (iso9660_FILE*)_file;
|
||||
long new_offset;
|
||||
|
||||
switch(whence)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
@ -76,7 +77,7 @@ void print_info(struct iso_primary_descriptor *ipd)
|
||||
}
|
||||
#endif
|
||||
|
||||
void iso9660_name(int ucs_level, char *buffer, struct iso_directory_record * idr)
|
||||
void iso9660_name(stream_VOLUME *volume, struct iso_directory_record *idr, char *buffer)
|
||||
{
|
||||
int j;
|
||||
unsigned char uh, ul, uc;
|
||||
@ -87,7 +88,7 @@ void iso9660_name(int ucs_level, char *buffer, struct iso_directory_record * idr
|
||||
else if (idr->name_len[0] == 1 && idr->name[0] == 1)
|
||||
strcpy(buffer, "..");
|
||||
else {
|
||||
switch (ucs_level) {
|
||||
switch (((iso9660_VOLUME*)volume)->ucs_level) {
|
||||
case 3:
|
||||
case 2:
|
||||
case 1:
|
||||
@ -134,7 +135,7 @@ void iso9660_name(int ucs_level, char *buffer, struct iso_directory_record * idr
|
||||
}
|
||||
}
|
||||
|
||||
iso9660_VOLUME *iso9660_mount(device_io_t *device)
|
||||
stream_VOLUME *iso9660_mount(device_io_t *device)
|
||||
{
|
||||
iso9660_VOLUME* volume;
|
||||
struct iso_primary_descriptor *jpd;
|
||||
@ -301,15 +302,16 @@ nextblock:
|
||||
volume->ucs_level = ucs_level;
|
||||
volume->device = device;
|
||||
|
||||
return volume;
|
||||
return (stream_VOLUME*)volume;
|
||||
}
|
||||
|
||||
int iso9660_umount(iso9660_VOLUME* volume)
|
||||
int iso9660_umount(stream_VOLUME* volume)
|
||||
{
|
||||
if (volume == NULL)
|
||||
iso9660_VOLUME *__volume = (iso9660_VOLUME *)volume;
|
||||
if (__volume == NULL)
|
||||
return -1;
|
||||
free(volume->descriptor);
|
||||
free(volume);
|
||||
free(__volume->descriptor);
|
||||
free(__volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7,18 +7,19 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
iso9660_FILE* iso9660_open(iso9660_VOLUME *volume, char* pathname)
|
||||
stream_FILE* iso9660_open(stream_VOLUME *volume, char* pathname)
|
||||
{
|
||||
struct iso_directory_record *root;
|
||||
struct iso_directory_record *idr;
|
||||
iso9660_FILE *file;
|
||||
|
||||
root = iso9660_get_root_node(volume);
|
||||
root = iso9660_get_root_node((iso9660_VOLUME*)volume);
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
||||
idr = iso9660_get_node(volume, root, pathname);
|
||||
idr = iso9660_get_node((iso9660_VOLUME*)volume, root, pathname);
|
||||
if (idr == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -30,9 +31,9 @@ iso9660_FILE* iso9660_open(iso9660_VOLUME *volume, char* pathname)
|
||||
file->size = isonum_733((char *)idr->size);
|
||||
file->offset = 0;
|
||||
file->current = -1;
|
||||
file->volume = volume;
|
||||
file->volume = (iso9660_VOLUME*)volume;
|
||||
|
||||
free(idr);
|
||||
|
||||
return file;
|
||||
return (stream_FILE*)file;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
static iso9660_DIR* iso9660_opendir_node(iso9660_VOLUME *volume, struct iso_directory_record *node)
|
||||
{
|
||||
@ -48,17 +49,17 @@ static struct iso_directory_record * seek_name(iso9660_VOLUME *volume,
|
||||
if (dir == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((idr = iso9660_readdir(dir)) != NULL)
|
||||
while ((idr = iso9660_readdir((stream_DIR*)dir)) != NULL)
|
||||
{
|
||||
iso9660_name(volume->ucs_level, name_buf, idr);
|
||||
iso9660_name((stream_VOLUME*)volume, idr, name_buf);
|
||||
if (strcmp(name, name_buf) == 0)
|
||||
{
|
||||
result = idr_new(idr);
|
||||
iso9660_closedir(dir);
|
||||
iso9660_closedir((stream_DIR*)dir);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
iso9660_closedir(dir);
|
||||
iso9660_closedir((stream_DIR*)dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -102,24 +103,24 @@ struct iso_directory_record* iso9660_get_node(
|
||||
return current;
|
||||
}
|
||||
|
||||
iso9660_DIR* iso9660_opendir(iso9660_VOLUME *volume, char *name)
|
||||
stream_DIR* iso9660_opendir(stream_VOLUME *volume, char *name)
|
||||
{
|
||||
iso9660_DIR *dir;
|
||||
struct iso_directory_record *node;
|
||||
|
||||
node = iso9660_get_root_node(volume);
|
||||
node = iso9660_get_root_node((iso9660_VOLUME*)volume);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
node = iso9660_get_node(volume, node, name);
|
||||
node = iso9660_get_node((iso9660_VOLUME*)volume, node, name);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
dir = iso9660_opendir_node(volume, node);
|
||||
dir = iso9660_opendir_node((iso9660_VOLUME*)volume, node);
|
||||
|
||||
free(node);
|
||||
|
||||
dir->volume = volume;
|
||||
dir->volume = (iso9660_VOLUME*)volume;
|
||||
|
||||
return dir;
|
||||
return (stream_DIR*)dir;
|
||||
}
|
||||
|
@ -8,9 +8,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
|
||||
size_t iso9660_read(stream_FILE *_file, void *buf, size_t count)
|
||||
{
|
||||
iso9660_FILE *file = (iso9660_FILE*)_file;
|
||||
size_t read = 0;
|
||||
|
||||
if ( count > (file->size - file->offset) )
|
||||
|
@ -7,9 +7,11 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "libiso9660.h"
|
||||
#include "iso9660.h"
|
||||
|
||||
struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir)
|
||||
struct iso_directory_record *iso9660_readdir(stream_DIR *_dir)
|
||||
{
|
||||
iso9660_DIR *dir = (iso9660_DIR*)_dir;
|
||||
struct iso_directory_record *idr;
|
||||
|
||||
if (dir->index > 2048 - offsetof(struct iso_directory_record, name[0]))
|
||||
|
@ -12,61 +12,18 @@
|
||||
|
||||
#include <libstream.h>
|
||||
|
||||
#define ISO9660_EXTENT_SIZE (2048)
|
||||
|
||||
typedef struct iso9660_VOLUME {
|
||||
int ucs_level;
|
||||
struct iso_primary_descriptor *descriptor;
|
||||
device_io_t *device;
|
||||
} iso9660_VOLUME;
|
||||
|
||||
typedef struct iso9660_DIR {
|
||||
iso9660_VOLUME *volume;
|
||||
int extent;
|
||||
int len;
|
||||
int index;
|
||||
unsigned char buffer[ISO9660_EXTENT_SIZE];
|
||||
} iso9660_DIR;
|
||||
|
||||
typedef struct iso9660_FILE {
|
||||
iso9660_VOLUME *volume;
|
||||
int base; /* first extent of the file */
|
||||
int size; /* size of the file */
|
||||
int offset;
|
||||
int current;
|
||||
unsigned char buffer[ISO9660_EXTENT_SIZE];
|
||||
} iso9660_FILE;
|
||||
|
||||
static inline int isonum_721(char *p)
|
||||
{
|
||||
return ((p[0] & 0xff)
|
||||
| ((p[1] & 0xff) << 8));
|
||||
}
|
||||
|
||||
static inline int isonum_723(char *p)
|
||||
{
|
||||
return (isonum_721(p));
|
||||
}
|
||||
|
||||
static inline int isonum_733(char *p)
|
||||
{
|
||||
return ((p[0] & 0xff) | ((p[1] & 0xff) << 8) |
|
||||
((p[2] & 0xff) << 16) | ((p[3] & 0xff) << 24));
|
||||
}
|
||||
|
||||
extern iso9660_VOLUME* iso9660_mount(device_io_t *device);
|
||||
extern int iso9660_umount(iso9660_VOLUME *volume);
|
||||
extern iso9660_DIR* iso9660_opendir(iso9660_VOLUME *, char *name);
|
||||
extern iso9660_FILE* iso9660_open(iso9660_VOLUME *, char* pathname);
|
||||
extern void iso9660_name(int ucs_level, char *buffer, struct iso_directory_record * idr);
|
||||
extern struct iso_directory_record *iso9660_get_root_node(iso9660_VOLUME* volume);
|
||||
extern int iso9660_closedir(iso9660_DIR *dir);
|
||||
extern struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir);
|
||||
extern int iso9660_init(device_io_t *device, filesystem_io_t *fs);
|
||||
extern stream_VOLUME* iso9660_mount(device_io_t *device);
|
||||
extern int iso9660_umount(stream_VOLUME *volume);
|
||||
extern stream_DIR* iso9660_opendir(stream_VOLUME *, char *name);
|
||||
extern stream_FILE* iso9660_open(stream_VOLUME *, char* pathname);
|
||||
extern int iso9660_closedir(stream_DIR *dir);
|
||||
extern struct iso_directory_record *iso9660_readdir(stream_DIR *dir);
|
||||
extern int iso9660_is_directory(struct iso_directory_record * idr);
|
||||
extern struct iso_directory_record* iso9660_get_node(iso9660_VOLUME *volume, struct iso_directory_record *dirnode, char *path);
|
||||
extern ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count);
|
||||
extern void iso9660_close(iso9660_FILE *file);
|
||||
extern int iso9660_lseek(iso9660_FILE *file, long offset, int whence);
|
||||
extern int iso9660_fstat(iso9660_FILE *file, struct stream_stat *buf);
|
||||
extern size_t iso9660_read(stream_FILE *file, void *buf, size_t count);
|
||||
extern void iso9660_close(stream_FILE *file);
|
||||
extern int iso9660_lseek(stream_FILE *file, long offset, int whence);
|
||||
extern int iso9660_fstat(stream_FILE *file, struct stream_stat *buf);
|
||||
extern void iso9660_name(stream_VOLUME *volume, struct iso_directory_record * idr, char *buffer);
|
||||
|
||||
#endif /* __LIBISO9660_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user