Add map_init.c, use stream_FILE with device->close()

This commit is contained in:
Laurent Vivier 2008-04-20 16:33:20 +00:00
parent 2c64fafc4f
commit 98bd88c574
4 changed files with 34 additions and 2 deletions

View File

@ -30,7 +30,7 @@ SOURCES = map_bootblock_get_type.c map_bootblock_is_valid.c \
map_set_bootinfo.c map_set_driver_info.c map_set_driver_number.c \
map_set_partition_name.c map_set_partition_type.c map_set_startup.c \
map_write.c map_block0_write.c map_read_sector.c \
map_write_sector.c map_get_blocksize.c
map_write_sector.c map_get_blocksize.c map_init.c
HEADERS = libmap.h

View File

@ -142,6 +142,7 @@ enum {
#define FIRST_LEVEL_SIZE (FLOPPY_SECTOR_SIZE * 2)
#define BOOTBLOCK_SIZE (FLOPPY_SECTOR_SIZE * 2)
extern int map_init(device_io_t *device, int partition);
extern map_t* map_open(device_io_t *device);
extern void map_close(map_t *map);
extern int map_get_number(map_t *map);

View File

@ -11,7 +11,7 @@
void map_close(map_t *map)
{
map->device->close(map->device);
map->device->close((stream_FILE*)map->device);
free(map->device);
free(map);
}

31
libmap/map_init.c Normal file
View File

@ -0,0 +1,31 @@
/*
*
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include "libmap.h"
int map_init(device_io_t *device, int partition)
{
int ret;
map_t *map;
map = map_open(device);
if (map == NULL)
return -1;
ret = map_read(map, partition);
if (ret == -1)
{
map_close(map);
return -1;
}
device->data = map;
device->read_sector = (stream_read_sector_t)map_read_sector;
device->close = (stream_close_t)map_close;
device->get_blocksize = (stream_get_blocksize_t)map_get_blocksize;
return 0;
}