change API of get_dev and get_rdev: return driver major number instead of device pathname

This commit is contained in:
Laurent Vivier 2006-06-01 22:17:33 +00:00
parent 56d2a72250
commit be323732d0
3 changed files with 36 additions and 19 deletions

View File

@ -49,14 +49,14 @@ static int get_device_info(int fd, short *id, unsigned long *first_block,
unsigned char channel;
unsigned char pun;
unsigned char lun;
char *driver;
int driver;
int disk;
int partition;
ret = emile_scsi_get_dev(fd, &driver, &disk, &partition);
if (ret == -1)
return -1;
sprintf(dev_name, "%s%c%d", driver, disk + 'a', partition);
emile_get_dev_name(dev_name, driver, disk, partition);
fd = open(dev_name, O_RDONLY);
if (fd == -1) {

View File

@ -12,14 +12,34 @@ static __attribute__((used)) char* rcsid = "$CVSHeader$";
#include "libemile.h"
/* SCSI disks */
int emile_get_dev_name(char *buffer, int driver, int disk, int partition)
{
switch(driver)
{
case MAJOR_HD:
if (partition == 0)
sprintf(buffer, "/dev/hd%c", 'a' + disk);
else
sprintf(buffer, "/dev/hd%c%d", 'a' + disk,
partition);
break;
case MAJOR_LOOP:
sprintf(buffer, "/dev/loop%d", disk);
break;
case MAJOR_SD:
if (partition == 0)
sprintf(buffer, "/dev/sd%c", 'a' + disk);
else
sprintf(buffer, "/dev/sd%c%d", 'a' + disk,
partition);
break;
default:
return -1;
}
return 0;
}
#define MAJOR_HD 3
#define MAJOR_SD 8
static char *scsi_base = "/dev/sd";
static char *ata_base = "/dev/hd";
int emile_scsi_get_dev(int fd, char** driver, int *disk, int *partition)
int emile_scsi_get_dev(int fd, int* driver, int *disk, int *partition)
{
struct stat st;
int ret;
@ -36,15 +56,18 @@ int emile_scsi_get_dev(int fd, char** driver, int *disk, int *partition)
major = (dev >> 8) & 0x0F; /* major number = driver id */
minor = dev & 0xFF; /* minor number = disk id */
*driver = major;
switch(major)
{
case MAJOR_SD: /* SCSI disks */
*driver = scsi_base;
*disk = minor >> 4;
*partition = minor & 0x0F;
break;
case MAJOR_LOOP: /* loop device */
*disk = minor & 0xFF;
*partition = 0;
break;
case MAJOR_HD: /* ATA disks */
*driver = ata_base;
*disk = minor >> 6;
*partition = minor & 0x3F;
break;

View File

@ -8,12 +8,7 @@ static __attribute__((used)) char* rcsid = "$CVSHeader$";
#include "partition.h"
#include "libemile.h"
#define MAJOR_HD 3
#define MAJOR_SD 8
static char *scsi_base = "/dev/sd";
static char *ide_base = "/dev/hd";
int emile_scsi_get_rdev(char* dev_name, char** driver, int *disk, int *partition)
int emile_scsi_get_rdev(char* dev_name, int* driver, int *disk, int *partition)
{
int ret;
struct stat st;
@ -28,15 +23,14 @@ int emile_scsi_get_rdev(char* dev_name, char** driver, int *disk, int *partition
return -1;
major = (st.st_rdev >> 8) & 0x0F;
*driver = major;
switch(major)
{
case MAJOR_SD:
*driver = scsi_base;
*disk = (st.st_rdev & 0xFF) >> 4;
*partition = st.st_rdev & 0x0F;
break;
case MAJOR_HD:
*driver = ide_base;
*disk = (st.st_rdev & 0xFF) >> 6;
*partition = st.st_rdev & 0x3F;
break;