Blame 0047-dracut-functions.sh-add-find_mp_fstype.patch

Harald Hoyer 12f6cc
From 81672479afb4806568f1dea7fac9b8d7271c71f6 Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 12f6cc
Date: Thu, 26 Jul 2012 17:00:07 +0200
Harald Hoyer 12f6cc
Subject: [PATCH] dracut-functions.sh: add find_mp_fstype()
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 dracut-functions.sh | 27 +++++++++++++++++++++++++++
Harald Hoyer 12f6cc
 1 file changed, 27 insertions(+)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 12f6cc
index 14c100d..0332351 100755
Harald Hoyer 12f6cc
--- a/dracut-functions.sh
Harald Hoyer 12f6cc
+++ b/dracut-functions.sh
Harald Hoyer 12f6cc
@@ -357,6 +357,33 @@ find_dev_fstype() {
Harald Hoyer 12f6cc
     return 1
Harald Hoyer 12f6cc
 }
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
+# find_dev_fstype <device>
Harald Hoyer 12f6cc
+# Echo the filesystem type for a given device.
Harald Hoyer 12f6cc
+# /proc/self/mountinfo is taken as the primary source of information
Harald Hoyer 12f6cc
+# and /etc/fstab is used as a fallback.
Harald Hoyer 12f6cc
+# No newline is appended!
Harald Hoyer 12f6cc
+# Example:
Harald Hoyer 12f6cc
+# $ find_dev_fstype /dev/sda2;echo
Harald Hoyer 12f6cc
+# ext4
Harald Hoyer 12f6cc
+find_mp_fstype() {
Harald Hoyer 12f6cc
+    local _x _mpt _majmin _dev _fs _maj _min
Harald Hoyer 12f6cc
+    while read _x _x _majmin _x _mpt _x _x _fs _dev _x; do
Harald Hoyer 12f6cc
+        [[ $_mpt = $1 ]] || continue
Harald Hoyer 12f6cc
+        echo -n $_fs;
Harald Hoyer 12f6cc
+        return 0;
Harald Hoyer 12f6cc
+    done < /proc/self/mountinfo
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    # fall back to /etc/fstab
Harald Hoyer 12f6cc
+    while read _dev _mpt _fs _x; do
Harald Hoyer 12f6cc
+        [[ $_mpt = $1 ]] || continue
Harald Hoyer 12f6cc
+        echo -n $_fs;
Harald Hoyer 12f6cc
+        return 0;
Harald Hoyer 12f6cc
+    done < /etc/fstab
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    return 1
Harald Hoyer 12f6cc
+}
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
 # finds the major:minor of the block device backing the root filesystem.
Harald Hoyer 12f6cc
 find_root_block_device() { find_block_device /; }
Harald Hoyer 12f6cc