Skip to content

Commit

Permalink
Add support for FUSE_COPY_FILE_RANGE
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Nov 11, 2020
1 parent 022f9e3 commit 17a192e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/fuse_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ pub enum fuse_opcode {
FUSE_RENAME2 = 45,
#[cfg(feature = "abi-7-24")]
FUSE_LSEEK = 46,
#[cfg(feature = "abi-7-28")]
FUSE_COPY_FILE_RANGE = 47,

#[cfg(target_os = "macos")]
FUSE_SETVOLNAME = 61,
Expand Down Expand Up @@ -419,6 +421,8 @@ impl TryFrom<u32> for fuse_opcode {
45 => Ok(fuse_opcode::FUSE_RENAME2),
#[cfg(feature = "abi-7-24")]
46 => Ok(fuse_opcode::FUSE_LSEEK),
#[cfg(feature = "abi-7-28")]
47 => Ok(fuse_opcode::FUSE_COPY_FILE_RANGE),

#[cfg(target_os = "macos")]
61 => Ok(fuse_opcode::FUSE_SETVOLNAME),
Expand Down Expand Up @@ -1073,3 +1077,15 @@ pub struct fuse_lseek_in {
pub struct fuse_lseek_out {
pub offset: i64,
}

#[repr(C)]
#[derive(Debug)]
pub struct fuse_copy_file_range_in {
pub fh_in: u64,
pub off_in: u64,
pub nodeid_out: u64,
pub fh_out: u64,
pub off_out: u64,
pub len: u64,
pub flags: u64,
}
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,23 @@ pub trait Filesystem {
reply.error(ENOSYS);
}

/// Copy the specified range from the source inode to the destination inode
fn copy_range(
&mut self,
_req: &Request<'_>,
_ino_in: u64,
_fh_in: u64,
_offset_in: u64,
_ino_out: u64,
_fh_out: u64,
_offset_out: u64,
_len: u64,
_flags: u64,
reply: ReplyWrite,
) {
reply.error(ENOSYS);
}

/// macOS only: Rename the volume. Set fuse_init_out.flags during init to
/// FUSE_VOL_RENAME to enable
#[cfg(target_os = "macos")]
Expand Down
10 changes: 10 additions & 0 deletions src/ll/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub enum Operation<'a> {
Lseek {
arg: &'a fuse_lseek_in,
},
#[cfg(feature = "abi-7-28")]
CopyFileRange {
arg: &'a fuse_copy_file_range_in,
},

#[cfg(target_os = "macos")]
SetVolName {
Expand Down Expand Up @@ -269,6 +273,8 @@ impl<'a> fmt::Display for Operation<'a> {
Operation::Rename2 { arg, name, newname } => write!(f, "RENAME2 name {:?}, newdir {:#018x}, newname {:?}", name, arg.newdir, newname),
#[cfg(feature = "abi-7-24")]
Operation::Lseek { arg } => write!(f, "LSEEK fh {}, offset {}, whence {}", arg.fh, arg.offset, arg.whence),
#[cfg(feature = "abi-7-28")]
Operation::CopyFileRange { arg } => write!(f, "COPY_FILE_RANGE fh_in {}, offset_in {}, fh_out {}, offset_out {}, inode_out {}, len {}", arg.fh_in, arg.off_in, arg.fh_out, arg.off_out, arg.nodeid_out, arg.len),

#[cfg(target_os = "macos")]
Operation::SetVolName { name } => write!(f, "SETVOLNAME name {:?}", name),
Expand Down Expand Up @@ -389,6 +395,10 @@ impl<'a> Operation<'a> {
},
#[cfg(feature = "abi-7-24")]
fuse_opcode::FUSE_LSEEK => Operation::Lseek { arg: data.fetch()? },
#[cfg(feature = "abi-7-28")]
fuse_opcode::FUSE_COPY_FILE_RANGE => {
Operation::CopyFileRange { arg: data.fetch()? }
}

#[cfg(target_os = "macos")]
fuse_opcode::FUSE_SETVOLNAME => Operation::SetVolName {
Expand Down
15 changes: 15 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ impl<'a> Request<'a> {
self.reply(),
);
}
#[cfg(feature = "abi-7-28")]
ll::Operation::CopyFileRange { arg } => {
se.filesystem.copy_range(
self,
self.request.nodeid(),
arg.fh_in,
arg.off_in,
arg.nodeid_out,
arg.fh_out,
arg.off_out,
arg.len,
arg.flags,
self.reply(),
);
}
#[cfg(target_os = "macos")]
ll::Operation::SetVolName { name } => {
se.filesystem.setvolname(self, name, self.reply());
Expand Down

0 comments on commit 17a192e

Please sign in to comment.