1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! # simple-fatfs
//!
//! An easy-to-use FAT filesystem library designed for usage in embedded systems
//!
//! ## Features
//!
//! - `no_std` support
//! - FAT12/16/32 support
//! - VFAT/LFN (long filenames) support
//! - Auto-`impl`s for [`std::io`] traits and structs
//! - Easy-to-implement [`io`] traits
//!
//! ## Usage
//!
//! The library uses [`embedded-io`](embedded_io) for IO operations.
//! Most notably, the storage medium is expected to implement at least the
//! [`Read`] and [`Seek`] traits (RO storage), while [`Write`] is optional
//! (R/W storage). Furthermore, [`ROFile`] & [`RWFile`] both implement [`Read`]
//! & [`Seek`], while [`RWFile`] also implements [`Write`]
//!
//! To use [`std::io`]'s respective traits, use the
//! [`embedded-io-adapters`](https://crates.io/crates/embedded-io-adapters) crate.
//!
//! ## Examples
//! ```
//! # // this test fails on a no_std environment, don't run it in such a case
//! extern crate simple_fatfs;
//! use simple_fatfs::*;
//! use simple_fatfs::io::*;
//!
//! use embedded_io_adapters::std::FromStd;
//!
//! const FAT_IMG: &[u8] = include_bytes!("../imgs/fat12.img");
//!
//! fn main() {
//! let mut cursor = FromStd::new(std::io::Cursor::new(FAT_IMG.to_owned()));
//!
//! // We can either pass by value or by (mutable) reference
//! // (Yes, the storage medium might be Read-Only, but reading is a mutable action)
//! let mut fs = FileSystem::new(&mut cursor, FSOptions::new()).unwrap();
//!
//! // Let's see what entries there are in the root directory
//! for entry in fs.read_dir("/").unwrap() {
//! // in a real world example, you probably don't wanna unwrap this
//! let entry = entry.unwrap();
//!
//! if entry.is_dir() {
//! println!("Directory: {}", entry.path())
//! } else if entry.is_file() {
//! println!("File: {}", entry.path())
//! } else {
//! unreachable!()
//! }
//! }
//!
//! // the disk image we currently use has a file named "root.txt"
//! // in the root directory. Let's read it
//! let mut file = fs.get_ro_file("/root.txt").unwrap();
//! let mut file_buf = vec![0; file.file_size() as usize];
//! file.read_exact(&mut file_buf).unwrap();
//! let string = str::from_utf8(&file_buf).unwrap();
//! println!("root.txt contents:\n{}", string);
//! }
//! ```
//!
//! [`Read`]: io::Read
//! [`Seek`]: io::Seek
//! [`Write`]: io::Write
// Even inside unsafe functions, we must acknowlegde the usage of unsafe code
// clippy attributes
// who thought this was a good idea for a deny lint?
extern crate alloc;
pub use *;
pub use embedded_io as io;
pub use *;
pub use *;
pub use *;
pub use *;