Skip to content

Commit

Permalink
track "attempted" mounts in PDDB
Browse files Browse the repository at this point in the history
this is to allow a UX process to clear the "waiting for boot"
indicator once an attempt has completed.

right now, it responds *after* the mount process is done,
so the "please waiting" text persists even doing a format.

I think that is...appropriate?
  • Loading branch information
bunnie committed Nov 6, 2022
1 parent 93dcfb7 commit 0646ec2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions services/pddb/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _,
}
Expand Down
14 changes: 14 additions & 0 deletions services/pddb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
17 changes: 17 additions & 0 deletions services/pddb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ fn wrapped_main() -> ! {

// track processes that want a notification of a mount event
let mut mount_notifications = Vec::<xous::MessageSender>::new();
let mut attempt_notifications = Vec::<xous::MessageSender>::new();

// track heap usage
let mut initial_heap: usize = 0;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0646ec2

Please sign in to comment.