Fix close, add dup
This commit is contained in:
parent
951831c4bb
commit
2fffe3ee77
6 changed files with 73 additions and 14 deletions
|
@ -11,7 +11,7 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
|||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
let file = context.files.get(fd).ok_or(Error::BadFile)?.ok_or(Error::BadFile)?;
|
||||
let file = context.get_file(fd).ok_or(Error::BadFile)?;
|
||||
file
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
|
|||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
let file = context.files.get(fd).ok_or(Error::BadFile)?.ok_or(Error::BadFile)?;
|
||||
let file = context.get_file(fd).ok_or(Error::BadFile)?;
|
||||
file
|
||||
};
|
||||
|
||||
|
@ -65,8 +65,8 @@ pub fn close(fd: usize) -> Result<usize> {
|
|||
let file = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
let file = context.files.get(fd).ok_or(Error::BadFile)?.ok_or(Error::BadFile)?;
|
||||
let mut context = context_lock.write();
|
||||
let file = context.remove_file(fd).ok_or(Error::BadFile)?;
|
||||
file
|
||||
};
|
||||
|
||||
|
@ -75,3 +75,19 @@ pub fn close(fd: usize) -> Result<usize> {
|
|||
let result = scheme_mutex.lock().close(file.number).and(Ok(0));
|
||||
result
|
||||
}
|
||||
|
||||
/// Duplicate file descriptor
|
||||
pub fn dup(fd: usize) -> Result<usize> {
|
||||
let file = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::NoProcess)?;
|
||||
let context = context_lock.read();
|
||||
let file = context.get_file(fd).ok_or(Error::BadFile)?;
|
||||
file
|
||||
};
|
||||
|
||||
let schemes = scheme::schemes();
|
||||
let scheme_mutex = schemes.get(file.scheme).ok_or(Error::BadFile)?;
|
||||
let result = scheme_mutex.lock().dup(file.number);
|
||||
result
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ pub enum Call {
|
|||
Exec = 11,
|
||||
/// Get process ID
|
||||
GetPid = 20,
|
||||
/// Duplicate file descriptor
|
||||
Dup = 41,
|
||||
/// Set process break
|
||||
Brk = 45,
|
||||
/// Set process I/O privilege level
|
||||
|
@ -52,6 +54,7 @@ impl Call {
|
|||
6 => Ok(Call::Close),
|
||||
11 => Ok(Call::Exec),
|
||||
20 => Ok(Call::GetPid),
|
||||
41 => Ok(Call::Dup),
|
||||
45 => Ok(Call::Brk),
|
||||
110 => Ok(Call::Iopl),
|
||||
120 => Ok(Call::Clone),
|
||||
|
@ -112,6 +115,7 @@ pub fn handle(a: usize, b: usize, c: usize, d: usize, e: usize, _f: usize) -> Re
|
|||
Call::Close => close(b),
|
||||
Call::Exec => exec(convert_slice(b as *const u8, c)?, convert_slice(d as *const [usize; 2], e)?),
|
||||
Call::GetPid => getpid(),
|
||||
Call::Dup => dup(b),
|
||||
Call::Brk => brk(b),
|
||||
Call::Iopl => iopl(b),
|
||||
Call::Clone => clone(b),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue