2005-11-12 19:12:13 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-09-05 12:39:22 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@Vivier.EU>
|
2005-11-12 19:12:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "libiso9660.h"
|
2008-04-20 16:29:49 +00:00
|
|
|
#include "iso9660.h"
|
2005-11-12 19:12:13 +00:00
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
static iso9660_DIR* iso9660_opendir_node(iso9660_VOLUME *volume, struct iso_directory_record *node)
|
2005-11-12 19:12:13 +00:00
|
|
|
{
|
|
|
|
iso9660_DIR *dir;
|
|
|
|
|
|
|
|
dir = (iso9660_DIR*)malloc(sizeof(iso9660_DIR));
|
|
|
|
if (dir == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2007-02-24 11:42:45 +00:00
|
|
|
dir->extent = isonum_733((char *)node->extent);
|
|
|
|
dir->len = isonum_733((char *)node->size);
|
2005-11-12 19:12:13 +00:00
|
|
|
dir->index = sizeof (dir->buffer);
|
2005-11-21 22:07:17 +00:00
|
|
|
dir->volume = volume;
|
2005-11-12 19:12:13 +00:00
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct iso_directory_record* idr_new(struct iso_directory_record* idr)
|
|
|
|
{
|
|
|
|
struct iso_directory_record* result;
|
|
|
|
int size = sizeof(*idr) + (int)idr->name_len[0];
|
|
|
|
|
|
|
|
result = (struct iso_directory_record*)malloc(size);
|
|
|
|
memcpy(result, idr, size);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
static struct iso_directory_record * seek_name(iso9660_VOLUME *volume,
|
|
|
|
struct iso_directory_record *idr,
|
|
|
|
char *name)
|
2005-11-12 19:12:13 +00:00
|
|
|
{
|
|
|
|
struct iso_directory_record *result;
|
|
|
|
char name_buf[256];
|
|
|
|
iso9660_DIR *dir;
|
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
dir = iso9660_opendir_node(volume, idr);
|
2005-11-12 19:12:13 +00:00
|
|
|
if (dir == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
while ((idr = iso9660_readdir((stream_DIR*)dir)) != NULL)
|
2005-11-12 19:12:13 +00:00
|
|
|
{
|
2008-04-20 16:29:49 +00:00
|
|
|
iso9660_name((stream_VOLUME*)volume, idr, name_buf);
|
2005-11-12 19:12:13 +00:00
|
|
|
if (strcmp(name, name_buf) == 0)
|
|
|
|
{
|
|
|
|
result = idr_new(idr);
|
2008-04-20 16:29:49 +00:00
|
|
|
iso9660_closedir((stream_DIR*)dir);
|
2005-11-12 19:12:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 16:29:49 +00:00
|
|
|
iso9660_closedir((stream_DIR*)dir);
|
2005-11-12 19:12:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iso_directory_record* iso9660_get_node(
|
2005-11-21 22:07:17 +00:00
|
|
|
iso9660_VOLUME *volume,
|
2005-11-12 19:12:13 +00:00
|
|
|
struct iso_directory_record *dirnode,
|
|
|
|
char *path)
|
|
|
|
{
|
|
|
|
struct iso_directory_record* result;
|
|
|
|
struct iso_directory_record* current;
|
|
|
|
char name[256];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
current = idr_new(dirnode);
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
/* ignore head '/' */
|
|
|
|
|
|
|
|
while (*path && *path == '/')
|
|
|
|
path++;
|
|
|
|
|
|
|
|
if (*path == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* extract first path component */
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (*path && *path != '/')
|
|
|
|
name[i++] = *path++;
|
|
|
|
name[i] = 0;
|
|
|
|
|
|
|
|
/* seek first component in current directory */
|
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
result = seek_name(volume, current, name);
|
2005-11-12 19:12:13 +00:00
|
|
|
if (result == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
free(current);
|
|
|
|
current = result;
|
|
|
|
}
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
stream_DIR* iso9660_opendir(stream_VOLUME *volume, char *name)
|
2005-11-12 19:12:13 +00:00
|
|
|
{
|
|
|
|
iso9660_DIR *dir;
|
|
|
|
struct iso_directory_record *node;
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
node = iso9660_get_root_node((iso9660_VOLUME*)volume);
|
2005-11-12 19:12:13 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
node = iso9660_get_node((iso9660_VOLUME*)volume, node, name);
|
2005-11-12 19:12:13 +00:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
dir = iso9660_opendir_node((iso9660_VOLUME*)volume, node);
|
2005-11-12 19:12:13 +00:00
|
|
|
|
|
|
|
free(node);
|
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
dir->volume = (iso9660_VOLUME*)volume;
|
2005-11-21 22:07:17 +00:00
|
|
|
|
2008-04-20 16:29:49 +00:00
|
|
|
return (stream_DIR*)dir;
|
2005-11-12 19:12:13 +00:00
|
|
|
}
|