diff --git a/Cargo.toml b/Cargo.toml index c64817d..c6e07e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,20 +3,9 @@ name = "simple-filesystem" version = "0.0.1" authors = ["WangRunji "] -[lib] -#crate-type = ["staticlib"] - -[profile.dev] -panic = 'abort' # prevent `_Unwind_Resume` link error - [dependencies] -spin = "0.4" bit-set = { default-features = false, version = "0.5" } # default-features contains 'std' static_assertions = "0.2.5" -[target.ucore.dependencies] -bitflags = "1.0" - [features] -debug_print = [] -ucore = [] \ No newline at end of file +debug_print = [] \ No newline at end of file diff --git a/Xargo.toml b/Xargo.toml deleted file mode 100644 index 10e8f71..0000000 --- a/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.ucore.dependencies] -alloc = {} \ No newline at end of file diff --git a/Makefile b/sfs-c/Makefile similarity index 65% rename from Makefile rename to sfs-c/Makefile index be19a06..3b65f15 100644 --- a/Makefile +++ b/sfs-c/Makefile @@ -1,6 +1,6 @@ ucore: rustup override set nightly-2018-04-01 - RUST_TARGET_PATH=$(shell pwd) xargo build --target ucore --features ucore + RUST_TARGET_PATH=$(shell pwd) xargo build --target ucore --release install-rust: which cargo || ( curl https://sh.rustup.rs -sSf | sh ) diff --git a/sfs-c/Xargo.toml b/sfs-c/Xargo.toml new file mode 100644 index 0000000..85b3939 --- /dev/null +++ b/sfs-c/Xargo.toml @@ -0,0 +1,2 @@ +[dependencies] +alloc = {} \ No newline at end of file diff --git a/src/c_interface.rs b/sfs-c/src/lib.rs similarity index 97% rename from src/c_interface.rs rename to sfs-c/src/lib.rs index a942f70..5fe193f 100644 --- a/src/c_interface.rs +++ b/sfs-c/src/lib.rs @@ -3,6 +3,18 @@ //! NOTE: Must link these sections: //! `*.got.*` `*.data.*` `*.rodata.*` +#![feature(allocator_api, global_allocator, lang_items)] +#![feature(alloc)] +#![no_std] + +#[macro_use] +extern crate alloc; +extern crate simple_filesystem; +#[macro_use] +extern crate bitflags; +#[macro_use] +extern crate static_assertions; + use alloc::{rc::Rc, boxed::Box, BTreeMap}; use core::cell::RefCell; use core::slice; @@ -11,8 +23,8 @@ use core::cmp::Ordering; use alloc::heap::{Alloc, AllocErr, Layout}; use core::mem::{size_of, self}; use core::ptr; -use vfs; -use blocked_device::BlockedDevice; +use simple_filesystem as sfs; +use simple_filesystem as vfs; /// Lang items for bare lib mod lang { @@ -331,7 +343,7 @@ impl IoBuf { } } -impl BlockedDevice for Device { +impl vfs::BlockedDevice for Device { fn block_size_log2(&self) -> u8 { if self.blocksize != 4096 { unimplemented!("block_size != 4096 is not supported yet"); @@ -562,6 +574,9 @@ static FS_OPS: FsOps = { /// Allocator supported by ucore functions pub struct UcoreAllocator; +#[global_allocator] +pub static UCORE_ALLOCATOR: UcoreAllocator = UcoreAllocator; + unsafe impl<'a> Alloc for &'a UcoreAllocator { unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { // cprintf!("alloc %d\n", layout.size()); diff --git a/ucore.json b/sfs-c/ucore.json similarity index 100% rename from ucore.json rename to sfs-c/ucore.json diff --git a/src/lib.rs b/src/lib.rs index e9d0141..12c3624 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,13 @@ #![feature(alloc)] #![feature(const_fn)] -#![cfg_attr(feature = "ucore", feature(allocator_api, global_allocator, lang_items))] #![no_std] -#[cfg(test)] +#[cfg(any(test, feature = "std"))] #[macro_use] extern crate std; -extern crate spin; #[macro_use] extern crate alloc; extern crate bit_set; -#[cfg(feature = "ucore")] -#[macro_use] -extern crate bitflags; #[macro_use] extern crate static_assertions; @@ -29,15 +24,9 @@ mod blocked_device; mod vfs; mod sfs; mod structs; -#[cfg(feature = "ucore")] -pub mod c_interface; #[cfg(test)] mod tests; pub use sfs::*; pub use vfs::*; pub use blocked_device::BlockedDevice; - -#[cfg(feature = "ucore")] -#[global_allocator] -pub static UCORE_ALLOCATOR: c_interface::UcoreAllocator = c_interface::UcoreAllocator{}; \ No newline at end of file diff --git a/src/sfs.rs b/src/sfs.rs index aa1bced..3dd7787 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -1,4 +1,3 @@ -use spin::Mutex; use bit_set::BitSet; use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String}; use core::cell::{RefCell, RefMut};