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