Skip to content

Backport #189 to make release v0.8.2 #191

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

Merged
merged 2 commits into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 17 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic

- None

## [Version 0.8.2] - 2025-06-07

### Changed

* Fixed writing at block start mid-file (previously overwrote subsequent file data with zeros up to the end of the block)

## [Version 0.8.1] - 2024-11-03

### Changed
Expand Down Expand Up @@ -174,13 +180,15 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.0...develop
[Version 0.8.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.0...v0.7.0
[Version 0.7.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.7.0...v0.6.0
[Version 0.6.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.6.0...v0.5.0
[Version 0.5.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.5.0...v0.4.0
[Version 0.4.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.4.0...v0.3.0
[Version 0.3.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.3.0...v0.2.1
[Version 0.2.1]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.2.1...v0.2.0
[Version 0.2.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.2.0...v0.1.1
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.2...develop
[Version 0.8.2]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.1...v0.8.2
[Version 0.8.1]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.0...v0.8.1
[Version 0.8.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.7.0...v0.8.0
[Version 0.7.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.6.0...v0.7.0
[Version 0.6.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.5.0...v0.6.0
[Version 0.5.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.4.0...v0.5.0
[Version 0.4.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.3.0...v0.4.0
[Version 0.3.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.2.1...v0.3.0
[Version 0.2.1]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.2.0...v0.2.1
[Version 0.2.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.1.1...v0.2.0
[Version 0.1.1]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/releases/tag/v0.1.1
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
name = "embedded-sdmmc"
readme = "README.md"
repository = "https://github.com/rust-embedded-community/embedded-sdmmc-rs"
version = "0.8.1"
version = "0.8.2"

[dependencies]
byteorder = {version = "1", default-features = false}
Expand Down
4 changes: 2 additions & 2 deletions src/volume_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ where
};
let mut blocks = [Block::new()];
let to_copy = core::cmp::min(block_avail, bytes_to_write - written);
if block_offset != 0 {
debug!("Partial block write");
if block_offset != 0 || to_copy != block_avail {
debug!("Partial block read/modify/write");
self.block_device
.read(&mut blocks, block_idx, "read")
.map_err(Error::DeviceError)?;
Expand Down
59 changes: 59 additions & 0 deletions tests/write_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,65 @@ fn flush_file() {
assert_eq!(entry.size, 64 * 3);
}

#[test]
fn random_access_write_file() {
let time_source = utils::make_time_source();
let disk = utils::make_block_device(utils::DISK_SOURCE).unwrap();
let mut volume_mgr: VolumeManager<utils::RamDisk<Vec<u8>>, utils::TestTimeSource, 4, 2, 1> =
VolumeManager::new_with_limits(disk, time_source, 0xAA00_0000);
let volume = volume_mgr
.open_raw_volume(VolumeIdx(0))
.expect("open volume");
let root_dir = volume_mgr.open_root_dir(volume).expect("open root dir");

// Open with string
let f = volume_mgr
.open_file_in_dir(root_dir, "README.TXT", Mode::ReadWriteTruncate)
.expect("open file");

let test_data = vec![0xCC; 1024];
volume_mgr.write(f, &test_data).expect("file write");

let length = volume_mgr.file_length(f).expect("get length");
assert_eq!(length, 1024);

for seek_offset in [100, 0] {
let mut expected_buffer = [0u8; 4];

// fetch some data at offset seek_offset
volume_mgr
.file_seek_from_start(f, seek_offset)
.expect("Seeking");
volume_mgr.read(f, &mut expected_buffer).expect("read file");

// modify first byte
expected_buffer[0] ^= 0xff;

// write only first byte, expecting the rest to not change
volume_mgr
.file_seek_from_start(f, seek_offset)
.expect("Seeking");
volume_mgr
.write(f, &expected_buffer[0..1])
.expect("file write");
volume_mgr.flush_file(f).expect("file flush");

// read and verify
volume_mgr
.file_seek_from_start(f, seek_offset)
.expect("file seek");
let mut read_buffer = [0xffu8, 0xff, 0xff, 0xff];
volume_mgr.read(f, &mut read_buffer).expect("file read");
assert_eq!(
read_buffer, expected_buffer,
"mismatch seek+write at offset {seek_offset} from start"
);
}

volume_mgr.close_file(f).expect("close file");
volume_mgr.close_dir(root_dir).expect("close dir");
volume_mgr.close_volume(volume).expect("close volume");
}
// ****************************************************************************
//
// End Of File
Expand Down