[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] make blktap find it's major through sysfs
This patch makes blktap find it's major number by searching sysfs instead of reading /proc/devices. -- Steve Signed-off-by: Steven Rostedt <srostedt@xxxxxxxxxx> diff -r f4ec8ed65c15 tools/blktap/drivers/blktapctrl.c --- a/tools/blktap/drivers/blktapctrl.c Thu Sep 28 21:41:44 2006 -0400 +++ b/tools/blktap/drivers/blktapctrl.c Thu Sep 28 21:54:10 2006 -0400 @@ -636,28 +636,56 @@ static void print_drivers(void) DPRINTF("Found driver: [%s]\n",dtypes[i]->name); } +#define MTAB "/proc/mounts" +#define BLKTAP_SYSFS_PATH "/class/xen/blktap0/dev" + +#define MAX_PATH 255 +#define _STR(x) #x +#define STR(x) _STR(x) + +static char sysfsdir[MAX_PATH + 1]; + +static int find_sysfsdir(void) +{ + FILE *fp; + char type[MAX_PATH + 1]; + + if ((fp = fopen(MTAB, "r")) == NULL) + return -1; + + while (fscanf(fp, "%*s %" + STR(MAX_PATH) + "s %" + STR(MAX_PATH) + "s %*s %*d %*d\n", + sysfsdir, type) == 2) { + if (strncmp(type, "sysfs", 5) == 0) + break; + } + fclose(fp); + + return strncmp(type, "sysfs", 5) == 0 ? 0 : -1; +} + static int find_blktap_major(void) { - FILE *fp; - int major; - char device[256]; - - if ((fp = fopen("/proc/devices", "r")) == NULL) - return -1; - - /* Skip title */ - fscanf(fp,"%*s %*s\n"); - while (fscanf(fp, "%d %255s\n", &major, device) == 2) { - if (strncmp("blktap", device, 6) == 0) - break; - } - - fclose(fp); - - if (strncmp("blktap", device, 6) == 0) - return major; - - return -1; + FILE *fp; + int major; + int minor; + + if (find_sysfsdir() < 0) + return -1; + + strncat(sysfsdir, BLKTAP_SYSFS_PATH, MAX_PATH); + + if ((fp = fopen(sysfsdir, "r")) == NULL) + return -1; + + fscanf(fp,"%d:%d",&major, &minor); + + fclose(fp); + + return major; } int main(int argc, char *argv[]) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |