Skip to content

Commit 4b6a5e3

Browse files
authored
fcntl: Adding F_TRANSFEREXTENTS fcntl constant for macOs. (#2504)
1 parent 8e5434c commit 4b6a5e3

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ targets = [
2828
]
2929

3030
[dependencies]
31-
libc = { version = "0.2.160", features = ["extra_traits"] }
31+
libc = { version = "0.2.164", features = ["extra_traits"] }
3232
bitflags = "2.3.3"
3333
cfg-if = "1.0"
3434
pin-utils = { version = "0.1.0", optional = true }

changelog/2504.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add FcntlArgs `F_TRANSFEREXTENTS` constant for Apple targets

src/fcntl.rs

+10
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,10 @@ 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+
libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd)
964+
},
955965
}
956966
};
957967

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)