diff options
author | Daniel Golle <daniel@makrotopia.org> | 2016-07-21 03:55:48 +0200 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2016-07-21 04:11:41 +0200 |
commit | bef7987f4b4ccc343f619172e28bcaaa12a19403 (patch) | |
tree | 0cd6bcd37752010fa140300f1012c5b00157d0d8 | |
parent | b5f6b8266465d8401a9699d5245c1058424f733c (diff) | |
download | fstools-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.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -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; } |