diff options
author | Karel Zak | 2011-10-11 10:47:44 +0200 |
---|---|---|
committer | Karel Zak | 2011-10-11 10:47:44 +0200 |
commit | dfd2c7146849120ed7576771135299047a929c09 (patch) | |
tree | 4470388beeece2daf97ff209b775843af43c73c6 /sys-utils/mountpoint.c | |
parent | mountpoint: return dev_t from dir_to_device (diff) | |
download | kernel-qcow2-util-linux-dfd2c7146849120ed7576771135299047a929c09.tar.gz kernel-qcow2-util-linux-dfd2c7146849120ed7576771135299047a929c09.tar.xz kernel-qcow2-util-linux-dfd2c7146849120ed7576771135299047a929c09.zip |
mountpoint: fallback on stat when /proc isn't mounted
Reported-by: <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/mountpoint.c')
-rw-r--r-- | sys-utils/mountpoint.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c index 273fea712..1182f7c3b 100644 --- a/sys-utils/mountpoint.c +++ b/sys-utils/mountpoint.c @@ -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)) |