Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 1dace674 authored by Ayush Singh's avatar Ayush Singh
Browse files

bb-imager: Remove rs-drivelist patch


- Same reason as for bin_file.

Signed-off-by: Ayush Singh's avatarAyush Singh <ayush@beagleboard.org>
parent 9ac63540
Branches
Tags
1 merge request!20Preperation to publish to crates.io
Pipeline #20924 passed with stages
in 3 minutes and 58 seconds
......@@ -180,9 +180,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.89"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
[[package]]
name = "approx"
......@@ -458,6 +458,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
name = "bb-imager"
version = "0.0.3"
dependencies = [
"anyhow",
"bin_file",
"chrono",
"const-hex",
......@@ -469,6 +470,7 @@ dependencies = [
"hidapi",
"liblzma",
"mbrman",
"plist",
"reqwest",
"rs-drivelist",
"security-framework",
......@@ -4176,14 +4178,13 @@ checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
[[package]]
name = "rs-drivelist"
version = "0.9.4"
source = "git+https://github.com/ir1keren/rs-drivelist.git#02a353f5f7caea88e9a13243aa95ec76bb5e59a8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d19d018ee3e5bab909d61ad8a0b7e24d5c02cdf46436cfaff4d13550a33773"
dependencies = [
"anyhow",
"derivative",
"json",
"plist",
"regex",
"serde",
"winapi",
]
......
......@@ -11,9 +11,6 @@ members = [
strip = true
lto = "thin"
[patch.crates-io]
rs-drivelist = { git = "https://github.com/ir1keren/rs-drivelist.git" }
[workspace.package]
version = "0.0.3"
edition = "2021"
......
......@@ -40,3 +40,5 @@ windows = { version = "0.58.0", features = ["Win32", "Win32_Storage", "Win32_Sto
[target.'cfg(target_os = "macos")'.dependencies]
security-framework = "2.11.1"
plist = "1.7.0"
anyhow = "1.0.91"
......@@ -92,6 +92,7 @@ pub(crate) async fn flash<W: AsyncReadExt + AsyncWriteExt + AsyncSeekExt + Unpin
// fatfs::format_volume(disk, fatfs::FormatVolumeOptions::new())
// }
#[cfg(not(target_os = "macos"))]
pub fn destinations() -> std::collections::HashSet<crate::Destination> {
rs_drivelist::drive_list()
.unwrap()
......@@ -101,3 +102,14 @@ pub fn destinations() -> std::collections::HashSet<crate::Destination> {
.map(|x| crate::Destination::sd_card(x.description, x.size, x.raw))
.collect()
}
#[cfg(target_os = "macos")]
pub fn destinations() -> std::collections::HashSet<crate::Destination> {
crate::pal::macos::rs_drivelist::diskutil()
.unwrap()
.into_iter()
.filter(|x| x.isRemovable)
.filter(|x| !x.isVirtual)
.map(|x| crate::Destination::sd_card(x.description, x.size, x.raw))
.collect()
}
......@@ -59,3 +59,92 @@ fn open_auth(path: String) -> crate::error::Result<File> {
let fd = i32::from_ne_bytes(output.stdout.try_into().unwrap());
Ok(unsafe { tokio::fs::File::from_raw_fd(fd) })
}
/// TODO: Remove once a new version of rs_drivelist is published to crates.io
pub(crate) mod rs_drivelist {
use rs_drivelist::device::{DeviceDescriptor, MountPoint};
use serde::Deserialize;
use std::process::Command;
#[derive(Deserialize, Debug)]
struct Disks {
#[serde(rename = "AllDisksAndPartitions")]
all_disks_and_partitions: Vec<Disk>,
}
#[derive(Deserialize, Debug)]
struct Disk {
#[serde(rename = "DeviceIdentifier")]
device_identifier: String,
#[serde(rename = "OSInternal")]
os_internal: bool,
#[serde(rename = "Size")]
size: u64,
#[serde(rename = "Content")]
content: String,
#[serde(rename = "Partitions")]
partitions: Vec<Partition>,
}
#[derive(Deserialize, Debug)]
struct Partition {
#[serde(rename = "MountPoint")]
mount_point: Option<String>,
#[serde(rename = "Content")]
content: String,
#[serde(rename = "Size")]
size: u64,
}
impl From<Disk> for DeviceDescriptor {
fn from(value: Disk) -> Self {
DeviceDescriptor {
enumerator: "diskutil".to_string(),
description: value.content,
size: value.size,
mountpoints: value.partitions.into_iter().map(MountPoint::from).collect(),
device: format!("/dev/{}", value.device_identifier),
raw: format!("/dev/r{}", value.device_identifier),
isSystem: value.os_internal,
isRemovable: !value.os_internal,
..Default::default()
}
}
}
impl From<Partition> for MountPoint {
fn from(value: Partition) -> Self {
MountPoint {
path: value.mount_point.unwrap_or_default(),
label: Some(value.content),
totalBytes: Some(value.size),
availableBytes: None,
}
}
}
pub(crate) fn diskutil() -> anyhow::Result<Vec<DeviceDescriptor>> {
let output = Command::new("diskutil").args(["list", "-plist"]).output()?;
if let Some(code) = output.status.code() {
if code != 0 {
return Err(anyhow::Error::msg(format!("lsblk ExitCode: {}", code)));
}
}
if output.stderr.len() > 0 {
return Err(anyhow::Error::msg(format!(
"lsblk stderr: {}",
std::str::from_utf8(&output.stderr).unwrap()
)));
}
let parsed: Disks = plist::from_bytes(&output.stdout).unwrap();
Ok(parsed
.all_disks_and_partitions
.into_iter()
.map(DeviceDescriptor::from)
.collect())
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment