EMILE/libcontainer/container_open.c

52 lines
1020 B
C
Raw Permalink Normal View History

2005-12-01 22:14:27 +00:00
/*
*
* (c) 2005 Laurent Vivier <Laurent@Vivier.EU>
2005-12-01 22:14:27 +00:00
*
*/
2005-12-02 00:49:11 +00:00
#include <stdio.h>
2005-12-01 22:14:27 +00:00
#include <stdlib.h>
#include "libcontainer.h"
#include "container.h"
2005-12-01 22:14:27 +00:00
stream_FILE *container_open(stream_VOLUME *volume, char *path)
2005-12-01 22:14:27 +00:00
{
container_FILE *file;
device_io_t *device = (device_io_t*)volume;
2005-12-01 22:14:27 +00:00
int block_size = device->get_blocksize(device->data);
unsigned long first, nbblocs;
int ret;
first = strtol(path, &path, 0);
if (*path != ',')
return NULL;
path++;
nbblocs = strtol(path, &path, 0);
if (*path != 0)
return NULL;
file = (container_FILE *)malloc(sizeof(container_FILE) + block_size);
if (file == NULL)
return NULL;
2005-12-02 00:49:11 +00:00
file->container = (struct emile_container*)malloc(block_size * nbblocs);
2005-12-01 22:14:27 +00:00
if (file->container == NULL)
{
free(file);
return NULL;
}
ret = device->read_sector(device->data, first, file->container, block_size * nbblocs);
if (ret == -1)
{
free(file->container);
free(file);
}
file->offset = 0;
2005-12-02 00:49:11 +00:00
file->device = device;
2005-12-01 22:14:27 +00:00
file->current_block = 0;
return (stream_FILE*)file;
2005-12-01 22:14:27 +00:00
}