hadris_fat/lib.rs
1//! # hadris-fat
2//!
3//! A `no_std`-compatible library for reading and writing FAT filesystems
4//! (FAT12, FAT16, FAT32) with optional exFAT support.
5//!
6//! ## Quick Start
7//!
8//! ```rust,no_run
9//! use std::fs::File;
10//! use hadris_fat::sync::FatFs;
11//!
12//! let file = File::open("disk.img").unwrap();
13//! let fs = FatFs::open(file).unwrap();
14//! let root = fs.root_dir();
15//! let mut iter = root.entries();
16//! while let Some(Ok(entry)) = iter.next_entry() {
17//! println!("{}", entry.name());
18//! }
19//! ```
20//!
21//! ## Feature Flags
22//!
23//! | Feature | Default | Description |
24//! |----------|---------|-------------|
25//! | `std` | Yes | Standard library support (enables `alloc`, `sync`, chrono clock) |
26//! | `alloc` | No | Heap allocation without full std |
27//! | `sync` | No | Synchronous API via `hadris-io` sync traits |
28//! | `async` | No | Asynchronous API via `hadris-io` async traits |
29//! | `read` | Yes | Read operations |
30//! | `write` | Yes | Write operations (requires `alloc` + `read`) |
31//! | `lfn` | Yes | Long filename (VFAT) support |
32//! | `cache` | No | FAT sector caching for reduced I/O |
33//! | `tool` | No | Analysis and diagnostic utilities |
34//! | `exfat` | No | exFAT filesystem support (WIP) |
35//!
36//! ## Dual Sync/Async Architecture
37//!
38//! This crate provides both synchronous and asynchronous APIs through
39//! a compile-time code transformation system. The same implementation
40//! source is compiled twice:
41//!
42//! - **`sync`** module: synchronous API (enabled by `sync` or `std` feature)
43//! - **`async`** module: asynchronous API (enabled by `async` feature)
44//!
45//! When the `std` feature is enabled (default), the synchronous API types
46//! are re-exported at the crate root for convenience.
47//!
48//! ## Modules
49//!
50//! - `error` — Error types for FAT operations
51//! - `file` — Short filename (8.3) types and validation
52//! - `raw` — On-disk structures: boot sector, BPB, directory entries
53//! - `sync::fs` — Filesystem handle and metadata
54//! - `sync::dir` — Directory iteration and entry types
55//! - `sync::read` — Read extension trait for file content
56//! - `sync::write` — Write extension trait for file modification
57//! - `sync::fat_table` — FAT table access (FAT12/16/32)
58//! - `sync::cache` — Optional FAT sector caching
59//! - `sync::format` — Filesystem formatting (requires `write`)
60//! - `sync::tool` — Analysis and verification (requires `tool`)
61
62#![no_std]
63#![allow(async_fn_in_trait)]
64
65#[cfg(feature = "std")]
66extern crate std;
67
68#[cfg(feature = "alloc")]
69extern crate alloc;
70
71// ---------------------------------------------------------------------------
72// Shared types (compiled once, not duplicated by sync/async modules)
73// ---------------------------------------------------------------------------
74
75pub mod error;
76pub mod file;
77pub mod raw;
78
79// ExFAT (WIP, stays at crate root for now)
80#[cfg(feature = "exfat")]
81pub mod exfat;
82
83// ---------------------------------------------------------------------------
84// Sync module
85// ---------------------------------------------------------------------------
86
87#[cfg(feature = "sync")]
88#[path = ""]
89pub mod sync {
90 //! Synchronous FAT filesystem API.
91 //!
92 //! All I/O operations use synchronous `Read`/`Write`/`Seek` traits.
93
94 pub use hadris_io::Result as IoResult;
95 pub use hadris_io::sync::{Parsable, Read, ReadExt, Seek, Writable, Write};
96 pub use hadris_io::{Error, ErrorKind, SeekFrom};
97
98 macro_rules! io_transform {
99 ($($item:tt)*) => { hadris_macros::strip_async!{ $($item)* } };
100 }
101
102 #[allow(unused_macros)]
103 macro_rules! sync_only {
104 ($($item:tt)*) => { $($item)* };
105 }
106
107 #[allow(unused_macros)]
108 macro_rules! async_only {
109 ($($item:tt)*) => {};
110 }
111
112 #[path = "."]
113 mod __inner {
114 #[cfg(feature = "cache")]
115 pub mod cache;
116 pub mod dir;
117 pub mod fat_table;
118 #[cfg(feature = "write")]
119 pub mod format;
120 pub mod fs;
121 pub mod io;
122 pub mod read;
123 #[cfg(feature = "tool")]
124 pub mod tool;
125 pub mod write;
126 }
127 pub use __inner::*;
128
129 // Convenience re-exports for backwards compatibility
130 pub use __inner::dir::{DirectoryEntry, FatDir, FileEntry};
131 pub use __inner::fat_table::{Fat, Fat12, Fat16, Fat32, FatType};
132 pub use __inner::fs::FatFs;
133 pub use __inner::read::FatFsReadExt;
134 #[cfg(feature = "tool")]
135 pub use __inner::tool::analysis::FatAnalysisExt;
136 #[cfg(feature = "tool")]
137 pub use __inner::tool::verify::FatVerifyExt;
138 #[cfg(feature = "write")]
139 pub use __inner::write::{FatDateTime, FatFsWriteExt};
140}
141
142// ---------------------------------------------------------------------------
143// Async module
144// ---------------------------------------------------------------------------
145
146#[cfg(feature = "async")]
147#[path = ""]
148pub mod r#async {
149 //! Asynchronous FAT filesystem API.
150 //!
151 //! All I/O operations use async `Read`/`Write`/`Seek` traits.
152
153 pub use hadris_io::Result as IoResult;
154 pub use hadris_io::r#async::{Parsable, Read, ReadExt, Seek, Writable, Write};
155 pub use hadris_io::{Error, ErrorKind, SeekFrom};
156
157 macro_rules! io_transform {
158 ($($item:tt)*) => { $($item)* };
159 }
160
161 #[allow(unused_macros)]
162 macro_rules! sync_only {
163 ($($item:tt)*) => {};
164 }
165
166 #[allow(unused_macros)]
167 macro_rules! async_only {
168 ($($item:tt)*) => { $($item)* };
169 }
170
171 #[path = "."]
172 mod __inner {
173 #[cfg(feature = "cache")]
174 pub mod cache;
175 pub mod dir;
176 pub mod fat_table;
177 #[cfg(feature = "write")]
178 pub mod format;
179 pub mod fs;
180 pub mod io;
181 pub mod read;
182 #[cfg(feature = "tool")]
183 pub mod tool;
184 pub mod write;
185 }
186 pub use __inner::*;
187}
188
189// ---------------------------------------------------------------------------
190// Default re-exports for backwards compatibility (sync)
191// ---------------------------------------------------------------------------
192
193#[cfg(feature = "sync")]
194pub use sync::*;
195
196// Re-exports from shared types
197pub use error::{FatError, Result};
198pub use raw::*;