Skip to content

Commit

Permalink
fcntl: Adding F_TRANSFEREXTENTS fcntl constant for macOs. (#2504)
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored Nov 18, 2024
1 parent 8e5434c commit 4b6a5e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions changelog/2504.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add FcntlArgs `F_TRANSFEREXTENTS` constant for Apple targets
10 changes: 10 additions & 0 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -952,6 +958,10 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
F_PREALLOCATE(st) => {
libc::fcntl(fd, libc::F_PREALLOCATE, st)
},
#[cfg(apple_targets)]
F_TRANSFEREXTENTS(rawfd) => {
libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd)
},
}
};

Expand Down
13 changes: 13 additions & 0 deletions test/test_fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 4b6a5e3

Please sign in to comment.