Skip to content

Commit a5f3a83

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

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/big_dir.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
log::info!("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+
log::info!("opening file {file_name} for writing");
27+
let mut file = match root_dir.open_file_in_dir(
28+
file_name.as_str(),
29+
embedded_sdmmc::Mode::ReadWriteCreateOrTruncate,
30+
) {
31+
Ok(f) => f,
32+
Err(err) => {
33+
log::error!("open file failed {:?}", err);
34+
break;
35+
}
36+
};
37+
let buf = b"hello world, from rust";
38+
log::info!("writing to file");
39+
file.write(&buf[..]).unwrap();
40+
log::info!("closing file");
41+
drop(file);
42+
}
43+
Ok(())
44+
}

0 commit comments

Comments
 (0)