Crates.io | fat32 |
lib.rs | fat32 |
version | 0.2.0 |
source | src |
created_at | 2020-06-03 11:03:22.295666 |
updated_at | 2020-10-16 11:07:35.876191 |
description | FAT32 FileSystem Library |
homepage | |
repository | https://github.com/Spxg/fat32 |
max_upload_size | |
id | 249605 |
size | 64,613 |
This is FAT32 FileSystem Library, which is #![no_std]
and does not use alloc
.
Test passed with sdio_sdhc and WindowsAPI.
std
, Can I Use This Crate?Of course you can, but I don't recommend it. You should use std::fs::File
OR other crates.
In order to support devices and environment which don't have std
, like
\\\\.\\E:
cargo test
You need make your library implement BlockDevice
trait:
pub trait BlockDevice {
type Error;
fn read(&self, buf: &mut [u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error>;
fn write(&self, buf: &[u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error>;
}
For example, I use my another library sdio_sdhc to implement:
impl BlockDevice for Card {
type Error = CmdError;
fn read(&self, buf: &mut [u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error> {
if number_of_blocks == 1 {
self.read_block(buf, address as u32)?
} else {
self.read_multi_blocks(buf, address as u32, number_of_blocks as u32)?
}
Ok(())
}
fn write(&self, buf: &[u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error> {
if number_of_blocks == 1 {
self.write_block(buf, address as u32)?
} else {
self.write_multi_blocks(buf, address as u32, number_of_blocks as u32)?
}
Ok(())
}
}
Now sdio_sdhc library supported fat32 filesystem. Then, add fat32 library to your application
# if no feature config, the BUFFER_SIZE is 512 Bytes
fat32 = "0.2"
If your card block is other size, like 1024 Bytes
[dependencies.fat32]
version = "0.2"
default-features = false
features = ["1024"]
Then, you can do some tests
// Card from sdio_sdhc crate
let card = Card::init().unwrap();
// Volume from fat32 crate
let cont = Volume::new(card);
// cd root dir
let root = cont.root_dir();
// create file named test.txt
root.create_file("test.txt").unwrap();
// open file
let mut file = root.open_file("test.txt").unwrap();
// write buffer to file
file.write(&[80; 1234]).unwrap();
If all goes well, the file was created with 1234 Bytes in root dir.