Skip to content

Commit e3f807f

Browse files
authored
Merge pull request #95 from rust-embedded-community/jgp-fixes
Cleaning up some comments, and fixing the close file bug.
2 parents 13d0cc1 + cf32701 commit e3f807f

40 files changed

+2889
-1833
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,5 @@ jobs:
1919
- uses: actions/checkout@v1
2020
- name: Build
2121
run: cargo build --no-default-features --features ${{matrix.features}} --verbose
22-
- name: Unpack Disk
23-
run: gunzip -fk disk.img.gz
24-
- name: Run Test Mount example
25-
run: cargo run --no-default-features --features ${{matrix.features}} --example test_mount ./disk.img
26-
- name: Unpack Disk
27-
run: gunzip -fk disk.img.gz
28-
- name: Run Create Test example
29-
run: cargo run --no-default-features --features ${{matrix.features}} --example create_test ./disk.img
30-
- name: Unpack Disk
31-
run: gunzip -fk disk.img.gz
32-
- name: Run Write Test example
33-
run: cargo run --no-default-features --features ${{matrix.features}} --example write_test ./disk.img
34-
- name: Run Unit Tests
22+
- name: Run Tests
3523
run: cargo test --no-default-features --features ${{matrix.features}} --verbose
36-

CHANGELOG.md

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,35 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Changed
1111

