2017-11-08 09:08:07 +08:00
|
|
|
Rust FAT FS
|
|
|
|
===========
|
2017-09-23 04:36:51 +08:00
|
|
|
|
2021-03-28 01:15:30 +08:00
|
|
|
[![CI Status](https://github.com/rafalh/rust-fatfs/actions/workflows/ci.yml/badge.svg)](https://github.com/rafalh/rust-fatfs/actions/workflows/ci.yml)
|
2017-10-11 06:57:31 +08:00
|
|
|
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
|
2021-03-28 01:15:30 +08:00
|
|
|
[![crates.io](https://img.shields.io/crates/v/fatfs)](https://crates.io/crates/fatfs)
|
2017-10-11 06:57:31 +08:00
|
|
|
[![Documentation](https://docs.rs/fatfs/badge.svg)](https://docs.rs/fatfs)
|
2018-06-05 04:35:15 +08:00
|
|
|
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.24+-yellow.svg)](https://blog.rust-lang.org/2018/02/15/Rust-1.24.html)
|
2017-09-27 20:21:01 +08:00
|
|
|
|
2018-06-20 23:55:46 +08:00
|
|
|
A FAT filesystem library implemented in Rust.
|
2017-09-24 20:34:07 +08:00
|
|
|
|
2017-09-25 04:12:38 +08:00
|
|
|
Features:
|
2018-12-08 23:59:10 +08:00
|
|
|
* read/write file using standard Read/Write traits
|
|
|
|
* read directory contents
|
|
|
|
* create/remove file or directory
|
|
|
|
* rename/move file or directory
|
|
|
|
* read/write file timestamps (updated automatically if `chrono` feature is enabled)
|
|
|
|
* format volume
|
|
|
|
* FAT12, FAT16, FAT32 compatibility
|
|
|
|
* LFN (Long File Names) extension is supported
|
|
|
|
* Basic no_std environment support
|
2017-09-25 04:12:38 +08:00
|
|
|
|
2017-11-08 09:08:07 +08:00
|
|
|
Usage
|
|
|
|
-----
|
2017-11-08 08:35:47 +08:00
|
|
|
|
2018-06-20 23:55:46 +08:00
|
|
|
Add this to your `Cargo.toml`:
|
2017-11-08 09:08:07 +08:00
|
|
|
|
|
|
|
[dependencies]
|
2018-06-20 23:56:03 +08:00
|
|
|
fatfs = "0.3"
|
2017-11-08 09:08:07 +08:00
|
|
|
|
2018-06-20 23:55:46 +08:00
|
|
|
and this to your crate root:
|
2017-11-08 09:08:07 +08:00
|
|
|
|
|
|
|
extern crate fatfs;
|
|
|
|
|
2018-06-20 23:58:45 +08:00
|
|
|
You can start using the `fatfs` library now:
|
2017-11-08 09:08:07 +08:00
|
|
|
|
2018-06-01 03:40:40 +08:00
|
|
|
let img_file = File::open("fat.img")?;
|
2018-06-21 01:08:50 +08:00
|
|
|
let fs = fatfs::FileSystem::new(img_file, fatfs::FsOptions::new())?;
|
2018-06-12 06:07:30 +08:00
|
|
|
let root_dir = fs.root_dir();
|
2018-06-01 03:40:40 +08:00
|
|
|
let mut file = root_dir.create_file("hello.txt")?;
|
|
|
|
file.write_all(b"Hello World!")?;
|
2017-11-08 08:35:47 +08:00
|
|
|
|
2018-06-21 01:08:50 +08:00
|
|
|
Note: it is recommended to wrap the underlying file struct in a buffering/caching object like `BufStream` from `fscommon` crate. For example:
|
|
|
|
|
|
|
|
extern crate fscommon;
|
|
|
|
let buf_stream = BufStream::new(img_file);
|
2019-05-21 06:48:26 +08:00
|
|
|
let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?;
|
2018-06-21 01:08:50 +08:00
|
|
|
|
2018-06-20 23:58:45 +08:00
|
|
|
See more examples in the `examples` subdirectory.
|
2017-09-23 04:36:51 +08:00
|
|
|
|
2018-05-10 07:00:24 +08:00
|
|
|
no_std usage
|
|
|
|
------------
|
|
|
|
|
2018-06-20 23:55:46 +08:00
|
|
|
Add this to your `Cargo.toml`:
|
2018-05-10 07:00:24 +08:00
|
|
|
|
|
|
|
[dependencies]
|
2018-06-20 23:56:03 +08:00
|
|
|
fatfs = { version = "0.3", features = ["core_io"], default-features = false }
|
2018-05-10 07:00:24 +08:00
|
|
|
|
2019-07-18 01:54:27 +08:00
|
|
|
For building in `no_std` mode a Rust compiler version compatible with `core_io` crate is required.
|
2018-05-10 21:00:59 +08:00
|
|
|
|
2019-07-18 01:54:27 +08:00
|
|
|
For now `core_io` supports only nightly Rust channel. See a date suffix in latest `core_io` crate version for exact
|
|
|
|
compiler version.
|
|
|
|
|
|
|
|
Additional features:
|
|
|
|
|
|
|
|
* `alloc` - use `alloc` crate for dynamic allocation. Required for LFN (long file name) support and API which uses
|
|
|
|
`String` type. You may have to provide a memory allocator implementation.
|
|
|
|
|
|
|
|
Note: above feature is enabled by default.
|
2018-05-10 07:00:24 +08:00
|
|
|
|
2017-09-23 04:36:51 +08:00
|
|
|
License
|
|
|
|
-------
|
2019-07-18 01:54:27 +08:00
|
|
|
The MIT license. See `LICENSE.txt`.
|