2007-10-02 14:21:34 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "libmap.h"
|
|
|
|
|
2007-10-09 19:02:42 +00:00
|
|
|
map_t* map_open(device_io_t *device)
|
2007-10-02 14:21:34 +00:00
|
|
|
{
|
|
|
|
map_t *map;
|
|
|
|
int ret;
|
2007-10-10 16:41:31 +00:00
|
|
|
int blocksize = device->get_blocksize(device);
|
2007-10-02 14:21:34 +00:00
|
|
|
|
|
|
|
ASSERT_DD(printf("INTERNAL ERROR: Bad Block 0 size structure\n");
|
|
|
|
return NULL;)
|
|
|
|
ASSERT_P(printf("INTERNAL ERROR: Bad Partition size structure\n");
|
|
|
|
return NULL;)
|
|
|
|
|
|
|
|
map = (map_t*)malloc(sizeof(map_t));
|
|
|
|
if (map == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2007-10-10 20:49:55 +00:00
|
|
|
map->device = malloc(sizeof(device_io_t));
|
|
|
|
if (map->device == NULL)
|
|
|
|
{
|
|
|
|
free(map);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(map->device, device, sizeof(device_io_t));
|
2007-10-02 14:21:34 +00:00
|
|
|
|
2007-10-10 16:41:31 +00:00
|
|
|
ret = device->read_sector(map->device->data, 0,
|
2007-10-09 19:02:42 +00:00
|
|
|
&map->drivers, sizeof(map->drivers));
|
2007-10-02 14:21:34 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
free(map);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-10 16:41:31 +00:00
|
|
|
ret = device->read_sector(map->device->data, sizeof(map->drivers) / blocksize,
|
2007-10-09 19:02:42 +00:00
|
|
|
&map->partition, sizeof(map->partition));
|
2007-10-02 14:21:34 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
free(map);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
map->current = 0;
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|