From 44614a0b3f536abbf0306391202642390b1076c2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 7 Mar 2026 22:07:34 +0100 Subject: [PATCH 1/2] Support removing schemes from a namespace This can be done using rmdir /scheme/my_scheme. Scheme implementations do not yet exit when all fds are closed, but you can now kill the service and restart it after you removed its scheme. --- bootstrap/src/initnsmgr.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bootstrap/src/initnsmgr.rs b/bootstrap/src/initnsmgr.rs index 11a8a10405..fa8b728a10 100644 --- a/bootstrap/src/initnsmgr.rs +++ b/bootstrap/src/initnsmgr.rs @@ -54,6 +54,9 @@ impl Namespace { fn get_scheme_fd(&self, scheme: &str) -> Option<&Arc> { self.schemes.get(scheme) } + fn remove_scheme(&mut self, scheme: &str) -> Option<()> { + self.schemes.remove(scheme).map(|_| ()) + } } #[derive(Debug, Clone)] @@ -324,21 +327,27 @@ impl<'sock> SchemeSync for NamespaceScheme<'sock> { } fn unlinkat(&mut self, fd: usize, path: &str, flags: usize, ctx: &CallerCtx) -> Result<()> { - let ns_access = { - let handle = self.handles.get(&fd); - match handle { - Some(Handle::Access(access)) => Some(access), - _ => None, - } - } - .ok_or_else(|| { + let ns_access = self.get_ns_access(fd).ok_or_else(|| { error!("Namespace with ID {} not found", fd); Error::new(ENOENT) })?; - let ns = ns_access.namespace.borrow(); + let mut ns = ns_access.namespace.borrow_mut(); let redox_path = RedoxPath::from_absolute(path).ok_or(Error::new(EINVAL))?; let (scheme, reference) = redox_path.as_parts().ok_or(Error::new(EINVAL))?; + if reference.as_ref().is_empty() { + if !ns_access.has_permission(NsPermissions::DELETE) { + error!("Permission denied to remove scheme for namespace {}", fd); + return Err(Error::new(EACCES)); + } + match ns.remove_scheme(scheme.as_ref()) { + Some(_) => return Ok(()), + None => { + error!("Scheme {} not found in namespace", scheme); + return Err(Error::new(ENODEV)); + } + } + } let Some(cap_fd) = ns.get_scheme_fd(scheme.as_ref()) else { error!("Scheme {} not found in namespace", scheme); return Err(Error::new(ENODEV)); From 331189d8465249a3248ccb4e619aae47f7f14961 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 7 Mar 2026 22:12:56 +0100 Subject: [PATCH 2/2] Rustfmt --- drivers/graphics/virtio-gpud/src/scheme.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/graphics/virtio-gpud/src/scheme.rs b/drivers/graphics/virtio-gpud/src/scheme.rs index 0ef55158f7..c8634a5e1e 100644 --- a/drivers/graphics/virtio-gpud/src/scheme.rs +++ b/drivers/graphics/virtio-gpud/src/scheme.rs @@ -569,6 +569,10 @@ impl<'a> GpuScheme { displays: vec![], }; - Ok(GraphicsScheme::new(adapter, "display.virtio-gpu".to_owned(), false)) + Ok(GraphicsScheme::new( + adapter, + "display.virtio-gpu".to_owned(), + false, + )) } }