2004-12-21 17:34:30 +00:00
|
|
|
static __attribute__((used)) char* rcsid = "$CVSHeader$";
|
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
|
2004-12-21 17:34:30 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "libemile.h"
|
|
|
|
|
2006-06-01 22:17:33 +00:00
|
|
|
int emile_get_dev_name(char *buffer, int driver, int disk, int partition)
|
|
|
|
{
|
|
|
|
switch(driver)
|
|
|
|
{
|
2006-09-13 21:32:45 +00:00
|
|
|
case MAJOR_IDE0:
|
2006-06-01 22:17:33 +00:00
|
|
|
if (partition == 0)
|
|
|
|
sprintf(buffer, "/dev/hd%c", 'a' + disk);
|
|
|
|
else
|
|
|
|
sprintf(buffer, "/dev/hd%c%d", 'a' + disk,
|
|
|
|
partition);
|
|
|
|
break;
|
2006-09-13 21:32:45 +00:00
|
|
|
case MAJOR_IDE1:
|
|
|
|
if (partition == 0)
|
|
|
|
sprintf(buffer, "/dev/hd%c", 'c' + disk);
|
|
|
|
else
|
|
|
|
sprintf(buffer, "/dev/hd%c%d", 'c' + disk,
|
|
|
|
partition);
|
|
|
|
break;
|
2006-06-01 22:17:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2004-12-27 21:39:19 +00:00
|
|
|
|
2006-06-01 22:17:33 +00:00
|
|
|
int emile_scsi_get_dev(int fd, int* driver, int *disk, int *partition)
|
2004-12-21 17:34:30 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int ret;
|
|
|
|
int dev;
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
|
|
|
|
ret = fstat(fd, &st);
|
|
|
|
if (ret == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
dev = S_ISREG(st.st_mode) ? st.st_dev : st.st_rdev;
|
|
|
|
|
2006-09-13 21:32:45 +00:00
|
|
|
major = (dev >> 8) & 0xFF; /* major number = driver id */
|
2004-12-21 17:34:30 +00:00
|
|
|
minor = dev & 0xFF; /* minor number = disk id */
|
|
|
|
|
2006-06-01 22:17:33 +00:00
|
|
|
*driver = major;
|
2004-12-21 17:34:30 +00:00
|
|
|
switch(major)
|
|
|
|
{
|
|
|
|
case MAJOR_SD: /* SCSI disks */
|
2004-12-27 21:39:19 +00:00
|
|
|
*disk = minor >> 4;
|
|
|
|
*partition = minor & 0x0F;
|
2004-12-21 17:34:30 +00:00
|
|
|
break;
|
2006-06-01 22:17:33 +00:00
|
|
|
case MAJOR_LOOP: /* loop device */
|
|
|
|
*disk = minor & 0xFF;
|
|
|
|
*partition = 0;
|
|
|
|
break;
|
2006-09-13 21:32:45 +00:00
|
|
|
case MAJOR_IDE0:
|
2005-11-29 23:46:07 +00:00
|
|
|
*disk = minor >> 6;
|
|
|
|
*partition = minor & 0x3F;
|
|
|
|
break;
|
2006-09-13 21:32:45 +00:00
|
|
|
case MAJOR_IDE1:
|
|
|
|
*disk = minor >> 6;
|
|
|
|
*partition = minor & 0x3F;
|
2004-12-21 17:34:30 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unknown device major number %d\n", major);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|