Add PartitionGuard implementations and enhance Partition functionality#754
Draft
ayodejiige wants to merge 2 commits intoOpenDevicePartnership:mainfrom
Draft
Add PartitionGuard implementations and enhance Partition functionality#754ayodejiige wants to merge 2 commits intoOpenDevicePartnership:mainfrom
ayodejiige wants to merge 2 commits intoOpenDevicePartnership:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new PartitionGuard type and corresponding Partition::lock() / Partition::try_lock() APIs to enable holding the underlying storage mutex across multiple partition operations, and wires up trait implementations so a guard can be used as a ReadNorFlash/NorFlash/BlockDevice where applicable.
Changes:
- Introduce
PartitionGuardplusPartition::{lock, try_lock}to explicitly hold the storage mutex. - Implement
embedded-storage-asynctraits forPartitionGuardandblock-device-drivertraits forPartitionGuard. - Adjust test module lint attributes (removed module-level clippy allowances).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| partition-manager/partition-manager/src/test/mod.rs | Removes module-level clippy allowances for test code. |
| partition-manager/partition-manager/src/lib.rs | Adds PartitionGuard, lock()/try_lock(), re-exports TryLockError, and adds Error::Locked. |
| partition-manager/partition-manager/src/ext/esa.rs | Adds PartitionGuard ErrorType + ReadNorFlash/NorFlash/MultiwriteNorFlash impls. |
| partition-manager/partition-manager/src/ext/bdd.rs | Adds PartitionGuard helpers and BlockDevice impls. |
Comment on lines
1
to
3
| mod mock; | ||
|
|
||
| #[cfg(feature = "bdd")] |
Comment on lines
+165
to
+166
| /// Could not acquire the storage lock. | ||
| Locked, |
Comment on lines
+89
to
+111
| async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| if !self.within_bounds(offset, bytes.len() as u32) { | ||
| return Err(Error::OutOfBounds); | ||
| } | ||
|
|
||
| Ok(self.guard.read(offset + self.offset, bytes).await?) | ||
| } | ||
|
|
||
| fn capacity(&self) -> usize { | ||
| self.size as usize | ||
| } | ||
| } | ||
|
|
||
| impl<F: ReadNorFlash, M: RawMutex> ReadNorFlash for PartitionGuard<'_, F, RW, M> { | ||
| const READ_SIZE: usize = F::READ_SIZE; | ||
|
|
||
| async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | ||
| if !self.within_bounds(offset, bytes.len() as u32) { | ||
| return Err(Error::OutOfBounds); | ||
| } | ||
|
|
||
| Ok(self.guard.read(offset + self.offset, bytes).await?) | ||
| } |
Comment on lines
+57
to
+60
| let offset = block_address * SIZE as u32; | ||
| let size = (data.len() * SIZE) as u32; | ||
| if !self.within_bounds(offset, size) { | ||
| Err(Error::OutOfBounds) |
Comment on lines
+49
to
+67
| /// Lock the underlying storage and return a guard that allows direct operations. | ||
| pub async fn lock(&self) -> PartitionGuard<'_, F, MARKER, M> { | ||
| PartitionGuard { | ||
| guard: self.storage.lock().await, | ||
| offset: self.offset, | ||
| size: self.size, | ||
| _marker: PhantomData, | ||
| } | ||
| } | ||
|
|
||
| /// Attempt to lock the underlying storage without blocking. | ||
| pub fn try_lock(&self) -> Result<PartitionGuard<'_, F, MARKER, M>, TryLockError> { | ||
| Ok(PartitionGuard { | ||
| guard: self.storage.try_lock()?, | ||
| offset: self.offset, | ||
| size: self.size, | ||
| _marker: PhantomData, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.