Skip to content

Commit 8416345

Browse files
committed
fcntl adding apple F_PREALLOCATE flag.
1 parent e599223 commit 8416345

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/fcntl.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ pub enum FcntlArg<'a> {
800800
/// Issue an advisory read async with no copy to user
801801
#[cfg(apple_targets)]
802802
F_RDADVISE(libc::radvisory),
803+
/// Pre-allocate storage with different policies on fd.
804+
#[cfg(apple_targets)]
805+
F_PREALLOCATE(&mut 'a libc::fstore_t),
803806
// TODO: Rest of flags
804807
}
805808

@@ -912,6 +915,10 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
912915
F_RDADVISE(rad) => {
913916
libc::fcntl(fd, libc::F_RDADVISE, &rad)
914917
}
918+
#[cfg(apple_targets)]
919+
F_PREALLOCATE(st) => {
920+
libc::fcntl(fd, libc::F_PREALLOCATE, st)
921+
},
915922
}
916923
};
917924

test/test_fcntl.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,25 @@ fn test_f_get_path() {
581581
);
582582
}
583583

584+
#[cfg(apple_targets)]
585+
#[test]
586+
fn test_f_preallocate() {
587+
use nix::fcntl::*;
588+
use std::os::unix::io::AsRawFd;
589+
590+
let tmp = NamedTempFile::new().unwrap();
591+
let fd = tmp.as_raw_fd();
592+
let mut st: libc::fstore_t = unsafe { std::mem::zeroed() };
593+
594+
st.fst_flags = libc::F_ALLOCATECONTIG as libc::c_uint;
595+
st.fst_posmode = libc::F_PEOFPOSMODE;
596+
st.fst_length = 1024;
597+
let res =
598+
fcntl(fd, FcntlArg::F_PREALLOCATE(&st)).expect("preallocation failed");
599+
600+
assert_eq!(res, 0);
601+
}
602+
584603
#[cfg(apple_targets)]
585604
#[test]
586605
fn test_f_get_path_nofirmlink() {

0 commit comments

Comments
 (0)