support ramfs in rcore-fs-fuse. fix ramfs INode ID.

master
WangRunji 5 years ago
parent f6c8b1988a
commit 51cbe5c129

@ -18,3 +18,4 @@ git-version = "0.3"
rcore-fs = { path = "../rcore-fs", features = ["std"] } rcore-fs = { path = "../rcore-fs", features = ["std"] }
rcore-fs-sfs = { path = "../rcore-fs-sfs" } rcore-fs-sfs = { path = "../rcore-fs-sfs" }
rcore-fs-sefs = { path = "../rcore-fs-sefs", features = ["std"] } rcore-fs-sefs = { path = "../rcore-fs-sefs", features = ["std"] }
rcore-fs-ramfs = { path = "../rcore-fs-ramfs" }

@ -6,7 +6,6 @@ use rcore_fs::vfs;
use std::collections::btree_map::BTreeMap; use std::collections::btree_map::BTreeMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::sync::Arc; use std::sync::Arc;
//use log::*;
use time::Timespec; use time::Timespec;
const TTL: Timespec = Timespec { sec: 1, nsec: 0 }; // 1 second const TTL: Timespec = Timespec { sec: 1, nsec: 0 }; // 1 second

@ -1,3 +1,6 @@
#[macro_use]
extern crate log;
#[cfg(feature = "use_fuse")] #[cfg(feature = "use_fuse")]
pub mod fuse; pub mod fuse;
pub mod zip; pub mod zip;

@ -11,6 +11,7 @@ use rcore_fs_fuse::fuse::VfsFuse;
use rcore_fs_fuse::zip::{unzip_dir, zip_dir}; use rcore_fs_fuse::zip::{unzip_dir, zip_dir};
use rcore_fs_sefs as sefs; use rcore_fs_sefs as sefs;
use rcore_fs_sfs as sfs; use rcore_fs_sfs as sfs;
use rcore_fs_ramfs as ramfs;
use git_version::git_version; use git_version::git_version;
@ -28,7 +29,7 @@ struct Opt {
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
dir: PathBuf, dir: PathBuf,
/// File system: [sfs | sefs] /// File system: [sfs | sefs | ramfs]
#[structopt(short = "f", long = "fs", default_value = "sfs")] #[structopt(short = "f", long = "fs", default_value = "sfs")]
fs: String, fs: String,
} }
@ -95,6 +96,9 @@ fn main() {
.expect("failed to open sefs"), .expect("failed to open sefs"),
} }
} }
"ramfs" => {
ramfs::RamFS::new()
}
_ => panic!("unsupported file system"), _ => panic!("unsupported file system"),
}; };
match opt.cmd { match opt.cmd {

@ -51,7 +51,7 @@ impl RamFS {
content: Vec::new(), content: Vec::new(),
extra: Metadata { extra: Metadata {
dev: 0, dev: 0,
inode: 0, inode: new_inode_id(),
size: 0, size: 0,
blk_size: 0, blk_size: 0,
blocks: 0, blocks: 0,
@ -59,7 +59,7 @@ impl RamFS {
mtime: Timespec { sec: 0, nsec: 0 }, mtime: Timespec { sec: 0, nsec: 0 },
ctime: Timespec { sec: 0, nsec: 0 }, ctime: Timespec { sec: 0, nsec: 0 },
type_: FileType::Dir, type_: FileType::Dir,
mode: 0, mode: 0o777,
nlinks: 1, nlinks: 1,
uid: 0, uid: 0,
gid: 0, gid: 0,
@ -137,24 +137,9 @@ impl INode for LockedINode {
fn metadata(&self) -> Result<Metadata> { fn metadata(&self) -> Result<Metadata> {
let file = self.0.read(); let file = self.0.read();
let extra = &file.extra; let mut metadata = file.extra.clone();
let size = file.content.len(); metadata.size = file.content.len();
Ok(Metadata { Ok(metadata)
dev: 0,
inode: extra.inode,
size: size,
blk_size: 4096,
blocks: size / 4096,
atime: extra.atime,
mtime: extra.mtime,
ctime: extra.ctime,
type_: extra.type_,
mode: extra.mode,
nlinks: extra.nlinks,
uid: extra.uid,
gid: extra.gid,
rdev: extra.rdev,
})
} }
fn set_metadata(&self, metadata: &Metadata) -> Result<()> { fn set_metadata(&self, metadata: &Metadata) -> Result<()> {
@ -208,16 +193,16 @@ impl INode for LockedINode {
content: Vec::new(), content: Vec::new(),
extra: Metadata { extra: Metadata {
dev: 0, dev: 0,
inode: 0, inode: new_inode_id(),
size: 0, size: 0,
blk_size: 0, blk_size: 0,
blocks: 0, blocks: 0,
atime: Timespec { sec: 0, nsec: 0 }, atime: Timespec { sec: 0, nsec: 0 },
mtime: Timespec { sec: 0, nsec: 0 }, mtime: Timespec { sec: 0, nsec: 0 },
ctime: Timespec { sec: 0, nsec: 0 }, ctime: Timespec { sec: 0, nsec: 0 },
type_: type_, type_,
mode: mode as u16, mode: mode as u16,
nlinks: 0, nlinks: 1,
uid: 0, uid: 0,
gid: 0, gid: 0,
rdev: data, rdev: data,
@ -341,3 +326,10 @@ fn lock_multiple<'a>(locks: &[&'a RwLock<RamFSINode>]) -> Vec<RwLockWriteGuard<'
order.sort_by_key(|&i| locks[i].read().extra.inode); order.sort_by_key(|&i| locks[i].read().extra.inode);
order.iter().map(|&i| locks[i].write()).collect() order.iter().map(|&i| locks[i].write()).collect()
} }
/// Generate a new inode id
fn new_inode_id() -> usize {
use core::sync::atomic::*;
static ID: AtomicUsize = AtomicUsize::new(1);
ID.fetch_add(1, Ordering::SeqCst)
}

@ -164,7 +164,7 @@ pub struct PollStatus {
/// Metadata of INode /// Metadata of INode
/// ///
/// Ref: [http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/stat.h.html] /// Ref: [http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/stat.h.html]
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq, Clone)]
pub struct Metadata { pub struct Metadata {
/// Device ID /// Device ID
pub dev: usize, // (major << 8) | minor pub dev: usize, // (major << 8) | minor

Loading…
Cancel
Save