From 33730236d62bbe922b4e7f67eb0e40a13200f911 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 8 Feb 2015 15:11:37 +0100 Subject: [PATCH] hdd_menu: fix is_mounted for device links It is possible to mount e.g. '/dev/disk/by-label/ext_drive', but is_mounted did not handle this case. Fix that. --- src/gui/hdd_menu.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 2f5a2905b..013568bdd 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -142,14 +142,25 @@ bool CHDDMenuHandler::is_mounted(const char *dev) else snprintf(devpath, sizeof(devpath), "/dev/%s", dev); - int devpathlen = strlen(devpath); char buffer[255]; + string realdev = backtick("readlink -f " + string(devpath)); + realdev = trim(realdev); FILE *f = fopen("/proc/mounts", "r"); if(f) { - while (!res && fgets(buffer, sizeof(buffer), f)) - if (!strncmp(buffer, devpath, devpathlen) - && (buffer[devpathlen] == ' ' || buffer[devpathlen] == '\t')) + while (!res && fgets(buffer, sizeof(buffer), f)) { + if (buffer[0] != '/') + continue; /* only "real" devices are interesting */ + char *p = strchr(buffer, ' '); + if (p) + *p = 0; /* terminate at first space, kernel-user ABI is fixed */ + if (!strcmp(buffer, devpath)) /* default '/dev/sda1' mount */ res = true; + else { /* now the case of '/dev/disk/by-label/myharddrive' mounts */ + string realmount = backtick("readlink -f " + string(buffer)); + if (realdev == trim(realmount)) + res = true; + } + } fclose(f); } printf("CHDDMenuHandler::is_mounted: dev [%s] is %s\n", devpath, res ? "mounted" : "not mounted");