#!/bin/bash

if [ -z "${__initrd_sh_functions-}" ]; then
__initrd_sh_functions=1

omit_pid() {
	: > "/.initrd/killall/$1"
}

devlinks_check() {
	local l
	for l in $DEVLINKS; do
		[ "$1" != "$l" ] ||
			return 0
	done
	return 1
}

get_majmin() {
	local v
	v="$(stat -L -c '%02t:%02T' "$1" 2>/dev/null)" &&
		printf '%d:%d\n' "0x${v%:*}" "0x${v#*:}" ||
		return 1
}

get_dev() {
	local name retval value

	if [ "$#" = 2 ]; then
		retval="$1"; shift
	fi
	name="$1"; shift

	case "$name" in
		'')
			return 1
			;;
		UUID=*)
			[ "$ID_FS_UUID" = "${name#UUID=}" ] ||
				return 1
			;;
		LABEL=*)
			[ "$ID_FS_LABEL" = "${name#LABEL=}" ] ||
				return 1
			;;
		/dev/disk/by-uuid/*)
			[ "/dev/disk/by-uuid/$ID_FS_UUID_ENC" = "$name" ] ||
				return 1
			;;
		/dev/disk/by-label/*)
			[ "/dev/disk/by-label/$ID_FS_LABEL_ENC" = "$name" ] ||
				return 1
			;;
		/dev/block/[0-9]*:[0-9]*)
			[ "/dev/block/$MAJOR:$MINOR" = "$name" ] ||
				return 1
			;;
		/*)
			[ "$DEVNAME" = "$name" ] || devlinks_check "$name" ||
				return 1
			;;
		*:*)
			[ "$MAJOR" = "${name%:*}" ] && [ "$MINOR" = "${name#*:}" ] ||
				return 1
			;;
		*)
			(_=$(( 0x$name ))) 2>/dev/null ||
				return 1
			[ "$MAJOR" = "$(( $value / 256 ))" ] && [ "$MINOR" = "$(( $value % 256 ))" ] ||
				return 1
			;;
	esac
	[ -z "$retval" ] ||
		eval "$retval=\"\$DEVNAME\""
}

readline()
{
        local __v=
        # shellcheck disable=SC2162
        read __v < "$2" ||:
        eval "$1=\"\$__v\""
}

_rootdelay_pause=/.initrd/rootdelay/pause

rootdelay_pause()
{
	mkdir -p "$_rootdelay_pause"
}

rootdelay_unpause()
{
	rm -rf "$_rootdelay_pause"
}

rootdelay_paused()
{
	[ -d "$_rootdelay_pause" ]
}

fi
