99fs-lib/fs-lib.sh: accept "UUID=" and "LABEL=" for fsck_single

with the reuse of crypt-lib.sh devnames() and putting it in
dracut-lib.sh, fsck_single() can use more generic names from /etc/fstab
master
Harald Hoyer 2011-12-02 16:47:24 +01:00
parent 452e46dbfc
commit 1939a4f96e
3 changed files with 41 additions and 38 deletions

View File

@ -100,43 +100,6 @@ test_dev() {
return $ret
}

# Get kernel name for given device. Device may be the name too (then the same
# is returned), a symlink (full path), UUID (prefixed with "UUID=") or label
# (prefixed with "LABEL="). If just a beginning of the UUID is specified or
# even an empty, function prints all device names which UUIDs match - every in
# single line.
#
# NOTICE: The name starts with "/dev/".
#
# Example:
# devnames UUID=123
# May print:
# /dev/dm-1
# /dev/sdb1
# /dev/sdf3
devnames() {
local dev="$1"; local d; local names

case "$dev" in
UUID=*)
dev="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \
&& return 255
[ -z "$dev" ] && return 255
;;
LABEL=*) dev="$(blkid -L "${dev#LABEL=}")" || return 255 ;;
/dev/?*) ;;
*) return 255 ;;
esac

for d in $dev; do
names="$names
$(readlink -e -q "$d")" || return 255
done

echo "${names#
}"
}

# match_dev devpattern dev
#
# Returns true if 'dev' matches 'devpattern'. Both 'devpattern' and 'dev' are

View File

@ -555,6 +555,44 @@ foreach_uuid_until() (
return 1
)

# Get kernel name for given device. Device may be the name too (then the same
# is returned), a symlink (full path), UUID (prefixed with "UUID=") or label
# (prefixed with "LABEL="). If just a beginning of the UUID is specified or
# even an empty, function prints all device names which UUIDs match - every in
# single line.
#
# NOTICE: The name starts with "/dev/".
#
# Example:
# devnames UUID=123
# May print:
# /dev/dm-1
# /dev/sdb1
# /dev/sdf3
devnames() {
local dev="$1"; local d; local names

case "$dev" in
UUID=*)
dev="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \
&& return 255
[ -z "$dev" ] && return 255
;;
LABEL=*) dev="$(blkid -L "${dev#LABEL=}")" || return 255 ;;
/dev/?*) ;;
*) return 255 ;;
esac

for d in $dev; do
names="$names
$(readlink -e -q "$d")" || return 255
done

echo "${names#
}"
}


usable_root() {
local _d
[ -d $1 ] || return 1

View File

@ -184,7 +184,9 @@ fsck_single() {
local _drv

[ $# -lt 2 ] && return 255

# if UUID= marks more than one device, take only the first one
[ -e "$_dev" ] || _dev=$(devnames "$_dev"| while read line; do if [ -n "$line" ]; then echo $line; break;fi;done)
[ -e "$_dev" ] || return 255
_fs=$(det_fs "$_dev" "$_fs")
fsck_able "$_fs" || return 255