From dfd2c7146849120ed7576771135299047a929c09 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 11 Oct 2011 10:47:44 +0200 Subject: mountpoint: fallback on stat when /proc isn't mounted Reported-by: Signed-off-by: Karel Zak --- sys-utils/mountpoint.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'sys-utils/mountpoint.c') 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)) -- cgit v1.2.3-55-g7522