Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking PR for write-functionality branch #1

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f79db1f
feat(write): implement Write for File & Seek beyond EOF allocates mor…
Oakchris1955 Aug 18, 2024
c689a64
chore: remove unnecessary impl
Oakchris1955 Aug 18, 2024
9775f2a
fix: seeking on a File wouldn't always happen correctly
Oakchris1955 Aug 19, 2024
6bd3534
feat(truncate): Public function to truncate a File down to a given size
Oakchris1955 Aug 19, 2024
a8ced4c
fix: also write FAT entries to the FAT table copies
Oakchris1955 Aug 20, 2024
4941c8c
fix: fix commit a8ced4c for no-std contexts
Oakchris1955 Aug 20, 2024
ad6747e
chore: writing FAT12 entries no longer reads sectors ahead-of-time
Oakchris1955 Aug 25, 2024
20adcf0
feat(file): split File struct into separate ROFile & RWFile
Oakchris1955 Aug 26, 2024
f427f9e
fix: correctly implement file attributes
Oakchris1955 Aug 28, 2024
21d83d6
fix: correctly parse 8.3 & LFN entries that span multiple sectors
Oakchris1955 Aug 29, 2024
f88942b
feat: add `remove()` method to RWFile struct
Oakchris1955 Aug 30, 2024
a60e55b
fix: `truncate()` now works if the new size is close to the old one
Oakchris1955 Aug 31, 2024
d8a5cfd
fix(fat32): various fat32-related bug fixes
Oakchris1955 Aug 31, 2024
418451a
test(fat32): create various fat32-related tests
Oakchris1955 Aug 31, 2024
8b61fea
refactor: split fs.rs file into multiple modules
Oakchris1955 Sep 1, 2024
a4503de
chore: various aesthetic changes
Oakchris1955 Sep 1, 2024
b891cc0
fix: properly handle FATs
Oakchris1955 Sep 3, 2024
d43d06a
chore: rename src/fs/ to src/fat/
Oakchris1955 Sep 7, 2024
66b1f78
fix: correctly handle calling RW methods on RO storage mediums
Oakchris1955 Sep 7, 2024
9e61bd8
chore: create a proper constructor for the FSProperties struct
Oakchris1955 Sep 7, 2024
fa7380d
chore: Update README.md
Oakchris1955 Sep 7, 2024
5fb88c9
refactor: minor entry chain-related changes
Oakchris1955 Sep 8, 2024
de85609
refactor: create modularized internal remove-related methods
Oakchris1955 Sep 8, 2024
61c83ed
feat(time): Add a Clock trait that will be used for generating file t…
Oakchris1955 Sep 8, 2024
dbeaf4b
feat: create alias method `remove_file`
Oakchris1955 Sep 12, 2024
7a2bc0c
fix: PathBuf's `.parent()` method wouldn't behave as expected
Oakchris1955 Sep 14, 2024
63b0f9b
feat: Add the ability to remove empty directories
Oakchris1955 Sep 14, 2024
842fce1
chore: enable clippy lints
Oakchris1955 Sep 14, 2024
02eb213
fix: don't expose the `.` & `..` entries to the end user
Oakchris1955 Sep 14, 2024
d19a04e
fix: sync the FSInfo struct on FAT32 filesystems
Oakchris1955 Sep 15, 2024
7803ab2
feat: add a proper unmount method
Oakchris1955 Sep 15, 2024
faf1be2
feat: add the ability to remove non-empty directories
Oakchris1955 Sep 21, 2024
d1c1015
chore: fix `faf1be2` for `no_std` contexts
Oakchris1955 Sep 21, 2024
38c46c5
refactor: split FileSystem::remove_entry_chain logic to other functions
Oakchris1955 Dec 22, 2024
4552d6f
feat: change expression to comply with clippy's manual_div_ceil
Oakchris1955 Dec 23, 2024
b368975
chore: replace the path module with a proper path library
Oakchris1955 Dec 25, 2024
9cea9f0
refactor: implement current directory location caching
Oakchris1955 Jan 7, 2025
6aa47d6
test: add a new test to check whether a file can be interpreted as a …
Oakchris1955 Jan 7, 2025
9e7255b
chore: change clippy::redundant_clone level to warn from deny
Oakchris1955 Jan 7, 2025
c57952f
chore: remove redundant path clones in tests
Oakchris1955 Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
}
},
"rust-analyzer.check.command": "clippy",
}
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ log = "0.4.22"
serde = { version = "1.0.204", default-features = false, features = [ "alloc", "derive" ] }
serde-big-array = "0.5.1"
time = { version = "0.3.36", default-features = false, features = [ "alloc", "parsing", "macros" ]}
typed-path = { version = "0.10.0", default-features = false }

[features]
default = ["std"]
std = ["displaydoc/std", "serde/std", "time/std"]
std = ["time/std", "time/local-offset"]

[dev-dependencies]
test-log = "0.2.16"
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ A fully-working FAT driver that covers the following criteria:

