change device interface

This commit is contained in:
Laurent Vivier 2005-11-13 19:43:28 +00:00
parent fc3659730a
commit aed2d777a0
10 changed files with 68 additions and 29 deletions

View File

@ -12,7 +12,7 @@ LIBRARY = libiso9660.a
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_read.c iso9660_close.c iso9660_init.c
HEADERS = libiso9660.a

14
libiso9660/iso9660_init.c Normal file
View File

@ -0,0 +1,14 @@
/*
*
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "libiso9660.h"
iso9660_read_t __iso9660_device_read;
void iso9660_init(iso9660_read_t func)
{
__iso9660_device_read = func;
}

View File

@ -16,6 +16,8 @@
static int iso9660_ucs_level = 0;
static struct iso_primary_descriptor *iso9660_volume;
extern iso9660_read_t __iso9660_device_read;
#ifdef DEBUG
void
printchars(s, n)
@ -144,12 +146,9 @@ int iso9660_mount(char* name)
struct iso_directory_record * idr;
int block;
if (iso9660_device_open() == -1)
return -1;
/* read filesystem descriptor */
iso9660_device_read(16, &ipd, sizeof (ipd));
__iso9660_device_read(16, &ipd, sizeof (ipd));
idr = (struct iso_directory_record *)ipd.root_directory_record;
/*
@ -229,7 +228,7 @@ int iso9660_mount(char* name)
nextblock:
block++;
iso9660_device_read(block, jpd, sizeof (*jpd));
__iso9660_device_read(block, jpd, sizeof (*jpd));
}
/*
@ -265,7 +264,7 @@ nextblock:
}
block++;
iso9660_device_read(block, jpd, sizeof (*jpd));
__iso9660_device_read(block, jpd, sizeof (*jpd));
}
/* Unable to find Joliet SVD */
@ -304,7 +303,6 @@ nextblock:
void iso9660_umount(void)
{
free(iso9660_volume);
iso9660_device_close();
}
struct iso_directory_record *iso9660_get_root_node()

View File

@ -9,6 +9,8 @@
#include "libiso9660.h"
extern iso9660_read_t __iso9660_device_read;
ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
{
size_t read = 0;
@ -21,7 +23,7 @@ ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
{
if (file->len <= 0)
return read;
iso9660_device_read(file->extent,
__iso9660_device_read(file->extent,
file->buffer,
sizeof (file->buffer));
file->len -= sizeof (file->buffer);

View File

@ -6,6 +6,8 @@
#include "libiso9660.h"
extern iso9660_read_t __iso9660_device_read;
struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir)
{
struct iso_directory_record *idr;
@ -14,7 +16,7 @@ struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir)
{
if (dir->len <= 0)
return NULL;
iso9660_device_read(dir->extent, dir->buffer, sizeof (dir->buffer));
__iso9660_device_read(dir->extent, dir->buffer, sizeof (dir->buffer));
dir->len -= sizeof (dir->buffer);
dir->extent++;
dir->index = 0;

View File

@ -10,6 +10,8 @@
#include <unistd.h>
#include <linux/iso_fs.h>
typedef void (*iso9660_read_t)(off_t offset, void* buffer, size_t size);
typedef struct iso9660_DIR {
int extent;
int len;
@ -53,10 +55,6 @@ extern struct iso_directory_record* iso9660_get_node(struct iso_directory_record
extern iso9660_FILE* iso9660_open(char* pathname);
extern ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count);
extern void iso9660_close(iso9660_FILE *file);
extern void iso9660_init(iso9660_read_t func);
/* imported function */
extern int iso9660_device_open(void);
extern void iso9660_device_close(void);
extern void iso9660_device_read(off_t offset, void* buffer, size_t size);
#endif /* __LIBISO9660_H__ */

View File

@ -4,23 +4,14 @@
*
*/
#include <libiso9660.h>
#include <sys/types.h>
#include "scsi.h"
#define SECTOR_SIZE (2048)
#define ISO_BLOCKS(X) (((X) / SECTOR_SIZE) + (((X)%SECTOR_SIZE)?1:0))
int iso9660_device_open(void)
{
return 0;
}
void iso9660_device_close(void)
{
}
void iso9660_device_read(off_t offset, void* buffer, size_t size)
void device_read(off_t offset, void* buffer, size_t size)
{
scsi_READ(3, offset, ISO_BLOCKS(size), buffer, size);
}

View File

@ -1,3 +1,9 @@
/*
*
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
@ -8,7 +14,7 @@
static const char *filename = "/dev/cdrom";
static FILE *infile = NULL;
int iso9660_device_open(void)
int device_open(void)
{
infile = fopen(filename, "rb");
if (infile == NULL)
@ -16,13 +22,13 @@ int iso9660_device_open(void)
return 0;
}
void iso9660_device_close(void)
void device_close(void)
{
if (infile)
fclose(infile);
}
void iso9660_device_read(off_t offset, void* buffer, size_t size)
void device_read(off_t offset, void* buffer, size_t size)
{
lseek(fileno(infile), offset << 11, SEEK_SET);
read(fileno(infile), buffer, ISO_BLOCKS(size) << 11);

View File

@ -1,3 +1,9 @@
/*
*
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
@ -8,6 +14,8 @@
#include <libiso9660.h>
#include "device.h"
int main(int argc, char **argv)
{
char *path;
@ -15,6 +23,10 @@ int main(int argc, char **argv)
char buffer[512];
size_t size;
device_open();
iso9660_init(device_read);
if (iso9660_mount(NULL) != 0)
return 1;
@ -36,5 +48,7 @@ int main(int argc, char **argv)
iso9660_umount();
device_close();
return 0;
}

View File

@ -1,3 +1,9 @@
/*
*
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
@ -8,6 +14,8 @@
#include <libiso9660.h>
#include "device.h"
static void list(char *path)
{
char name_buf[256];
@ -35,6 +43,10 @@ int main(int argc, char **argv)
{
char *path;
device_open();
iso9660_init(device_read);
if (iso9660_mount(NULL) != 0)
return -1;
@ -47,5 +59,7 @@ int main(int argc, char **argv)
iso9660_umount();
device_close();
return (0);
}