libmap: add map_write_driver.c

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Laurent Vivier 2015-11-10 00:16:50 +01:00
parent 7b836064ad
commit 9b3737d9cc
3 changed files with 33 additions and 1 deletions

View File

@ -30,7 +30,8 @@ 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_read_driver.c
map_write_sector.c map_get_blocksize.c map_init.c map_read_driver.c \
map_write_driver.c
HEADERS = libmap.h

View File

@ -187,4 +187,5 @@ 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);
extern int map_write_driver(map_t *map, int driver_number, char *driver);
#endif

30
libmap/map_write_driver.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdlib.h>
#include "libmap.h"
/* the size information in DrvInfo must be the same as the driver size in memory */
int map_write_driver(map_t *map, int driver_number, char *driver)
{
int block, size;
int blocksize;
int ret;
if (driver == NULL)
return -1;
if (!map_is_valid(map))
return -1;
blocksize = map_get_blocksize(map);
if (driver_number > map_get_driver_number(map))
return -1;
block = read_long((u_int32_t*)&map->drivers.DrvInfo[driver_number].Block);
size = read_short((u_int16_t*)&map->drivers.DrvInfo[driver_number].Size);
ret = map->device->write_sector(map->device->data, block, driver, size * blocksize);
return ret;
}