Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcntl: Adding F_TRANSFEREXTENTS fcntl constant for macOs. #2504

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, just realized that I missed this type when added I/O safety to this module. 😵‍💫

// 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);
}