Skip to content

Commit

Permalink
Update FUSE
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Sep 26, 2017
1 parent 070aeb5 commit 541a581
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
14 changes: 4 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ spin = { git = "https://github.com/messense/spin-rs", rev = "020f1b3f" }
redox_syscall = "0.1"

[target.'cfg(unix)'.dependencies]
fuse = "0.2"
fuse = "0.3"
libc = "0.2"
time = "0.1"
13 changes: 10 additions & 3 deletions src/bin/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ fn main() {
Ok(filesystem) => {
println!("redoxfs: opened filesystem {}", path);

if let Some(mountpoint) = env::args_os().nth(2) {
mount(filesystem, &mountpoint, write);
process::exit(0);
if let Some(mountpoint) = env::args().nth(2) {
match mount(filesystem, &mountpoint, write) {
Ok(()) => {
process::exit(0);
},
Err(err) => {
println!("redoxfs: failed to mount {} to {}: {}", path, mountpoint, err);
process::exit(1);
}
}
} else {
println!("redoxfs: no mount point provided");
usage();
Expand Down
15 changes: 8 additions & 7 deletions src/mount/fuse.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extern crate fuse;
extern crate time;

use std::path::Path;
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};

use disk::Disk;
Expand Down Expand Up @@ -54,7 +55,7 @@ fn node_attr(node: &(u64, Node)) -> FileAttr {
}

impl<D: Disk> Filesystem for Fuse<D> {
fn lookup(&mut self, _req: &Request, parent_block: u64, name: &Path, reply: ReplyEntry) {
fn lookup(&mut self, _req: &Request, parent_block: u64, name: &OsStr, reply: ReplyEntry) {
match self.fs.find_node(name.to_str().unwrap(), parent_block) {
Ok(node) => {
reply.entry(&TTL, &node_attr(&node), 0);
Expand Down Expand Up @@ -235,7 +236,7 @@ impl<D: Disk> Filesystem for Fuse<D> {
}
}

fn create(&mut self, _req: &Request, parent_block: u64, name: &Path, mode: u32, flags: u32, reply: ReplyCreate) {
fn create(&mut self, _req: &Request, parent_block: u64, name: &OsStr, mode: u32, flags: u32, reply: ReplyCreate) {
let ctime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
match self.fs.create_node(Node::MODE_FILE | (mode as u16 & Node::MODE_PERM), name.to_str().unwrap(), parent_block, ctime.as_secs(), ctime.subsec_nanos()) {
Ok(node) => {
Expand All @@ -248,7 +249,7 @@ impl<D: Disk> Filesystem for Fuse<D> {
}
}

fn mkdir(&mut self, _req: &Request, parent_block: u64, name: &Path, mode: u32, reply: ReplyEntry) {
fn mkdir(&mut self, _req: &Request, parent_block: u64, name: &OsStr, mode: u32, reply: ReplyEntry) {
let ctime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
match self.fs.create_node(Node::MODE_DIR | (mode as u16 & Node::MODE_PERM), name.to_str().unwrap(), parent_block, ctime.as_secs(), ctime.subsec_nanos()) {
Ok(node) => {
Expand All @@ -261,7 +262,7 @@ impl<D: Disk> Filesystem for Fuse<D> {
}
}

fn rmdir(&mut self, _req: &Request, parent_block: u64, name: &Path, reply: ReplyEmpty) {
fn rmdir(&mut self, _req: &Request, parent_block: u64, name: &OsStr, reply: ReplyEmpty) {
match self.fs.remove_node(Node::MODE_DIR, name.to_str().unwrap(), parent_block) {
Ok(()) => {
reply.ok();
Expand All @@ -272,7 +273,7 @@ impl<D: Disk> Filesystem for Fuse<D> {
}
}

fn unlink(&mut self, _req: &Request, parent_block: u64, name: &Path, reply: ReplyEmpty) {
fn unlink(&mut self, _req: &Request, parent_block: u64, name: &OsStr, reply: ReplyEmpty) {
match self.fs.remove_node(Node::MODE_FILE, name.to_str().unwrap(), parent_block) {
Ok(()) => {
reply.ok();
Expand All @@ -298,7 +299,7 @@ impl<D: Disk> Filesystem for Fuse<D> {
}
}

fn symlink(&mut self, _req: &Request, parent_block: u64, name: &Path, link: &Path, reply: ReplyEntry) {
fn symlink(&mut self, _req: &Request, parent_block: u64, name: &OsStr, link: &Path, reply: ReplyEntry) {
let ctime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
match self.fs.create_node(Node::MODE_SYMLINK | 0o777, name.to_str().unwrap(), parent_block, ctime.as_secs(), ctime.subsec_nanos()) {
Ok(node) => {
Expand Down
13 changes: 7 additions & 6 deletions src/mount/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io;
use std::fs::File;
use std::path::Path;

Expand All @@ -11,7 +12,7 @@ mod fuse;
mod redox;

#[cfg(all(unix, target_os = "macos"))]
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, mut write: File) {
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, mut write: File) -> io::Result<()> {
use std::ffi::OsStr;
use std::io::Write;

Expand All @@ -27,22 +28,22 @@ pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P,
// be `root`, thus that we need to allow `root` to have access.
OsStr::new("-o"),
OsStr::new("defer_permissions"),
]);
])
}

#[cfg(all(unix, not(target_os = "macos")))]
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, mut write: File) {
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, mut write: File) -> io::Result<()> {
use std::io::Write;

let _ = write.write(&[0]);
drop(write);

fuse::mount(fuse::Fuse {
fs: filesystem
}, mountpoint, &[]);
}, mountpoint, &[])
}

#[cfg(target_os = "redox")]
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, write: File) {
redox::mount(filesystem, mountpoint, write);
pub fn mount<D: Disk, P: AsRef<Path>>(filesystem: FileSystem<D>, mountpoint: &P, write: File) -> io::Result<()> {
redox::mount(filesystem, mountpoint, write)
}
35 changes: 17 additions & 18 deletions src/mount/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ extern crate spin;

use syscall::{Packet, Scheme};
use std::fs::File;
use std::io::{Read, Write};
use std::io::{self, Read, Write};
use std::path::Path;

use self::scheme::FileScheme;

pub mod resource;
pub mod scheme;

pub fn mount<P: AsRef<Path>>(filesystem: filesystem::FileSystem, mountpoint: &P, mut write: File) {
pub fn mount<P: AsRef<Path>>(filesystem: filesystem::FileSystem, mountpoint: &P, mut write: File) -> io::Result<()> {
let mountpoint = mountpoint.as_ref();
match File::create(format!(":{}", mountpoint.display())) {
Ok(mut socket) => {
println!("redoxfs: mounted filesystem on {}:", mountpoint.display());

let _ = write.write(&[0]);
drop(write);

let scheme = FileScheme::new(format!("{}", mountpoint.display()), filesystem);
loop {
let mut packet = Packet::default();
socket.read(&mut packet).unwrap();
scheme.handle(&mut packet);
socket.write(&packet).unwrap();
}
},
Err(err) => println!("redoxfs: failed to create {} scheme: {}", mountpoint.display(), err)
let mut socket = File::create(format!(":{}", mountpoint.display()))?;

println!("redoxfs: mounted filesystem on {}:", mountpoint.display());

let _ = write.write(&[0]);
drop(write);

let scheme = FileScheme::new(format!("{}", mountpoint.display()), filesystem);
loop {
let mut packet = Packet::default();
socket.read(&mut packet).unwrap();
scheme.handle(&mut packet);
socket.write(&packet).unwrap();
}

Ok(())
}

0 comments on commit 541a581

Please sign in to comment.