Implement kfpath on more schemes

This commit is contained in:
Jeremy Soller
2025-11-14 11:36:49 -07:00
parent 64ea4251ee
commit cbea1aca3d
5 changed files with 20 additions and 5 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ impl KernelScheme for EventScheme {
}
fn kfpath(&self, _id: usize, buf: UserSliceWo, _token: &mut CleanLockToken) -> Result<usize> {
buf.copy_common_bytes_from_slice(b"event:")
buf.copy_common_bytes_from_slice(b"/scheme/event/")
}
fn fevent(
+4
View File
@@ -295,6 +295,10 @@ impl KernelScheme for MemoryScheme {
HandleTy::Translation => Err(Error::new(EOPNOTSUPP)),
}
}
fn kfpath(&self, id: usize, buf: UserSliceWo, token: &mut CleanLockToken) -> Result<usize> {
//TODO: construct useful path?
buf.copy_common_bytes_from_slice("/scheme/memory/".as_bytes())
}
fn kfstatvfs(&self, _file: usize, dst: UserSliceWo, _token: &mut CleanLockToken) -> Result<()> {
let used = used_frames() as u64;
let free = free_frames() as u64;
+8 -3
View File
@@ -19,7 +19,7 @@ use super::{CallerCtx, GlobalSchemes, KernelScheme, OpenResult, StrOrBytes};
// TODO: Preallocate a number of scheme IDs, since there can only be *one* root namespace, and
// therefore only *one* pipe scheme.
static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(1);
static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(0);
// TODO: SLOB?
static PIPES: RwLock<L1, HashMap<usize, Arc<Pipe>>> =
@@ -29,14 +29,15 @@ const MAX_QUEUE_SIZE: usize = 65536;
// In almost all places where Rust (and LLVM) uses pointers, they are limited to nonnegative isize,
// so this is fine.
const WRITE_NOT_READ_BIT: usize = 1 << (usize::BITS - 1);
const WRITE_NOT_READ_BIT: usize = 1;
fn from_raw_id(id: usize) -> (bool, usize) {
(id & WRITE_NOT_READ_BIT != 0, id & !WRITE_NOT_READ_BIT)
}
pub fn pipe(token: &mut CleanLockToken) -> Result<(usize, usize)> {
let id = PIPE_NEXT_ID.fetch_add(1, Ordering::Relaxed);
// Bit 0 is used for WRITE_NOT_READ_BIT
let id = PIPE_NEXT_ID.fetch_add(2, Ordering::Relaxed);
PIPES.write(token.token()).insert(
id,
@@ -334,6 +335,10 @@ impl KernelScheme for PipeScheme {
}
}
}
fn kfpath(&self, id: usize, buf: UserSliceWo, token: &mut CleanLockToken) -> Result<usize> {
//TODO: construct useful path?
buf.copy_common_bytes_from_slice("/scheme/pipe/".as_bytes())
}
fn kfstat(&self, _id: usize, buf: UserSliceWo, _token: &mut CleanLockToken) -> Result<()> {
buf.copy_exactly(&Stat {
st_mode: MODE_FIFO | 0o666,
+6
View File
@@ -630,6 +630,12 @@ impl KernelScheme for ProcScheme {
let Handle { context, kind } = handle;
kind.kwriteoff(id, context, buf, token)
}
fn kfpath(&self, id: usize, buf: UserSliceWo, token: &mut CleanLockToken) -> Result<usize> {
//TODO: construct useful path?
buf.copy_common_bytes_from_slice("/scheme/kernel.proc/".as_bytes())
}
fn kfstat(&self, id: usize, buffer: UserSliceWo, token: &mut CleanLockToken) -> Result<()> {
let handles = HANDLES.read(token.token());
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
+1 -1
View File
@@ -148,7 +148,7 @@ impl KernelScheme for TimeScheme {
.get(&id)
.ok_or(Error::new(EBADF))?;
let scheme_path = format!("time:{}", clock).into_bytes();
let scheme_path = format!("/scheme/time/{}", clock).into_bytes();
buf.copy_common_bytes_from_slice(&scheme_path)
}
}