#!/bin/bash -efu

. /.initrd/initenv
. uevent-sh-functions
. initrd-sh-functions

eof=
while [ -z "$eof" ]; do
	read -r fsdev fsdir fstype fsopts freq passno ||
		eof=1
	[ -n "$fsdev" ] ||
		continue

	if [ -n "${ROOTONLY-}" ]; then
		[ "$fsdir" = "$rootmnt" ] ||
			continue
	fi

	fsoptions=()
	readarray -d, -t fsoptions < <(printf '%s' "$fsopts")

	dev=
	for o in "${fsoptions[@]}"; do
		if [ "$o" = 'x-initrd-mount-virtual' ]; then
			# A virtual mountpoint does not have a real device and
			# fires every time a block device is found. Let's let
			# the handler decide to process this event or ignore it.
			dev="$fsdev"
			break
		fi
	done

	[ -n "$dev" ] || get_dev dev "$fsdev" ||
		continue

	event="$(make_event)"

	cat > "$event" <<-EOF
		MOUNTDEV="$dev"
		MOUNTPOINT="$fsdir"
	EOF

	release_event mountdev "$event"
done < /etc/fstab
