2017-11-08 09:08:07 +08:00
|
|
|
Rust FAT FS
|
|
|
|
===========
|
2017-09-23 04:36:51 +08:00
|
|
|
|
2017-11-09 06:00:30 +08:00
|
|
|
[![Travis Build Status](https://travis-ci.org/rafalh/rust-fatfs.svg?branch=master)](https://travis-ci.org/rafalh/rust-fatfs)
|
2017-10-11 06:57:31 +08:00
|
|
|
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
|
|
|
|
[![crates.io](http://meritbadge.herokuapp.com/fatfs)](https://crates.io/crates/fatfs)
|
|
|
|
[![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-06-20 23:55:46 +08:00
|
|
|
* read/write file using standard Read/Write traits,
|
|
|
|
* read directory contents,
|
|
|
|
* create/remove file or directory,
|
|
|
|
* rename/move file or directory,
|
2018-05-10 21:05:44 +08:00
|
|
|
* read/write file timestamps (updated automatically if `chrono` feature is enabled),
|
2017-10-21 22:25:04 +08:00
|
|
|
* FAT12, FAT16, FAT32 compatibility,
|
2018-06-20 23:55:46 +08:00
|
|
|
* LFN (Long File Names) extension is supported,
|
2018-05-10 21:05:44 +08:00
|
|
|
* 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);
|
|
|
|
let fs = fatfs::FileSystem::new(img_file, fatfs::FsOptions::new())?;
|
|
|
|
|
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
|
|
|
|
2018-05-10 21:14:09 +08:00
|
|
|
Note: LFN support requires `alloc` and `core_io/collections` features and makes use of `alloc` crate.
|
2018-05-10 21:00:59 +08:00
|
|
|
You may have to provide a memory allocator implementation.
|
|
|
|
|
2018-06-20 23:55:46 +08:00
|
|
|
For building in `no_std` mode a nightly Rust compiler version compatible with the current `core_io` crate is required.
|
|
|
|
See a date string in the `core_io` dependency version.
|
2018-05-10 07:00:24 +08:00
|
|
|
|
2017-09-23 04:36:51 +08:00
|
|
|
License
|
|
|
|
-------
|
|
|
|
The MIT license. See LICENSE.txt.
|