summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2016-07-21 03:55:48 +0200
committerDaniel Golle <daniel@makrotopia.org>2016-07-21 04:11:41 +0200
commitbef7987f4b4ccc343f619172e28bcaaa12a19403 (patch)
tree0cd6bcd37752010fa140300f1012c5b00157d0d8
parentb5f6b8266465d8401a9699d5245c1058424f733c (diff)
downloadfstools-bef7987f4b4ccc343f619172e28bcaaa12a19403.tar.gz
block: also check /proc/self/mountinfo to find mountpoint
Matching only the device name doesn't always work, e.g. in case of /dev/root. Thus also check the device(minor,major) which can be scraped from /proc/self/mountinfo. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-rw-r--r--block.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/block.c b/block.c
index a06e200..58487a1 100644
--- a/block.c
+++ b/block.c
@@ -588,9 +588,10 @@ static struct blkid_struct_probe* find_block_info(char *uuid, char *label, char
static char* find_mount_point(char *block)
{
FILE *fp = fopen("/proc/mounts", "r");
- static char line[256];
+ static char line[256], *saveptr;
int len = strlen(block);
char *point = NULL;
+ struct stat s;
if(!fp)
return NULL;
@@ -612,6 +613,32 @@ static char* find_mount_point(char *block)
fclose(fp);
+ if (point)
+ return point;
+
+ if (stat(block, &s))
+ return NULL;
+
+ if (!S_ISBLK(s.st_mode))
+ return NULL;
+
+ fp = fopen("/proc/self/mountinfo", "r");
+ if(!fp)
+ return NULL;
+
+ while (fgets(line, sizeof(line), fp)) {
+ strtok_r(line, " \t", &saveptr);
+ strtok_r(NULL, " \t", &saveptr);
+ if (atoi(strtok_r(NULL, ":", &saveptr)) == major(s.st_rdev) &&
+ atoi(strtok_r(NULL, " \t", &saveptr)) == minor(s.st_rdev)) {
+ strtok_r(NULL, " \t", &saveptr);
+ point = strtok_r(NULL, " \t", &saveptr);
+ break;
+ }
+ }
+
+ fclose(fp);
+
return point;
}