2018-05-18 00:31:33 +08:00
|
|
|
extern crate fatfs;
|
2018-06-16 23:57:29 +08:00
|
|
|
extern crate fscommon;
|
2018-05-18 00:31:33 +08:00
|
|
|
|
2018-06-16 23:57:29 +08:00
|
|
|
use std::{fs, io};
|
|
|
|
use fatfs::{FileSystem, FsOptions};
|
|
|
|
use fscommon::{BufStream, StreamSlice};
|
2018-05-18 00:31:33 +08:00
|
|
|
|
2018-06-01 03:40:40 +08:00
|
|
|
fn main() -> io::Result<()> {
|
2018-05-18 00:31:33 +08:00
|
|
|
// Open disk image
|
2018-06-01 03:40:40 +08:00
|
|
|
let file = fs::File::open("resources/fat32.img")?;
|
2018-05-18 00:31:33 +08:00
|
|
|
// Provide sample partition localization. In real application it should be read from MBR/GPT.
|
|
|
|
let first_lba = 0;
|
|
|
|
let last_lba = 10000;
|
|
|
|
// Create partition using provided start address and size in bytes
|
2018-06-16 23:57:29 +08:00
|
|
|
let partition = StreamSlice::new(file, first_lba, last_lba + 1)?;
|
2018-05-18 00:31:33 +08:00
|
|
|
// Create buffered stream to optimize file access
|
2018-06-14 05:26:13 +08:00
|
|
|
let buf_rdr = BufStream::new(partition);
|
2018-05-18 00:31:33 +08:00
|
|
|
// Finally initialize filesystem struct using provided partition
|
2018-06-14 05:26:13 +08:00
|
|
|
let fs = FileSystem::new(buf_rdr, FsOptions::new())?;
|
2018-05-18 00:31:33 +08:00
|
|
|
// Read and display volume label
|
|
|
|
println!("Volume Label: {}", fs.volume_label());
|
2018-06-01 03:40:40 +08:00
|
|
|
// other operations...
|
|
|
|
Ok(())
|
2018-05-18 00:31:33 +08:00
|
|
|
}
|