mirror of
https://github.com/vivier/EMILE.git
synced 2025-04-07 12:38:58 +00:00
Add iso9660_VOLUME
This commit is contained in:
parent
48c114c2f2
commit
8a104ca7ca
@ -6,15 +6,15 @@ TOP = $(shell pwd)
|
||||
VPATH=$(TOP)
|
||||
|
||||
TARGET = native
|
||||
CFLAGS = -nostdlib -nodefaultlibs -Wall -Werror -Wno-multichar -fpic
|
||||
CPPFLAGS =
|
||||
CFLAGS = -nostdlib -nodefaultlibs -Wall -Werror -Wno-multichar -fpic -g
|
||||
CPPFLAGS = -I$(TOP)/../libstream
|
||||
|
||||
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_init.c \
|
||||
iso9660_read.c iso9660_close.c \
|
||||
iso9660_lseek.c
|
||||
|
||||
HEADERS = libiso9660.h
|
||||
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (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;
|
||||
}
|
@ -8,8 +8,6 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
extern iso9660_read_t __iso9660_device_read;
|
||||
|
||||
int iso9660_lseek(iso9660_FILE *file, long offset, int whence)
|
||||
{
|
||||
long new_offset;
|
||||
|
@ -13,11 +13,6 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
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)
|
||||
@ -81,7 +76,7 @@ void print_info(struct iso_primary_descriptor *ipd)
|
||||
}
|
||||
#endif
|
||||
|
||||
void iso9660_name(char *buffer, struct iso_directory_record * idr)
|
||||
void iso9660_name(int ucs_level, char *buffer, struct iso_directory_record * idr)
|
||||
{
|
||||
int j;
|
||||
unsigned char uh, ul, uc;
|
||||
@ -92,7 +87,7 @@ void iso9660_name(char *buffer, struct iso_directory_record * idr)
|
||||
else if (idr->name_len[0] == 1 && idr->name[0] == 1)
|
||||
strcpy(buffer, "..");
|
||||
else {
|
||||
switch (iso9660_ucs_level) {
|
||||
switch (ucs_level) {
|
||||
case 3:
|
||||
case 2:
|
||||
case 1:
|
||||
@ -139,16 +134,18 @@ void iso9660_name(char *buffer, struct iso_directory_record * idr)
|
||||
}
|
||||
}
|
||||
|
||||
int iso9660_mount(char* name)
|
||||
iso9660_VOLUME *iso9660_mount(device_io_t *device)
|
||||
{
|
||||
iso9660_VOLUME* volume;
|
||||
struct iso_primary_descriptor *jpd;
|
||||
struct iso_primary_descriptor ipd;
|
||||
struct iso_directory_record * idr;
|
||||
int block;
|
||||
int ucs_level;
|
||||
|
||||
/* read filesystem descriptor */
|
||||
|
||||
__iso9660_device_read(16, &ipd, sizeof (ipd));
|
||||
device->read_sector(device->data, 16, &ipd, sizeof (ipd));
|
||||
idr = (struct iso_directory_record *)ipd.root_directory_record;
|
||||
|
||||
/*
|
||||
@ -165,7 +162,7 @@ int iso9660_mount(char* name)
|
||||
(strncmp(&((char *)&ipd)[9], "CDROM", 5) == 0) &&
|
||||
(((char *)&ipd)[14] == 1)) {
|
||||
printf("Incompatible format: High Sierra format\n");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -182,7 +179,7 @@ int iso9660_mount(char* name)
|
||||
(strncmp(ipd.id, ISO_STANDARD_ID, sizeof (ipd.id)) != 0) ||
|
||||
(ipd.version[0] != 1)) {
|
||||
printf("Not ISO 9660 format\n");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -196,7 +193,7 @@ int iso9660_mount(char* name)
|
||||
jpd = (struct iso_primary_descriptor *)
|
||||
malloc(sizeof(struct iso_primary_descriptor));
|
||||
if (jpd == NULL)
|
||||
return -1;
|
||||
return NULL;
|
||||
|
||||
memcpy(jpd, &ipd, sizeof (ipd));
|
||||
while ((u_int8_t)jpd->type[0] != ISO_VD_END) {
|
||||
@ -228,7 +225,7 @@ int iso9660_mount(char* name)
|
||||
|
||||
nextblock:
|
||||
block++;
|
||||
__iso9660_device_read(block, jpd, sizeof (*jpd));
|
||||
device->read_sector(device->data, block, jpd, sizeof (*jpd));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -244,7 +241,7 @@ nextblock:
|
||||
if ((ipd.type[0] != ISO_VD_PRIMARY) ||
|
||||
(strncmp(ipd.id, ISO_STANDARD_ID, sizeof (ipd.id)) != 0) ||
|
||||
(ipd.version[0] != 1))
|
||||
return -1;
|
||||
return NULL;
|
||||
|
||||
block = 16;
|
||||
memcpy(jpd, &ipd, sizeof (ipd));
|
||||
@ -264,48 +261,58 @@ nextblock:
|
||||
}
|
||||
|
||||
block++;
|
||||
__iso9660_device_read(block, jpd, sizeof (*jpd));
|
||||
device->read_sector(device->data, block, jpd, sizeof (*jpd));
|
||||
}
|
||||
|
||||
/* Unable to find Joliet SVD */
|
||||
|
||||
if (((unsigned char) jpd->type[0] == ISO_VD_END)) {
|
||||
free(jpd);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (jpd->unused3[2]) {
|
||||
case '@':
|
||||
iso9660_ucs_level = 1;
|
||||
ucs_level = 1;
|
||||
break;
|
||||
case 'C':
|
||||
iso9660_ucs_level = 2;
|
||||
ucs_level = 2;
|
||||
break;
|
||||
case 'E':
|
||||
iso9660_ucs_level = 3;
|
||||
ucs_level = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (iso9660_ucs_level > 3) {
|
||||
/* Don't know what iso9660_ucs_level */
|
||||
if (ucs_level > 3) {
|
||||
/* Don't know what ucs_level */
|
||||
free(jpd);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (jpd->unused3[3] == ' ')
|
||||
printf("Warning: Joliet escape sequence uses illegal space at offset 3\n");
|
||||
|
||||
iso9660_volume = jpd;
|
||||
volume = (iso9660_VOLUME*)malloc(sizeof(iso9660_VOLUME));
|
||||
if (volume == NULL)
|
||||
return NULL;
|
||||
|
||||
volume->descriptor = jpd;
|
||||
volume->ucs_level = ucs_level;
|
||||
volume->device = device;
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
int iso9660_umount(iso9660_VOLUME* volume)
|
||||
{
|
||||
if (volume == NULL)
|
||||
return -1;
|
||||
free(volume->descriptor);
|
||||
free(volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void iso9660_umount(void)
|
||||
struct iso_directory_record *iso9660_get_root_node(iso9660_VOLUME* volume)
|
||||
{
|
||||
free(iso9660_volume);
|
||||
}
|
||||
|
||||
struct iso_directory_record *iso9660_get_root_node()
|
||||
{
|
||||
return (struct iso_directory_record *)iso9660_volume->root_directory_record;
|
||||
return (struct iso_directory_record *)volume->descriptor->root_directory_record;
|
||||
}
|
||||
|
@ -8,17 +8,17 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
iso9660_FILE* iso9660_open(char* pathname)
|
||||
iso9660_FILE* iso9660_open(iso9660_VOLUME *volume, char* pathname)
|
||||
{
|
||||
struct iso_directory_record *root;
|
||||
struct iso_directory_record *idr;
|
||||
iso9660_FILE *file;
|
||||
|
||||
root = iso9660_get_root_node();
|
||||
root = iso9660_get_root_node(volume);
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
||||
idr = iso9660_get_node(root, pathname);
|
||||
idr = iso9660_get_node(volume, root, pathname);
|
||||
if (idr == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -30,6 +30,7 @@ iso9660_FILE* iso9660_open(char* pathname)
|
||||
file->size = isonum_733((unsigned char *)idr->size);
|
||||
file->offset = 0;
|
||||
file->current = -1;
|
||||
file->volume = volume;
|
||||
|
||||
free(idr);
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
static iso9660_DIR* iso9660_opendir_node(struct iso_directory_record *node)
|
||||
static iso9660_DIR* iso9660_opendir_node(iso9660_VOLUME *volume, struct iso_directory_record *node)
|
||||
{
|
||||
iso9660_DIR *dir;
|
||||
|
||||
@ -20,6 +20,7 @@ static iso9660_DIR* iso9660_opendir_node(struct iso_directory_record *node)
|
||||
dir->extent = isonum_733((unsigned char *)node->extent);
|
||||
dir->len = isonum_733((unsigned char *)node->size);
|
||||
dir->index = sizeof (dir->buffer);
|
||||
dir->volume = volume;
|
||||
|
||||
return dir;
|
||||
}
|
||||
@ -35,20 +36,21 @@ static struct iso_directory_record* idr_new(struct iso_directory_record* idr)
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct iso_directory_record * seek_name(struct iso_directory_record *idr,
|
||||
char *name)
|
||||
static struct iso_directory_record * seek_name(iso9660_VOLUME *volume,
|
||||
struct iso_directory_record *idr,
|
||||
char *name)
|
||||
{
|
||||
struct iso_directory_record *result;
|
||||
char name_buf[256];
|
||||
iso9660_DIR *dir;
|
||||
|
||||
dir = iso9660_opendir_node(idr);
|
||||
dir = iso9660_opendir_node(volume, idr);
|
||||
if (dir == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((idr = iso9660_readdir(dir)) != NULL)
|
||||
{
|
||||
iso9660_name(name_buf, idr);
|
||||
iso9660_name(volume->ucs_level, name_buf, idr);
|
||||
if (strcmp(name, name_buf) == 0)
|
||||
{
|
||||
result = idr_new(idr);
|
||||
@ -61,6 +63,7 @@ static struct iso_directory_record * seek_name(struct iso_directory_record *idr,
|
||||
}
|
||||
|
||||
struct iso_directory_record* iso9660_get_node(
|
||||
iso9660_VOLUME *volume,
|
||||
struct iso_directory_record *dirnode,
|
||||
char *path)
|
||||
{
|
||||
@ -89,7 +92,7 @@ struct iso_directory_record* iso9660_get_node(
|
||||
|
||||
/* seek first component in current directory */
|
||||
|
||||
result = seek_name(current, name);
|
||||
result = seek_name(volume, current, name);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -99,22 +102,24 @@ struct iso_directory_record* iso9660_get_node(
|
||||
return current;
|
||||
}
|
||||
|
||||
iso9660_DIR* iso9660_opendir(char *name)
|
||||
iso9660_DIR* iso9660_opendir(iso9660_VOLUME *volume, char *name)
|
||||
{
|
||||
iso9660_DIR *dir;
|
||||
struct iso_directory_record *node;
|
||||
|
||||
node = iso9660_get_root_node();
|
||||
node = iso9660_get_root_node(volume);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
node = iso9660_get_node(node, name);
|
||||
node = iso9660_get_node(volume, node, name);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
dir = iso9660_opendir_node(node);
|
||||
dir = iso9660_opendir_node(volume, node);
|
||||
|
||||
free(node);
|
||||
|
||||
dir->volume = volume;
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#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;
|
||||
@ -41,8 +39,9 @@ ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
|
||||
|
||||
part = extents_nb * ISO9660_EXTENT_SIZE;
|
||||
|
||||
__iso9660_device_read(offset_extent,
|
||||
buf + read, part);
|
||||
file->volume->device->read_sector(file->volume->device->data,
|
||||
offset_extent,
|
||||
buf + read, part);
|
||||
file->offset += part;
|
||||
count -= part;
|
||||
read += part;
|
||||
@ -51,9 +50,10 @@ ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
|
||||
}
|
||||
|
||||
file->current = offset_extent;
|
||||
__iso9660_device_read(offset_extent,
|
||||
file->buffer,
|
||||
ISO9660_EXTENT_SIZE);
|
||||
file->volume->device->read_sector(file->volume->device->data,
|
||||
offset_extent,
|
||||
file->buffer,
|
||||
ISO9660_EXTENT_SIZE);
|
||||
}
|
||||
|
||||
part = ISO9660_EXTENT_SIZE - offset_index;
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "libiso9660.h"
|
||||
|
||||
extern iso9660_read_t __iso9660_device_read;
|
||||
|
||||
struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir)
|
||||
{
|
||||
struct iso_directory_record *idr;
|
||||
@ -16,7 +14,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));
|
||||
dir->volume->device->read_sector(dir->volume->device->data, dir->extent, dir->buffer, sizeof (dir->buffer));
|
||||
dir->len -= sizeof (dir->buffer);
|
||||
dir->extent++;
|
||||
dir->index = 0;
|
||||
|
@ -10,11 +10,18 @@
|
||||
#include <unistd.h>
|
||||
#include <linux/iso_fs.h>
|
||||
|
||||
typedef void (*iso9660_read_t)(off_t offset, void* buffer, size_t size);
|
||||
#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;
|
||||
@ -22,6 +29,7 @@ typedef struct iso9660_DIR {
|
||||
} iso9660_DIR;
|
||||
|
||||
typedef struct iso9660_FILE {
|
||||
iso9660_VOLUME *volume;
|
||||
int base; /* first extent of the file */
|
||||
int size; /* size of the file */
|
||||
int offset;
|
||||
@ -46,19 +54,18 @@ static inline int isonum_733(char *p)
|
||||
((p[2] & 0xff) << 16) | ((p[3] & 0xff) << 24));
|
||||
}
|
||||
|
||||
extern int iso9660_mount(char* name);
|
||||
extern void iso9660_name(char *buffer, struct iso_directory_record * idr);
|
||||
extern void iso9660_umount(void);
|
||||
extern struct iso_directory_record *iso9660_get_root_node(void);
|
||||
extern iso9660_DIR* iso9660_opendir(char *name);
|
||||
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_is_directory(struct iso_directory_record * idr);
|
||||
extern struct iso_directory_record* iso9660_get_node(struct iso_directory_record *dirnode, char *path);
|
||||
extern iso9660_FILE* iso9660_open(char* pathname);
|
||||
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 void iso9660_init(iso9660_read_t func);
|
||||
extern int iso9660_fseek(iso9660_FILE *file, long offset, int whence);
|
||||
extern int iso9660_lseek(iso9660_FILE *file, long offset, int whence);
|
||||
|
||||
#endif /* __LIBISO9660_H__ */
|
||||
|
@ -13,21 +13,25 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <libiso9660.h>
|
||||
#include <libstream.h>
|
||||
|
||||
#include "device.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *path;
|
||||
device_io_t device;
|
||||
iso9660_FILE* file;
|
||||
iso9660_VOLUME *volume;
|
||||
char buffer[512];
|
||||
size_t size;
|
||||
|
||||
device_open();
|
||||
device.data = device_open();
|
||||
device.read_sector = (stream_read_sector_t)device_read_sector;
|
||||
device.close = (stream_close_t)device_close;
|
||||
|
||||
iso9660_init(device_read);
|
||||
|
||||
if (iso9660_mount(NULL) != 0)
|
||||
volume = iso9660_mount(&device);
|
||||
if (volume == NULL)
|
||||
return 1;
|
||||
|
||||
if (argc > 1)
|
||||
@ -35,7 +39,7 @@ int main(int argc, char **argv)
|
||||
else
|
||||
path = "/";
|
||||
|
||||
file = iso9660_open(path);
|
||||
file = iso9660_open(volume, path);
|
||||
if (file == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s not found\n", path);
|
||||
@ -46,9 +50,9 @@ int main(int argc, char **argv)
|
||||
write(STDOUT_FILENO, buffer, size);
|
||||
iso9660_close(file);
|
||||
|
||||
iso9660_umount();
|
||||
iso9660_umount(volume);
|
||||
|
||||
device_close();
|
||||
device_close(device.data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,19 +16,19 @@
|
||||
|
||||
#include "device.h"
|
||||
|
||||
static void list(char *path)
|
||||
static void list(iso9660_VOLUME *volume, char *path)
|
||||
{
|
||||
char name_buf[256];
|
||||
iso9660_DIR *dir;
|
||||
struct iso_directory_record *idr;
|
||||
|
||||
dir = iso9660_opendir(path);
|
||||
dir = iso9660_opendir(volume, path);
|
||||
if (dir == NULL)
|
||||
return;
|
||||
|
||||
while ((idr = iso9660_readdir(dir)) != NULL)
|
||||
{
|
||||
iso9660_name(name_buf, idr);
|
||||
iso9660_name(volume->ucs_level, name_buf, idr);
|
||||
|
||||
if (iso9660_is_directory(idr)) {
|
||||
printf("%s/\n", name_buf);
|
||||
@ -42,12 +42,15 @@ static void list(char *path)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *path;
|
||||
device_io_t device;
|
||||
iso9660_VOLUME *volume;
|
||||
|
||||
device_open();
|
||||
device.data = device_open();
|
||||
device.read_sector = (stream_read_sector_t)device_read_sector;
|
||||
device.close = (stream_close_t)device_close;
|
||||
|
||||
iso9660_init(device_read);
|
||||
|
||||
if (iso9660_mount(NULL) != 0)
|
||||
volume = iso9660_mount(&device);
|
||||
if (volume == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc > 1)
|
||||
@ -55,11 +58,11 @@ int main(int argc, char **argv)
|
||||
else
|
||||
path = "/";
|
||||
|
||||
list(path);
|
||||
list(volume, path);
|
||||
|
||||
iso9660_umount();
|
||||
iso9660_umount(volume);
|
||||
|
||||
device_close();
|
||||
device_close(device.data);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user