2004-12-21 17:34:30 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
|
2004-12-21 17:34:30 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-10-04 20:52:37 +00:00
|
|
|
#include "../libmap/libmap.h"
|
2004-12-21 17:34:30 +00:00
|
|
|
#include "libemile.h"
|
|
|
|
|
2006-06-01 22:17:33 +00:00
|
|
|
int emile_scsi_get_rdev(char* dev_name, int* driver, int *disk, int *partition)
|
2004-12-21 17:34:30 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct stat st;
|
|
|
|
int major;
|
|
|
|
|
|
|
|
ret = stat(dev_name, &st);
|
|
|
|
if (ret == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!S_ISBLK(st.st_mode))
|
|
|
|
/* not a block device */
|
|
|
|
return -1;
|
|
|
|
|
2006-09-13 21:32:45 +00:00
|
|
|
major = (st.st_rdev >> 8) & 0xFF;
|
2006-06-01 22:17:33 +00:00
|
|
|
*driver = major;
|
2005-02-02 14:25:55 +00:00
|
|
|
switch(major)
|
|
|
|
{
|
|
|
|
case MAJOR_SD:
|
|
|
|
*disk = (st.st_rdev & 0xFF) >> 4;
|
2006-09-13 21:32:45 +00:00
|
|
|
if (partition) *partition = st.st_rdev & 0x0F;
|
2005-02-02 14:25:55 +00:00
|
|
|
break;
|
2006-09-13 21:32:45 +00:00
|
|
|
case MAJOR_IDE0:
|
|
|
|
case MAJOR_IDE1:
|
2006-10-15 16:48:35 +00:00
|
|
|
*disk = (st.st_rdev & 0xFF) >> 6;
|
2006-09-13 21:32:45 +00:00
|
|
|
if (partition) *partition = st.st_rdev & 0x3F;
|
2005-02-02 14:25:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-12-21 17:34:30 +00:00
|
|
|
return -1;
|
2005-02-02 14:25:55 +00:00
|
|
|
}
|
2004-12-21 17:34:30 +00:00
|
|
|
|
2004-12-22 22:48:16 +00:00
|
|
|
return 0;
|
2004-12-21 17:34:30 +00:00
|
|
|
}
|