Skip to content

Commit eece03c

Browse files
committed
Check for existing mountpoints on install device
Signed-off-by: djach7 <djachimo@redhat.com>
1 parent ab6c4a6 commit eece03c

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

lib/src/blockdev.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,22 @@ impl Device {
5050
self.children.as_ref().map_or(false, |v| !v.is_empty())
5151
}
5252

53-
// I know I can pretty this up, very much a wip
54-
pub(crate) fn is_mounted_in_pid_mounts(&self, pid: rustix::process::Pid) -> Result<bool> {
53+
// Return true if device is mounted anywhere
54+
pub(crate) fn is_mounted_in_pid_mounts(&self) -> Result<bool> {
5555
let output = Command::new("findmnt")
5656
.arg("-N")
57-
//.arg((pid.as_raw_nonzero()).to_string())
5857
.arg("1")
59-
//.arg("-S")
60-
//.arg("/dev/vdb3")
61-
//.arg(self.path())
6258
.arg("--output=SOURCE")
6359
.output()
6460
.expect("Failed to execute findmnt");
6561

66-
// findmnt -N 1 --output=SOURCE
67-
6862
let mounts = String::from_utf8(output.stdout).unwrap();
6963

70-
let mut mounts_present = false;
71-
7264
if mounts.contains(&self.path()) {
73-
//if mounts.contains("/dev/vdb3") {
74-
mounts_present = true;
65+
return Ok(true);
7566
}
7667

77-
println!("{mounts}");
78-
79-
Ok(mounts_present)
68+
Ok(false)
8069
}
8170

8271
// The "start" parameter was only added in a version of util-linux that's only

lib/src/install/baseline.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ pub(crate) fn install_create_rootfs(
163163
let devpath: Utf8PathBuf = device.path().into();
164164

165165
// Always disallow writing to mounted device
166-
if device.is_mounted_in_pid_mounts(rustix::process::getpid()).expect("Failed to check mountpoints") {
167-
println!("{:?}", rustix::process::getpid());
166+
if device
167+
.is_mounted_in_pid_mounts()
168+
.expect("Failed to check mountpoints")
169+
{
168170
anyhow::bail!("Device {} is mounted", device.path())
169171
}
170172

0 commit comments

Comments
 (0)