libmap: add map_read_driver.c

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Laurent Vivier 2015-11-10 00:11:48 +01:00
parent 081c7f96ee
commit 7b836064ad
3 changed files with 36 additions and 1 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_checksum.c \
map_write_sector.c map_get_blocksize.c map_init.c
map_write_sector.c map_get_blocksize.c map_init.c map_read_driver.c
HEADERS = libmap.h

View File

@ -186,4 +186,5 @@ extern int map_write_sector(map_t* map, off_t block, char *buffer, size_t nb);
extern int map_get_blocksize(map_t *map);
extern unsigned short map_checksum(unsigned char *addr, unsigned int length);
extern unsigned short map_checksum_ATA(unsigned char *addr, unsigned int length);
extern char *map_read_driver(map_t *map, int driver_number);
#endif

34
libmap/map_read_driver.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdlib.h>
#include "libmap.h"
char *map_read_driver(map_t *map, int driver_number)
{
int block, size;
int blocksize;
char *driver;
int ret;
if (!map_is_valid(map))
return NULL;
blocksize = map_get_blocksize(map);
if (driver_number > map_get_driver_number(map))
return NULL;
block = read_long((u_int32_t*)&map->drivers.DrvInfo[driver_number].Block);
size = read_short((u_int16_t*)&map->drivers.DrvInfo[driver_number].Size);
driver = malloc(size * blocksize);
if (driver == NULL)
return NULL;
ret = map->device->read_sector(map->device->data, block, driver, size * blocksize);
if (ret == -1) {
free(driver);
driver = NULL;
}
return driver;
}