From fa03f7b11238e79927a736b52790644e4c6462b9 Mon Sep 17 00:00:00 2001 From: Ben Pig Chu Date: Thu, 20 Dec 2018 12:27:21 +0800 Subject: [PATCH] use the simple-filesystem crate with FsError --- kernel/Cargo.lock | 6 +++--- kernel/Cargo.toml | 3 +++ kernel/src/fs.rs | 3 ++- kernel/src/syscall.rs | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 064af4a..958b992 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -253,7 +253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "simple-filesystem" version = "0.0.1" -source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread#249383f7e3f195e0a8ce858f40394e9d5f7f58e0" +source = "git+https://github.com/benpigchu/SimpleFileSystem-Rust?branch=ucore-fs-enhance#b216da64ce4ee9cb24059478ffd4fa80ab8f30d2" dependencies = [ "bit-vec 0.5.0 (git+https://github.com/AltSysrq/bit-vec.git)", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -323,7 +323,7 @@ dependencies = [ "pc-keyboard 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "riscv 0.3.0 (git+https://github.com/riscv-and-rust-and-decaf/riscv)", - "simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread)", + "simple-filesystem 0.0.1 (git+https://github.com/benpigchu/SimpleFileSystem-Rust?branch=ucore-fs-enhance)", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ucore-memory 0.1.0", @@ -466,7 +466,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread)" = "" +"checksum simple-filesystem 0.0.1 (git+https://github.com/benpigchu/SimpleFileSystem-Rust?branch=ucore-fs-enhance)" = "" "checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c" "checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f" "checksum static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "389ce475f424f267dbed6479cbd8f126c5e1afb053b0acdaa019c74305fc65d1" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 6718500..17305ec 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -56,6 +56,9 @@ aarch64 = { git = "https://github.com/equation314/aarch64" } atags = { path = "../crate/atags" } bcm2837 = { path = "../crate/bcm2837", optional = true } +[patch.'https://github.com/wangrunji0408/SimpleFileSystem-Rust'] +simple-filesystem = { git = "https://github.com/benpigchu/SimpleFileSystem-Rust", branch = "ucore-fs-enhance" } + [package.metadata.bootimage] default-target = "x86_64-blog_os.json" output = "target/x86_64-blog_os/bootimage.bin" diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index c10bf90..10f85fe 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -136,7 +136,8 @@ impl INode for Stdout { fn read_at(&self, _offset: usize, _buf: &mut [u8]) -> Result { unimplemented!() } fn write_at(&self, _offset: usize, buf: &[u8]) -> Result { use core::str; - let s = str::from_utf8(buf).map_err(|_| ())?; + //we do not care the utf-8 things, we just want to print it! + let s = unsafe{ str::from_utf8_unchecked(buf) }; print!("{}", s); Ok(buf.len()) } diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 5ba5cb3..61c7540 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -1,6 +1,6 @@ //! System call -use simple_filesystem::{INode, file::File, FileInfo, FileType}; +use simple_filesystem::{INode, file::File, FileInfo, FileType, FsError}; use core::{slice, str}; use alloc::{sync::Arc, vec::Vec, string::String}; use spin::Mutex; @@ -291,8 +291,8 @@ pub enum SysError { InvalidArgument, } -impl From<()> for SysError { - fn from(_: ()) -> Self { +impl From for SysError { + fn from(_: FsError) -> Self { SysError::VfsError } }