fatfs/lib.rs
1//! A FAT filesystem library implemented in Rust.
2//!
3//! # Usage
4//!
5//! This crate is [on crates.io](https://crates.io/crates/fatfs) and can be
6//! used by adding `fatfs` to the dependencies in your project's `Cargo.toml`.
7//!
8//! ```toml
9//! [dependencies]
10//! fatfs = "0.4"
11//! ```
12//!
13//! # Examples
14//!
15//! ```rust
16//! use std::io::prelude::*;
17//!
18//! fn main() -> std::io::Result<()> {
19//! # std::fs::copy("resources/fat16.img", "tmp/fat.img")?;
20//! // Initialize a filesystem object
21//! let img_file = std::fs::OpenOptions::new().read(true).write(true)
22//! .open("tmp/fat.img")?;
23//! let buf_stream = fscommon::BufStream::new(img_file);
24//! let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?;
25//! let root_dir = fs.root_dir();
26//!
27//! // Write a file
28//! root_dir.create_dir("foo")?;
29//! let mut file = root_dir.create_file("foo/hello.txt")?;
30//! file.truncate()?;
31//! file.write_all(b"Hello World!")?;
32//!
33//! // Read a directory
34//! let dir = root_dir.open_dir("foo")?;
35//! for r in dir.iter() {
36//! let entry = r?;
37//! println!("{}", entry.file_name());
38//! }
39//! # std::fs::remove_file("tmp/fat.img")?;
40//! # Ok(())
41//! }
42//! ```
43
44#![crate_type = "lib"]
45#![cfg_attr(not(feature = "std"), no_std)]
46// Disable warnings to not clutter code with cfg too much
47#![cfg_attr(not(all(feature = "alloc", feature = "lfn")), allow(dead_code, unused_imports))]
48#![warn(clippy::pedantic)]
49#![allow(
50 clippy::module_name_repetitions,
51 clippy::cast_possible_truncation,
52 clippy::bool_to_int_with_if, // less readable
53 clippy::uninlined_format_args, // not supported before Rust 1.58.0
54)]
55
56extern crate log;
57
58#[cfg(all(not(feature = "std"), feature = "alloc"))]
59extern crate alloc;
60
61#[macro_use]
62mod log_macros;
63
64mod boot_sector;
65mod dir;
66mod dir_entry;
67mod error;
68mod file;
69mod fs;
70mod io;
71mod table;
72mod time;
73
74pub use crate::dir::*;
75pub use crate::dir_entry::*;
76pub use crate::error::*;
77pub use crate::file::*;
78pub use crate::fs::*;
79pub use crate::io::*;
80pub use crate::time::*;