Skip to content

Commit fec3af5

Browse files
committed
Add example which tries to totally fill the root directory.
1 parent 3a459d7 commit fec3af5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/big_dir.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern crate embedded_sdmmc;
2+
3+
mod linux;
4+
use linux::*;
5+
6+
use embedded_sdmmc::{Error, VolumeManager};
7+
8+
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
9+
env_logger::init();
10+
let mut args = std::env::args().skip(1);
11+
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
12+
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
13+
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
14+
let mut volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
15+
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
16+
let mut volume = volume_mgr
17+
.open_volume(embedded_sdmmc::VolumeIdx(1))
18+
.unwrap();
19+
println!("Volume: {:?}", volume);
20+
let mut root_dir = volume.open_root_dir().unwrap();
21+
22+
let mut file_num = 0;
23+
loop {
24+
file_num += 1;
25+
let file_name = format!("{}.da", file_num);
26+
println!("opening file {file_name} for writing");
27+
let mut file = root_dir
28+
.open_file_in_dir(
29+
file_name.as_str(),
30+
embedded_sdmmc::Mode::ReadWriteCreateOrTruncate,
31+
)
32+
.unwrap();
33+
let buf = b"hello world, from rust";
34+
println!("writing to file");
35+
file.write(&buf[..]).unwrap();
36+
println!("closing file");
37+
drop(file);
38+
}
39+
}

0 commit comments

Comments
 (0)