aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-09-10 11:01:18 +0200
committerDaniel Mueller <deso@posteo.net>2021-01-10 21:04:47 -0800
commit23dee1867bba7d899bd806b4ed41d29a2800db89 (patch)
tree42565444447bca967469eec60b97b9c8eaa71848 /src
parenta4f43e20faf5b3490da989932151514fe6c97cbc (diff)
downloadnitrocli-23dee1867bba7d899bd806b4ed41d29a2800db89.tar.gz
nitrocli-23dee1867bba7d899bd806b4ed41d29a2800db89.tar.bz2
Print SD card usage in Storage status
The Storage device keeps track of the areas of the SD card that have been written to during this power cycle. This data can be accessed using the NK_get_SD_usage_data function that returns a range of the SD card that has not been written. This data can be used as a guide line when creating new hidden volumes. This patch adds the SD card usage data to the output of the status command for Nitrokey Storage devices.
Diffstat (limited to 'src')
-rw-r--r--src/commands.rs10
-rw-r--r--src/tests/status.rs1
2 files changed, 10 insertions, 1 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 64da866..d81e095 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -6,6 +6,7 @@
use std::convert::TryFrom as _;
use std::fmt;
use std::mem;
+use std::ops;
use std::ops::Deref as _;
use std::thread;
use std::time;
@@ -334,11 +335,13 @@ where
fn print_storage_status(
ctx: &mut Context<'_>,
status: &nitrokey::StorageStatus,
+ sd_card_usage: &ops::Range<u8>,
) -> anyhow::Result<()> {
println!(
ctx,
r#" Storage:
SD card ID: {id:#x}
+ SD card usage: {usagestart}% .. {usageend}% not written
firmware: {fw}
storage keys: {sk}
volumes:
@@ -346,6 +349,8 @@ fn print_storage_status(
encrypted: {ve}
hidden: {vh}"#,
id = status.serial_number_sd_card,
+ usagestart = sd_card_usage.start,
+ usageend = sd_card_usage.end,
fw = if status.firmware_locked {
"locked"
} else {
@@ -398,8 +403,11 @@ fn print_status(
let status = device
.get_storage_status()
.context("Failed to retrieve storage status")?;
+ let sd_card_usage = device
+ .get_sd_card_usage()
+ .context("Failed to retrieve SD card usage")?;
- print_storage_status(ctx, &status)
+ print_storage_status(ctx, &status, &sd_card_usage)
} else {
Ok(())
}
diff --git a/src/tests/status.rs b/src/tests/status.rs
index fe69d78..ca16121 100644
--- a/src/tests/status.rs
+++ b/src/tests/status.rs
@@ -50,6 +50,7 @@ fn output_storage(model: nitrokey::Model) -> anyhow::Result<()> {
admin retry count: [0-3]
Storage:
SD card ID: 0x[[:xdigit:]]{8}
+ SD card usage: \d+% .. \d+% not written
firmware: (un)?locked
storage keys: (not )?created
volumes: