Add memory scheme, implement fstatvfs
This commit is contained in:
parent
b88ea01723
commit
bfeae4072b
30
kernel/scheme/memory.rs
Normal file
30
kernel/scheme/memory.rs
Normal file
|
@ -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<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn fstatvfs(&self, _file: usize, stat: &mut StatVfs) -> Result<usize> {
|
||||
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<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ed85622c9f22400bfbe5c6ce393fb86a7d7b40a9
|
||||
Subproject commit fe68f368a7e8cf3a690651da596fb769ac1cb20e
|
Loading…
Reference in a new issue