diff options
author | Simon Rettberg | 2019-03-15 10:15:43 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-03-15 10:15:43 +0100 |
commit | b9917c1f5bfe47f8a438adf8e2424db166e674d0 (patch) | |
tree | fedc01a03b121681c21450c4f0b8b2c3cde1ddfc | |
parent | fix search/replace for ash (diff) | |
download | slx-tools-b9917c1f5bfe47f8a438adf8e2424db166e674d0.tar.gz slx-tools-b9917c1f5bfe47f8a438adf8e2424db166e674d0.tar.xz slx-tools-b9917c1f5bfe47f8a438adf8e2424db166e674d0.zip |
Simplify checks, consider zram as volatile too
-rw-r--r-- | slx-tools | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -28,9 +28,9 @@ get_backing_dev_mp() { is_volatile() { [ -z "$1" ] && return 2 local _dev="$(get_backing_dev "$1")" - [ -z "$_dev" ] && return 0 - # NOTE: ash does not search/replace when the expression is surrounded by quotes - [ "x$_dev" = "x"${_dev//\/dev\/mapper/} ] && return 1 + [ -z "$_dev" ] && return 0 # No result, assume tmpfs + [ "$_dev" = "${_dev#/dev/zram}" ] && return 0 # zram is in RAM, like tmpfs + [ "$_dev" = "${_dev#/dev/mapper/}" ] && return 1 # Doesn't start with /dev/mapper, assume some kind of storage local _mp="$(get_backing_dev_mp "$1")" [ -z "$_mp" ] && return 2 # it is a device mapper device, check if it was setup in dracut's initramfs. @@ -44,8 +44,7 @@ is_volatile() { get_dm_backing_size() { [ -z "$1" ] && return 1 local _dev="$(get_backing_dev $1)" - # NOTE: ash does not search/replace when the expression is surrounded by quotes - [ "x$_dev" = "x"${_dev//\/dev\/mapper/} ] && return 1 + [ "$_dev" = "${_dev#/dev/mapper/}" ] && return 1 local _dm_line="$(grep -m1 -E "^${_dev}\s+/\s+type=[^0]" "$dmstate")" [ -z "$_dm_line" ] && return 1 local _dm_dev_size="$(echo "$_dm_line" | grep -Po '(?<=physical_size=|virtual_size=)\w*' )" @@ -53,7 +52,7 @@ get_dm_backing_size() { } regex_match() { - echo "$1" | grep -qE "$2" + echo "$1" | grep -qP "$2" } get_partitions_by_id () { @@ -96,3 +95,4 @@ get_partitions_by_id () { && echo "$(blockdev --getsize64 "$dev") $dev" done | sort -n -k1 -r | cut -d' ' -f2 } + |