libmap: add map_update_checksum.c

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Laurent Vivier 2015-11-10 00:36:28 +01:00
parent 9b3737d9cc
commit 02fdcb3eb4
3 changed files with 38 additions and 1 deletions

View File

@ -31,7 +31,7 @@ SOURCES = map_bootblock_get_type.c map_bootblock_is_valid.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_driver.c
map_write_driver.c map_update_checksum.c
HEADERS = libmap.h

View File

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

View File

@ -0,0 +1,36 @@
#include <stdlib.h>
#include "libmap.h"
int map_update_checksum(map_t *map, int driver_number)
{
char *driver;
int blocksize;
int block;
int part;
int length, checksum;
int ret;
driver = map_read_driver(map, driver_number);
if (driver == NULL)
return -1;
blocksize = map_get_blocksize(map);
block = read_long((u_int32_t*)&map->drivers.DrvInfo[driver_number].Block);
part = map_seek_driver_partition(map, block * blocksize / 512);
map_read(map, part);
length = read_long((u_int32_t*)&map->partition.BootSize);
checksum = map_checksum((unsigned char*)driver, length);
write_long((u_int32_t*)&map->partition.BootCksum, checksum);
free(driver);
ret = map_write(map, part);
if (ret != part)
return -1;
return 0;
}