12-
- None
12+
- Writing to a file no longer flushes file metadata to the Directory Entry.
13+
Instead closing a file now flushes file metadata to the Directory Entry.
14+
Requires mutable access to the Volume ([#94]).
15+
- Files now have the correct length when modified, not appended ([#72]).
16+
- Calling `SdCard::get_card_type` will now perform card initialisation ([#87] and [#90]).
17+
- Removed warning about unused arguments.
18+
- Types are now documented at the top level ([#86]).
19+
- Renamed `Cluster` to `ClusterId` and stopped you adding two together
20+
21+
[#72]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/72
22+
[#86]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/86
23+
[#87]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/87
24+
[#90]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/90
25+
[#94]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/94
1326

1427
### Added
1528

16-
- None
29+
- New examples, `append_file`, `create_file`, `delete_file`, `list_dir`
30+
- New test cases `tests/directories.rs`, `tests/read_file.rs`
1731

1832
### Removed
1933

20-
- None
34+
- __Breaking Change__: `Controller` alias for `VolumeManager` removed.
35+
- __Breaking Change__: `VolumeManager::open_dir_entry` removed, as it was unsafe to the user to randomly pick a starting cluster.
36+
- Old examples `create_test`, `test_mount`, `write_test`, `delete_test`
2137

2238
## [Version 0.5.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.5.0) - 2023-05-20
2339

24-
### Changes
40+
### Changes in v0.5.0
2541

2642
- __Breaking Change__: Renamed `Controller` to `VolumeManager`, to better describe what it does.
2743
- __Breaking Change__: Renamed `SdMmcSpi` to `SdCard`
@@ -31,21 +47,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3147
- More robust card intialisation procedure, with added retries
3248
- Supports building with neither `defmt` nor `log` logging
3349

34-
### Added
50+
### Added in v0.5.0
3551

3652
- Added `mark_card_as_init` method, if you know the card is initialised and want to skip the initialisation step
3753

38-
### Removed
54+
### Removed in v0.5.0
3955

4056
- __Breaking Change__: Removed `BlockSpi` type - card initialisation now handled as an internal state variable
4157

4258
## [Version 0.4.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.4.0) - 2023-01-18
4359

44-
### Changes
60+
### Changes in v0.4.0
61+
4562
- Optionally use [defmt](https://github.com/knurling-rs/defmt) for logging.
4663
Controlled by `defmt-log` feature flag.
4764
- __Breaking Change__: Use SPI blocking traits instead to ease SPI peripheral sharing.
48-
See: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/28
65+
See: <https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/28>
4966
- Added `Controller::has_open_handles` and `Controller::free` methods.
5067
- __Breaking Change__: Changed interface to enforce correct SD state at compile time.
5168
- __Breaking Change__: Added custom error type for `File` operations.
@@ -58,33 +75,33 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5875

5976
## [Version 0.3.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.3.0) - 2019-12-16
6077

61-
### Changes
78+
### Changes in v0.3.0
6279

63-
* Updated to `v2` embedded-hal traits.
64-
* Added open support for all modes.
65-
* Added write support for files.
66-
* Added `Info_Sector` tracking for FAT32.
67-
* Change directory iteration to look in all the directory's clusters.
68-
* Added `write_test` and `create_test`.
69-
* De-duplicated FAT16 and FAT32 code (https://github.com/thejpster/embedded-sdmmc-rs/issues/10)
80+
- Updated to `v2` embedded-hal traits.
81+
- Added open support for all modes.
82+
- Added write support for files.
83+
- Added `Info_Sector` tracking for FAT32.
84+
- Change directory iteration to look in all the directory's clusters.
85+
- Added `write_test` and `create_test`.
86+
- De-duplicated FAT16 and FAT32 code (<https://github.com/thejpster/embedded-sdmmc-rs/issues/10>)
7087

7188
## [Version 0.2.1](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.2.1) - 2019-02-19
7289

73-
### Changes
90+
### Changes in v0.2.1
7491

75-
* Added `readme=README.md` to `Cargo.toml`
92+
- Added `readme=README.md` to `Cargo.toml`
7693

7794
## [Version 0.2.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.2.0) - 2019-01-24
7895

79-
### Changes
96+
### Changes in v0.2.0
8097

81-
* Reduce delay waiting for response. Big speed improvements.
98+
- Reduce delay waiting for response. Big speed improvements.
8299

83100
## [Version 0.1.0](https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.1.1) - 2018-12-23
84101

85-
### Changes
102+
### Changes in v0.1.0
86103

87-
* Can read blocks from an SD Card using an `embedded_hal::SPI` device and a
104+
- Can read blocks from an SD Card using an `embedded_hal::SPI` device and a
88105
`embedded_hal::OutputPin` for Chip Select.
89-
* Can read partition tables and open a FAT32 or FAT16 formatted partition.
90-
* Can open and iterate the root directory of a FAT16 formatted partition.
106+
- Can read partition tables and open a FAT32 or FAT16 formatted partition.
107+
- Can open and iterate the root directory of a FAT16 formatted partition.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ log = {version = "0.4", default-features = false, optional = true}
2020
[dev-dependencies]
2121
env_logger = "0.9"
2222
hex-literal = "0.3"
23+
flate2 = "1.0"
24+
sha256 = "1.4"
25+
chrono = "0.4"
2326

2427
[features]
2528
default = ["log"]

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,35 @@ let mut volume_mgr = embedded_sdmmc::VolumeManager::new(sdcard, time_source);
2323
// It doesn't hold a reference to the Volume Manager and so must be passed back
2424
// to every Volume Manager API call. This makes it easier to handle multiple
2525
// volumes in parallel.
26-
let mut volume0 = volume_mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
26+
let volume0 = volume_mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
2727
println!("Volume 0: {:?}", volume0);
2828
// Open the root directory (passing in the volume we're using).
2929
let root_dir = volume_mgr.open_root_dir(&volume0)?;
3030
// Open a file called "MY_FILE.TXT" in the root directory
31-
let mut my_file = volume_mgr.open_file_in_dir(
32-
&mut volume0,
33-
&root_dir,
31+
let my_file = volume_mgr.open_file_in_dir(
32+
root_dir,
3433
"MY_FILE.TXT",
3534
embedded_sdmmc::Mode::ReadOnly,
3635
)?;
3736
// Print the contents of the file
38-
while !my_file.eof() {
37+
while !volume_manager.file_eof(my_file).unwrap() {
3938
let mut buffer = [0u8; 32];
4039
let num_read = volume_mgr.read(&volume0, &mut my_file, &mut buffer)?;
4140
for b in &buffer[0..num_read] {
4241
print!("{}", *b as char);
4342
}
4443
}
45-
volume_mgr.close_file(&volume0, my_file)?;
46-
volume_mgr.close_dir(&volume0, root_dir);
44+
volume_mgr.close_file(my_file)?;
45+
volume_mgr.close_dir(root_dir)?;
4746
```
4847

4948
### Open directories and files
5049

51-
By default the `VolumeManager` will initialize with a maximum number of `4` open directories and files. This can be customized by specifying the `MAX_DIR` and `MAX_FILES` generic consts of the `VolumeManager`:
50+
By default the `VolumeManager` will initialize with a maximum number of `4` open directories, files and volumes. This can be customized by specifying the `MAX_DIR`, `MAX_FILES` and `MAX_VOLUMES` generic consts of the `VolumeManager`:
5251

5352
```rust
54-
// Create a volume manager with a maximum of 6 open directories and 12 open files
55-
let mut cont: VolumeManager<_, _, 6, 12> = VolumeManager::new_with_limits(block, time_source);
53+
// Create a volume manager with a maximum of 6 open directories, 12 open files, and 4 volumes (or partitions)
54+
let mut cont: VolumeManager<_, _, 6, 12, 4> = VolumeManager::new_with_limits(block, time_source);
5655
```
5756

5857
## Supported features

examples/append_file.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Append File Example.
2+
//!
3+
//! ```bash
4+
//! $ cargo run --example append_file -- ./disk.img
5+
//! $ cargo run --example append_file -- /dev/mmcblk0
6+
//! ```
7+
//!
8+
//! If you pass a block device it should be unmounted. No testing has been
9+
//! performed with Windows raw block devices - please report back if you try
10+
//! this! There is a gzipped example disk image which you can gunzip and test
11+
//! with if you don't have a suitable block device.
12+
//!
13+
//! ```bash
14+
//! zcat ./tests/disk.img.gz > ./disk.img
15+
//! $ cargo run --example append_file -- ./disk.img
16+
//! ```
17+
18+
extern crate embedded_sdmmc;
19+
20+
mod linux;
21+
use linux::*;
22+
23+
const FILE_TO_APPEND: &str = "README.TXT";
24+
25+
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
26+
27+
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
28+
env_logger::init();
29+
let mut args = std::env::args().skip(1);
30+
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
31+
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
32+
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
33+
let mut volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
34+
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
35+
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
36+
let root_dir = volume_mgr.open_root_dir(volume)?;
37+
println!("\nCreating file {}...", FILE_TO_APPEND);
38+
let f = volume_mgr.open_file_in_dir(root_dir, FILE_TO_APPEND, Mode::ReadWriteAppend)?;
39+
volume_mgr.write(f, b"\r\n\r\nThis has been added to your file.\r\n")?;
40+
volume_mgr.close_file(f)?;
41+
volume_mgr.close_dir(root_dir)?;
42+
Ok(())
43+
}
44+
45+
// ****************************************************************************
46+
//
47+
// End Of File
48+
//
49+
// ****************************************************************************

examples/create_file.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! Create File Example.
2+
//!
3+
//! ```bash
4+
//! $ cargo run --example create_file -- ./disk.img
5+
//! $ cargo run --example create_file -- /dev/mmcblk0
6+
//! ```
7+
//!
8+
//! If you pass a block device it should be unmounted. No testing has been
9+
//! performed with Windows raw block devices - please report back if you try
10+
//! this! There is a gzipped example disk image which you can gunzip and test
11+
//! with if you don't have a suitable block device.
12+
//!
13+
//! ```bash
14+
//! zcat ./tests/disk.img.gz > ./disk.img
15+
//! $ cargo run --example create_file -- ./disk.img
16+
//! ```
17+
18+
extern crate embedded_sdmmc;
19+
20+
mod linux;
21+
use linux::*;
22+
23+
const FILE_TO_CREATE: &str = "CREATE.TXT";
24+
25+
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
26+
27+
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
28+
env_logger::init();
29+
let mut args = std::env::args().skip(1);
30+
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
31+
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
32+
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
33+
let mut volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
34+
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
35+
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
36+
let root_dir = volume_mgr.open_root_dir(volume)?;
37+
println!("\nCreating file {}...", FILE_TO_CREATE);
38+
// This will panic if the file already exists: use ReadWriteCreateOrAppend
39+
// or ReadWriteCreateOrTruncate instead if you want to modify an existing
40+
// file.
41+
let f = volume_mgr.open_file_in_dir(root_dir, FILE_TO_CREATE, Mode::ReadWriteCreate)?;
42+
volume_mgr.write(f, b"Hello, this is a new file on disk\r\n")?;
43+
volume_mgr.close_file(f)?;
44+
volume_mgr.close_dir(root_dir)?;
45+
Ok(())
46+
}
47+
48+
// ****************************************************************************
49+
//
50+
// End Of File
51+
//
52+
// ****************************************************************************

0 commit comments

Comments
 (0)