rename 'sfs-c' to 'rcore-fs-ucore', update to Rust 2018

master
WangRunji 6 years ago
parent 066cd14cce
commit f7c75234de

@ -13,7 +13,6 @@ required-features = ["std"]
bit-vec = { default-features = false, git = "https://github.com/AltSysrq/bit-vec.git" } # default-features contains 'std' bit-vec = { default-features = false, git = "https://github.com/AltSysrq/bit-vec.git" } # default-features contains 'std'
static_assertions = "0.3" static_assertions = "0.3"
spin = "0.4" spin = "0.4"
time = "0.1"
[features] [features]
std = [] std = []

@ -25,15 +25,21 @@ impl<T: vfs::FileSystem> VfsWrapper<T> {
inodes.insert(1, fs.root_inode()); inodes.insert(1, fs.root_inode());
VfsWrapper { fs, inodes } VfsWrapper { fs, inodes }
} }
fn trans_time(time: vfs::Timespec) -> Timespec {
Timespec {
sec: time.sec,
nsec: time.nsec,
}
}
fn trans_attr(info: vfs::FileInfo) -> FileAttr { fn trans_attr(info: vfs::FileInfo) -> FileAttr {
FileAttr { FileAttr {
ino: info.inode as u64, ino: info.inode as u64,
size: info.size as u64, size: info.size as u64,
blocks: info.blocks as u64, blocks: info.blocks as u64,
atime: info.atime, atime: Self::trans_time(info.atime),
mtime: info.mtime, mtime: Self::trans_time(info.mtime),
ctime: info.ctime, ctime: Self::trans_time(info.ctime),
crtime: Timespec::new(0, 0), crtime: Timespec { sec: 0, nsec: 0 },
kind: Self::trans_type(info.type_), kind: Self::trans_type(info.type_),
perm: info.mode, perm: info.mode,
nlink: info.nlinks as u32, nlink: info.nlinks as u32,

@ -1,7 +1,8 @@
[package] [package]
name = "sfs-c" name = "rcore-fs-ucore"
version = "0.0.1" version = "0.1.0"
authors = ["WangRunji <wangrunji0408@163.com>"] authors = ["WangRunji <wangrunji0408@163.com>"]
edition = "2018"
[lib] [lib]
crate-type = ["staticlib"] crate-type = ["staticlib"]
@ -11,7 +12,10 @@ panic = 'abort' # prevent `_Unwind_Resume` link error
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
static_assertions = "0.2.5" static_assertions = "0.3"
simple-filesystem = { path = ".." } simple-filesystem = { path = ".." }
spin = "0.4" spin = "0.4"
lazy_static = { version = "1.1", features = ["spin_no_std"] } lazy_static = { version = "1.2", features = ["spin_no_std"] }
[features]
debug_print = []

@ -1,5 +1,5 @@
ucore: ucore:
rustup override set nightly rustup override set nightly-2019-01-28
cargo xbuild --target ucore.json --release cargo xbuild --target ucore.json --release
install-rust: install-rust:

@ -3,42 +3,32 @@
//! NOTE: Must link these sections: //! NOTE: Must link these sections:
//! `*.got.*` `*.data.*` `*.rodata.*` //! `*.got.*` `*.data.*` `*.rodata.*`
#![feature(allocator_api)]
#![feature(lang_items)] #![feature(lang_items)]
#![feature(alloc)] #![feature(alloc)]
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(compiler_builtins_lib)]
#![no_std] #![no_std]
#[macro_use] #[macro_use]
extern crate alloc; extern crate alloc;
extern crate simple_filesystem;
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
#[macro_use] #[macro_use]
extern crate static_assertions;
#[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate spin; #[macro_use]
extern crate static_assertions;
use alloc::{sync::Arc, boxed::Box, collections::BTreeMap}; use alloc::{boxed::Box, collections::BTreeMap, sync::Arc};
use core::cell::RefCell;
use core::slice;
use core::ops::Deref;
use core::cmp::Ordering;
use core::alloc::{GlobalAlloc, Layout}; use core::alloc::{GlobalAlloc, Layout};
use core::mem::{size_of, self}; use core::mem;
use core::ptr; use core::ops::Deref;
use simple_filesystem as sfs; use core::slice;
use simple_filesystem as vfs; use simple_filesystem::{sfs, vfs};
use vfs::FileSystem;
use spin::Mutex; use spin::Mutex;
/// Lang items for bare lib /// Lang items for bare lib
mod lang { mod lang {
use alloc::fmt;
use core::panic::PanicInfo;
use core::alloc::Layout; use core::alloc::Layout;
use core::panic::PanicInfo;
#[lang = "eh_personality"] #[lang = "eh_personality"]
#[no_mangle] #[no_mangle]
@ -52,7 +42,7 @@ mod lang {
#[panic_handler] #[panic_handler]
#[no_mangle] #[no_mangle]
extern fn panic_fmt(info: &PanicInfo) -> ! { extern fn panic(info: &PanicInfo) -> ! {
use super::ucore::__panic; use super::ucore::__panic;
let location = info.location().unwrap(); let location = info.location().unwrap();
let message = info.message().unwrap(); let message = info.message().unwrap();
@ -120,7 +110,6 @@ mod libc {
#[no_mangle] #[no_mangle]
pub extern fn sfs_do_mount(dev: *mut Device, fs_store: &mut *mut Fs) -> ErrorCode { 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) }; let fs = unsafe { ucore::create_fs_for_sfs(&FS_OPS) };
debug_assert!(!dev.is_null()); debug_assert!(!dev.is_null());
let mut device = unsafe { Box::from_raw(dev) }; // TODO: fix unsafe 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 pos = pos as usize;
let info = inode.info().unwrap(); let info = inode.info().unwrap();
if pos > info.size { if pos > info.size {
inode.resize(pos); inode.resize(pos).unwrap();
} }
return ErrorCode::Ok; return ErrorCode::Ok;
} }

@ -24,15 +24,11 @@ mod structs;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub use crate::sfs::*;
pub use crate::vfs::*;
pub use crate::blocked_device::BlockedDevice;
#[cfg(any(test, feature = "std"))] #[cfg(any(test, feature = "std"))]
pub mod std_impl { pub mod std_impl {
use std::fs::File; use std::fs::File;
use std::io::{Read, Write, Seek, SeekFrom}; use std::io::{Read, Write, Seek, SeekFrom};
use super::Device; use super::vfs::Device;
impl Device for File { impl Device for File {
fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option<usize> { fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option<usize> {

@ -6,12 +6,11 @@ use core::slice;
use bit_vec::BitVec; use bit_vec::BitVec;
use spin::{Mutex, RwLock}; use spin::{Mutex, RwLock};
use time::Timespec;
use crate::dirty::Dirty; use crate::dirty::Dirty;
use crate::structs::*; use crate::structs::*;
use crate::util::*; use crate::util::*;
use crate::vfs::{self, Device, FileSystem, FsError, INode}; use crate::vfs::{self, Device, FileSystem, FsError, INode, Timespec};
impl Device { impl Device {
fn read_block(&mut self, id: BlockId, offset: usize, buf: &mut [u8]) -> vfs::Result<()> { 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, mode: 0o777,
type_: vfs::FileType::from(disk_inode.type_.clone()), type_: vfs::FileType::from(disk_inode.type_.clone()),
blocks: disk_inode.blocks as usize, blocks: disk_inode.blocks as usize,
atime: Timespec::new(0, 0), atime: Timespec { sec: 0, nsec: 0 },
mtime: Timespec::new(0, 0), mtime: Timespec { sec: 0, nsec: 0 },
ctime: Timespec::new(0, 0), ctime: Timespec { sec: 0, nsec: 0 },
nlinks: disk_inode.nlinks as usize, nlinks: disk_inode.nlinks as usize,
uid: 0, uid: 0,
gid: 0, gid: 0,

@ -1,7 +1,7 @@
use alloc::{vec::Vec, string::String, sync::Arc}; use alloc::{vec::Vec, string::String, sync::Arc};
use core::any::Any; use core::any::Any;
use core::result; use core::result;
use time::Timespec; pub use super::blocked_device::BlockedDevice;
/// Interface for FS to read & write /// Interface for FS to read & write
/// TODO: use std::io::{Read, Write} /// TODO: use std::io::{Read, Write}
@ -111,6 +111,12 @@ pub struct FileInfo {
pub gid: usize, 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)] #[derive(Debug, Eq, PartialEq)]
pub enum FileType { pub enum FileType {
File, File,

Loading…
Cancel
Save