From 825062222c966b09c222fbc52966da04062c5af4 Mon Sep 17 00:00:00 2001 From: Tony Asleson Date: Tue, 9 Apr 2024 15:01:14 -0500 Subject: [PATCH] mount: canonicalize device path for single device node If we pass a symlink for a single device node we fail to locate the device node. Canonicalize the device node before we try to read up the superblock. This allows the following to work. # bcachefs mount /dev/mapper/vg-thinvolume /mnt/lv_thin Signed-off-by: Tony Asleson --- src/commands/cmd_mount.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/cmd_mount.rs b/src/commands/cmd_mount.rs index 53a20217..8d0e2e90 100644 --- a/src/commands/cmd_mount.rs +++ b/src/commands/cmd_mount.rs @@ -4,6 +4,7 @@ use clap::Parser; use uuid::Uuid; use std::io::{stdout, IsTerminal}; use std::path::PathBuf; +use std::fs; use crate::key; use crate::key::UnlockPolicy; use std::ffi::{CString, c_char, c_void}; @@ -125,11 +126,13 @@ fn get_devices_by_uuid(uuid: Uuid) -> anyhow::Result anyhow::Result> { let mut udev = udev::Enumerator::new()?; + let canonical = fs::canonicalize(device)?; + udev.match_subsystem("block")?; for dev in udev.scan_devices()?.into_iter() { if let Some(devnode) = dev.devnode() { - if devnode == device { + if devnode == canonical { let devnode_owned = devnode.to_owned(); let sb_result = read_super_silent(&devnode_owned); if let Ok(sb) = sb_result {