From a88268b8cc124b6f721ba17ab01a3f6d5800c749 Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Sun, 17 Jul 2011 12:47:30 -0400 Subject: partx: get partition number with sysfs lib Now that we have this feature, there's no need to manually parse sysfs in partx. Signed-off-by: Davidlohr Bueso --- partx/partx.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'partx/partx.c') diff --git a/partx/partx.c b/partx/partx.c index d8a4119c2..e29e50dcc 100644 --- a/partx/partx.c +++ b/partx/partx.c @@ -30,6 +30,7 @@ #include "strutils.h" #include "xalloc.h" #include "partx.h" +#include "sysfs.h" #include "at.h" /* this is the default upper limit, could be modified by --nr */ @@ -123,8 +124,6 @@ static int column_name_to_id(const char *name, size_t namesz) * * Note that this function tries to use sysfs, otherwise it assumes that the * last characters are always numeric (sda1, sdc20, etc). - * - * Returns -1 on error. */ static int get_partno_from_device(char *partition, dev_t devno) { @@ -135,21 +134,10 @@ static int get_partno_from_device(char *partition, dev_t devno) assert(partition); if (devno) { - /* the device exists, read the partition number from /sys - * TODO: move this to stuff to lib/sysfs.c */ - char path[PATH_MAX]; - FILE *f; - - snprintf(path, sizeof(path), - _PATH_SYS_DEVBLOCK "/%d:%d/partition", - major(devno), minor(devno)); - f = fopen(path, "r"); - if (f) { - if (fscanf(f, "%d", &partno) != 1) - partno = 0; - fclose(f); - } - if (partno) + struct sysfs_cxt cxt; + + sysfs_init(&cxt, devno, NULL); + if (sysfs_read_int(&cxt, "partition", &partno) >= 0) return partno; } -- cgit v1.2.3-55-g7522