mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-22 10:29:31 +00:00
libmap: add map_read_driver.c
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
parent
081c7f96ee
commit
7b836064ad
@ -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_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_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.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
|
HEADERS = libmap.h
|
||||||
|
|
||||||
|
@ -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 int map_get_blocksize(map_t *map);
|
||||||
extern unsigned short map_checksum(unsigned char *addr, unsigned int length);
|
extern unsigned short map_checksum(unsigned char *addr, unsigned int length);
|
||||||
extern unsigned short map_checksum_ATA(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
|
#endif
|
||||||
|
34
libmap/map_read_driver.c
Normal file
34
libmap/map_read_driver.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user