mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-21 18:30:20 +00:00
libmap: add map_write_driver.c
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
parent
7b836064ad
commit
9b3737d9cc
@ -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
|
||||
|
||||
|
@ -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
30
libmap/map_write_driver.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user