Skip to content

Add PartitionGuard implementations and enhance Partition functionality#754

Draft
ayodejiige wants to merge 2 commits intoOpenDevicePartnership:mainfrom
ayodejiige:partition-try-lock
Draft

Add PartitionGuard implementations and enhance Partition functionality#754
ayodejiige wants to merge 2 commits intoOpenDevicePartnership:mainfrom
ayodejiige:partition-try-lock

Conversation

@ayodejiige
Copy link

No description provided.

Copilot AI review requested due to automatic review settings March 17, 2026 20:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PartitionGuard plus Partition::{lock, try_lock} to explicitly hold the storage mutex.
  • Implement embedded-storage-async traits for PartitionGuard and block-device-driver traits for PartitionGuard.
  • 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,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants