diff --git a/libmap/Makefile b/libmap/Makefile index 9370a43..e9e48ea 100644 --- a/libmap/Makefile +++ b/libmap/Makefile @@ -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 diff --git a/libmap/libmap.h b/libmap/libmap.h index 2335288..c62bb02 100644 --- a/libmap/libmap.h +++ b/libmap/libmap.h @@ -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 diff --git a/libmap/map_write_driver.c b/libmap/map_write_driver.c new file mode 100644 index 0000000..0326875 --- /dev/null +++ b/libmap/map_write_driver.c @@ -0,0 +1,30 @@ +#include + +#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; +}