xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/media (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1#!/bin/sh
2#
3# Print out the type of device
4#
5
6if [ "$1" = "-h" ] ; then
7	echo "Show whether a vdev is a file, hdd, ssd, or iscsi."
8	exit
9fi
10
11# shellcheck disable=SC2154
12if [ -b "$VDEV_UPATH" ]; then
13	device="${VDEV_UPATH##*/}"
14	read -r val 2>/dev/null < "/sys/block/$device/queue/rotational"
15	case "$val" in
16		0) MEDIA="ssd" ;;
17		1) MEDIA="hdd" ;;
18		*) MEDIA="invalid" ;;
19	esac
20
21	vpd_pg83="/sys/block/$device/device/vpd_pg83"
22	if [ -f "$vpd_pg83" ]; then
23		if grep -q --binary "iqn." "$vpd_pg83"; then
24			MEDIA="iscsi"
25		fi
26	fi
27else
28	if [ -f "$VDEV_UPATH" ]; then
29		MEDIA="file"
30	fi
31fi
32
33echo "media=$MEDIA"
34