summaryrefslogtreecommitdiffstats
path: root/sys-utils/mountpoint.c
diff options
context:
space:
mode:
authorKarel Zak2011-10-11 11:26:31 +0200
committerKarel Zak2011-10-11 11:26:31 +0200
commiteb9d3706aa70492dc859939a1403906d08ccdc57 (patch)
treec6f958c1182a4bc9c1ff63ed767e1875c655d855 /sys-utils/mountpoint.c
parentRevert "mountpoint: refactor exit path" (diff)
downloadkernel-qcow2-util-linux-eb9d3706aa70492dc859939a1403906d08ccdc57.tar.gz
kernel-qcow2-util-linux-eb9d3706aa70492dc859939a1403906d08ccdc57.tar.xz
kernel-qcow2-util-linux-eb9d3706aa70492dc859939a1403906d08ccdc57.zip
mountpoint: support symbolic and relative paths
Reported-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/mountpoint.c')
-rw-r--r--sys-utils/mountpoint.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c
index 1182f7c3b..5cc833d4f 100644
--- a/sys-utils/mountpoint.c
+++ b/sys-utils/mountpoint.c
@@ -44,6 +44,7 @@ static dev_t dir_to_device(const char *spec)
{
struct libmnt_table *tb = mnt_new_table_from_file("/proc/self/mountinfo");
struct libmnt_fs *fs;
+ struct libmnt_cache *cache;
dev_t res = 0;
if (!tb) {
@@ -52,13 +53,17 @@ static dev_t dir_to_device(const char *spec)
* is independent on /proc, but not able to detect bind mounts.
*/
struct stat pst, st;
- char buf[PATH_MAX];
+ char buf[PATH_MAX], *cn;
int len;
if (stat(spec, &st) != 0)
return 0;
- len = snprintf(buf, sizeof(buf), "%s/..", spec);
+ cn = mnt_resolve_path(spec, NULL); /* canonicalize */
+
+ len = snprintf(buf, sizeof(buf), "%s/..", cn ? cn : spec);
+ free(cn);
+
if (len < 0 || (size_t) len + 1 > sizeof(buf))
return 0;
if (stat(buf, &pst) !=0)
@@ -71,11 +76,16 @@ static dev_t dir_to_device(const char *spec)
return 0;
}
+ /* to canonicalize all necessary paths */
+ cache = mnt_new_cache();
+ mnt_table_set_cache(tb, cache);
+
fs = mnt_table_find_target(tb, spec, MNT_ITER_BACKWARD);
if (fs && mnt_fs_get_target(fs))
res = mnt_fs_get_devno(fs);
mnt_free_table(tb);
+ mnt_free_cache(cache);
return res;
}