rust-fatfs/examples/partition.rs

26 lines
893 B
Rust
Raw Normal View History

extern crate fatfs;
extern crate fscommon;
use std::{fs, io};
2018-06-29 00:13:07 +08:00
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(())
}