From bfeae4072b268adb3358af157ee704383e9555eb Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 28 Dec 2016 11:38:42 -0700 Subject: [PATCH] Add memory scheme, implement fstatvfs --- kernel/scheme/memory.rs | 30 ++++++++++++++++++++++++++++++ kernel/scheme/mod.rs | 5 +++++ programs/coreutils | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 kernel/scheme/memory.rs diff --git a/kernel/scheme/memory.rs b/kernel/scheme/memory.rs new file mode 100644 index 0000000..9db0c48 --- /dev/null +++ b/kernel/scheme/memory.rs @@ -0,0 +1,30 @@ +use arch::memory::{free_frames, used_frames}; + +use syscall::data::StatVfs; +use syscall::error::*; +use syscall::scheme::Scheme; + +pub struct MemoryScheme; + +impl Scheme for MemoryScheme { + fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result { + Ok(0) + } + + fn fstatvfs(&self, _file: usize, stat: &mut StatVfs) -> Result { + let used = used_frames() as u64; + let free = free_frames() as u64; + + stat.f_bsize = 4096; + stat.f_blocks = used + free; + stat.f_bfree = free; + stat.f_bavail = stat.f_bfree; + + Ok(0) + } + + /// Close the file `number` + fn close(&self, _file: usize) -> Result { + Ok(0) + } +} diff --git a/kernel/scheme/mod.rs b/kernel/scheme/mod.rs index abb9e12..f9676e8 100644 --- a/kernel/scheme/mod.rs +++ b/kernel/scheme/mod.rs @@ -20,6 +20,7 @@ use self::event::EventScheme; use self::env::EnvScheme; use self::initfs::InitFsScheme; use self::irq::IrqScheme; +use self::memory::MemoryScheme; use self::null::NullScheme; use self::pipe::PipeScheme; use self::root::RootScheme; @@ -45,6 +46,9 @@ pub mod irq; #[cfg(feature="live")] pub mod live; +/// `memory:` - a scheme for accessing physical memory +pub mod memory; + /// `null:` - a scheme that will discard all writes, and read no bytes pub mod null; @@ -124,6 +128,7 @@ impl SchemeList { self.insert(ns, Box::new(*b"debug"), |scheme_id| Arc::new(Box::new(DebugScheme::new(scheme_id)))).unwrap(); self.insert(ns, Box::new(*b"initfs"), |_| Arc::new(Box::new(InitFsScheme::new()))).unwrap(); self.insert(ns, Box::new(*b"irq"), |scheme_id| Arc::new(Box::new(IrqScheme::new(scheme_id)))).unwrap(); + self.insert(ns, Box::new(*b"memory"), |_| Arc::new(Box::new(MemoryScheme))).unwrap(); self.insert(ns, Box::new(*b"pipe"), |scheme_id| Arc::new(Box::new(PipeScheme::new(scheme_id)))).unwrap(); } diff --git a/programs/coreutils b/programs/coreutils index ed85622..fe68f36 160000 --- a/programs/coreutils +++ b/programs/coreutils @@ -1 +1 @@ -Subproject commit ed85622c9f22400bfbe5c6ce393fb86a7d7b40a9 +Subproject commit fe68f368a7e8cf3a690651da596fb769ac1cb20e