Skip to content

Commit

Permalink
Add file handle for get_attr requests. (#279)
Browse files Browse the repository at this point in the history
* Add file handle for get_attr requests.

* Fix examples

* Rename fd to fh

* Rename that last fd to fh

---------

Co-authored-by: jcarl <jcarl@locusrobotics.com>
  • Loading branch information
IamTheCarl and IamTheCarl authored Mar 28, 2024
1 parent 4147f8a commit 76ea821
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Filesystem for HelloFS {
}
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) {
fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ino {
1 => reply.attr(&TTL, &HELLO_DIR_ATTR),
2 => reply.attr(&TTL, &HELLO_TXT_ATTR),
Expand Down
2 changes: 1 addition & 1 deletion examples/notify_inval_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'a> Filesystem for ClockFS<'a> {
}
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) {
fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ClockFS::stat(ino) {
Some(a) => reply.attr(&self.timeout, &a),
None => reply.error(ENOENT),
Expand Down
2 changes: 1 addition & 1 deletion examples/notify_inval_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a> Filesystem for ClockFS<'a> {
}
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) {
fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match self.stat(ino) {
Some(a) => reply.attr(&Duration::MAX, &a),
None => reply.error(ENOENT),
Expand Down
2 changes: 1 addition & 1 deletion examples/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl fuser::Filesystem for FSelFS {
reply.entry(&Duration::ZERO, &self.get_data().filestat(idx), 0);
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: fuser::ReplyAttr) {
fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: fuser::ReplyAttr) {
if ino == FUSE_ROOT_ID {
let a = FileAttr {
ino: FUSE_ROOT_ID,
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl Filesystem for SimpleFS {

fn forget(&mut self, _req: &Request, _ino: u64, _nlookup: u64) {}

fn getattr(&mut self, _req: &Request, inode: u64, reply: ReplyAttr) {
fn getattr(&mut self, _req: &Request, inode: u64, _fh: Option<u64>, reply: ReplyAttr) {
match self.get_inode(inode) {
Ok(attrs) => reply.attr(&Duration::new(0, 0), &attrs.into()),
Err(error_code) => reply.error(error_code),
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,11 @@ pub trait Filesystem {
}

/// Get file attributes.
fn getattr(&mut self, _req: &Request<'_>, ino: u64, reply: ReplyAttr) {
warn!("[Not Implemented] getattr(ino: {:#x?})", ino);
fn getattr(&mut self, _req: &Request<'_>, ino: u64, fh: Option<u64>, reply: ReplyAttr) {
warn!(
"[Not Implemented] getattr(ino: {:#x?}, fh: {:#x?})",
ino, fh
);
reply.error(ENOSYS);
}

Expand Down
22 changes: 21 additions & 1 deletion src/ll/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! perform.

use super::fuse_abi::{fuse_in_header, fuse_opcode, InvalidOpcodeError};

use super::{fuse_abi as abi, Errno, Response};
#[cfg(feature = "serializable")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -328,9 +329,23 @@ mod op {
#[derive(Debug)]
pub struct GetAttr<'a> {
header: &'a fuse_in_header,

#[cfg(feature = "abi-7-9")]
arg: &'a fuse_getattr_in,
}
impl_request!(GetAttr<'_>);

#[cfg(feature = "abi-7-9")]
impl<'a> GetAttr<'a> {
pub fn file_handle(&self) -> Option<FileHandle> {
if self.arg.getattr_flags & crate::FUSE_GETATTR_FH != 0 {
Some(FileHandle(self.arg.fh))
} else {
None
}
}
}

/// Set file attributes.
#[derive(Debug)]
pub struct SetAttr<'a> {
Expand Down Expand Up @@ -1634,7 +1649,12 @@ mod op {
header,
arg: data.fetch()?,
}),
fuse_opcode::FUSE_GETATTR => Operation::GetAttr(GetAttr { header }),
fuse_opcode::FUSE_GETATTR => Operation::GetAttr(GetAttr {
header,

#[cfg(feature = "abi-7-9")]
arg: data.fetch()?,
}),
fuse_opcode::FUSE_SETATTR => Operation::SetAttr(SetAttr {
header,
arg: data.fetch()?,
Expand Down
14 changes: 12 additions & 2 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,19 @@ impl<'a> Request<'a> {
se.filesystem
.forget(self, self.request.nodeid().into(), x.nlookup()); // no reply
}
ll::Operation::GetAttr(_) => {
ll::Operation::GetAttr(_attr) => {
#[cfg(feature = "abi-7-9")]
se.filesystem.getattr(
self,
self.request.nodeid().into(),
_attr.file_handle().map(|fh| fh.into()),
self.reply(),
);

// Pre-abi-7-9 does not support providing a file handle.
#[cfg(not(feature = "abi-7-9"))]
se.filesystem
.getattr(self, self.request.nodeid().into(), self.reply());
.getattr(self, self.request.nodeid().into(), None, self.reply());
}
ll::Operation::SetAttr(x) => {
se.filesystem.setattr(
Expand Down

0 comments on commit 76ea821

Please sign in to comment.