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.3"
11//! ```
12//!
13//! And this in your crate root:
14//!
15//! ```rust
16//! extern crate fatfs;
17//! ```
18//!
19//! # Examples
20//!
21//! ```rust
22//! // Declare external crates
23//! // Note: `fscommon` crate is used to speedup IO operations
24//! extern crate fatfs;
25//! extern crate fscommon;
26//!
27//! use std::io::prelude::*;
28//!
29//! fn main() -> std::io::Result<()> {
30//!     # std::fs::copy("resources/fat16.img", "tmp/fat.img")?;
31//!     // Initialize a filesystem object
32//!     let img_file = std::fs::OpenOptions::new().read(true).write(true)
33//!         .open("tmp/fat.img")?;
34//!     let buf_stream = fscommon::BufStream::new(img_file);
35//!     let fs = fatfs::FileSystem::new(buf_stream, fatfs::FsOptions::new())?;
36//!     let root_dir = fs.root_dir();
37//!
38//!     // Write a file
39//!     root_dir.create_dir("foo")?;
40//!     let mut file = root_dir.create_file("foo/hello.txt")?;
41//!     file.truncate()?;
42//!     file.write_all(b"Hello World!")?;
43//!
44//!     // Read a directory
45//!     let dir = root_dir.open_dir("foo")?;
46//!     for r in dir.iter() {
47//!         let entry = r?;
48//!         println!("{}", entry.file_name());
49//!     }
50//!     # std::fs::remove_file("tmp/fat.img")?;
51//!     # Ok(())
52//! }
53//! ```
54
55#![crate_type = "lib"]
56#![crate_name = "fatfs"]
57#![cfg_attr(not(feature = "std"), no_std)]
58#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(alloc))]
59// Disable warnings to not clutter code with cfg too much
60#![cfg_attr(not(feature = "alloc"), allow(dead_code, unused_imports))]
61// Inclusive ranges requires Rust 1.26.0
62#![allow(ellipsis_inclusive_range_patterns)]
63// `dyn` syntax requires Rust 1.27.0
64#![allow(bare_trait_objects)]
65// `alloc` compiler feature is needed in Rust before 1.36
66#![cfg_attr(all(not(feature = "std"), feature = "alloc"), allow(stable_features))]
67
68extern crate byteorder;
69
70#[macro_use]
71extern crate bitflags;
72
73#[macro_use]
74extern crate log;
75
76#[cfg(feature = "chrono")]
77extern crate chrono;
78
79#[cfg(not(feature = "std"))]
80extern crate core_io;
81
82#[cfg(all(not(feature = "std"), feature = "alloc"))]
83extern crate alloc;
84
85mod boot_sector;
86mod dir;
87mod dir_entry;
88mod file;
89mod fs;
90mod table;
91mod time;
92
93#[cfg(not(feature = "std"))]
94mod byteorder_core_io;
95
96#[cfg(feature = "std")]
97use byteorder as byteorder_ext;
98#[cfg(not(feature = "std"))]
99use byteorder_core_io as byteorder_ext;
100#[cfg(not(feature = "std"))]
101use core_io as io;
102#[cfg(feature = "std")]
103use std as core;
104
105#[cfg(feature = "std")]
106use std::io;
107
108pub use dir::*;
109pub use dir_entry::*;
110pub use file::*;
111pub use fs::*;
112pub use time::*;