Cleanup to use question mark
This commit is contained in:
parent
afde5f5b5d
commit
9afe0645e1
|
@ -8,33 +8,23 @@ use super::{Error, Result};
|
|||
/// Read syscall
|
||||
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
println!("Read {}: {:X} {}", fd, buf.as_ptr() as usize, buf.len());
|
||||
if let Some(context_lock) = context::contexts().current() {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
if let Some(file) = context.files.get(fd) {
|
||||
let file = context.files.get(fd).ok_or(Error::BadFile)?;
|
||||
println!("{:?}", file);
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(Error::BadFile)
|
||||
}
|
||||
} else {
|
||||
Err(Error::NoProcess)
|
||||
}
|
||||
}
|
||||
|
||||
/// Write syscall
|
||||
pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
|
||||
println!("Write {}: {:X} {}", fd, buf.as_ptr() as usize, buf.len());
|
||||
if let Some(context_lock) = context::contexts().current() {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
if let Some(file) = context.files.get(fd) {
|
||||
let file = context.files.get(fd).ok_or(Error::BadFile);
|
||||
println!("{:?}: {:?}", file, ::core::str::from_utf8(buf));
|
||||
Ok(buf.len())
|
||||
} else {
|
||||
Err(Error::BadFile)
|
||||
}
|
||||
} else {
|
||||
Err(Error::NoProcess)
|
||||
}
|
||||
}
|
||||
|
||||
/// Open syscall
|
||||
|
@ -45,31 +35,20 @@ pub fn open(path: &[u8], flags: usize) -> Result<usize> {
|
|||
println!("Open namespace {:?} reference {:?}: {:X}", namespace_opt.map(::core::str::from_utf8), reference_opt.map(::core::str::from_utf8), flags);
|
||||
|
||||
let file = {
|
||||
if let Some(namespace) = namespace_opt {
|
||||
let namespace = namespace_opt.ok_or(Error::NoEntry)?;
|
||||
let schemes = scheme::schemes();
|
||||
if let Some(scheme_mutex) = schemes.get(namespace) {
|
||||
scheme_mutex.lock().open(reference_opt.unwrap_or(b""), flags)
|
||||
} else {
|
||||
Err(Error::NoEntry)
|
||||
}
|
||||
} else {
|
||||
Err(Error::NoEntry)
|
||||
}
|
||||
}?;
|
||||
let scheme_mutex = schemes.get(namespace).ok_or(Error::NoEntry)?;
|
||||
let file = scheme_mutex.lock().open(reference_opt.unwrap_or(b""), flags)?;
|
||||
file
|
||||
};
|
||||
|
||||
if let Some(context_lock) = context::contexts().current() {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let mut context = context_lock.write();
|
||||
if let Some(fd) = context.add_file(::context::file::File {
|
||||
context.add_file(::context::file::File {
|
||||
scheme: 0,
|
||||
number: file
|
||||
}) {
|
||||
Ok(fd)
|
||||
} else {
|
||||
Err(Error::TooManyFiles)
|
||||
}
|
||||
} else {
|
||||
Err(Error::NoProcess)
|
||||
}
|
||||
}).ok_or(Error::TooManyFiles)
|
||||
}
|
||||
|
||||
/// Close syscall
|
||||
|
|
|
@ -23,10 +23,8 @@ pub fn exec(path: &[u8], args: &[[usize; 2]]) -> Result<usize> {
|
|||
}
|
||||
|
||||
pub fn getpid() -> Result<usize> {
|
||||
if let Some(context_lock) = context::contexts().current() {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
Ok(context.id)
|
||||
} else {
|
||||
Err(Error::NoProcess)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue