From 3628ec9825a1b4a4c2e2a1d3134647854d6c053e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Sat, 29 Dec 2018 20:42:49 +0100 Subject: [PATCH] Add mkfatfs example --- examples/cat.rs | 2 +- examples/mkfatfs.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 examples/mkfatfs.rs diff --git a/examples/cat.rs b/examples/cat.rs index dba0411..375996f 100644 --- a/examples/cat.rs +++ b/examples/cat.rs @@ -13,7 +13,7 @@ fn main() -> io::Result<()> { let buf_rdr = BufStream::new(file); let fs = FileSystem::new(buf_rdr, FsOptions::new())?; let root_dir = fs.root_dir(); - let mut file = root_dir.open_file(&env::args().nth(1).unwrap())?; + let mut file = root_dir.open_file(&env::args().nth(1).expect("filename expected"))?; let mut buf = vec![]; file.read_to_end(&mut buf)?; print!("{}", String::from_utf8_lossy(&buf)); diff --git a/examples/mkfatfs.rs b/examples/mkfatfs.rs new file mode 100644 index 0000000..cd0d40a --- /dev/null +++ b/examples/mkfatfs.rs @@ -0,0 +1,16 @@ +extern crate fatfs; +extern crate fscommon; + +use std::env; +use std::fs; +use std::io; + +use fscommon::BufStream; + +fn main() -> io::Result<()> { + let filename = env::args().nth(1).expect("image path expected"); + let file = fs::OpenOptions::new().read(true).write(true).open(&filename)?; + let buf_file = BufStream::new(file); + fatfs::format_volume(buf_file, fatfs::FormatVolumeOptions::new())?; + Ok(()) +}