Add context and file structs
This commit is contained in:
parent
49739d47e8
commit
4e270bb807
9 changed files with 88 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
//! Filesystem syscalls
|
||||
|
||||
use super::Result;
|
||||
use super::{Error, Result};
|
||||
|
||||
/// Read syscall
|
||||
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
|
@ -11,13 +11,25 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
|||
/// Write syscall
|
||||
pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
|
||||
println!("Write {}: {}", fd, buf.len());
|
||||
Ok(0)
|
||||
if let Some(file) = unsafe { &mut ::context::CONTEXT }.files.get(fd) {
|
||||
println!("{:?}: {:?}", file, ::core::str::from_utf8(buf));
|
||||
Ok(buf.len())
|
||||
} else {
|
||||
Err(Error::BadFile)
|
||||
}
|
||||
}
|
||||
|
||||
/// Open syscall
|
||||
pub fn open(path: &[u8], flags: usize) -> Result<usize> {
|
||||
println!("Open {:?}: {:X}", ::core::str::from_utf8(path), flags);
|
||||
Ok(0)
|
||||
if let Some(fd) = unsafe { &mut ::context::CONTEXT }.add_file(::context::file::File {
|
||||
scheme: 0,
|
||||
number: 0
|
||||
}) {
|
||||
Ok(fd)
|
||||
} else {
|
||||
Err(Error::TooManyFiles)
|
||||
}
|
||||
}
|
||||
|
||||
/// Close syscall
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue