Most stuff should be complete.

This commit is contained in:
2026-06-24 17:44:17 +02:00
parent 76a04b7d3e
commit 212fa7ed44
4 changed files with 161 additions and 65 deletions
+20 -20
View File
@@ -111,29 +111,29 @@ pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError>
/// 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> {
let out = Command::new(cmd).args(args).output()?;
if out.status.success() {
Ok(String::from_utf8(out.stdout)?)
} else {
Err(CommandFailed::new(cmd, args, out.stderr).into())
}
}
// pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandError> {
// let out = Command::new(cmd).args(args).output()?;
// if out.status.success() {
// Ok(String::from_utf8(out.stdout)?)
// } else {
// Err(CommandFailed::new(cmd, args, out.stderr).into())
// }
// }
// ls /dev/disk/by-partlabel/
// here we can find gpt part labels
pub fn list_gpt_labeled_devs() -> Result<Vec<String>, ExecCommandError> {
use std::os::unix::fs::FileTypeExt;
let mut res: Vec<String> = Vec::new();
for maybe_entry in fs::read_dir("/dev/disk/by-partlabel/")? {
let entry = maybe_entry?;
if entry.file_type()?.is_block_device() {
res.push(entry.path().to_str().unwrap().to_string());
}
}
// pub fn list_gpt_labeled_devs() -> Result<Vec<String>, ExecCommandError> {
// use std::os::unix::fs::FileTypeExt;
// let mut res: Vec<String> = Vec::new();
// for maybe_entry in fs::read_dir("/dev/disk/by-partlabel/")? {
// let entry = maybe_entry?;
// if entry.file_type()?.is_block_device() {
// res.push(entry.path().to_str().unwrap().to_string());
// }
// }
Ok(res)
}
// Ok(res)
// }
/// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0somedev
/// Ok so. It is stupid, because bcacheutils far from ideal.
@@ -183,7 +183,7 @@ pub fn bcachefs_unlock(pass: String, dev: &str) -> Result<bool, ExecCommandError
/// Cheking if device is encripted
pub fn bzzpss_dev_encrypted(dev_name: &str) -> Result<bool, ExecCommandError> {
match exec_command("bcachefs", &vec!["unlock", "--check"]) {
match exec_command("bcachefs", &vec!["unlock", "--check", dev_name]) {
Ok(_) => Ok(true), // if status OK - dev encrypted
Err(ExecCommandError::CommandFailed(_)) => Ok(false), // if bcachefs returned error - unencrypted
Err(ex) => Err(ex), // othervice its error