]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mountpoint: fallback on stat when /proc isn't mounted
authorKarel Zak <kzak@redhat.com>
Tue, 11 Oct 2011 08:47:44 +0000 (10:47 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Oct 2011 08:47:44 +0000 (10:47 +0200)
Reported-by: <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/mountpoint.c

index 273fea712ee47fbc2d72974641f2286b33379844..1182f7c3bda108211ca3c436790a31b2bcd253d7 100644 (file)
@@ -46,8 +46,30 @@ static dev_t dir_to_device(const char *spec)
        struct libmnt_fs *fs;
        dev_t res = 0;
 
-       if (!tb)
+       if (!tb) {
+               /*
+                * Fallback. Traditional way to detect mountpoints. This way
+                * is independent on /proc, but not able to detect bind mounts.
+                */
+               struct stat pst, st;
+               char buf[PATH_MAX];
+               int len;
+
+               if (stat(spec, &st) != 0)
+                       return 0;
+
+               len = snprintf(buf, sizeof(buf), "%s/..", spec);
+               if (len < 0 || (size_t) len + 1 > sizeof(buf))
+                       return 0;
+               if (stat(buf, &pst) !=0)
+                       return 0;
+
+               if ((st.st_dev != pst.st_dev) ||
+                   (st.st_dev == pst.st_dev && st.st_ino == pst.st_ino))
+                       return st.st_dev;
+
                return 0;
+       }
 
        fs = mnt_table_find_target(tb, spec, MNT_ITER_BACKWARD);
        if (fs && mnt_fs_get_target(fs))