Skip to content

Commit ccfcccb

Browse files
committed
blockdev: update get_devices() to get_parent_devices()
1 parent 6ebaf42 commit ccfcccb

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/bios.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Bios {
9898

9999
// check bios_boot partition on gpt type disk
100100
fn get_bios_boot_partition(&self) -> Option<String> {
101-
match blockdev::get_single_device("/") {
101+
match blockdev::get_single_device() {
102102
Ok(device) => {
103103
let bios_boot_part =
104104
blockdev::get_bios_boot_partition(&device).expect("get bios_boot part");
@@ -162,7 +162,7 @@ impl Component for Bios {
162162
};
163163

164164
let target_root = "/";
165-
let device = blockdev::get_single_device(&target_root)?;
165+
let device = blockdev::get_single_device()?;
166166
self.run_grub_install(target_root, &device)?;
167167
log::debug!("Install grub modules on {device}");
168168
Ok(InstalledContent {
@@ -180,7 +180,7 @@ impl Component for Bios {
180180
let updatemeta = self.query_update(sysroot)?.expect("update available");
181181
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
182182
let dest_root = std::fs::read_link(dest_fd)?;
183-
let device = blockdev::get_single_device(&dest_root)?;
183+
let device = blockdev::get_single_device()?;
184184

185185
let dest_root = dest_root.to_string_lossy().into_owned();
186186
self.run_grub_install(&dest_root, &device)?;

src/blockdev.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
3030
}
3131

3232
// Get single device for the target root
33-
pub fn get_single_device<P: AsRef<Path>>(target_root: P) -> Result<String> {
34-
let mut devices = get_devices(&target_root)?.into_iter();
33+
pub fn get_single_device() -> Result<String> {
34+
let mut devices = get_parent_devices(None).iter();
3535
let Some(parent) = devices.next() else {
3636
anyhow::bail!("Failed to find parent device");
3737
};
3838

3939
if let Some(next) = devices.next() {
4040
anyhow::bail!("Found multiple parent devices {parent} and {next}; not currently supported");
4141
}
42-
Ok(parent)
42+
Ok(parent.to_string())
4343
}
4444

4545
/// Find esp partition on the same device
@@ -58,11 +58,11 @@ pub fn get_esp_partition(device: &str) -> Result<Option<String>> {
5858
Ok(None)
5959
}
6060

61-
/// Find all ESP partitions on the devices with mountpoint boot
61+
/// Find all ESP partitions on the devices
6262
#[allow(dead_code)]
63-
pub fn find_colocated_esps<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
63+
pub fn find_colocated_esps() -> Result<Vec<String>> {
6464
// first, get the parent device
65-
let devices = get_devices(&target_root).with_context(|| "while looking for colocated ESPs")?;
65+
let devices = get_parent_devices(None);
6666

6767
// now, look for all ESPs on those devices
6868
let mut esps = Vec::new();
@@ -89,12 +89,11 @@ pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
8989
Ok(None)
9090
}
9191

92-
/// Find all bios_boot partitions on the devices with mountpoint boot
92+
/// Find all bios_boot partitions on the devices
9393
#[allow(dead_code)]
94-
pub fn find_colocated_bios_boot<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
94+
pub fn find_colocated_bios_boot() -> Result<Vec<String>> {
9595
// first, get the parent device
96-
let devices =
97-
get_devices(&target_root).with_context(|| "looking for colocated bios_boot parts")?;
96+
let devices = get_parent_devices(None);
9897

9998
// now, look for all bios_boot parts on those devices
10099
let mut bios_boots = Vec::new();

0 commit comments

Comments
 (0)