[LTP] [PATCH V4 1/10] tst_device: Add tst_is_mounted() helper

Viresh Kumar viresh.kumar@linaro.org
Wed Feb 26 07:28:37 CET 2020


On 26-02-20, 13:14, Zorro Lang wrote:
> For example, if path is "/mnt/test", and we get a line as "/mnt/test/mnt1 ..."
> or "/mnt/mnt/test", Then this function thinks "/mnt/test" is a mountpoint.
> 
> We can refer to util-linux/sys-utils/mountpoint.c a little, but it's complicated,
> or we can call mountpoint command directly?

This is working fine for me, does this looks okay now ?

diff --git a/lib/tst_device.c b/lib/tst_device.c
index d99fb8bc554a..8bf6dacf5973 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -388,25 +388,16 @@ int tst_umount(const char *path)
 
 int tst_is_mounted(const char *path)
 {
-       char line[256];
-       FILE *file;
-       int ret = 0;
-
-       file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
-
-       while (fgets(line, sizeof(line), file)) {
-               if (strstr(line, path) != NULL) {
-                       ret = 1;
-                       break;
-               }
-       }
+       char cmd[PATH_MAX];
+       int ret;
 
-       SAFE_FCLOSE(NULL, file);
+       snprintf(cmd, sizeof(cmd), "mountpoint -q %s", path);
+       ret = tst_system(cmd);
 
-       if (!ret)
+       if (ret)
                tst_resm(TINFO, "No device is mounted at %s", path);
 
-       return ret;
+       return !ret;
 }

-- 
viresh


More information about the ltp mailing list