From 7dce019c98dca84fa0b81ffd309225cfd19835f6 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Tue, 21 Dec 2004 17:56:53 +0000 Subject: [PATCH] correct fd, use emile_scsi_get_dev() --- libemile/emile_scsi_create_container.c | 28 +++++--------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/libemile/emile_scsi_create_container.c b/libemile/emile_scsi_create_container.c index 7fc5821..46a3de0 100644 --- a/libemile/emile_scsi_create_container.c +++ b/libemile/emile_scsi_create_container.c @@ -19,8 +19,6 @@ static __attribute__((used)) char* rcsid = "$CVSHeader$"; #include "libemile.h" -#define MAJOR_SD 8 /* SCSI disks */ - struct scsi_id { int dev; int host_unique_id; @@ -42,36 +40,23 @@ static int get_scsi_path(int fd, unsigned char *host, unsigned char *channel, return ret; } -static int get_device_info(int device, int *id, unsigned long *first_block, +static int get_device_info(int fd, int *id, unsigned long *first_block, int *block_size) { - int fd; int ret; char dev_name[16]; - int major; - int minor; struct hd_geometry geom; unsigned char host; unsigned char channel; unsigned char pun; unsigned char lun; - major = (device >> 8) & 0x0F; /* major number = driver id */ - minor = device & 0xFF; /* minor number = disk id */ - switch(major) - { - case MAJOR_SD: /* SCSI disks */ - sprintf(dev_name, "/dev/sd%c%d", 'a' + (minor >> 4), - minor & 0x0F); - break; - - default: - fprintf(stderr, "Unknown device major number %d\n", major); + ret = emile_scsi_get_dev(dev_name, fd); + if (ret == -1) return -1; - } fd = open(dev_name, O_RDONLY); - if (fd == 1) { + if (fd == -1) { fprintf(stderr, "Cannot open device %s (%s)\n", dev_name, strerror(errno)); return -1; @@ -128,7 +113,6 @@ int emile_scsi_create_container(int fd, struct emile_container* container) int last_physical; int zone; int aggregate; - int dev; ret = fstat(fd, &st); if (ret == -1) { @@ -136,9 +120,7 @@ int emile_scsi_create_container(int fd, struct emile_container* container) return -1; } - dev = S_ISREG(st.st_mode) ? st.st_dev : st.st_rdev; - - ret = get_device_info(dev, &id, &first_block, §or_size); + ret = get_device_info(fd, &id, &first_block, §or_size); if (ret != 0) return -1;