xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/media (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
1eda14cbcSMatt Macy#!/bin/sh
2eda14cbcSMatt Macy#
3eda14cbcSMatt Macy# Print out the type of device
4eda14cbcSMatt Macy#
5eda14cbcSMatt Macy
6eda14cbcSMatt Macyif [ "$1" = "-h" ] ; then
753b70c86SMartin Matuska	echo "Show whether a vdev is a file, hdd, ssd, or iscsi."
8eda14cbcSMatt Macy	exit
9eda14cbcSMatt Macyfi
10eda14cbcSMatt Macy
11*e92ffd9bSMartin Matuska# shellcheck disable=SC2154
12eda14cbcSMatt Macyif [ -b "$VDEV_UPATH" ]; then
13dae17134SMartin Matuska	device="${VDEV_UPATH##*/}"
14dae17134SMartin Matuska	read -r val 2>/dev/null < "/sys/block/$device/queue/rotational"
15dae17134SMartin Matuska	case "$val" in
16dae17134SMartin Matuska		0) MEDIA="ssd" ;;
17dae17134SMartin Matuska		1) MEDIA="hdd" ;;
18*e92ffd9bSMartin Matuska		*) MEDIA="invalid" ;;
19dae17134SMartin Matuska	esac
2053b70c86SMartin Matuska
2153b70c86SMartin Matuska	vpd_pg83="/sys/block/$device/device/vpd_pg83"
2253b70c86SMartin Matuska	if [ -f "$vpd_pg83" ]; then
2353b70c86SMartin Matuska		if grep -q --binary "iqn." "$vpd_pg83"; then
2453b70c86SMartin Matuska			MEDIA="iscsi"
2553b70c86SMartin Matuska		fi
2653b70c86SMartin Matuska	fi
27eda14cbcSMatt Macyelse
28eda14cbcSMatt Macy	if [ -f "$VDEV_UPATH" ]; then
29eda14cbcSMatt Macy		MEDIA="file"
30eda14cbcSMatt Macy	fi
31eda14cbcSMatt Macyfi
32eda14cbcSMatt Macy
33eda14cbcSMatt Macyecho "media=$MEDIA"
34