Skip to content

Commit e5a94c6

Browse files
committed
blockdev: Use -b for lsblk, hard require size property
I noticed that the JSON format inconsistently uses human-readable sizes for some properties, but not others. `size` happens to be one of the ones were it outputs human readable. But I think we will often want to operate on the raw byte value on our own, so let's tell lsblk to just give us raw numbers and do formatting where needed. While we're here, just hard require the `size` property. I don't think any block devices can be missing this. Signed-off-by: Colin Walters <[email protected]>
1 parent c6cb003 commit e5a94c6

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

lib/src/blockdev.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) struct Device {
2929
pub(crate) model: Option<String>,
3030
pub(crate) partlabel: Option<String>,
3131
pub(crate) children: Option<Vec<Device>>,
32-
pub(crate) size: Option<String>,
32+
pub(crate) size: u64,
3333
#[serde(rename = "maj:min")]
3434
pub(crate) maj_min: Option<String>,
3535
// NOTE this one is not available on older util-linux, and
@@ -97,7 +97,7 @@ pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
9797

9898
fn list_impl(dev: Option<&Utf8Path>) -> Result<Vec<Device>> {
9999
let o = Command::new("lsblk")
100-
.args(["-J", "-O"])
100+
.args(["-J", "-b", "-O"])
101101
.args(dev)
102102
.output()?;
103103
if !o.status.success() {

lib/src/install/baseline.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn mkfs<'a>(
125125
opts: impl IntoIterator<Item = &'a str>,
126126
) -> Result<uuid::Uuid> {
127127
let devinfo = crate::blockdev::list_dev(dev.into())?;
128-
let size = devinfo.size.as_deref().unwrap_or("(unknown)");
128+
let size = ostree_ext::glib::format_size(devinfo.size);
129129
let u = uuid::Uuid::new_v4();
130130
let mut t = Task::new(
131131
&format!("Creating {label} filesystem ({fs}) on device {dev} (size={size})"),
@@ -210,12 +210,8 @@ pub(crate) fn install_create_rootfs(
210210
};
211211
let serial = device.serial.as_deref().unwrap_or("<unknown>");
212212
let model = device.model.as_deref().unwrap_or("<unknown>");
213-
let size = device
214-
.size
215-
.as_deref()
216-
.ok_or_else(|| anyhow::anyhow!("Missing size for blockdev"))?;
217213
println!("Block setup: {block_setup}");
218-
println!(" Size: {size}",);
214+
println!(" Size: {}", device.size);
219215
println!(" Serial: {serial}");
220216
println!(" Model: {model}");
221217

0 commit comments

Comments
 (0)