Skip to content

Commit 6a41167

Browse files
Allow showing hex content of littlefs files
1 parent b51ca13 commit 6a41167

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ all-features = true
2424

2525
[[example]]
2626
name = "list"
27-
required-features = ["alloc"]
27+
required-features = ["alloc", "littlefs2-core/heapless07"]
2828

2929
[dependencies]
3030
delog = "0.1.0"
@@ -36,6 +36,7 @@ littlefs2-sys = { version = "0.3.1", features = ["multiversion"] }
3636
ssmarshal = "1"
3737
serde = { version = "1.0", default-features = false, features = ["derive"] }
3838
clap = { version = "4.5.31", features = ["derive"] }
39+
hex = "0.4.3"
3940
# trybuild = "1"
4041

4142
[features]

examples/list.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct Args {
2727
lookahead_size: Option<usize>,
2828
#[arg(short, long)]
2929
block_count: Option<usize>,
30+
#[arg(short, long)]
31+
show_hex: bool,
3032
}
3133

3234
const BLOCK_COUNT: usize = 288;
@@ -64,21 +66,26 @@ fn main() {
6466
println!();
6567

6668
let path = PathBuf::new();
67-
list(&fs, &path);
69+
list(&fs, &path, args.show_hex);
6870
}
6971

70-
fn list(fs: &dyn DynFilesystem, path: &Path) {
72+
fn list(fs: &dyn DynFilesystem, path: &Path, show_hex: bool) {
7173
fs.read_dir_and_then(path, &mut |iter| {
7274
for entry in iter {
7375
let entry = entry.unwrap();
7476
match entry.file_type() {
75-
FileType::File => println!("F {}", entry.path()),
77+
FileType::File => {
78+
println!("F {}", entry.path());
79+
if show_hex {
80+
let bytes: heapless::Vec<u8, 4096> = fs.read(entry.path()).unwrap();
81+
println!(" {}", hex::encode_upper(&bytes));
82+
}
83+
}
7684
FileType::Dir => match entry.file_name().as_str() {
7785
"." => (),
7886
".." => (),
7987
_ => {
80-
println!("D {}", entry.path());
81-
list(fs, entry.path());
88+
list(fs, entry.path(), show_hex);
8289
}
8390
},
8491
}

0 commit comments

Comments
 (0)