Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/bin/rdcore/rootmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ pub fn get_boot_mount_from_cmdline_args(
if let Some(path) = boot_mount {
Ok(Some(Mount::from_existing(path)?))
} else if let Some(devpath) = boot_device {
let devinfo = lsblk_single(Path::new(devpath))?;
let devinfo = blkid_single(Path::new(devpath))?;
let fs = devinfo
.get("FSTYPE")
.get("TYPE")
.with_context(|| format!("failed to query filesystem for {}", devpath))?;
Ok(Some(Mount::try_mount(
devpath,
Expand All @@ -100,10 +100,7 @@ pub fn get_boot_mount_from_cmdline_args(
}

fn device_to_kargs(root: &Mount, device: PathBuf) -> Result<Option<Vec<String>>> {
let blkinfo = lsblk_single(&device)?;
let blktype = blkinfo
.get("TYPE")
.with_context(|| format!("missing TYPE for {}", device.display()))?;
let blktype = get_block_device_type(&device)?;
// a `match {}` construct would be nice here, but for RAID it's a prefix match
if blktype.starts_with("raid") || blktype == "linear" {
Ok(Some(get_raid_kargs(&device)?))
Expand Down
20 changes: 17 additions & 3 deletions src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl Mount {
}

pub fn get_filesystem_uuid(&self) -> Result<String> {
let devinfo = lsblk_single(Path::new(&self.device))?;
let devinfo = blkid_single(Path::new(&self.device))?;
devinfo
.get("UUID")
.map(String::from)
Expand Down Expand Up @@ -772,13 +772,16 @@ fn read_sysfs_dev_block_value(maj: u64, min: u64, field: &str) -> Result<String>
Ok(read_to_string(&path)?.trim_end().into())
}

pub fn lsblk_single(dev: &Path) -> Result<HashMap<String, String>> {
pub fn get_block_device_type(dev: &Path) -> Result<String> {
let mut devinfos = lsblk(Path::new(dev), false)?;
if devinfos.is_empty() {
// this should never happen because `lsblk` itself would've failed
bail!("no lsblk results for {}", dev.display());
}
Ok(devinfos.remove(0))
devinfos
.remove(0)
.remove("TYPE")
.with_context(|| format!("missing TYPE for {}", dev.display()))
}

/// Returns all available filesystems.
Expand Down Expand Up @@ -876,6 +879,17 @@ fn blkid() -> Result<Vec<HashMap<String, String>>> {
Ok(result)
}

pub fn blkid_single(dev: &Path) -> Result<HashMap<String, String>> {
let mut cmd = Command::new("blkid");
cmd.arg(dev);
let output = cmd_output(&mut cmd)?;
if output.is_empty() {
// this should never happen because `blkid` itself would've failed
bail!("no blkid results for {}", dev.display());
}
Ok(split_blkid_line(&output))
}

/// This is a bit fuzzy, but... this function will return every block device in the parent
/// hierarchy of `device` capable of containing other partitions. So e.g. parent devices of type
/// "part" doesn't match, but "disk" and "mpath" does.
Expand Down