From 07d6ceb8ba85fe1cf459dd4b4eba102afa65533b Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 2 Dec 2005 01:17:30 +0000 Subject: [PATCH] mapfile size is the size of the filesystem blocksize --- libemile/emile_second_create_mapfile.c | 41 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/libemile/emile_second_create_mapfile.c b/libemile/emile_second_create_mapfile.c index 579ee6f..26f9634 100644 --- a/libemile/emile_second_create_mapfile.c +++ b/libemile/emile_second_create_mapfile.c @@ -6,40 +6,51 @@ #include #include +#include #include #include #include +#include #include "libemile.h" -#define MAPFILE_SIZE 4096 - struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfile, char* kernel) { struct emile_container *container; int fd; int ret; short unit_id_map; - - container = (struct emile_container *)malloc(MAPFILE_SIZE); - if (container == NULL) - { - fprintf(stderr, "ERROR: cannot allocate memory for container\n"); - return NULL; - } + int block_size; /* create container of the kernel */ fd = open(kernel, O_RDONLY); if (fd == -1) { - free(container); fprintf(stderr, "ERROR: cannot open kernel\n"); return NULL; } + /* get filesystem block size */ + + ret = ioctl(fd, FIGETBSZ, &block_size); + if (ret != 0) { + close(fd); + perror("ioctl(FIGETBSZ)"); + return NULL; + } + + container = (struct emile_container *)malloc(block_size); + if (container == NULL) + { + fprintf(stderr, "ERROR: cannot allocate memory for container\n"); + close(fd); + return NULL; + } + + ret = emile_scsi_create_container(fd, &unit_id_map, container, - (MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block)); + (block_size - sizeof(struct emile_container)) / sizeof(struct emile_block)); close(fd); if (ret != 0) @@ -59,11 +70,11 @@ struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfil return NULL; } - ret = write(fd, container, MAPFILE_SIZE); + ret = write(fd, container, block_size); close(fd); - if (ret != MAPFILE_SIZE) + if (ret != block_size) { fprintf(stderr, "ERROR: cannot write map file (%s)\n", mapfile); free(container); @@ -81,7 +92,7 @@ struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfil } ret = emile_scsi_create_container(fd, unit_id, container, - (MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block)); + (block_size - sizeof(struct emile_container)) / sizeof(struct emile_block)); close(fd); if (ret != 0) @@ -98,7 +109,7 @@ struct emile_container *emile_second_create_mapfile(short *unit_id, char *mapfil return NULL; } - if (container->size != MAPFILE_SIZE) + if (container->size != block_size) { fprintf(stderr, "ERROR: map file size is bad (%d)\n", container->size); free(container);