Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement fstat for fuse file handles via getattr #1512

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
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
Loading