From 85f56f87b04cc7497c0841c3e1016eb9cc2167e1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 Jan 2024 15:52:50 +0100 Subject: [dev] find_partitions: Add --rw option to skip scanning ro devices --- modules/dev.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/dev.inc b/modules/dev.inc index 13b042f..c054b63 100644 --- a/modules/dev.inc +++ b/modules/dev.inc @@ -8,7 +8,13 @@ # The output will be a list of matching devices, # sorted from largest to smallest. dev_find_partitions() { - local ID dev target + local ID dev target rw + # check if only interested in writable devices + rw= + if [ "$1" = "--rw" ]; then + shift + rw=1 + fi # target for the scan, defaults to /dev to check everything if [ "${1:0:1}" = "/" ] && [ -b "$1" ]; then target="$1" @@ -40,6 +46,7 @@ dev_find_partitions() { done local label number mbrid uuid for dev in $(find $target* -type b); do + [ -n "$rw" ] && [ "$( cat "/sys/class/block/$dev/ro" )" = "1" ] && continue dev_get_type "$dev" || continue echo "$dev is $number - MBR=$mbrid, UUID=$uuid, label=$label" >&2 if regex_imatch "$mbrid" "^($want_type)$" || regex_imatch "$uuid" "^($want_uuid)$" \ -- cgit v1.2.3-55-g7522