diff --git a/Cargo.toml b/Cargo.toml index 213e716b78..e60c9ce52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ ] [dependencies] -libc = { version = "0.2.160", features = ["extra_traits"] } +libc = { version = "0.2.164", features = ["extra_traits"] } bitflags = "2.3.3" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } diff --git a/changelog/2504.added.md b/changelog/2504.added.md new file mode 100644 index 0000000000..562b081380 --- /dev/null +++ b/changelog/2504.added.md @@ -0,0 +1 @@ +Add FcntlArgs `F_TRANSFEREXTENTS` constant for Apple targets diff --git a/src/fcntl.rs b/src/fcntl.rs index a233c2fcde..67e3a7c2b5 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -819,6 +819,12 @@ pub enum FcntlArg<'a> { /// is used as both IN/OUT as both its l2p_devoffset and /// l2p_contigbytes can be used for more specific queries. F_LOG2PHYS_EXT(&'a mut libc::log2phys), + /// Transfer any extra space in the file past the logical EOF + /// (as previously allocated via F_PREALLOCATE) to another file. + /// The other file is specified via a file descriptor as the lone extra argument. + /// Both descriptors must reference regular files in the same volume. + #[cfg(apple_targets)] + F_TRANSFEREXTENTS(RawFd), // TODO: Rest of flags } @@ -952,6 +958,10 @@ pub fn fcntl(fd: Fd, arg: FcntlArg) -> Result { F_PREALLOCATE(st) => { libc::fcntl(fd, libc::F_PREALLOCATE, st) }, + #[cfg(apple_targets)] + F_TRANSFEREXTENTS(rawfd) => { + libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd) + }, } }; diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index e59eecec8e..2068435b98 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -792,3 +792,16 @@ fn test_f_log2phys() { assert_ne!(res, -1); assert_ne!({ info.l2p_devoffset }, 3); } + +#[cfg(apple_targets)] +#[test] +fn test_f_transferextents() { + use nix::fcntl::*; + use std::os::fd::AsRawFd; + + let tmp1 = NamedTempFile::new().unwrap(); + let tmp2 = NamedTempFile::new().unwrap(); + let res = fcntl(&tmp1, FcntlArg::F_TRANSFEREXTENTS(tmp2.as_raw_fd())) + .expect("transferextents failed"); + assert_ne!(res, -1); +}