forked from M-Labs/rust-fatfs
892c3974d3
BufStream is universal and can be used with any filesystem so its place is in different crate. Also moved Partition struct from examples to fscommon::StreamSlice struct (please note constructor arguments has changed).
25 lines
892 B
Rust
25 lines
892 B
Rust
extern crate fatfs;
|
|
extern crate fscommon;
|
|
|
|
use std::{fs, io};
|
|
use fatfs::{FileSystem, FsOptions};
|
|
use fscommon::{BufStream, StreamSlice};
|
|
|
|
fn main() -> io::Result<()> {
|
|
// Open disk image
|
|
let file = fs::File::open("resources/fat32.img")?;
|
|
// 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
|
|
let partition = StreamSlice::new(file, first_lba, last_lba + 1)?;
|
|
// Create buffered stream to optimize file access
|
|
let buf_rdr = BufStream::new(partition);
|
|
// Finally initialize filesystem struct using provided partition
|
|
let fs = FileSystem::new(buf_rdr, FsOptions::new())?;
|
|
// Read and display volume label
|
|
println!("Volume Label: {}", fs.volume_label());
|
|
// other operations...
|
|
Ok(())
|
|
}
|