Skip to content

Commit

Permalink
implement fstat for fuse file handles via getattr
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mueller678 committed Dec 17, 2024
1 parent 24afa3d commit fb570b6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/fs/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,31 @@ pub(crate) mod ops {
}
}

#[derive(Debug)]
pub(crate) struct Getattr;

impl Op for Getattr {
const OP_CODE: fuse_opcode = fuse_opcode::FUSE_GETATTR;
type InStruct = fuse_getattr_in;
type InPayload = ();
type OutStruct = fuse_attr_out;
type OutPayload = ();
}

impl Getattr {
pub(crate) fn create(nid: u64, fh: u64, getattr_flags: u32) -> (Cmd<Self>, u32) {
let cmd = Cmd::new(
nid,
fuse_getattr_in {
getattr_flags,
fh,
..Default::default()
},
);
(cmd, 0)
}
}

#[derive(Debug)]
pub(crate) struct Readlink;

Expand Down Expand Up @@ -694,6 +719,23 @@ impl FuseFileHandleInner {
Err(io::Error::EIO)
}
}

fn fstat(&mut self) -> io::Result<FileAttr> {
debug!("FUSE getattr");
if let (Some(nid), Some(fh)) = (self.fuse_nid, self.fuse_fh) {
let (cmd, rsp_payload_len) = ops::Getattr::create(nid, fh, FUSE_GETATTR_FH);
let rsp = get_filesystem_driver()
.ok_or(io::Error::ENOSYS)?
.lock()
.send_command(cmd, rsp_payload_len)?;
if rsp.headers.out_header.error < 0 {
return Err(io::Error::EIO);
}
Ok(rsp.headers.op_header.attr.into())
} else {
Err(io::Error::EIO)
}
}
}

impl Drop for FuseFileHandleInner {
Expand Down Expand Up @@ -736,6 +778,10 @@ impl ObjectInterface for FuseFileHandle {
async fn lseek(&self, offset: isize, whence: SeekWhence) -> io::Result<isize> {
self.0.lock().await.lseek(offset, whence)
}

async fn fstat(&self) -> io::Result<FileAttr> {
self.0.lock().await.fstat()
}
}

impl Clone for FuseFileHandle {
Expand Down

0 comments on commit fb570b6

Please sign in to comment.