From 2103067f25b6e81be2b86df7143ce765c5b24ab5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 24 Oct 2025 17:13:12 +0200 Subject: [PATCH] udev: introduce ID_BLOCK_SUBSYSTEM property Virtual block devices are a bit weird: they have no parent device, and thus cannot be related to the subsystem they belong to, except by pattern matching their name. This is OK to do if one knows what to look for. However for tools that do not want to carry a list of known subsystems with their appropriate matching patters this sucks. Let's introduce a new ID_BLOCK_SUBSYSTEM property we can set on block devices that carries an explicit string for this. Do so for a small number of key subsystems: DM, loopback and zram. --- rules.d/60-block.rules | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rules.d/60-block.rules b/rules.d/60-block.rules index cf307389b84..9d54a65e022 100644 --- a/rules.d/60-block.rules +++ b/rules.d/60-block.rules @@ -14,3 +14,11 @@ ACTION!="remove", SUBSYSTEM=="block", \ # Reset access rights to each loopback device once it gets detached. ACTION=="change", SUBSYSTEM=="block", KERNEL=="loop*", ENV{DISK_MEDIA_CHANGE}=="1", TEST!="loop/backing_file", GROUP="disk", MODE="660" + +# Provide a somewhat cleaned up field indicating the subsystem various +# 'virtual' block devices belong too, in order to avoid replicating name based +# pattern matching in every consumer +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="dm-*", ENV{ID_BLOCK_SUBSYSTEM}="dm" +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="loop*", ENV{ID_BLOCK_SUBSYSTEM}="loop" +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="md*", ENV{ID_BLOCK_SUBSYSTEM}="md" +ACTION!="remove", SUBSYSTEM=="block", KERNEL=="zram*", ENV{ID_BLOCK_SUBSYSTEM}="zram" -- 2.47.3