Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/async_hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use fuser::experimental::{
AsyncFilesystem, DirEntListBuilder, GetAttrResponse, LookupResponse, RequestContext,
TokioAdapter,
};
use fuser::{FileAttr, FileType, MountOption, experimental};
use fuser::{FileAttr, FileType, INodeNo, MountOption, experimental};
use libc::ENOENT;
use std::ffi::OsStr;
use std::time::{Duration, UNIX_EPOCH};

const TTL: Duration = Duration::from_secs(1); // 1 second

const HELLO_DIR_ATTR: FileAttr = FileAttr {
ino: 1,
ino: INodeNo::ROOT,
size: 0,
blocks: 0,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -31,7 +31,7 @@ const HELLO_DIR_ATTR: FileAttr = FileAttr {
const HELLO_TXT_CONTENT: &str = "Hello World!\n";

const HELLO_TXT_ATTR: FileAttr = FileAttr {
ino: 2,
ino: INodeNo(2),
size: 13,
blocks: 1,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -55,10 +55,10 @@ impl AsyncFilesystem for HelloFS {
async fn lookup(
&self,
_context: &RequestContext,
parent: u64,
parent: INodeNo,
name: &OsStr,
) -> experimental::Result<LookupResponse> {
if parent == 1 && name.to_str() == Some("hello.txt") {
if parent == INodeNo::ROOT && name.to_str() == Some("hello.txt") {
Ok(LookupResponse::new(TTL, HELLO_TXT_ATTR, 0))
} else {
Err(ENOENT)
Expand All @@ -68,10 +68,10 @@ impl AsyncFilesystem for HelloFS {
async fn getattr(
&self,
_context: &RequestContext,
ino: u64,
ino: INodeNo,
_file_handle: Option<u64>,
) -> experimental::Result<GetAttrResponse> {
match ino {
match ino.0 {
1 => Ok(GetAttrResponse::new(TTL, HELLO_DIR_ATTR)),
2 => Ok(GetAttrResponse::new(TTL, HELLO_TXT_ATTR)),
_ => Err(ENOENT),
Expand All @@ -81,15 +81,15 @@ impl AsyncFilesystem for HelloFS {
async fn read(
&self,
_context: &RequestContext,
ino: u64,
ino: INodeNo,
_file_handle: u64,
offset: i64,
_size: u32,
_flags: i32,
_lock: Option<u64>,
out_data: &mut Vec<u8>,
) -> experimental::Result<()> {
if ino == 2 {
if ino.0 == 2 {
out_data.extend_from_slice(&HELLO_TXT_CONTENT.as_bytes()[offset as usize..]);
Ok(())
} else {
Expand All @@ -100,12 +100,12 @@ impl AsyncFilesystem for HelloFS {
async fn readdir(
&self,
_context: &RequestContext,
ino: u64,
ino: INodeNo,
_file_handle: u64,
offset: i64,
mut builder: DirEntListBuilder<'_>,
) -> experimental::Result<()> {
if ino != 1 {
if ino != INodeNo::ROOT {
return Err(ENOENT);
}

Expand All @@ -117,7 +117,7 @@ impl AsyncFilesystem for HelloFS {

for (i, entry) in entries.into_iter().enumerate().skip(offset as usize) {
// i + 1 means the index of the next entry
if builder.add(entry.0, (i + 1) as i64, entry.1, entry.2) {
if builder.add(INodeNo(entry.0), (i + 1) as i64, entry.1, entry.2) {
break;
}
}
Expand Down
32 changes: 16 additions & 16 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Arg, ArgAction, Command, crate_version};
use fuser::{
FileAttr, FileType, Filesystem, MountOption, ReplyAttr, ReplyData, ReplyDirectory, ReplyEntry,
Request,
FileAttr, FileType, Filesystem, INodeNo, MountOption, ReplyAttr, ReplyData, ReplyDirectory,
ReplyEntry, Request,
};
use libc::ENOENT;
use std::ffi::OsStr;
Expand All @@ -10,7 +10,7 @@ use std::time::{Duration, UNIX_EPOCH};
const TTL: Duration = Duration::from_secs(1); // 1 second

const HELLO_DIR_ATTR: FileAttr = FileAttr {
ino: 1,
ino: INodeNo::ROOT,
size: 0,
blocks: 0,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -30,7 +30,7 @@ const HELLO_DIR_ATTR: FileAttr = FileAttr {
const HELLO_TXT_CONTENT: &str = "Hello World!\n";

const HELLO_TXT_ATTR: FileAttr = FileAttr {
ino: 2,
ino: INodeNo(2),
size: 13,
blocks: 1,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -50,16 +50,16 @@ const HELLO_TXT_ATTR: FileAttr = FileAttr {
struct HelloFS;

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

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ino {
fn getattr(&mut self, _req: &Request<'_>, ino: INodeNo, _fh: Option<u64>, reply: ReplyAttr) {
match u64::from(ino) {
1 => reply.attr(&TTL, &HELLO_DIR_ATTR),
2 => reply.attr(&TTL, &HELLO_TXT_ATTR),
_ => reply.error(ENOENT),
Expand All @@ -68,16 +68,16 @@ impl Filesystem for HelloFS {

fn read(
&mut self,
_req: &Request,
ino: u64,
_req: &Request<'_>,
ino: INodeNo,
_fh: u64,
offset: i64,
_size: u32,
_flags: i32,
_lock: Option<u64>,
_lock_owner: Option<u64>,
reply: ReplyData,
) {
if ino == 2 {
if u64::from(ino) == 2 {
reply.data(&HELLO_TXT_CONTENT.as_bytes()[offset as usize..]);
} else {
reply.error(ENOENT);
Expand All @@ -86,13 +86,13 @@ impl Filesystem for HelloFS {

fn readdir(
&mut self,
_req: &Request,
ino: u64,
_req: &Request<'_>,
ino: INodeNo,
_fh: u64,
offset: i64,
mut reply: ReplyDirectory,
) {
if ino != 1 {
if u64::from(ino) != 1 {
reply.error(ENOENT);
return;
}
Expand All @@ -105,7 +105,7 @@ impl Filesystem for HelloFS {

for (i, entry) in entries.into_iter().enumerate().skip(offset as usize) {
// i + 1 means the index of the next entry
if reply.add(entry.0, (i + 1) as i64, entry.1, entry.2) {
if reply.add(INodeNo(entry.0), (i + 1) as i64, entry.1, entry.2) {
break;
}
}
Expand Down
38 changes: 19 additions & 19 deletions examples/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use clap::{Arg, ArgAction, Command, crate_version};
use fuser::{
FileAttr, FileType, Filesystem, MountOption, ReplyAttr, ReplyData, ReplyDirectory, ReplyEntry,
Request,
FileAttr, FileType, Filesystem, INodeNo, MountOption, ReplyAttr, ReplyData, ReplyDirectory,
ReplyEntry, ReplyIoctl, Request,
};
use libc::{EINVAL, ENOENT};
use log::debug;
Expand All @@ -29,7 +29,7 @@ impl FiocFS {
let gid = nix::unistd::getgid().into();

let root_attr = FileAttr {
ino: 1,
ino: INodeNo::ROOT,
size: 0,
blocks: 0,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -47,7 +47,7 @@ impl FiocFS {
};

let fioc_file_attr = FileAttr {
ino: 2,
ino: INodeNo(2),
size: 0,
blocks: 1,
atime: UNIX_EPOCH, // 1970-01-01 00:00:00
Expand All @@ -73,16 +73,16 @@ impl FiocFS {
}

impl Filesystem for FiocFS {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent == 1 && name.to_str() == Some("fioc") {
fn lookup(&mut self, _req: &Request<'_>, parent: INodeNo, name: &OsStr, reply: ReplyEntry) {
if parent == INodeNo::ROOT && name.to_str() == Some("fioc") {
reply.entry(&TTL, &self.fioc_file_attr, 0);
} else {
reply.error(ENOENT);
}
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ino {
fn getattr(&mut self, _req: &Request<'_>, ino: INodeNo, _fh: Option<u64>, reply: ReplyAttr) {
match ino.0 {
1 => reply.attr(&TTL, &self.root_attr),
2 => reply.attr(&TTL, &self.fioc_file_attr),
_ => reply.error(ENOENT),
Expand All @@ -91,16 +91,16 @@ impl Filesystem for FiocFS {

fn read(
&mut self,
_req: &Request,
ino: u64,
_req: &Request<'_>,
ino: INodeNo,
_fh: u64,
offset: i64,
_size: u32,
_flags: i32,
_lock: Option<u64>,
_lock_owner: Option<u64>,
reply: ReplyData,
) {
if ino == 2 {
if ino == INodeNo(2) {
reply.data(&self.content[offset as usize..]);
} else {
reply.error(ENOENT);
Expand All @@ -109,13 +109,13 @@ impl Filesystem for FiocFS {

fn readdir(
&mut self,
_req: &Request,
ino: u64,
_req: &Request<'_>,
ino: INodeNo,
_fh: u64,
offset: i64,
mut reply: ReplyDirectory,
) {
if ino != 1 {
if ino != INodeNo::ROOT {
reply.error(ENOENT);
return;
}
Expand All @@ -128,7 +128,7 @@ impl Filesystem for FiocFS {

for (i, entry) in entries.into_iter().enumerate().skip(offset as usize) {
// i + 1 means the index of the next entry
if reply.add(entry.0, (i + 1) as i64, entry.1, entry.2) {
if reply.add(INodeNo(entry.0), (i + 1) as i64, entry.1, entry.2) {
break;
}
}
Expand All @@ -138,15 +138,15 @@ impl Filesystem for FiocFS {
fn ioctl(
&mut self,
_req: &Request<'_>,
ino: u64,
ino: INodeNo,
_fh: u64,
_flags: u32,
cmd: u32,
in_data: &[u8],
_out_size: u32,
reply: fuser::ReplyIoctl,
reply: ReplyIoctl,
) {
if ino != 2 {
if ino != INodeNo(2) {
reply.error(EINVAL);
return;
}
Expand Down
Loading