From 1f0d6c81f3330f42b0845c41c11d43ede92b0d4b Mon Sep 17 00:00:00 2001 From: Sherlock Holo Date: Mon, 20 Feb 2023 11:06:33 +0800 Subject: [PATCH] feat: add write_flags arguments in the write operation --- Cargo.toml | 2 +- examples/src/memfs/main.rs | 1 + examples/src/path_memfs/main.rs | 4 +++- src/path/inode_path_bridge.rs | 2 ++ src/path/path_filesystem.rs | 6 +++++- src/raw/filesystem.rs | 6 +++++- src/raw/flags.rs | 12 ++++++++++++ src/raw/mod.rs | 1 + src/raw/session.rs | 1 + 9 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/raw/flags.rs diff --git a/Cargo.toml b/Cargo.toml index 5732440..139fdde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fuse3" -version = "0.6.1" +version = "0.7.0" authors = ["Sherlock Holo "] edition = "2021" readme = "README.md" diff --git a/examples/src/memfs/main.rs b/examples/src/memfs/main.rs index 08422d9..a38544b 100644 --- a/examples/src/memfs/main.rs +++ b/examples/src/memfs/main.rs @@ -554,6 +554,7 @@ impl Filesystem for Fs { _fh: u64, offset: u64, mut data: &[u8], + _write_flags: u32, _flags: u32, ) -> Result { let inner = self.0.read().await; diff --git a/examples/src/path_memfs/main.rs b/examples/src/path_memfs/main.rs index af65aa9..d5c7953 100644 --- a/examples/src/path_memfs/main.rs +++ b/examples/src/path_memfs/main.rs @@ -518,6 +518,7 @@ impl PathFilesystem for Fs { _fh: u64, offset: u64, data: &[u8], + _write_flags: u32, _flags: u32, ) -> Result { let path = path.ok_or_else(Errno::new_not_exist)?.to_string_lossy(); @@ -861,8 +862,9 @@ impl PathFilesystem for Fs { .read(req, from_path, fh_in, offset_in, length as _) .await?; + // write_flags set to 0 because we don't care it in this example implement let ReplyWrite { written } = self - .write(req, to_path, fh_out, offset_out, &data.data, flags as _) + .write(req, to_path, fh_out, offset_out, &data.data, 0, flags as _) .await?; Ok(ReplyCopyFileRange { diff --git a/src/path/inode_path_bridge.rs b/src/path/inode_path_bridge.rs index 490e2e7..8c403c2 100644 --- a/src/path/inode_path_bridge.rs +++ b/src/path/inode_path_bridge.rs @@ -574,6 +574,7 @@ where fh: u64, offset: u64, data: &[u8], + write_flags: u32, flags: u32, ) -> Result { let path = self @@ -589,6 +590,7 @@ where fh, offset, data, + write_flags, flags, ) .await diff --git a/src/path/path_filesystem.rs b/src/path/path_filesystem.rs index fc445d1..768703b 100644 --- a/src/path/path_filesystem.rs +++ b/src/path/path_filesystem.rs @@ -194,7 +194,10 @@ pub trait PathFilesystem { /// exception to this is when the file has been opened in `direct_io` mode, in which case the /// return value of the write system call will reflect the return value of this operation. `fh` /// will contain the value set by the open method, or will be undefined if the open method - /// didn't set any value. when `path` is None, it means the path may be deleted. + /// didn't set any value. When `path` is None, it means the path may be deleted. When + /// `write_flags` contains [`FUSE_WRITE_CACHE`](crate::raw::flags::FUSE_WRITE_CACHE), means the + /// write operation is a delay write. + #[allow(clippy::too_many_arguments)] async fn write( &self, req: Request, @@ -202,6 +205,7 @@ pub trait PathFilesystem { fh: u64, offset: u64, data: &[u8], + write_flags: u32, flags: u32, ) -> Result { Err(libc::ENOSYS.into()) diff --git a/src/raw/filesystem.rs b/src/raw/filesystem.rs index 0bd1f14..d961ea7 100644 --- a/src/raw/filesystem.rs +++ b/src/raw/filesystem.rs @@ -184,7 +184,10 @@ pub trait Filesystem { /// exception to this is when the file has been opened in `direct_io` mode, in which case the /// return value of the write system call will reflect the return value of this operation. `fh` /// will contain the value set by the open method, or will be undefined if the open method - /// didn't set any value. + /// didn't set any value. When `write_flags` contains + /// [`FUSE_WRITE_CACHE`](crate::raw::flags::FUSE_WRITE_CACHE), means the write operation is a + /// delay write. + #[allow(clippy::too_many_arguments)] async fn write( &self, req: Request, @@ -192,6 +195,7 @@ pub trait Filesystem { fh: u64, offset: u64, data: &[u8], + write_flags: u32, flags: u32, ) -> Result { Err(libc::ENOSYS.into()) diff --git a/src/raw/flags.rs b/src/raw/flags.rs new file mode 100644 index 0000000..2809792 --- /dev/null +++ b/src/raw/flags.rs @@ -0,0 +1,12 @@ +//! request flags. + +pub use crate::raw::abi::FUSE_IOCTL_32BIT; +pub use crate::raw::abi::FUSE_IOCTL_COMPAT; +pub use crate::raw::abi::FUSE_IOCTL_DIR; +pub use crate::raw::abi::FUSE_IOCTL_MAX_IOV; +pub use crate::raw::abi::FUSE_IOCTL_RETRY; +pub use crate::raw::abi::FUSE_IOCTL_UNRESTRICTED; +pub use crate::raw::abi::FUSE_POLL_SCHEDULE_NOTIFY; +pub use crate::raw::abi::FUSE_READ_LOCKOWNER; +pub use crate::raw::abi::FUSE_WRITE_CACHE; +pub use crate::raw::abi::FUSE_WRITE_LOCKOWNER; diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 0f0747d..078342b 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -14,6 +14,7 @@ pub use session::{MountHandle, Session}; pub(crate) mod abi; mod connection; mod filesystem; +pub mod flags; pub mod reply; mod request; pub(crate) mod session; diff --git a/src/raw/session.rs b/src/raw/session.rs index c67cdbe..ada67c7 100644 --- a/src/raw/session.rs +++ b/src/raw/session.rs @@ -1873,6 +1873,7 @@ impl Session { write_in.fh, write_in.offset, &data, + write_in.write_flags, write_in.flags, ) .await