From 00a5bcb37714b8c3f3972fe81a7d97bae9338252 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 13 Apr 2022 12:08:23 +0100 Subject: [PATCH] shutils.in: Add get_fs_mount_point() function Allow getting the mount point of a given filesystem. This is useful to detect the location of e.g. tracefs --- devlib/bin/scripts/shutils.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in index 0cca5bb..2212c3b 100755 --- a/devlib/bin/scripts/shutils.in +++ b/devlib/bin/scripts/shutils.in @@ -10,6 +10,8 @@ SED=${SED:-$BUSYBOX sed} CAT=${CAT:-$BUSYBOX cat} AWK=${AWK:-$BUSYBOX awk} PS=${PS:-$BUSYBOX ps} +MOUNT=${MOUNT:-$BUSYBOX mount} +PRINTF=${PRINTF:-$BUSYBOX printf} ################################################################################ # CPUFrequency Utility Functions @@ -319,6 +321,16 @@ get_android_system_id() { echo "$hardware/$kernel/$filesystem" } +get_fs_mount_point() { + local path=$(LC_ALL=C $MOUNT -t "$1" | $SED -n "s/$1 on \(.*\) type $1 .*/\1/p;q") + if [ "$path" == "" ]; then + return 1 + else + $PRINTF "%s" "$path" + return 0 + fi +} + ################################################################################ # Main Function Dispatcher ################################################################################