#fat #no-std

no-std ape-fatfs

适用于嵌入式系统的多功能 FAT 库

2 个不稳定版本

0.2.0 2023年5月17日
0.1.0 2023年4月22日

#587 in 嵌入式开发

每月 38 次下载
ape-mbr 中使用

MIT 许可证

240KB
5.5K SLoC

ApeFATFS

MIT License Crates.io Documentation APE

适用于嵌入式系统的多功能 FAT 库

使用方法

此 crate 可以通过将 fatfs 添加到项目的 Cargo.toml 依赖项中来使用。

[dependencies]
ape-fatfs = "0.2.0"
# Comment out the above and uncomment the below to enable no_std support
# ape-fatfs = { default_features = false, version = 0.2.0 }

示例

use std::io::prelude::*;
use ape_fatfs::{
    fs::{
        FsOptions,
        FileSystem,
    }
};

fn main() {
    # std::fs::copy("resources/fat16.img", "fat.img").unwrap();
    // Initialize a filesystem object
    let img_file = std::fs::OpenOptions::new().read(true).write(true)
        .open("fat.img").unwrap();
    let buf_stream = fscommon::BufStream::new(img_file);
    let fs = FileSystem::new(buf_stream, FsOptions::new()).unwrap();
    let root_dir = fs.root_dir();

    // Write a file
    root_dir.create_dir("foo").unwrap();
    let mut file = root_dir.create_file("foo/hello.txt").unwrap();
    file.truncate().unwrap();
    file.write_all(b"Hello World!").unwrap();

    // Read a directory
    let dir = root_dir.open_dir("foo").unwrap();
    for r in dir.iter() {
        let entry = r.unwrap();
        println!("{}", entry.file_name());
    }
    # std::fs::remove_file("fat.img").unwrap();
}

依赖项

~1.6–7.5MB
~47K SLoC