- [x] FAT12 support (just handle entries between 2 sectors)
- [x] Distinguish between dirs and files in paths (this must also be verified by the filesystem, just like in the `std`)
- [ ] Check whether system endianness matters (FAT is little-endian)
- [x] Check whether system endianness matters (FAT is little-endian)
PS: it does in fact matter. [bincode](https://crates.io/crates/bincode), which we use for (de)serialization allows us to configure the default endianess
- [ ] Handle non-printable characters in names of files and directories
- [ ] ExFAT support
- [ ] when [feature(error_in_core)](https://github.com/rust-lang/rust/issues/103765) gets released to stable, bump MSRV & use the `core::error::Error` trait instead of our custom `error::Error`

[crates.io]: https://crates.io
[rafalh's rust-fatfs]: https://github.com/rafalh/rust-fatfs
- [x] ~~when [feature(error_in_core)](https://github.com/rust-lang/rust/issues/103765) gets released to stable, bump MSRV & use the `core::error::Error` trait instead of our custom `error::Error`~~
this feature is now stabilized. However, [after a couple of community recommendations](https://www.reddit.com/r/rust/comments/1ejukow/comment/lgg3dtb/), we will be switching to [embedded-io] in the near future, which has its own `Error` trait, so that means...
- [ ] replace custom `io` implementation with the [embedded-io] crate

## Acknowledgements

Expand All @@ -44,3 +44,7 @@ This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
## License

[MIT](LICENSE)

[crates.io]: https://crates.io
[rafalh's rust-fatfs]: https://github.com/rafalh/rust-fatfs
[embedded-io]: https://crates.io/crates/embedded-io
Binary file modified imgs/fat12.img
Binary file not shown.
2 changes: 1 addition & 1 deletion imgs/fat12.img.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ec293f4087abbd287e6024fc7918836de91ced075428f15688b9fb2462733990 *imgs/fat12.img
d591b06414897e425d4cd02550d22b60ff1b3c16d1dca3fdff532a115eefa47f *imgs/fat12.img
Binary file modified imgs/fat16.img
Binary file not shown.
2 changes: 1 addition & 1 deletion imgs/fat16.img.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4eddf671476c0ac64ca0ae3bf8837e07515082f89975ddd2ff43113fde521558 *imgs/fat16.img
894fe3973c733f6a1e2e86661a5ba40c84f926bfd3710b655b49bebd0d22246d *imgs/fat16.img
Binary file modified imgs/fat32.img
Binary file not shown.
2 changes: 1 addition & 1 deletion imgs/fat32.img.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
604b7fdf8131868241dc4f33817994838f0da4d9795d400c0120e460cf7897e1 *imgs/fat32.img
5e49c78dfcf001666926151f1a95df991f91729016cc3949fc589702604d2a5f *imgs/fat32.img
33 changes: 27 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[cfg(not(feature = "std"))]
use core::*;
#[cfg(feature = "std")]
use std::*;
use core::fmt;

/// Base error type
///
Expand Down Expand Up @@ -51,6 +48,8 @@ pub trait IOErrorKind: PartialEq + Sized {
fn new_interrupted() -> Self;
/// Create a new `InvalidData` [`IOErrorKind`]
fn new_invalid_data() -> Self;
/// Create a new `Unsupported` [`IOErrorKind`]
fn new_unsupported() -> Self;

#[inline]
/// Check whether this [`IOErrorKind`] is of kind `UnexpectedEOF`
Expand All @@ -67,6 +66,11 @@ pub trait IOErrorKind: PartialEq + Sized {
fn is_invalid_data(&self) -> bool {
self == &Self::new_invalid_data()
}
/// Check whether this [`IOErrorKind`] is of kind `Unsupported`
#[inline]
fn is_unsupported(&self) -> bool {
self == &Self::new_unsupported()
}
}

#[cfg(feature = "std")]
Expand All @@ -83,6 +87,10 @@ impl IOErrorKind for std::io::ErrorKind {
fn new_invalid_data() -> Self {
std::io::ErrorKind::InvalidData
}
#[inline]
fn new_unsupported() -> Self {
std::io::ErrorKind::Unsupported
}
}

/// An error type that denotes that there is something wrong
Expand All @@ -95,11 +103,20 @@ pub enum InternalFSError {
InvalidBPBSig,
/**
Invalid FAT32 FSInfo signature.
Perhaps the FSInfo structure or the FAT32 EBR's fat_info field is malformed?
Perhaps the FSInfo structure or the FAT32 Ebr's fat_info field is malformed?
*/
InvalidFSInfoSig,
/**
The FAT and it's copies do not much.
This is either the result of some bad FAT library that chose to ignore the FAT copies
or perhaps the storage medium has been corrupted (most likely).
Either way, we are not handling this FileSystem
*/
MismatchingFATTables,
/// Encountered a malformed cluster chain
MalformedClusterChain,
/// Encountered a malformed directory entry chain
MalformedEntryChain,
}

/// An error indicating that a filesystem-related operation has failed
Expand All @@ -112,7 +129,7 @@ where
#[displaydoc("An internal FS error occured: {0}")]
InternalFSError(InternalFSError),
/**
The [PathBuf](`crate::path::PathBuf`) provided is malformed.
The [Path](`crate::Path`) provided is malformed.

This is mostly an error variant used for internal testing.
If you get this error, open an issue: <https://github.com/Oakchris1955/simple-fatfs/issues>
Expand All @@ -129,6 +146,10 @@ where
NotADirectory,
/// Found a directory when we expected a file
IsADirectory,
/// Expected an empty directory
DirectoryNotEmpty,
/// This file cannot be modified, as it is read-only
ReadOnlyFile,
/// A file or directory wasn't found
NotFound,
/// An IO error occured
Expand Down
Loading
Loading