From 628d40d9579ef33635e8a13d3a5cd565e09c5708 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 20 Sep 2006 21:47:43 +0000 Subject: [PATCH] add emile_first_set_param_scsi_extents --- libemile/Makefile | 3 +- libemile/emile_first_set_param_scsi_extents.c | 66 +++++++++++++++++++ libemile/libemile.h | 3 + 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 libemile/emile_first_set_param_scsi_extents.c diff --git a/libemile/Makefile b/libemile/Makefile index e45be21..492abf5 100644 --- a/libemile/Makefile +++ b/libemile/Makefile @@ -39,7 +39,8 @@ SOURCES = emile_block0_write.c emile_checksum.c emile_first_get_param.c \ emile_second_set_configuration.c emile_second_get_next_property.c \ emile_second_get_property.c emile_second_set_property.c \ emile_second_remove_property.c emile_second_create_mapfile.c \ - emile_second_set_param.c emile_second_get_param.c + emile_second_set_param.c emile_second_get_param.c \ + emile_first_set_param_scsi_extents.c HEADERS = emile.h libemile.h partition.h bootblock.h diff --git a/libemile/emile_first_set_param_scsi_extents.c b/libemile/emile_first_set_param_scsi_extents.c new file mode 100644 index 0000000..6d9a524 --- /dev/null +++ b/libemile/emile_first_set_param_scsi_extents.c @@ -0,0 +1,66 @@ +static __attribute__((used)) char* rcsid = "$CVSHeader$"; +/* + * + * (c) 2004-2006 Laurent Vivier + * + */ + +#include +#include +#include +#include +#include +#include + +#include "libemile.h" +#include "emile.h" + +#define BLOCK_SIZE 512 /* FIXME: should ask the disk driver */ + + +int emile_first_set_param_scsi_extents( int fd, int drive_num, int second_offset, int size) +{ + int fd; + int ret; + char first[1024]; + int current; + unsigned short max_blocks; + int location; + + location = lseek(fd, 0, SEEK_CUR); + if (location == -1) + return EEMILE_CANNOT_READ_FIRST; + + ret = read(fd, first, 1024); + if (ret == -1) + return EEMILE_CANNOT_READ_FIRST; + + max_blocks = read_short((u_int16_t*)&first[1022]) / 6; + + write_short((u_int16_t*)&first[1014], BLOCK_SIZE); + write_short((u_int16_t*)&first[1016], drive_num); + + write_long((u_int32_t*)&first[1018], 0); + current = 1014; + + current -= 2; + write_short((u_int16_t*)&first[current], (size + BLOCK_SIZE - 1) / BLOCK_SIZE); + current -= 4; + write_long((u_int32_t*)&first[current], second_offset); + + /* mark end of blocks list */ + current -= 2; + write_short((u_int16_t*)(&first[current]), 0); + /* set second level size */ + write_long((u_int32_t*)&first[1018], (size + BLOCK_SIZE - 1) / BLOCK_SIZE * BLOCK_SIZE); + + ret = lseek(fd, location, SEEK_SET); + if (ret != 0) + return EEMILE_CANNOT_WRITE_FIRST; + + ret = write(fd, first, 1024); + if (ret == -1) + return EEMILE_CANNOT_WRITE_FIRST; + + return 0; +} diff --git a/libemile/libemile.h b/libemile/libemile.h index a31ec8a..324c109 100644 --- a/libemile/libemile.h +++ b/libemile/libemile.h @@ -78,6 +78,9 @@ extern int emile_first_set_param(int fd, unsigned short tune_mask, extern int emile_first_get_param(int fd, int *drive_num, int *second_offset, int *second_size); extern int emile_first_set_param_scsi(int fd, char *second_name); +extern int emile_first_set_param_scsi_extents(int fd, + int drive_num, int second_offset, + int second_size); struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfile, char* kernel); extern int emile_is_url(char *path); extern int emile_floppy_create_image(char* first_level, char* second_level,