diff options
author | Karel Zak | 2015-03-10 13:35:56 +0100 |
---|---|---|
committer | Karel Zak | 2015-03-10 13:49:57 +0100 |
commit | cc06a01ec551ed2bcd397a5097165b4434179b34 (patch) | |
tree | bbdfb43dea554a0c315aa647718ee946c7813f0a /libmount/src/tab.c | |
parent | findmnt: don't rely on st_dev for --target (diff) | |
download | kernel-qcow2-util-linux-cc06a01ec551ed2bcd397a5097165b4434179b34.tar.gz kernel-qcow2-util-linux-cc06a01ec551ed2bcd397a5097165b4434179b34.tar.xz kernel-qcow2-util-linux-cc06a01ec551ed2bcd397a5097165b4434179b34.zip |
libmount: cleanup fs root detection code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r-- | libmount/src/tab.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c index cd20ad0b2..09896ccb6 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -47,6 +47,7 @@ #include "strutils.h" #include "loopdev.h" #include "fileutils.h" +#include "canonicalize.h" int is_mountinfo(struct libmnt_table *tb) { @@ -1166,6 +1167,20 @@ struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb, return NULL; } +static char *remove_mountpoint_from_path(const char *path, const char *mnt) +{ + char *res; + const char *p; + size_t sz; + + sz = strlen(mnt); + p = sz > 1 ? path + sz : path; + + res = *p ? strdup(p) : strdup("/"); + DBG(UTILS, ul_debug("%s fs-root is %s", path, res)); + return res; +} + /* * tb: /proc/self/mountinfo * fs: filesystem @@ -1185,7 +1200,8 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb, unsigned long mountflags, char **fsroot) { - char *root = NULL, *mnt = NULL; + char *root = NULL; + const char *mnt = NULL; const char *fstype; struct libmnt_fs *src_fs = NULL; @@ -1203,10 +1219,15 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb, DBG(TAB, ul_debug("fs-root for bind")); src = xsrc = mnt_resolve_spec(mnt_fs_get_source(fs), tb->cache); - if (src) - mnt = mnt_get_mountpoint(src); + if (src) { + struct libmnt_fs *fs = mnt_table_find_mountpoint(tb, + src, MNT_ITER_BACKWARD); + if (fs) + mnt = mnt_fs_get_target(fs); + } + if (mnt) - root = mnt_get_fs_root(src, mnt); + root = remove_mountpoint_from_path(src, mnt); if (xsrc && !tb->cache) { free(xsrc); @@ -1273,11 +1294,9 @@ dflt: DBG(TAB, ul_debug("FS root result: %s", root)); - free(mnt); return src_fs; err: free(root); - free(mnt); return NULL; } @@ -1710,6 +1729,7 @@ done: return rc; } + int main(int argc, char *argv[]) { struct libmnt_test tss[] = { |