use types::bounded::CapSlot; #[derive(Debug, Clone, Copy)] pub struct StorageHandle(u16); impl StorageHandle { pub fn raw(&self) -> u16 { self.0 } } fn pack_path(path: &[u8]) -> (usize, usize) { let mut w0 = [0u8; 8]; let mut w1 = [0u8; 8]; for (i, &b) in path.iter().enumerate() { if i < 8 { w0[i] = b; } else if i < 16 { w1[i - 8] = b; } } (usize::from_le_bytes(w0), usize::from_le_bytes(w1)) } pub fn storage_open(endpoint: CapSlot, path: &[u8]) -> Option { let (w0, w1) = pack_path(path); let _ = userspace::syscall::send(endpoint.value() as usize, 0, w0, w1, 0); let (tag, handle, _, _) = userspace::syscall::receive(endpoint.value() as usize); if tag == 0 { Some(StorageHandle(handle as u16)) } else { None } } pub fn storage_close(endpoint: CapSlot, handle: StorageHandle) { let _ = userspace::syscall::send( endpoint.value() as usize, 3, handle.raw() as usize, 0, 0, ); } pub fn storage_write_binary(endpoint: CapSlot, path: &[u8], _binary: &[u8]) { let (w0, w1) = pack_path(path); let _ = userspace::syscall::send(endpoint.value() as usize, 5, w0, w1, 0); }