Skip to content

fix(devices): hide system loop and busy volumes - #2104

Closed
zhouwg wants to merge 1 commit into
lgse:mainfrom
kantv-linux:kan
Closed

zhouwg wants to merge 1 commit into
lgse:mainfrom
kantv-linux:kan

Conversation

@zhouwg

@zhouwg zhouwg commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Strata's DEVICES section lists volumes that cannot be operated normally.

Cause

System-held devices surface as ordinary volumes:

  1. gvfs lists loop devices set up by root (its filter only skips loops set up by other users), so the live rootfs squashfs loop shows up as an unmounted volume. The kernel already holds it as the overlay lower layer, so every mount attempt returns EBUSY.
  2. The ISO behind that squashfs is likewise held (its filesystem stays alive through the loop's backing file, but no mount is visible to the volume monitor), so mount and eject both fail with EBUSY.

Fix

Hides volumes that are not user media:

  • unmounted loop device volumes (/dev/loopN, including partitions) --- system plumbing such as a live rootfs squashfs; mounted loop volumes keep their rows;
  • unmounted volumes whose block device rejects an O_EXCL open with EBUSY, which is mount(8)'s own "already mounted" test.

Busy error text is mapped to the existing "The item is in use" string in the mount/eject error dialogs, keeping backend wording out of the UI.

Volumes without a filesystem are not affected --- gvfs exposes no volume for them, so this fix neither hides nor shows them.

Visual evidence

Before fix:
screenshot-2026-11-09_14-25-13-173
screenshot-2026-11-09_14-25-23-926
screenshot-2026-11-09_14-25-41-181

After partially fix
screenshot-2026-11-09_15-44-43-076
screenshot-2026-11-09_15-44-53-374

Expected result(after fully fix):
screenshot-2026-11-09_19-46-43-860

How to test

This is a corner case: launch the QEMU VM with two virtual disks and a bootable LiveISO.

qemu-system-x86_64 -enable-kvm -cpu host -m 4G -smp 2 -drive file=kanlinux.qcow2,format=qcow2,if=virtio -drive file=kanlinux-data.qcow2,format=qcow2,if=virtio -cdrom kan-linux-0.3.2-x86_64.iso -boot d -device virtio-vga,xres=1920,yres=1080 -display gtk  -usb -device usb-tablet -audiodev pa,id=audio0,out.buffer-length=100000,in.buffer-length=100000,timer-period=1000 -device intel-hda -device hda-duplex,audiodev=audio0 -netdev user,id=net0,hostfwd=tcp::2222-:22 -device virtio-net-pci,netdev=net0

Related issue

N / A

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, Paired with MiMoCode + MiMo-V2.6-Pro, use MiMo-V2.6-Pro to generate the fix, then reviewed/tested manually.

@github-actions github-actions Bot added the fix label Nov 9, 2026
@l0gicgate

Copy link
Copy Markdown
Contributor

Review

Not pushed. This fork belongs to an organization, so "Allow edits by maintainers" is unavailable and I could not push to kan. The fixes below are in the patch at the end of this comment; it applies cleanly to ae89bc807 with git apply.

Merged main at 1a697bbfd locally, no conflicts.

CI on ae89bc807 fails. The run needed maintainer approval; once approved, Quality build and lint stops at cargo fmt --check (src/services/mod.rs, src/services/file_source/tests.rs, src/ui/window/devices.rs), so the test shards never ran. Run locally, the existing ui::window::device_release::tests::flush_failure_does_not_start_unmount also fails on this branch: its G_IO_ERROR_FAILED "device busy" fixture is rewritten to "The item is in use".

Findings, all fixed in the patch

  1. The loop rule also hides disk images the user attached. is_unmounted_loop_device hides every unmounted /dev/loopN volume. The comment says such a loop "is already automounted by gvfs", but GVfs only marks it (should_automount); a desktop automounter does the mounting. Without one (Hyprland, Sway), udisksctl loop-setup -f disk.iso produces an unmounted volume that Devices lists on main and this PR removes. GVfs sets should_automount on a loop exactly when SetupByUID is the current user (gvfsudisks2volume.c), and reports the volume class as loop. The patch hides a loop only when its class is loop and it is not marked for automount, which still covers a root image set up by the initramfs and drops the device-name parsing.

  2. The busy probe opens device nodes on the UI thread. hides_volume runs twice per volume on every sidebar rebuild, and block_device_is_busy calls open(2) on the block device each time. On an optical drive that open can wait on the drive (runtime resume, media check, a damaged disc), freezing the window. It also takes an exclusive claim on each rebuild, which can race a mount in progress. The patch runs the probe through the same off-thread cache the crypto hints use (extracted as devices/probe_cache.rs), re-probing when volumes or drives change. The row is listed until the first answer arrives, then the sidebar rebuilds.

  3. busy_reason matches too much. Any message containing "busy" became "The item is in use". UDisks messages carry device labels and mount paths, so Error mounting /dev/sdb1 at /run/media/me/BUSYBOX: wrong fs type lost its real cause, and in decide_gio the text match overrode typed GIO errors. The patch matches the phrases resource busy, mount point busy and target is busy, only on G_IO_ERROR_FAILED, in one gio_device_error_message used by both dialogs.

  4. Formatting, and the three long doc comments, tightened.

Tests

  • unmounted_loop_devices_are_not_user_media is replaced by a_loop_the_user_attached_is_not_system_plumbing, since the name parser it covered is gone.
  • busy_probe_is_quiet_for_devices_we_can_open is kept as a_device_that_cannot_be_probed_is_not_reported_as_held.
  • busy_failures_read_as_a_plain_reason is replaced by busy_device_failures_read_as_in_use, which adds the label case.
  • The off-thread path is covered by the existing crypto_hints_are_read_off_the_ui_thread_and_rebuild_the_sidebar_when_they_arrive, which now exercises the shared cache.

Validation, on the patched branch merged with main

  • ./scripts/test-headless.py -- ui::window:: ui::browser::location:: services::file_source::: 468 passed, 0 failed
  • cargo fmt --all --check and cargo clippy --all-targets --all-features -- -D warnings: clean (native, not the pinned container)
  • scripts/code-health.sh on the touched files: no new findings; devices.rs is 91 lines shorter than on this branch
  • Not run: the full Rust suite and QA scenarios (the change is confined to the Devices listing and two error dialogs), and no manual check against a live ISO, which I cannot reproduce here

Open points

  • @zhouwg please confirm on the live ISO that the squashfs loop and the ISO volume are still hidden with the patch. The loop case relies on the loop having been set up outside UDisks (SetupByUID 0) and the session not running as root; a root session falls through to the exclusive-open probe instead.
  • The exclusive-open probe only detects anything when the user can open the device node, which for a regular user means optical drives (uaccess). Other held devices return EACCES and stay listed.
  • The busy phrases are English. A UDisks daemon running in another locale keeps the backend text, as before this PR.
  • The PR has no linked issue; the repository workflow is issue-first.
Patch against ae89bc807
diff --git a/src/services/file_source.rs b/src/services/file_source.rs
index 6dbf68ad7..b2ea6098e 100644
--- a/src/services/file_source.rs
+++ b/src/services/file_source.rs
@@ -259,13 +259,22 @@ pub(crate) fn describes_refused_credentials(message: &str) -> bool {
     .any(|reason| message.contains(reason))
 }
 
-/// A device held by the system fails as generic `G_IO_ERROR_FAILED` whose text
-/// is the backend's own ("Device or resource busy"); show the plain reason.
-pub(crate) fn busy_reason(message: &str) -> Option<&'static str> {
-    message
-        .to_ascii_lowercase()
-        .contains("busy")
-        .then_some("The item is in use")
+/// [`gio_error_message`] for mount, unmount and eject failures. UDisks and
+/// eject(1) report a busy device as `G_IO_ERROR_FAILED`, with the cause only
+/// in the system's own text.
+pub(crate) fn gio_device_error_message(error: &glib::Error) -> String {
+    if error.matches(gtk::gio::IOErrorEnum::Failed) && describes_busy_device(error.message()) {
+        return crate::i18n::tr("The item is in use");
+    }
+    gio_error_message(error)
+}
+
+/// Whole phrases, because these messages also carry device labels and mount paths.
+fn describes_busy_device(message: &str) -> bool {
+    let message = message.to_ascii_lowercase();
+    ["resource busy", "mount point busy", "target is busy"]
+        .iter()
+        .any(|reason| message.contains(reason))
 }
 
 fn gio_error_reason(error: &glib::Error) -> Option<&'static str> {
diff --git a/src/services/file_source/tests.rs b/src/services/file_source/tests.rs
index dab56e7c7..ee8911818 100644
--- a/src/services/file_source/tests.rs
+++ b/src/services/file_source/tests.rs
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: MIT
 
 use super::{
-    LocationValidationError, UriCredentials, backend_unavailable_message, busy_reason,
-    error_detail_in, io_error_message, sanitize_uri_credentials, validate_uri_credentials,
+    LocationValidationError, UriCredentials, backend_unavailable_message, error_detail_in,
+    gio_device_error_message, io_error_message, sanitize_uri_credentials, validate_uri_credentials,
 };
 
 #[test]
@@ -275,14 +275,20 @@ fn default_fill_reports_unsupported_synchronously() {
 }
 
 #[test]
-fn busy_failures_read_as_a_plain_reason() {
+fn busy_device_failures_read_as_in_use() {
+    use gtk::{gio::IOErrorEnum, glib::Error};
+    for busy in [
+        "Error ejecting /dev/sr0: eject: cannot open /dev/sr0: Device or resource busy",
+        "Error mounting /dev/loop0 at /run/media/me/live: /dev/loop0 already mounted or mount point busy",
+    ] {
+        assert_eq!(
+            gio_device_error_message(&Error::new(IOErrorEnum::Failed, busy)),
+            "The item is in use"
+        );
+    }
+    let labelled = "Error mounting /dev/sdb1 at /run/media/me/BUSYBOX: wrong fs type";
     assert_eq!(
-        busy_reason("Error ejecting /dev/sr0: eject: cannot open /dev/sr0: Device or resource busy"),
-        Some("The item is in use")
+        gio_device_error_message(&Error::new(IOErrorEnum::Failed, labelled)),
+        labelled
     );
-    assert_eq!(
-        busy_reason("/dev/loop0 already mounted or mount point busy"),
-        Some("The item is in use")
-    );
-    assert_eq!(busy_reason("No such file or folder"), None);
 }
diff --git a/src/services/mod.rs b/src/services/mod.rs
index 67b4c30e0..f78c37513 100644
--- a/src/services/mod.rs
+++ b/src/services/mod.rs
@@ -57,10 +57,9 @@ pub use file_source::{
     backend_unavailable_message, sanitize_uri_credentials, validate_uri_credentials,
 };
 pub(crate) use file_source::{
-    INVALID_NAME_REASON, UNEXPECTED_SYSTEM_ERROR, busy_reason, describes_refused_credentials,
-    error_detail,
-    gio_backend_error_message, gio_error_detail, gio_error_message, io_error_detail,
-    io_error_message, sanitize_failure_message, system_error_text,
+    INVALID_NAME_REASON, UNEXPECTED_SYSTEM_ERROR, describes_refused_credentials, error_detail,
+    gio_backend_error_message, gio_device_error_message, gio_error_detail, gio_error_message,
+    io_error_detail, io_error_message, sanitize_failure_message, system_error_text,
 };
 pub use install_source::{InstallSource, ManagedInstall};
 pub(crate) use install_source::{ensure_self_managed, installed_executable};
diff --git a/src/ui/browser/location/volumes.rs b/src/ui/browser/location/volumes.rs
index 47b0808d2..5a003145c 100644
--- a/src/ui/browser/location/volumes.rs
+++ b/src/ui/browser/location/volumes.rs
@@ -291,13 +291,10 @@ impl ViewState {
         } else {
             self.finish_unlock_slot(&mount.waited.keys);
             if !mount_error_is_cancelled(&error) {
-                let message = crate::services::busy_reason(error.message())
-                    .map(crate::i18n::tr)
-                    .unwrap_or_else(|| error.to_string());
                 show_error_dialog(
                     &self.overlay,
                     &crate::i18n::tr("Unable to mount volume"),
-                    &message,
+                    &crate::services::gio_device_error_message(&error),
                 );
             }
         }
diff --git a/src/ui/window/device_release/run.rs b/src/ui/window/device_release/run.rs
index 8a9822f4c..d76c302da 100644
--- a/src/ui/window/device_release/run.rs
+++ b/src/ui/window/device_release/run.rs
@@ -68,9 +68,7 @@ pub(in crate::ui::window) fn decide_gio(
             safe_to_remove: false,
         },
         Err(error) => {
-            let mut message = crate::services::busy_reason(error.message())
-                .map(crate::i18n::tr)
-                .unwrap_or_else(|| crate::services::gio_error_message(&error));
+            let mut message = crate::services::gio_device_error_message(&error);
             if let Some(progress) = progress.map(str::trim).filter(|line| !line.is_empty()) {
                 message.push('\n');
                 message.push_str(progress);
diff --git a/src/ui/window/devices.rs b/src/ui/window/devices.rs
index de7445295..b9f8c2d22 100644
--- a/src/ui/window/devices.rs
+++ b/src/ui/window/devices.rs
@@ -11,6 +11,12 @@ use gtk::{gio, prelude::*};
 
 use crate::adapters::MountTable;
 
+mod held;
+mod probe_cache;
+
+pub(super) use held::{is_exclusively_held, is_system_loop};
+use probe_cache::ProbeCache;
+
 pub(super) fn block_device_from_mount_table(table: &MountTable, path: &Path) -> Option<PathBuf> {
     table
         .source_for(path)
@@ -42,47 +48,6 @@ pub(super) fn label_identity(uuid: Option<&str>, root_uri: Option<&str>) -> Opti
         })
 }
 
-/// A loop device node name: `loop0`, or a partition such as `loop0p1`.
-pub(super) fn is_loop_device_name(name: &str) -> bool {
-    let Some(rest) = name.strip_prefix("loop") else {
-        return false;
-    };
-    let (digits, partition) = match rest.split_once('p') {
-        Some((digits, partition)) => (digits, Some(partition)),
-        None => (rest, None),
-    };
-    let number = |text: &str| !text.is_empty() && text.bytes().all(|byte| byte.is_ascii_digit());
-    number(digits) && partition.is_none_or(number)
-}
-
-/// An unmounted loop device is system plumbing — the live rootfs squashfs sits
-/// on one — not user media, so Devices hides it instead of offering a mount
-/// that cannot succeed. A loop the user set up is already automounted by gvfs
-/// and stays listed as its mount.
-pub(super) fn is_unmounted_loop_device(unix_device: Option<&str>, has_mount: bool) -> bool {
-    !has_mount
-        && unix_device.is_some_and(|device| {
-            device
-                .rsplit('/')
-                .next()
-                .is_some_and(is_loop_device_name)
-        })
-}
-
-/// A device the kernel already holds — the live medium backing the rootfs, for
-/// one — is busy even when the volume monitor shows no mount. `O_EXCL` on a
-/// block device is mount(8)'s own "already mounted or mount point busy" test,
-/// so a volume that fails it is hidden rather than offered as mountable.
-pub(super) fn block_device_is_busy(unix_device: &str) -> bool {
-    use std::os::unix::fs::OpenOptionsExt;
-    std::fs::OpenOptions::new()
-        .read(true)
-        .custom_flags(libc::O_EXCL | libc::O_NONBLOCK)
-        .open(unix_device)
-        .err()
-        .is_some_and(|error| error.raw_os_error() == Some(libc::EBUSY))
-}
-
 pub(super) fn device_identity(
     unix_device: Option<&str>,
     uuid: Option<&str>,
@@ -598,15 +563,8 @@ pub(super) fn encrypted_device_is_locked(
     }
 }
 
-#[derive(Default)]
-struct CryptoHints {
-    known: RefCell<HashMap<String, BlockCryptoHint>>,
-    pending: RefCell<HashSet<String>>,
-    monitor: OnceCell<gio::VolumeMonitor>,
-}
-
 thread_local! {
-    static CRYPTO_HINTS: CryptoHints = CryptoHints::default();
+    static CRYPTO_HINTS: ProbeCache<BlockCryptoHint> = ProbeCache::default();
 }
 
 pub(super) fn block_crypto_hint(unix_device: &str) -> BlockCryptoHint {
@@ -617,56 +575,7 @@ fn block_crypto_hint_with(
     unix_device: &str,
     probe: fn(&str) -> BlockCryptoHint,
 ) -> BlockCryptoHint {
-    CRYPTO_HINTS.with(|hints| {
-        hints.monitor.get_or_init(|| {
-            let monitor = gio::VolumeMonitor::get();
-            let recheck = move || recheck_crypto_hints(probe);
-            monitor.connect_volume_added(move |_, _| recheck());
-            monitor.connect_volume_removed(move |_, _| recheck());
-            monitor.connect_volume_changed(move |_, _| recheck());
-            monitor.connect_drive_connected(move |_, _| recheck());
-            monitor.connect_drive_disconnected(move |_, _| recheck());
-            monitor.connect_drive_changed(move |_, _| recheck());
-            monitor
-        });
-    });
-    let known = CRYPTO_HINTS.with(|hints| hints.known.borrow().get(unix_device).cloned());
-    known.unwrap_or_else(|| {
-        probe_crypto_hint(unix_device.to_owned(), probe);
-        BlockCryptoHint::default()
-    })
-}
-
-fn recheck_crypto_hints(probe: fn(&str) -> BlockCryptoHint) {
-    let devices: Vec<String> =
-        CRYPTO_HINTS.with(|hints| hints.known.borrow().keys().cloned().collect());
-    for device in devices {
-        probe_crypto_hint(device, probe);
-    }
-}
-
-fn probe_crypto_hint(unix_device: String, probe: fn(&str) -> BlockCryptoHint) {
-    if !CRYPTO_HINTS.with(|hints| hints.pending.borrow_mut().insert(unix_device.clone())) {
-        return;
-    }
-    gtk::glib::MainContext::default().spawn_local(async move {
-        let device = unix_device.clone();
-        let hint = gio::spawn_blocking(move || probe(&device))
-            .await
-            .unwrap_or_default();
-        let changed = CRYPTO_HINTS.with(|hints| {
-            hints.pending.borrow_mut().remove(&unix_device);
-            let seen = hints
-                .known
-                .borrow_mut()
-                .insert(unix_device, hint.clone())
-                .unwrap_or_default();
-            seen != hint
-        });
-        if changed {
-            super::device_release::refresh_sidebars();
-        }
-    });
+    probe_cache::cached(&CRYPTO_HINTS, unix_device, probe)
 }
 
 fn probe_block_crypto(unix_device: &str) -> BlockCryptoHint {
diff --git a/src/ui/window/devices/held.rs b/src/ui/window/devices/held.rs
new file mode 100644
index 000000000..4a3f0bfff
--- /dev/null
+++ b/src/ui/window/devices/held.rs
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: MIT
+
+//! Volumes GVfs lists although the system holds them, so they cannot be mounted.
+
+use super::probe_cache::{self, ProbeCache};
+
+thread_local! {
+    static HELD: ProbeCache<bool> = ProbeCache::default();
+}
+
+/// GVfs marks a loop for automount only when this user attached it. Any other
+/// loop is system plumbing, such as the root image of a live system.
+pub(in crate::ui::window) fn is_system_loop(class: Option<&str>, should_automount: bool) -> bool {
+    class == Some("loop") && !should_automount
+}
+
+pub(in crate::ui::window) fn is_exclusively_held(unix_device: &str) -> bool {
+    probe_cache::cached(&HELD, unix_device, exclusive_open_is_refused)
+}
+
+/// The kernel refuses `O_EXCL` on a block device that a file system or another
+/// holder has claimed, including one mounted where the volume monitor cannot see.
+pub(super) fn exclusive_open_is_refused(unix_device: &str) -> bool {
+    use std::os::unix::fs::OpenOptionsExt;
+    std::fs::OpenOptions::new()
+        .read(true)
+        .custom_flags(libc::O_EXCL | libc::O_NONBLOCK)
+        .open(unix_device)
+        .err()
+        .is_some_and(|error| error.raw_os_error() == Some(libc::EBUSY))
+}
diff --git a/src/ui/window/devices/probe_cache.rs b/src/ui/window/devices/probe_cache.rs
new file mode 100644
index 000000000..24bb31cb6
--- /dev/null
+++ b/src/ui/window/devices/probe_cache.rs
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: MIT
+
+//! Block-device facts read off the UI thread and kept until the devices change.
+
+use std::{
+    cell::{OnceCell, RefCell},
+    collections::{HashMap, HashSet},
+    thread::LocalKey,
+};
+
+use gtk::{gio, prelude::*};
+
+pub(super) struct ProbeCache<T> {
+    known: RefCell<HashMap<String, T>>,
+    pending: RefCell<HashSet<String>>,
+    monitor: OnceCell<gio::VolumeMonitor>,
+}
+
+impl<T> Default for ProbeCache<T> {
+    fn default() -> Self {
+        Self {
+            known: RefCell::default(),
+            pending: RefCell::default(),
+            monitor: OnceCell::new(),
+        }
+    }
+}
+
+pub(super) trait Fact: Clone + Default + PartialEq + Send + 'static {}
+
+impl<T: Clone + Default + PartialEq + Send + 'static> Fact for T {}
+
+type Cache<T> = &'static LocalKey<ProbeCache<T>>;
+
+/// The known fact, or its default while the first probe runs. The sidebars
+/// rebuild when a probe changes the answer.
+pub(super) fn cached<T: Fact>(cache: Cache<T>, unix_device: &str, probe: fn(&str) -> T) -> T {
+    cache.with(|state| {
+        state.monitor.get_or_init(|| {
+            let monitor = gio::VolumeMonitor::get();
+            let recheck = move || recheck(cache, probe);
+            monitor.connect_volume_added(move |_, _| recheck());
+            monitor.connect_volume_removed(move |_, _| recheck());
+            monitor.connect_volume_changed(move |_, _| recheck());
+            monitor.connect_drive_connected(move |_, _| recheck());
+            monitor.connect_drive_disconnected(move |_, _| recheck());
+            monitor.connect_drive_changed(move |_, _| recheck());
+            monitor
+        });
+    });
+    let known = cache.with(|state| state.known.borrow().get(unix_device).cloned());
+    known.unwrap_or_else(|| {
+        start(cache, unix_device.to_owned(), probe);
+        T::default()
+    })
+}
+
+fn recheck<T: Fact>(cache: Cache<T>, probe: fn(&str) -> T) {
+    let devices: Vec<String> = cache.with(|state| state.known.borrow().keys().cloned().collect());
+    for device in devices {
+        start(cache, device, probe);
+    }
+}
+
+fn start<T: Fact>(cache: Cache<T>, unix_device: String, probe: fn(&str) -> T) {
+    if !cache.with(|state| state.pending.borrow_mut().insert(unix_device.clone())) {
+        return;
+    }
+    gtk::glib::MainContext::default().spawn_local(async move {
+        let device = unix_device.clone();
+        let fact = gio::spawn_blocking(move || probe(&device))
+            .await
+            .unwrap_or_default();
+        let changed = cache.with(|state| {
+            state.pending.borrow_mut().remove(&unix_device);
+            let seen = state
+                .known
+                .borrow_mut()
+                .insert(unix_device, fact.clone())
+                .unwrap_or_default();
+            seen != fact
+        });
+        if changed {
+            super::super::device_release::refresh_sidebars();
+        }
+    });
+}
diff --git a/src/ui/window/devices/tests.rs b/src/ui/window/devices/tests.rs
index da304ae79..e878c25a4 100644
--- a/src/ui/window/devices/tests.rs
+++ b/src/ui/window/devices/tests.rs
@@ -643,24 +643,26 @@ fn a_device_check_refused_while_its_mount_stalls_never_hides_the_device() {
 }
 
 #[test]
-fn unmounted_loop_devices_are_not_user_media() {
-    assert!(is_loop_device_name("loop0"));
-    assert!(is_loop_device_name("loop10"));
-    assert!(is_loop_device_name("loop0p1"));
-    assert!(!is_loop_device_name("loop"));
-    assert!(!is_loop_device_name("loopx"));
-    assert!(!is_loop_device_name("vda2"));
-    assert!(is_unmounted_loop_device(Some("/dev/loop0"), false));
-    assert!(is_unmounted_loop_device(Some("/dev/loop0p1"), false));
-    assert!(!is_unmounted_loop_device(Some("/dev/loop0"), true));
-    assert!(!is_unmounted_loop_device(Some("/dev/sr0"), false));
-    assert!(!is_unmounted_loop_device(Some("/dev/vda2"), false));
-    assert!(!is_unmounted_loop_device(None, false));
+fn a_loop_the_user_attached_is_not_system_plumbing() {
+    for (class, should_automount, system) in [
+        (Some("loop"), false, true),
+        (Some("loop"), true, false),
+        (Some("device"), false, false),
+        (None, false, false),
+    ] {
+        assert_eq!(
+            is_system_loop(class, should_automount),
+            system,
+            "{class:?} automount {should_automount}"
+        );
+    }
 }
 
 #[test]
-fn busy_probe_is_quiet_for_devices_we_can_open() {
-    assert!(!block_device_is_busy("/definitely/not/a/device"));
+fn a_device_that_cannot_be_probed_is_not_reported_as_held() {
+    assert!(!held::exclusive_open_is_refused("/definitely/not/a/device"));
     let free = tempfile::NamedTempFile::new().expect("temp file");
-    assert!(!block_device_is_busy(free.path().to_str().expect("utf-8")));
+    assert!(!held::exclusive_open_is_refused(
+        free.path().to_str().expect("utf-8")
+    ));
 }
diff --git a/src/ui/window/gio_devices.rs b/src/ui/window/gio_devices.rs
index ba1ce024d..a4fc45845 100644
--- a/src/ui/window/gio_devices.rs
+++ b/src/ui/window/gio_devices.rs
@@ -47,6 +47,17 @@ pub(in crate::ui) fn gio_volume_unix_device(volume: &gio::Volume) -> Option<glib
     volume.identifier(gio::VOLUME_IDENTIFIER_KIND_UNIX_DEVICE.as_str())
 }
 
+/// An unmounted volume the system holds cannot be mounted, so it gets no row.
+pub(super) fn gio_volume_is_system_held(volume: &gio::Volume) -> bool {
+    if volume.get_mount().is_some() {
+        return false;
+    }
+    let class = volume.identifier(gio::VOLUME_IDENTIFIER_KIND_CLASS.as_str());
+    devices::is_system_loop(class.as_deref(), volume.should_automount())
+        || gio_volume_unix_device(volume)
+            .is_some_and(|device| devices::is_exclusively_held(&device))
+}
+
 pub(crate) fn gio_volume_is_encrypted(volume: &gio::Volume) -> bool {
     gio_icons_are_encrypted(
         &volume.icon(),
diff --git a/src/ui/window/sidebar_devices.rs b/src/ui/window/sidebar_devices.rs
index 01aab55fd..915bb8e14 100644
--- a/src/ui/window/sidebar_devices.rs
+++ b/src/ui/window/sidebar_devices.rs
@@ -22,8 +22,8 @@ use super::{
     drive_dialogs::PropertiesTarget,
     gio_devices::{
         gio_mount_is_encrypted, gio_volume_is_encrypted, gio_volume_is_locked,
-        gio_volume_unix_device, mount_placement, orphaned_password_drives,
-        password_drive_placement, volume_placement,
+        gio_volume_is_system_held, gio_volume_unix_device, mount_placement,
+        orphaned_password_drives, password_drive_placement, volume_placement,
     },
     launch::navigate_to_gio_file,
     sidebar,
@@ -232,16 +232,7 @@ impl SidebarState {
 
     /// A local-only sidebar lists only volumes that are, or would mount as, local paths.
     fn hides_volume(&self, volume: &gio::Volume) -> bool {
-        if super::devices::is_unmounted_loop_device(
-            gio_volume_unix_device(volume).as_deref(),
-            volume.get_mount().is_some(),
-        ) {
-            return true;
-        }
-        if volume.get_mount().is_none()
-            && gio_volume_unix_device(volume)
-                .is_some_and(|device| super::devices::block_device_is_busy(&device))
-        {
+        if gio_volume_is_system_held(volume) {
             return true;
         }
         if !self.local_only {

@l0gicgate

Copy link
Copy Markdown
Contributor

The reviewed branch is now on this repository as fix/2104-hide-system-held-volumes: your commit, main merged at 241df3202, and the two fix commits from the review above. CI is green on it, including the full Rust suite and the QA scenarios: https://github.com/lgse/strata/actions/runs/42621309506

@zhouwg to bring this PR's checks green, fast-forward kan to it:

git switch kan
git pull --ff-only https://github.com/lgse/strata.git fix/2104-hide-system-held-volumes
git push

Please also confirm on the live ISO that the squashfs loop and the ISO volume stay hidden with these changes.

@l0gicgate

Copy link
Copy Markdown
Contributor

@zhouwg please enable me to push to your branch so I can fix and merge.

@l0gicgate

Copy link
Copy Markdown
Contributor

Superseded by #2105.

This fork does not allow maintainer pushes, so the review fixes could not land on kan. #2105 carries your commit unchanged, with main merged and the fixes from the review above on top, so your authorship is kept in the history.

Closing this one in its favour. @zhouwg if you can, please check #2105 on the live ISO and confirm there that the squashfs loop and the ISO volume are still hidden.

@l0gicgate l0gicgate closed this Nov 9, 2026
@zhouwg

zhouwg commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@zhouwg please enable me to push to your branch so I can fix and merge.

sorry to reply so late because of timezone issue. and I see the fix has been merged to mainline. Thank you.

@zhouwg

zhouwg commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #2105.

This fork does not allow maintainer pushes, so the review fixes could not land on kan. #2105 carries your commit unchanged, with main merged and the fixes from the review above on top, so your authorship is kept in the history.

Closing this one in its favour. @zhouwg if you can, please check #2105 on the live ISO and confirm there that the squashfs loop and the ISO volume are still hidden.

After aligning with upstream, the issues described in this PR has gone:

screenshot-2026-11-10_09-06-59-065 screenshot-2026-11-10_09-07-23-609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants