[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#784709: [PATCH] use lsblk to attemp to guess partition's fs type



If not found it will fallback to use other tools.

Note that fs_type function is not expected to return error code
different than zero even if it failed to detect type.

If filesystem is undermined then "NOT-DETECTED" will be echoed.

This change will prevent mount to hang on extended part (#768902)

Signed-off-by: Philippe Coval <rzr@gna.org>
Bug-Debian: 768902
---
 common.sh                                | 23 ++++++++++++++++++-----
 linux-boot-probes/common/50mounted-tests |  2 +-
 os-probes/common/50mounted-tests         |  1 +
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/common.sh b/common.sh
index 30e245e..f89c07d 100644
--- a/common.sh
+++ b/common.sh
@@ -106,14 +106,27 @@ item_in_dir () {
 # We can't always tell the filesystem type up front, but if we have the
 # information then we should use it. Note that we can't use block-attr here
 # as it's only available in udebs.
+# If not detected after different attempts then "NOT-DETECTED" will be printed
+# because function is not supposed to exit error codes.
 fs_type () {
+	local fstype=""
 	if (export PATH="/lib/udev:$PATH"; type vol_id) >/dev/null 2>&1; then
-		PATH="/lib/udev:$PATH" vol_id --type "$1" 2>/dev/null
-	elif type blkid >/dev/null 2>&1; then
-		blkid -o value -s TYPE "$1" 2>/dev/null
-	else
-		return 0
+		PATH="/lib/udev:$PATH" \
+			fstype=$(vol_id --type "$1" 2>/dev/null \
+			|| echo "")
+		[ "$fstype" = "" ] || { echo "$fstype" ; return 0; }
+	fi
+	if type lsblk >/dev/null 2>&1 ; then
+		fstype=$(lsblk --nodeps --noheading --output fstype -- "$1" || echo "")
+		[ "$fstype" = "" ] || { echo "$fstype" ; return 0; }
+	fi
+	if type blkid >/dev/null 2>&1; then
+		fstype=$(blkid -o value -s TYPE "$1" 2>/dev/null \
+		|| echo "")
+		[ "$fstype" = "" ] || { echo "$fstype" ; return 0; }
 	fi
+	echo "NOT-DETECTED"
+	return 0
 }
 
 parse_proc_mounts () {
diff --git a/linux-boot-probes/common/50mounted-tests b/linux-boot-probes/common/50mounted-tests
index 41e26e6..ee1e9f2 100755
--- a/linux-boot-probes/common/50mounted-tests
+++ b/linux-boot-probes/common/50mounted-tests
@@ -5,7 +5,7 @@ set -e
 
 partition="$1"
 
-types="$(fs_type "$partition")" || types=NOT-DETECTED
+types="$(fs_type "$partition")"
 if [ "$types" = NOT-DETECTED ]; then
 	debug "$1 type not recognised; skipping"
 	exit 0
diff --git a/os-probes/common/50mounted-tests b/os-probes/common/50mounted-tests
index 561163b..67744bd 100755
--- a/os-probes/common/50mounted-tests
+++ b/os-probes/common/50mounted-tests
@@ -6,6 +6,7 @@ partition="$1"
 . /usr/share/os-prober/common.sh
 
 types="$(fs_type "$partition")" || types=NOT-DETECTED
+[ "" != "$types" ] || types=NOT-DETECTED
 if [ "$types" = NOT-DETECTED ]; then
 	debug "$1 type not recognised; skipping"
 	exit 0
-- 
2.1.4


Reply to: