WIP: Schemes
This commit is contained in:
parent
8a6d9b8c9d
commit
19077d69db
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ bochs: build/harddrive.bin
|
||||||
bochs -f bochs.$(ARCH)
|
bochs -f bochs.$(ARCH)
|
||||||
|
|
||||||
qemu: build/harddrive.bin
|
qemu: build/harddrive.bin
|
||||||
qemu-system-$(ARCH) -serial mon:stdio -drive file=$<,format=raw,index=0,media=disk
|
qemu-system-$(ARCH) -serial mon:stdio -drive file=$<,format=raw,index=0,media=disk -nographic
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,9 @@ pub mod context;
|
||||||
/// Intrinsics for panic handling
|
/// Intrinsics for panic handling
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
|
|
||||||
|
/// Schemes, filesystem handlers
|
||||||
|
pub mod scheme;
|
||||||
|
|
||||||
/// Syscall handlers
|
/// Syscall handlers
|
||||||
pub mod syscall;
|
pub mod syscall;
|
||||||
|
|
||||||
|
@ -101,9 +104,9 @@ pub mod tests;
|
||||||
pub extern fn kmain() {
|
pub extern fn kmain() {
|
||||||
println!("TEST");
|
println!("TEST");
|
||||||
|
|
||||||
println!("{:?}", syscall::open(b"stdin", 0));
|
println!("{:?}", syscall::open(b"debug:", 0));
|
||||||
println!("{:?}", syscall::open(b"stdout", 0));
|
println!("{:?}", syscall::open(b"debug:", 0));
|
||||||
println!("{:?}", syscall::open(b"stderr", 0));
|
println!("{:?}", syscall::open(b"debug:", 0));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
33
kernel/scheme/debug.rs
Normal file
33
kernel/scheme/debug.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use core::str;
|
||||||
|
use syscall::Result;
|
||||||
|
use super::Scheme;
|
||||||
|
|
||||||
|
pub struct DebugScheme;
|
||||||
|
|
||||||
|
impl Scheme for DebugScheme {
|
||||||
|
fn open(&mut self, path: &[u8], flags: usize) -> Result<usize> {
|
||||||
|
println!("DebugScheme::open: {}", unsafe { str::from_utf8_unchecked(path) });
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read the file `number` into the `buffer`
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes read
|
||||||
|
fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write the `buffer` to the `file`
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes written
|
||||||
|
fn write(&mut self, file: usize, buffer: &[u8]) -> Result<usize> {
|
||||||
|
//TODO: Write bytes, do not convert to str
|
||||||
|
print!("{}", unsafe { str::from_utf8_unchecked(buffer) });
|
||||||
|
Ok(buffer.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Close the file `number`
|
||||||
|
fn close(&mut self, file: usize) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,38 @@
|
||||||
/// A scheme is a primitive for handling filesystem syscalls in Redox.
|
//! # Schemes
|
||||||
/// Schemes accept paths from the kernel for `open`, and file descriptors that they generate
|
//! A scheme is a primitive for handling filesystem syscalls in Redox.
|
||||||
/// are then passed for operations like `close`, `read`, `write`, etc.
|
//! Schemes accept paths from the kernel for `open`, and file descriptors that they generate
|
||||||
///
|
//! are then passed for operations like `close`, `read`, `write`, etc.
|
||||||
/// The kernel validates paths and file descriptors before they are passed to schemes,
|
//!
|
||||||
/// also stripping the scheme identifier of paths if necessary.
|
//! The kernel validates paths and file descriptors before they are passed to schemes,
|
||||||
|
//! also stripping the scheme identifier of paths if necessary.
|
||||||
|
|
||||||
|
use syscall::Result;
|
||||||
|
|
||||||
|
use self::debug::DebugScheme;
|
||||||
|
|
||||||
|
/// Debug scheme
|
||||||
|
pub mod debug;
|
||||||
|
|
||||||
|
/// Schemes list
|
||||||
|
pub static mut SCHEME: DebugScheme = DebugScheme;
|
||||||
|
|
||||||
|
/// A scheme trait, implemented by a scheme handler
|
||||||
pub trait Scheme {
|
pub trait Scheme {
|
||||||
/// Open the file at `path` with `flags`.
|
/// Open the file at `path` with `flags`.
|
||||||
///
|
///
|
||||||
/// Returns a file descriptor or an error
|
/// Returns a file descriptor or an error
|
||||||
fn open(path: &str, flags: usize) -> Result<usize>;
|
fn open(&mut self, path: &[u8], flags: usize) -> Result<usize>;
|
||||||
|
|
||||||
|
/// Read the file `number` into the `buffer`
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes read
|
||||||
|
fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize>;
|
||||||
|
|
||||||
|
/// Write the `buffer` to the `file`
|
||||||
|
///
|
||||||
|
/// Returns the number of bytes written
|
||||||
|
fn write(&mut self, file: usize, buffer: &[u8]) -> Result<usize>;
|
||||||
|
|
||||||
|
/// Close the file `number`
|
||||||
|
fn close(&mut self, file: usize) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Filesystem syscalls
|
//! Filesystem syscalls
|
||||||
|
|
||||||
|
use scheme::Scheme;
|
||||||
|
|
||||||
use super::{Error, Result};
|
use super::{Error, Result};
|
||||||
|
|
||||||
/// Read syscall
|
/// Read syscall
|
||||||
|
@ -27,9 +29,10 @@ pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
|
||||||
/// Open syscall
|
/// Open syscall
|
||||||
pub fn open(path: &[u8], flags: usize) -> Result<usize> {
|
pub fn open(path: &[u8], flags: usize) -> Result<usize> {
|
||||||
println!("Open {:?}: {:X}", ::core::str::from_utf8(path), flags);
|
println!("Open {:?}: {:X}", ::core::str::from_utf8(path), flags);
|
||||||
|
let file = unsafe { &mut ::scheme::SCHEME }.open(path, flags)?;
|
||||||
if let Some(fd) = unsafe { &mut ::context::CONTEXT }.add_file(::context::file::File {
|
if let Some(fd) = unsafe { &mut ::context::CONTEXT }.add_file(::context::file::File {
|
||||||
scheme: 0,
|
scheme: 0,
|
||||||
number: 0
|
number: file
|
||||||
}) {
|
}) {
|
||||||
Ok(fd)
|
Ok(fd)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue