change interface of emile_second_create_mapfile()

This commit is contained in:
Laurent Vivier 2005-12-01 22:16:06 +00:00
parent ee35f84292
commit 364c09f440
4 changed files with 20 additions and 12 deletions

View File

@ -39,7 +39,7 @@ static int get_scsi_path(int fd, unsigned char *host, unsigned char *channel,
return ret; return ret;
} }
static int get_device_info(int fd, int *id, unsigned long *first_block, static int get_device_info(int fd, short *id, unsigned long *first_block,
int *block_size) int *block_size)
{ {
int ret; int ret;
@ -101,11 +101,11 @@ static int get_device_info(int fd, int *id, unsigned long *first_block,
return -1; \ return -1; \
} }
int emile_scsi_create_container(int fd, struct emile_container* container, int maxblocks) int emile_scsi_create_container(int fd, short *unit_id,
struct emile_container* container, int maxblocks)
{ {
int ret; int ret;
struct stat st; struct stat st;
int id;
unsigned long first_block; unsigned long first_block;
int sector_size; int sector_size;
int block_size; int block_size;
@ -123,12 +123,11 @@ int emile_scsi_create_container(int fd, struct emile_container* container, int m
return -1; return -1;
} }
ret = get_device_info(fd, &id, &first_block, &sector_size); ret = get_device_info(fd, unit_id, &first_block, &sector_size);
if (ret != 0) if (ret != 0)
return -1; return -1;
container->size = st.st_size; container->size = st.st_size;
container->unit_id = (u_int16_t)id;
/* get filesystem block size */ /* get filesystem block size */

View File

@ -14,11 +14,12 @@
#define MAPFILE_SIZE 4096 #define MAPFILE_SIZE 4096
struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel) struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfile, char* kernel)
{ {
struct emile_container *container; struct emile_container *container;
int fd; int fd;
int ret; int ret;
short unit_id_map;
container = (struct emile_container *)malloc(MAPFILE_SIZE); container = (struct emile_container *)malloc(MAPFILE_SIZE);
if (container == NULL) if (container == NULL)
@ -37,7 +38,7 @@ struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel)
return NULL; return NULL;
} }
ret = emile_scsi_create_container(fd, container, ret = emile_scsi_create_container(fd, &unit_id_map, container,
(MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block)); (MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block));
close(fd); close(fd);
@ -79,7 +80,7 @@ struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel)
return NULL; return NULL;
} }
ret = emile_scsi_create_container(fd, container, ret = emile_scsi_create_container(fd, unit_id, container,
(MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block)); (MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block));
close(fd); close(fd);
@ -90,6 +91,13 @@ struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel)
return NULL; return NULL;
} }
if (unit_id_map != *unit_id)
{
fprintf(stderr, "ERROR: map file must be on the same disk as the file to map\n");
free(container);
return NULL;
}
if (container->size != MAPFILE_SIZE) if (container->size != MAPFILE_SIZE)
{ {
fprintf(stderr, "ERROR: map file size is bad (%d)\n", container->size); fprintf(stderr, "ERROR: map file size is bad (%d)\n", container->size);

View File

@ -71,11 +71,11 @@ 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, extern int emile_first_get_param(int fd, int *drive_num, int *second_offset,
int *second_size); int *second_size);
extern int emile_first_set_param_scsi(int fd, char *second_name); extern int emile_first_set_param_scsi(int fd, char *second_name);
struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel); struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfile, char* kernel);
extern int emile_floppy_create_image(char* first_level, char* second_level, extern int emile_floppy_create_image(char* first_level, char* second_level,
char* kernel_image, char* ramdisk, char* kernel_image, char* ramdisk,
char* image); char* image);
extern int emile_scsi_create_container(int fd, extern int emile_scsi_create_container(int fd, short *unit_id,
struct emile_container* container, int maxbloks); struct emile_container* container, int maxbloks);
extern emile_map_t* emile_map_open(char* dev, int flags); extern emile_map_t* emile_map_open(char* dev, int flags);
extern void emile_map_close(emile_map_t *map); extern void emile_map_close(emile_map_t *map);

View File

@ -689,9 +689,10 @@ int main(int argc, char **argv)
{ {
char *configuration; char *configuration;
struct emile_container *container; struct emile_container *container;
short unit_id;
char map_info[64]; char map_info[64];
container = emile_second_create_mapfile(map_path, kernel_path); container = emile_second_create_mapfile(&unit_id, map_path, kernel_path);
if (container == NULL) if (container == NULL)
{ {
fprintf(stderr, fprintf(stderr,
@ -707,7 +708,7 @@ int main(int argc, char **argv)
/* set kernel info */ /* set kernel info */
sprintf(map_info, "container:(sd%d)0x%x,0x%x", container->unit_id, sprintf(map_info, "container:(sd%d)0x%x,0x%x", unit_id,
container->blocks[0].offset, container->blocks[0].count); container->blocks[0].offset, container->blocks[0].count);
emile_second_set_property(configuration, "kernel", map_info); emile_second_set_property(configuration, "kernel", map_info);