2017-11-09 03:40:36 +08:00
|
|
|
extern crate fatfs;
|
2018-06-16 23:57:29 +08:00
|
|
|
extern crate fscommon;
|
2017-11-09 03:40:36 +08:00
|
|
|
|
|
|
|
use std::fs::OpenOptions;
|
2018-06-01 03:40:40 +08:00
|
|
|
use std::io::{self, prelude::*};
|
2017-11-09 03:40:36 +08:00
|
|
|
|
2018-06-16 23:57:29 +08:00
|
|
|
use fatfs::{FileSystem, FsOptions};
|
|
|
|
use fscommon::BufStream;
|
2017-11-09 03:40:36 +08:00
|
|
|
|
2018-06-01 03:40:40 +08:00
|
|
|
fn main() -> io::Result<()> {
|
2017-11-09 03:40:36 +08:00
|
|
|
let img_file = match OpenOptions::new().read(true).write(true).open("fat.img") {
|
|
|
|
Ok(file) => file,
|
|
|
|
Err(err) => {
|
2018-06-01 03:40:40 +08:00
|
|
|
println!("Failed to open image!");
|
|
|
|
return Err(err);
|
2018-06-29 00:13:07 +08:00
|
|
|
},
|
2017-11-09 03:40:36 +08:00
|
|
|
};
|
2018-06-14 05:26:13 +08:00
|
|
|
let buf_stream = BufStream::new(img_file);
|
2017-11-09 03:40:36 +08:00
|
|
|
let options = FsOptions::new().update_accessed_date(true);
|
2018-06-14 05:26:13 +08:00
|
|
|
let fs = FileSystem::new(buf_stream, options)?;
|
2018-06-01 03:40:40 +08:00
|
|
|
let mut file = fs.root_dir().create_file("hello.txt")?;
|
|
|
|
file.write_all(b"Hello World!")?;
|
|
|
|
Ok(())
|
2017-11-09 03:40:36 +08:00
|
|
|
}
|