From f7c75234de5de9c57798f533376f13539a22f514 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 11 Feb 2019 12:10:51 +0800 Subject: [PATCH] rename 'sfs-c' to 'rcore-fs-ucore', update to Rust 2018 --- Cargo.toml | 1 - rcore-fs-fuse/src/main.rs | 14 +++++++++---- {sfs-c => rcore-fs-ucore}/Cargo.toml | 12 +++++++---- {sfs-c => rcore-fs-ucore}/Makefile | 2 +- {sfs-c => rcore-fs-ucore}/src/lib.rs | 31 +++++++++------------------- {sfs-c => rcore-fs-ucore}/ucore.json | 0 src/lib.rs | 8 ++----- src/sfs.rs | 9 ++++---- src/vfs.rs | 8 ++++++- 9 files changed, 42 insertions(+), 43 deletions(-) rename {sfs-c => rcore-fs-ucore}/Cargo.toml (58%) rename {sfs-c => rcore-fs-ucore}/Makefile (76%) rename {sfs-c => rcore-fs-ucore}/src/lib.rs (97%) rename {sfs-c => rcore-fs-ucore}/ucore.json (100%) diff --git a/Cargo.toml b/Cargo.toml index 13db878..8cb7f81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ required-features = ["std"] bit-vec = { default-features = false, git = "https://github.com/AltSysrq/bit-vec.git" } # default-features contains 'std' static_assertions = "0.3" spin = "0.4" -time = "0.1" [features] std = [] \ No newline at end of file diff --git a/rcore-fs-fuse/src/main.rs b/rcore-fs-fuse/src/main.rs index fe9f260..dcfe50b 100644 --- a/rcore-fs-fuse/src/main.rs +++ b/rcore-fs-fuse/src/main.rs @@ -25,15 +25,21 @@ impl VfsWrapper { inodes.insert(1, fs.root_inode()); VfsWrapper { fs, inodes } } + fn trans_time(time: vfs::Timespec) -> Timespec { + Timespec { + sec: time.sec, + nsec: time.nsec, + } + } fn trans_attr(info: vfs::FileInfo) -> FileAttr { FileAttr { ino: info.inode as u64, size: info.size as u64, blocks: info.blocks as u64, - atime: info.atime, - mtime: info.mtime, - ctime: info.ctime, - crtime: Timespec::new(0, 0), + atime: Self::trans_time(info.atime), + mtime: Self::trans_time(info.mtime), + ctime: Self::trans_time(info.ctime), + crtime: Timespec { sec: 0, nsec: 0 }, kind: Self::trans_type(info.type_), perm: info.mode, nlink: info.nlinks as u32, diff --git a/sfs-c/Cargo.toml b/rcore-fs-ucore/Cargo.toml similarity index 58% rename from sfs-c/Cargo.toml rename to rcore-fs-ucore/Cargo.toml index 2ca60a9..12f4103 100644 --- a/sfs-c/Cargo.toml +++ b/rcore-fs-ucore/Cargo.toml @@ -1,7 +1,8 @@ [package] -name = "sfs-c" -version = "0.0.1" +name = "rcore-fs-ucore" +version = "0.1.0" authors = ["WangRunji "] +edition = "2018" [lib] crate-type = ["staticlib"] @@ -11,7 +12,10 @@ panic = 'abort' # prevent `_Unwind_Resume` link error [dependencies] bitflags = "1.0" -static_assertions = "0.2.5" +static_assertions = "0.3" simple-filesystem = { path = ".." } spin = "0.4" -lazy_static = { version = "1.1", features = ["spin_no_std"] } \ No newline at end of file +lazy_static = { version = "1.2", features = ["spin_no_std"] } + +[features] +debug_print = [] \ No newline at end of file diff --git a/sfs-c/Makefile b/rcore-fs-ucore/Makefile similarity index 76% rename from sfs-c/Makefile rename to rcore-fs-ucore/Makefile index a0b3773..0aa4f15 100644 --- a/sfs-c/Makefile +++ b/rcore-fs-ucore/Makefile @@ -1,5 +1,5 @@ ucore: - rustup override set nightly + rustup override set nightly-2019-01-28 cargo xbuild --target ucore.json --release install-rust: diff --git a/sfs-c/src/lib.rs b/rcore-fs-ucore/src/lib.rs similarity index 97% rename from sfs-c/src/lib.rs rename to rcore-fs-ucore/src/lib.rs index 8f8ae49..1a64588 100644 --- a/sfs-c/src/lib.rs +++ b/rcore-fs-ucore/src/lib.rs @@ -3,42 +3,32 @@ //! NOTE: Must link these sections: //! `*.got.*` `*.data.*` `*.rodata.*` -#![feature(allocator_api)] #![feature(lang_items)] #![feature(alloc)] #![feature(panic_info_message)] -#![feature(compiler_builtins_lib)] #![no_std] #[macro_use] extern crate alloc; -extern crate simple_filesystem; #[macro_use] extern crate bitflags; #[macro_use] -extern crate static_assertions; -#[macro_use] extern crate lazy_static; -extern crate spin; +#[macro_use] +extern crate static_assertions; -use alloc::{sync::Arc, boxed::Box, collections::BTreeMap}; -use core::cell::RefCell; -use core::slice; -use core::ops::Deref; -use core::cmp::Ordering; +use alloc::{boxed::Box, collections::BTreeMap, sync::Arc}; use core::alloc::{GlobalAlloc, Layout}; -use core::mem::{size_of, self}; -use core::ptr; -use simple_filesystem as sfs; -use simple_filesystem as vfs; -use vfs::FileSystem; +use core::mem; +use core::ops::Deref; +use core::slice; +use simple_filesystem::{sfs, vfs}; use spin::Mutex; /// Lang items for bare lib mod lang { - use alloc::fmt; - use core::panic::PanicInfo; use core::alloc::Layout; + use core::panic::PanicInfo; #[lang = "eh_personality"] #[no_mangle] @@ -52,7 +42,7 @@ mod lang { #[panic_handler] #[no_mangle] - extern fn panic_fmt(info: &PanicInfo) -> ! { + extern fn panic(info: &PanicInfo) -> ! { use super::ucore::__panic; let location = info.location().unwrap(); let message = info.message().unwrap(); @@ -120,7 +110,6 @@ mod libc { #[no_mangle] pub extern fn sfs_do_mount(dev: *mut Device, fs_store: &mut *mut Fs) -> ErrorCode { - use sfs; let fs = unsafe { ucore::create_fs_for_sfs(&FS_OPS) }; debug_assert!(!dev.is_null()); let mut device = unsafe { Box::from_raw(dev) }; // TODO: fix unsafe @@ -521,7 +510,7 @@ static INODE_OPS: INodeOps = { let pos = pos as usize; let info = inode.info().unwrap(); if pos > info.size { - inode.resize(pos); + inode.resize(pos).unwrap(); } return ErrorCode::Ok; } diff --git a/sfs-c/ucore.json b/rcore-fs-ucore/ucore.json similarity index 100% rename from sfs-c/ucore.json rename to rcore-fs-ucore/ucore.json diff --git a/src/lib.rs b/src/lib.rs index 04d218e..d511088 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,15 +24,11 @@ mod structs; #[cfg(test)] mod tests; -pub use crate::sfs::*; -pub use crate::vfs::*; -pub use crate::blocked_device::BlockedDevice; - #[cfg(any(test, feature = "std"))] pub mod std_impl { use std::fs::File; use std::io::{Read, Write, Seek, SeekFrom}; - use super::Device; + use super::vfs::Device; impl Device for File { fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option { @@ -51,4 +47,4 @@ pub mod std_impl { } } } -} \ No newline at end of file +} diff --git a/src/sfs.rs b/src/sfs.rs index 67f3e73..35e67a8 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -6,12 +6,11 @@ use core::slice; use bit_vec::BitVec; use spin::{Mutex, RwLock}; -use time::Timespec; use crate::dirty::Dirty; use crate::structs::*; use crate::util::*; -use crate::vfs::{self, Device, FileSystem, FsError, INode}; +use crate::vfs::{self, Device, FileSystem, FsError, INode, Timespec}; impl Device { fn read_block(&mut self, id: BlockId, offset: usize, buf: &mut [u8]) -> vfs::Result<()> { @@ -277,9 +276,9 @@ impl vfs::INode for INodeImpl { mode: 0o777, type_: vfs::FileType::from(disk_inode.type_.clone()), blocks: disk_inode.blocks as usize, - atime: Timespec::new(0, 0), - mtime: Timespec::new(0, 0), - ctime: Timespec::new(0, 0), + atime: Timespec { sec: 0, nsec: 0 }, + mtime: Timespec { sec: 0, nsec: 0 }, + ctime: Timespec { sec: 0, nsec: 0 }, nlinks: disk_inode.nlinks as usize, uid: 0, gid: 0, diff --git a/src/vfs.rs b/src/vfs.rs index 89bbf9a..7dbf331 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -1,7 +1,7 @@ use alloc::{vec::Vec, string::String, sync::Arc}; use core::any::Any; use core::result; -use time::Timespec; +pub use super::blocked_device::BlockedDevice; /// Interface for FS to read & write /// TODO: use std::io::{Read, Write} @@ -111,6 +111,12 @@ pub struct FileInfo { pub gid: usize, } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub struct Timespec { + pub sec: i64, + pub nsec: i32 +} + #[derive(Debug, Eq, PartialEq)] pub enum FileType { File,