Blame 0044-apply-ro-and-rw-options-from-cmdline-to-mount.patch

Harald Hoyer 12f6cc
From 79148c2945e4799796b24cadf1769e413841f768 Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: =?UTF-8?q?Amadeusz=20=C5=BBo=C5=82nowski?= <aidecoe@aidecoe.name>
Harald Hoyer 12f6cc
Date: Thu, 26 Jul 2012 15:05:26 +0200
Harald Hoyer 12f6cc
Subject: [PATCH] apply "ro" and "rw" options from cmdline to / mount
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
rflags is no longer guaranteed to be non empty.  / is mounted according
Harald Hoyer 12f6cc
to rootflags parameter but forced ro at first.  Later it is remounted
Harald Hoyer 12f6cc
according to /etc/fstab + rootflags parameter and "ro"/"rw".  If
Harald Hoyer 12f6cc
parameters are still the same as for first mount, / isn't remounted.
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
Conflicts:
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
    modules.d/95rootfs-block/mount-root.sh
Harald Hoyer 12f6cc
    modules.d/99base/parse-root-opts.sh
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 modules.d/95rootfs-block/mount-root.sh | 35 ++++++++--------------------------
Harald Hoyer 12f6cc
 modules.d/99base/parse-root-opts.sh    | 11 ++++-------
Harald Hoyer 12f6cc
 2 files changed, 12 insertions(+), 34 deletions(-)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer 12f6cc
index ef8ca3c..de9753a 100755
Harald Hoyer 12f6cc
--- a/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer 12f6cc
+++ b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer 12f6cc
@@ -5,32 +5,13 @@
Harald Hoyer 12f6cc
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
Harald Hoyer 12f6cc
 type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
-filter_rootopts() {
Harald Hoyer 12f6cc
-    rootopts=$1
Harald Hoyer 12f6cc
-    # strip ro and rw options
Harald Hoyer 12f6cc
-    local OLDIFS="$IFS"
Harald Hoyer 12f6cc
-    IFS=,
Harald Hoyer 12f6cc
-    set -- $rootopts
Harald Hoyer 12f6cc
-    IFS="$OLDIFS"
Harald Hoyer 12f6cc
-    local v
Harald Hoyer 12f6cc
-    while [ $# -gt 0 ]; do
Harald Hoyer 12f6cc
-        case $1 in
Harald Hoyer 12f6cc
-            defaults);;
Harald Hoyer 12f6cc
-            *)
Harald Hoyer 12f6cc
-                v="$v,${1}";;
Harald Hoyer 12f6cc
-        esac
Harald Hoyer 12f6cc
-        shift
Harald Hoyer 12f6cc
-    done
Harald Hoyer 12f6cc
-    rootopts=${v#,}
Harald Hoyer 12f6cc
-    echo $rootopts
Harald Hoyer 12f6cc
-}
Harald Hoyer 12f6cc
-
Harald Hoyer 12f6cc
 mount_root() {
Harald Hoyer 12f6cc
     local _ret
Harald Hoyer 12f6cc
+    local _rflags_ro="$rflags,ro"
Harald Hoyer 12f6cc
     # sanity - determine/fix fstype
Harald Hoyer 12f6cc
     rootfs=$(det_fs "${root#block:}" "$fstype")
Harald Hoyer 12f6cc
-    while ! mount -t ${rootfs} -o "$rflags",ro "${root#block:}" "$NEWROOT"; do
Harald Hoyer 12f6cc
-        warn "Failed to mount -t ${rootfs} -o $rflags,ro ${root#block:} $NEWROOT"
Harald Hoyer 12f6cc
+    while ! mount -t ${rootfs} -o "$_rflags_ro" "${root#block:}" "$NEWROOT"; do
Harald Hoyer 12f6cc
+        warn "Failed to mount -t ${rootfs} -o $_rflags_ro ${root#block:} $NEWROOT"
Harald Hoyer 12f6cc
         fsck_ask_err
Harald Hoyer 12f6cc
     done
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
@@ -96,13 +77,13 @@ mount_root() {
Harald Hoyer 12f6cc
                 break
Harald Hoyer 12f6cc
             fi
Harald Hoyer 12f6cc
         done < "$NEWROOT/etc/fstab"
Harald Hoyer 12f6cc
-
Harald Hoyer 12f6cc
-        rootopts=$(filter_rootopts $rootopts)
Harald Hoyer 12f6cc
     fi
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
     # we want rootflags (rflags) to take precedence so prepend rootopts to
Harald Hoyer 12f6cc
-    # them; rflags is guaranteed to not be empty
Harald Hoyer 12f6cc
-    rflags="${rootopts:+${rootopts},}${rflags}"
Harald Hoyer 12f6cc
+    # them
Harald Hoyer 12f6cc
+    rflags="${rootopts},${rflags}"
Harald Hoyer 12f6cc
+    rflags="${rflags#,}"
Harald Hoyer 12f6cc
+    rflags="${rflags%,}"
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
     # backslashes are treated as escape character in fstab
Harald Hoyer 12f6cc
     # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
Harald Hoyer 12f6cc
@@ -125,7 +106,7 @@ mount_root() {
Harald Hoyer 12f6cc
     if ! ismounted "$NEWROOT"; then
Harald Hoyer 12f6cc
         info "Mounting ${root#block:} with -o ${rflags}"
Harald Hoyer 12f6cc
         mount "$NEWROOT" 2>&1 | vinfo
Harald Hoyer 12f6cc
-    else
Harald Hoyer 12f6cc
+    elif ! are_lists_eq , "$rflags" "$_rflags_ro" defaults; then
Harald Hoyer 12f6cc
         info "Remounting ${root#block:} with -o ${rflags}"
Harald Hoyer 12f6cc
         mount -o remount "$NEWROOT" 2>&1 | vinfo
Harald Hoyer 12f6cc
     fi
Harald Hoyer 12f6cc
diff --git a/modules.d/99base/parse-root-opts.sh b/modules.d/99base/parse-root-opts.sh
Harald Hoyer 12f6cc
index 44dcc09..7b0b758 100755
Harald Hoyer 12f6cc
--- a/modules.d/99base/parse-root-opts.sh
Harald Hoyer 12f6cc
+++ b/modules.d/99base/parse-root-opts.sh
Harald Hoyer 12f6cc
@@ -4,13 +4,10 @@
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
 root=$(getarg root=)
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
-if rflags="$(getarg rootflags=)"; then
Harald Hoyer 12f6cc
-    getarg rw && rflags="${rflags},rw"
Harald Hoyer 12f6cc
-    getarg ro && rflags="${rflags},ro"
Harald Hoyer 12f6cc
-else
Harald Hoyer 12f6cc
-    getarg rw && rflags=rw
Harald Hoyer 12f6cc
-    getarg ro && rflags=ro
Harald Hoyer 12f6cc
-fi
Harald Hoyer 12f6cc
+rflags="$(getarg rootflags=)"
Harald Hoyer 12f6cc
+getargbool 0 rw && rflags="${rflags},rw"
Harald Hoyer 12f6cc
+getargbool 0 ro && rflags="${rflags},ro"
Harald Hoyer 12f6cc
+rflags="${rflags#,}"
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
 fstype="$(getarg rootfstype=)"
Harald Hoyer 12f6cc
 if [ -z "$fstype" ]; then