Skip to content

Commit

Permalink
Check for existing mountpoints on install device
Browse files Browse the repository at this point in the history
Signed-off-by: djach7 <djachimo@redhat.com>
  • Loading branch information
djach7 committed Oct 3, 2024
1 parent ab6c4a6 commit 738eb54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
19 changes: 4 additions & 15 deletions lib/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,22 @@ impl Device {
self.children.as_ref().map_or(false, |v| !v.is_empty())
}

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

// findmnt -N 1 --output=SOURCE

let mounts = String::from_utf8(output.stdout).unwrap();

let mut mounts_present = false;

if mounts.contains(&self.path()) {
//if mounts.contains("/dev/vdb3") {
mounts_present = true;
return Ok(true);
}

println!("{mounts}");

Ok(mounts_present)
Ok(false)
}

// The "start" parameter was only added in a version of util-linux that's only
Expand Down
3 changes: 1 addition & 2 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ pub(crate) fn install_create_rootfs(
let devpath: Utf8PathBuf = device.path().into();

// Always disallow writing to mounted device
if device.is_mounted_in_pid_mounts(rustix::process::getpid()).expect("Failed to check mountpoints") {
println!("{:?}", rustix::process::getpid());
if device.is_mounted_in_pid_mounts().expect("Failed to check mountpoints") {
anyhow::bail!("Device {} is mounted", device.path())
}

Expand Down

0 comments on commit 738eb54

Please sign in to comment.