Use lsblk to attempt to guess partition's fs type
authorPhilippe Coval <rzr@gna.org>
Fri, 20 Jan 2017 12:25:24 +0000 (12:25 +0000)
committerColin Watson <cjwatson@debian.org>
Fri, 20 Jan 2017 12:25:24 +0000 (12:25 +0000)
If not found it will fall back to other tools.

Note that fs_type function is not expected to return a non-zero error
code even if it failed to detect the type.

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

This change will prevent mount hanging on extended partitions (#768902).

Signed-off-by: Philippe Coval <rzr@gna.org>
Tweaked-by: Colin Watson <cjwatson@debian.org>
Bug-Debian: 768902

common.sh
debian/changelog
linux-boot-probes/common/50mounted-tests
os-probes/common/50mounted-tests

index 98d39fa..a57e2a4 100644 (file)
--- a/common.sh
+++ b/common.sh
@@ -103,14 +103,24 @@ 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 || true)
+               [ -z "$fstype" ] || { echo "$fstype"; return; }
+       fi
+       if type lsblk >/dev/null 2>&1 ; then
+               fstype=$(lsblk --nodeps --noheading --output FSTYPE -- "$1" || true)
+               [ -z "$fstype" ] || { echo "$fstype"; return; }
+       fi
+       if type blkid >/dev/null 2>&1; then
+               fstype=$(blkid -o value -s TYPE "$1" 2>/dev/null || true)
+               [ -z "$fstype" ] || { echo "$fstype"; return; }
        fi
+       echo "NOT-DETECTED"
 }
 
 is_dos_extended_partition() {
index d3bd37b..c72c0cb 100644 (file)
@@ -28,6 +28,8 @@ os-prober (1.72) UNRELEASED; urgency=medium
   * Add os-release support (based loosely on a patch by Török Edwin; closes:
     #794409).
   * Add Devuan detection (thanks, David Hare; closes: #801631).
+  * Work harder to avoid trying to mount extended partitions (thanks,
+    Philippe Coval; closes: #784709).
 
  -- Colin Watson <cjwatson@debian.org>  Sat, 31 Dec 2016 17:11:49 +0000
 
index bb7e005..01bca81 100755 (executable)
@@ -21,7 +21,7 @@ do_unmount() {
 
 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
index f2a007d..779c3c3 100755 (executable)
@@ -19,7 +19,7 @@ do_unmount() {
        rmdir "$tmpmnt" || true
 }
 
-types="$(fs_type "$partition")" || types=NOT-DETECTED
+types="$(fs_type "$partition")"
 if [ "$types" = NOT-DETECTED ]; then
        debug "$1 type not recognised; skipping"
        exit 0