summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-01-29 15:52:50 +0100
committerSimon Rettberg2024-01-29 15:52:50 +0100
commit85f56f87b04cc7497c0841c3e1016eb9cc2167e1 (patch)
treea5f1bc10946289771204aa67ad3bde310dfa1fef
parent[is] New module (diff)
downloadslx-tools-85f56f87b04cc7497c0841c3e1016eb9cc2167e1.tar.gz
slx-tools-85f56f87b04cc7497c0841c3e1016eb9cc2167e1.tar.xz
slx-tools-85f56f87b04cc7497c0841c3e1016eb9cc2167e1.zip
[dev] find_partitions: Add --rw option to skip scanning ro devices
-rw-r--r--modules/dev.inc9
1 files changed, 8 insertions, 1 deletions
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)$" \