findmnt uses the option "-v, --nofsroot" to exclusive the [/dir] in the
SOURCE column for bind-mounts, then if $_mntpoint equals to
$_mntpoint_nofsroot, the mountpoint is not bind mounted directory.
the value of $_mntpoint may be
/dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the
directory is bind mounted. The former part represents the device path, the
rest part is the bind mounted directory which quotes by bracket "[]".
Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
---
kdump-lib.sh | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index b6dcea0..74b3c1c 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -86,6 +86,38 @@ get_root_fs_device()
return
}
+# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
+# in the SOURCE column for bind-mounts, then if $_mntpoint equals to
+# $_mntpoint_nofsroot, the mountpoint is not bind mounted directory.
+is_bind_mount()
+{
+ local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}')
+ local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}')
+
+ if [[ $_mntpoint = $_mntpoint_nofsroot ]]; then
+ return 1
+ else
+ return 0
+ fi
+}
+
+# the value of $_mntpoint will be
+# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the
+# directory is bind mounted. The former part represents the device path, rest
+# part is the bind mounted directory which quotes by bracket "[]".
+get_bind_mount_directory()
+{
+ local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}')
+ local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}')
+
+ _mntpoint=${_mntpoint#*$_mntpoint_nofsroot}
+
+ _mntpoint=${_mntpoint#[}
+ _mntpoint=${_mntpoint%]}
+
+ echo $_mntpoint
+}
+
get_mntpoint_from_path()
{
echo $(df $1 | tail -1 | awk '{print $NF}')
--
1.9.3