2个版本
| 0.1.1 | 2023年5月17日 | 
|---|---|
| 0.1.0 | 2023年4月22日 | 
1291 in 文件系统
26 每月下载量
22KB
375 行
ApeMBR
简单的Crate,用于磁盘与其分区之间的接口
该Crate特别设计用于在磁盘和文件系统库之间提供接口,其中两者都可实现嵌入式_io。
简单明了,正如其应有的样子。
用法
可以通过在项目中的 Cargo.toml 依赖项中添加 ape-mbr 来使用此Crate。
[dependencies]
ape-mbr = "0.1.0"
示例
以下是如何与 ape-fatfs 配合使用 ape-mbr 的示例
use std::io::prelude::*;
use ape_fatfs::{
    fs::{
        FsOptions,
        FileSystem,
    },
    io::{
        StdIoWrapper
    }
};
use ape_mbr::{
    PartitionId,
    MBR,
};
fn main() {
    // Initialize the MBR
    let img_file = std::fs::OpenOptions::new().read(true).write(true)
        .open("test.img").unwrap();
    let img_file = StdIoWrapper::new(img_file);
   
    let mut mbr = MBR::new(img_file).unwrap();
    let mut p1 = mbr.get_partition(PartitionId::One).unwrap();
    
    let fs = FileSystem::new(p1, 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());
    }
}
依赖关系
~320–780KB
~18K SLoC