SHA256
Using blkid utility to determine dev name by gpt partlabel.
This commit is contained in:
+29
-1
@@ -110,6 +110,34 @@ pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError>
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets device node aka /dev/sda1 from gpr partition label
|
||||
/// blkid -s PARTLABEL --match-token "PARTLABEL=primary"
|
||||
pub fn find_partlabel(partlabel: &str) -> Result<String, ExecCommandError> {
|
||||
let out = Command::new("/usr/bin/blkid")
|
||||
.args([
|
||||
"-s",
|
||||
"PARTLABEL",
|
||||
"--match-token",
|
||||
format!("\"PARTLABEL={}\"", partlabel).as_str(),
|
||||
])
|
||||
.output()?;
|
||||
if out.status.success() {
|
||||
let out_text = String::from_utf8(out.stdout)?;
|
||||
|
||||
let split_res = out_text.split_once(':').ok_or_else(|| {
|
||||
ExecCommandError::Other(format!("Unexpected blkid output format: \"{}\"", out_text))
|
||||
})?;
|
||||
|
||||
Ok(split_res.0.to_string())
|
||||
} else {
|
||||
Err(ExecCommandError::Other(format!(
|
||||
"Connot find device with partlabel={} or something other is wrong: \"{}\"",
|
||||
partlabel,
|
||||
String::from_utf8(out.stderr).unwrap_or_else(|_| String::new())
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
/// exec given command with arguments, returning stdout parsed to UTF-8 string
|
||||
/// capturing stderr in case or failure
|
||||
// pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandError> {
|
||||
@@ -224,7 +252,7 @@ pub fn list_bzzpss_snaps(snaps_dir: &str) -> Result<Vec<String>, ExecCommandErro
|
||||
// mount -t sysfs none /sys
|
||||
// modprobe bcachefs
|
||||
pub fn prepare_env() -> Result<(), String> {
|
||||
use nix::mount::{mount, MsFlags};
|
||||
use nix::mount::{MsFlags, mount};
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user