diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c index 5800154f3..d47566977 100644 --- a/device_mapper/ioctl/libdm-iface.c +++ b/device_mapper/ioctl/libdm-iface.c @@ -198,6 +198,7 @@ static int _get_proc_number(const char *file, const char *name, char *line = NULL; size_t len; uint32_t num; + unsigned blocksection = (strcmp(file, PROC_DEVICES) == 0) ? 0 : 1; if (!(fl = fopen(file, "r"))) { log_sys_error("fopen", file); @@ -205,7 +206,9 @@ static int _get_proc_number(const char *file, const char *name, } while (getline(&line, &len, fl) != -1) { - if (sscanf(line, "%u %255s\n", &num, &nm[0]) == 2) { + if (!blocksection && (line[0] == 'B')) + blocksection = 1; + else if (sscanf(line, "%u %255s\n", &num, &nm[0]) == 2) { if (!strcmp(name, nm)) { if (number) { *number = num; diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index a579578c9..2ddd10358 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -197,6 +197,7 @@ static int _get_proc_number(const char *file, const char *name, char *line = NULL; size_t len; uint32_t num; + unsigned blocksection = (strcmp(file, PROC_DEVICES) == 0) ? 0 : 1; if (!(fl = fopen(file, "r"))) { log_sys_error("fopen", file); @@ -204,7 +205,9 @@ static int _get_proc_number(const char *file, const char *name, } while (getline(&line, &len, fl) != -1) { - if (sscanf(line, "%u %255s\n", &num, &nm[0]) == 2) { + if (!blocksection && (line[0] == 'B')) + blocksection = 1; + else if (sscanf(line, "%u %255s\n", &num, &nm[0]) == 2) { if (!strcmp(name, nm)) { if (number) { *number = num;