#!/bin/bash -efu
# SPDX-License-Identifier: GPL-3.0-or-later

. sh-functions
. guess-functions

$TRACE_SOURCE "Processing ..."

process_fstype() {
	local device="$1"

	fstype="$(sys_blkid -o value -s TYPE -c /dev/null "$device")" ||
		return 0

	case "$fstype" in
		swap|swsuspend)
			;;
		*)
			guess_fstype "$device" "$fstype"
			;;
	esac
}

process_devices() {
	local rc=1

	for device_file; do
		majmin="$(get_majmin "$device_file")" ||
			continue

		# kernel >= 2.6.27
		guess_device "/dev/block/$majmin"

		[ ! -b "$device_file" ] ||
			process_fstype "$device_file"
		rc=0
	done

	return $rc
}

pass=()
for d in ${DEVICES-}; do
	! in_list "$d" "${pass[@]}" ||
		continue
	process_devices "$d"
	pass+=("$d")
done
