Skip to content

Commit

Permalink
Migrate to fully async library/session handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ianoc committed Feb 25, 2021
1 parent 4ef2b28 commit 8796eaf
Show file tree
Hide file tree
Showing 14 changed files with 2,819 additions and 1,075 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ log = "0.4.6"
users = "0.11.0"
page_size = "0.4.2"
serde = {version = "1.0.102", features = ["std", "derive"], optional = true}
pool = "0.1.4"
tokio = {version = "1.1.0", features = ["fs", "net", "macros", "rt-multi-thread", "sync", "time"]}
async-trait = "0.1.42"
futures = "0.3.12"
zerocopy = "0.3"

[dev-dependencies]
env_logger = "0.8"
clap = "2.32"
bincode = "1.3.1"
serde = {version = "1.0.102", features=["std", "derive"]}
dashmap = "4.0.2"

[build-dependencies]
pkg-config = {version = "0.3.14", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ targets = [
# The path where the advisory database is cloned/fetched into
db-path = "~/.cargo/advisory-db"
# The url of the advisory database to use
db-url = "https://github.com/rustsec/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"]
# The lint level for security vulnerabilities
vulnerability = "deny"
# The lint level for unmaintained crates
Expand Down
46 changes: 27 additions & 19 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

use fuser::{
FileAttr, FileType, Filesystem, MountOption, ReplyAttr, ReplyData, ReplyDirectory, ReplyEntry,
Request,
Expand Down Expand Up @@ -51,26 +53,27 @@ const HELLO_TXT_ATTR: FileAttr = FileAttr {

struct HelloFS;

#[async_trait::async_trait]
impl Filesystem for HelloFS {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
async fn lookup(&self, _req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent == 1 && name.to_str() == Some("hello.txt") {
reply.entry(&TTL, &HELLO_TXT_ATTR, 0);
reply.entry(&TTL, &HELLO_TXT_ATTR, 0).await;
} else {
reply.error(ENOENT);
reply.error(ENOENT).await;
}
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) {
async fn getattr(&self, _req: &Request<'_>, ino: u64, reply: ReplyAttr) {
match ino {
1 => reply.attr(&TTL, &HELLO_DIR_ATTR),
2 => reply.attr(&TTL, &HELLO_TXT_ATTR),
_ => reply.error(ENOENT),
1 => reply.attr(&TTL, &HELLO_DIR_ATTR).await,
2 => reply.attr(&TTL, &HELLO_TXT_ATTR).await,
_ => reply.error(ENOENT).await,
}
}

fn read(
&mut self,
_req: &Request,
async fn read(
&self,
_req: &Request<'_>,
ino: u64,
_fh: u64,
offset: i64,
Expand All @@ -80,22 +83,24 @@ impl Filesystem for HelloFS {
reply: ReplyData,
) {
if ino == 2 {
reply.data(&HELLO_TXT_CONTENT.as_bytes()[offset as usize..]);
reply
.data(&HELLO_TXT_CONTENT.as_bytes()[offset as usize..])
.await;
} else {
reply.error(ENOENT);
reply.error(ENOENT).await;
}
}

fn readdir(
&mut self,
_req: &Request,
async fn readdir(
&self,
_req: &Request<'_>,
ino: u64,
_fh: u64,
offset: i64,
mut reply: ReplyDirectory,
) {
if ino != 1 {
reply.error(ENOENT);
reply.error(ENOENT).await;
return;
}

Expand All @@ -111,11 +116,12 @@ impl Filesystem for HelloFS {
break;
}
}
reply.ok();
reply.ok().await;
}
}

fn main() {
#[tokio::main]
async fn main() {
env_logger::init();
let mountpoint = env::args_os().nth(1).unwrap();
let mut options = vec![MountOption::RO, MountOption::FSName("hello".to_string())];
Expand All @@ -124,5 +130,7 @@ fn main() {
options.push(MountOption::AutoUnmount);
}
}
fuser::mount2(HelloFS, mountpoint, &options).unwrap();
fuser::mount2(HelloFS, 5, mountpoint, &options)
.await
.unwrap();
}
7 changes: 5 additions & 2 deletions examples/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ struct NullFS;

impl Filesystem for NullFS {}

fn main() {
#[tokio::main]
async fn main() {
env_logger::init();
let mountpoint = env::args_os().nth(1).unwrap();
fuser::mount2(NullFS, mountpoint, &[MountOption::AutoUnmount]).unwrap();
fuser::mount2(NullFS, 5, mountpoint, &[MountOption::AutoUnmount])
.await
.unwrap();
}
Loading

0 comments on commit 8796eaf

Please sign in to comment.