diff --git a/services/pddb/src/api.rs b/services/pddb/src/api.rs index f78ef71c9..370dd68d4 100644 --- a/services/pddb/src/api.rs +++ b/services/pddb/src/api.rs @@ -236,6 +236,9 @@ pub(crate) enum Opcode { /// Bulk read of a dictionary DictBulkRead = 52, + /// Mount was attempted + MountAttempted = 53, + /// This key type could not be decoded InvalidOpcode = u32::MAX as _, } diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index ed79008e6..97f43dd1e 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -164,6 +164,20 @@ impl Pddb { } } } + pub fn mount_attempted_blocking(&self) { + loop { + let ret = send_message(self.conn, Message::new_blocking_scalar( + Opcode::MountAttempted.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query"); + match ret { + xous::Result::Scalar2(code, _count) => { + if code == 0 { // mounted successfully + break; + } + }, + _ => panic!("Internal error"), + } + } + } /// Attempts to mount the system basis. Returns `true` on success, `false` on failure. /// This call may cause a password request box to pop up, in the case that the boot PIN is not currently cached. /// diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 787caaf93..e542055af 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -590,6 +590,7 @@ fn wrapped_main() -> ! { // track processes that want a notification of a mount event let mut mount_notifications = Vec::::new(); + let mut attempt_notifications = Vec::::new(); // track heap usage let mut initial_heap: usize = 0; @@ -649,6 +650,17 @@ fn wrapped_main() -> ! { mount_notifications.push(msg.sender); // defer response until later } }), + Opcode::MountAttempted => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { + #[cfg(not(target_os = "xous"))] // hosted mode always passes + xous::return_scalar2(msg.sender, 0, 0).expect("couldn't return scalar"); + + #[cfg(target_os = "xous")] + if basis_cache.basis_count() > 0 { // if there's anything in the cache, we're mounted; by definition it was attempted + xous::return_scalar2(msg.sender, 0, 0).expect("couldn't return scalar"); + } else { + attempt_notifications.push(msg.sender); // defer response until later + } + }), // The return code from this is a scalar2 with the following meanings: // (code, count): // - code = 0 -> successful mount @@ -717,6 +729,11 @@ fn wrapped_main() -> ! { profiling::do_query_work(); } } + // this is so that the UX can drop the initial "waiting for boot" message + // the attempt is credited even if it was aborted or failed. + for requester in attempt_notifications.drain(..) { + xous::return_scalar2(requester, 0, 0).expect("couldn't return scalar"); + } }), Opcode::PeriodicScrub => { let current_heap = heap_usage();