fit for multi-thread sfs

- use global root inode
- remove global IDE on x86
master
WangRunji 6 years ago
parent 16fb733497
commit 91bd411a8f

7
kernel/Cargo.lock generated

@ -209,9 +209,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "simple-filesystem" name = "simple-filesystem"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust#e26f14c55f2b5e767ac7055bab874d039fbe1f05" source = "git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread#d75aab77d685791d6d919f901cc8ec8f29075ff6"
dependencies = [ dependencies = [
"bit-vec 0.5.0 (git+https://github.com/AltSysrq/bit-vec.git)", "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)",
"static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -270,7 +271,7 @@ dependencies = [
"raw-cpuid 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw-cpuid 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"riscv 0.3.0 (git+https://github.com/riscv-and-rust-and-decaf/riscv)", "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)", "simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread)",
"spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ucore-memory 0.1.0", "ucore-memory 0.1.0",
@ -398,7 +399,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 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 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 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)" = "<none>" "checksum simple-filesystem 0.0.1 (git+https://github.com/wangrunji0408/SimpleFileSystem-Rust?branch=multi-thread)" = "<none>"
"checksum skeptic 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "061203a849117b0f7090baf8157aa91dac30545208fbb85166ac58b4ca33d89c" "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 spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5"

@ -27,7 +27,7 @@ lazy_static = { version = "1.0.0", features = ["spin_no_std"] }
bit-allocator = { path = "../crate/bit-allocator" } bit-allocator = { path = "../crate/bit-allocator" }
ucore-memory = { path = "../crate/memory" } ucore-memory = { path = "../crate/memory" }
ucore-process = { path = "../crate/process" } ucore-process = { path = "../crate/process" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust", branch = "multi-thread" }
[target.'cfg(target_arch = "x86_64")'.dependencies] [target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = { git = "https://github.com/wangrunji0408/bootloader" } bootloader = { git = "https://github.com/wangrunji0408/bootloader" }

@ -2,16 +2,9 @@
//! //!
//! Borrow from Rucore project. Thanks GWord! //! Borrow from Rucore project. Thanks GWord!
//! Port from ucore C code. //! Port from ucore C code.
use spin::Mutex;
lazy_static! {
pub static ref DISK0: LockedIde = LockedIde(Mutex::new(IDE::new(0)));
pub static ref DISK1: LockedIde = LockedIde(Mutex::new(IDE::new(1)));
}
pub const BLOCK_SIZE: usize = 512; pub const BLOCK_SIZE: usize = 512;
pub struct LockedIde(pub Mutex<IDE>);
pub struct IDE { pub struct IDE {
num: u8, num: u8,
/// I/O Base /// I/O Base

@ -1,7 +1,7 @@
use simple_filesystem::*; use simple_filesystem::*;
use alloc::boxed::Box; use alloc::{boxed::Box, sync::Arc};
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use arch::driver::ide; use arch::driver::ide::IDE;
use spin::Mutex; use spin::Mutex;
// Hard link user program // Hard link user program
@ -9,25 +9,33 @@ use spin::Mutex;
global_asm!(r#" global_asm!(r#"
.section .rodata .section .rodata
.align 12 .align 12
_binary_user_riscv_img_start: .global _user_img_start
.global _user_img_end
_user_img_start:
.incbin "../user/user-riscv.img" .incbin "../user/user-riscv.img"
_binary_user_riscv_img_end: _user_img_end:
"#); "#);
pub fn shell() { lazy_static! {
#[cfg(target_arch = "riscv32")] static ref ROOT_INODE: Arc<INode> = {
let device = { #[cfg(target_arch = "riscv32")]
extern { let device = {
fn _binary_user_riscv_img_start(); extern {
fn _binary_user_riscv_img_end(); fn _user_img_start();
} fn _user_img_end();
Box::new(unsafe { MemBuf::new(_binary_user_riscv_img_start, _binary_user_riscv_img_end) }) }
Box::new(unsafe { MemBuf::new(_user_img_start, _user_img_end) })
};
#[cfg(target_arch = "x86_64")]
let device = Box::new(IDE::new(1));
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");
sfs.root_inode()
}; };
#[cfg(target_arch = "x86_64")] }
let device = Box::new(&ide::DISK1);
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS"); pub fn shell() {
let root = sfs.root_inode(); let files = ROOT_INODE.list().unwrap();
let files = root.borrow().list().unwrap();
println!("Available programs: {:?}", files); println!("Available programs: {:?}", files);
// Avoid stack overflow in release mode // Avoid stack overflow in release mode
@ -43,9 +51,9 @@ pub fn shell() {
if name == "" { if name == "" {
continue; continue;
} }
if let Ok(file) = root.borrow().lookup(name.as_str()) { if let Ok(file) = ROOT_INODE.lookup(name.as_str()) {
use process::*; use process::*;
let len = file.borrow().read_at(0, &mut *buf).unwrap(); let len = file.read_at(0, &mut *buf).unwrap();
let pid = processor().manager().add(ContextImpl::new_user(&buf[..len])); let pid = processor().manager().add(ContextImpl::new_user(&buf[..len]));
processor().manager().wait(thread::current().id(), pid); processor().manager().wait(thread::current().id(), pid);
processor().yield_now(); processor().yield_now();
@ -80,16 +88,16 @@ impl Device for MemBuf {
use core::slice; use core::slice;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
impl BlockedDevice for &'static ide::DISK1 { impl BlockedDevice for IDE {
const BLOCK_SIZE_LOG2: u8 = 9; const BLOCK_SIZE_LOG2: u8 = 9;
fn read_at(&mut self, block_id: usize, buf: &mut [u8]) -> bool { fn read_at(&mut self, block_id: usize, buf: &mut [u8]) -> bool {
assert!(buf.len() >= ide::BLOCK_SIZE); assert!(buf.len() >= ide::BLOCK_SIZE);
let buf = unsafe { slice::from_raw_parts_mut(buf.as_ptr() as *mut u32, ide::BLOCK_SIZE / 4) }; let buf = unsafe { slice::from_raw_parts_mut(buf.as_ptr() as *mut u32, ide::BLOCK_SIZE / 4) };
self.0.lock().read(block_id as u64, 1, buf).is_ok() self.read(block_id as u64, 1, buf).is_ok()
} }
fn write_at(&mut self, block_id: usize, buf: &[u8]) -> bool { fn write_at(&mut self, block_id: usize, buf: &[u8]) -> bool {
assert!(buf.len() >= ide::BLOCK_SIZE); assert!(buf.len() >= ide::BLOCK_SIZE);
let buf = unsafe { slice::from_raw_parts(buf.as_ptr() as *mut u32, ide::BLOCK_SIZE / 4) }; let buf = unsafe { slice::from_raw_parts(buf.as_ptr() as *mut u32, ide::BLOCK_SIZE / 4) };
self.0.lock().write(block_id as u64, 1, buf).is_ok() self.write(block_id as u64, 1, buf).is_ok()
} }
} }
Loading…
Cancel
Save