Skip to content

Commit 96ca676

Browse files
committed
fcntl: Adding F_TRANSFEREXTENTS fcntl constant for macOs.
1 parent 6cfbf2d commit 96ca676

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/fcntl.rs

+12
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ pub enum FcntlArg<'a> {
819819
/// is used as both IN/OUT as both its l2p_devoffset and
820820
/// l2p_contigbytes can be used for more specific queries.
821821
F_LOG2PHYS_EXT(&'a mut libc::log2phys),
822+
/// Transfer any extra space in the file past the logical EOF
823+
/// (as previously allocated via F_PREALLOCATE) to another file.
824+
/// The other file is specified via a file descriptor as the lone extra argument.
825+
/// Both descriptors must reference regular files in the same volume.
826+
#[cfg(apple_targets)]
827+
F_TRANSFEREXTENTS(RawFd),
822828
// TODO: Rest of flags
823829
}
824830

@@ -952,6 +958,12 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
952958
F_PREALLOCATE(st) => {
953959
libc::fcntl(fd, libc::F_PREALLOCATE, st)
954960
},
961+
#[cfg(apple_targets)]
962+
F_TRANSFEREXTENTS(rawfd) => {
963+
// FIXME: ongoing (PR)[https://github.com/rust-lang/libc/pull/3925/files]
964+
const F_TRANSFEREXTENTS: c_int = 110;
965+
libc::fcntl(fd, F_TRANSFEREXTENTS, rawfd)
966+
},
955967
}
956968
};
957969

test/test_fcntl.rs

+13
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,16 @@ fn test_f_log2phys() {
792792
assert_ne!(res, -1);
793793
assert_ne!({ info.l2p_devoffset }, 3);
794794
}
795+
796+
#[cfg(apple_targets)]
797+
#[test]
798+
fn test_f_transferextents() {
799+
use nix::fcntl::*;
800+
use std::os::fd::AsRawFd;
801+
802+
let tmp1 = NamedTempFile::new().unwrap();
803+
let tmp2 = NamedTempFile::new().unwrap();
804+
let res = fcntl(&tmp1, FcntlArg::F_TRANSFEREXTENTS(tmp2.as_raw_fd()))
805+
.expect("transferextents failed");
806+
assert_ne!(res, -1);
807+
}

0 commit comments

Comments
 (0)