Skip to content

Commit 037b27f

Browse files
committed
fcntl adding apple F_PREALLOCATE flag.
1 parent 590ab4d commit 037b27f

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
@@ -692,6 +692,9 @@ pub enum FcntlArg<'a> {
692692
/// Return the full path without firmlinks of the fd.
693693
#[cfg(apple_targets)]
694694
F_GETPATH_NOFIRMLINK(&'a mut PathBuf),
695+
/// Pre-allocate storage with different policies on fd.
696+
#[cfg(apple_targets)]
697+
F_PREALLOCATE(&'a libc::fstore_t),
695698
// TODO: Rest of flags
696699
}
697700

@@ -797,6 +800,10 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
797800
*path = PathBuf::from(OsString::from(optr.to_str().unwrap()));
798801
return Ok(ok_res)
799802
},
803+
#[cfg(apple_targets)]
804+
F_PREALLOCATE(st) => {
805+
libc::fcntl(fd, libc::F_PREALLOCATE, st)
806+
},
800807
}
801808
};
802809

test/test_fcntl.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,25 @@ fn test_f_get_path() {
630630
);
631631
}
632632

633+
#[cfg(apple_targets)]
634+
#[test]
635+
fn test_f_preallocate() {
636+
use nix::fcntl::*;
637+
use std::os::unix::io::AsRawFd;
638+
639+
let tmp = NamedTempFile::new().unwrap();
640+
let fd = tmp.as_raw_fd();
641+
let mut st: libc::fstore_t = unsafe { std::mem::zeroed() };
642+
643+
st.fst_flags = libc::F_ALLOCATECONTIG as libc::c_uint;
644+
st.fst_posmode = libc::F_PEOFPOSMODE;
645+
st.fst_length = 1024;
646+
let res =
647+
fcntl(fd, FcntlArg::F_PREALLOCATE(&st)).expect("preallocation failed");
648+
649+
assert_eq!(res, 0);
650+
}
651+
633652
#[cfg(apple_targets)]
634653
#[test]
635654
fn test_f_get_path_nofirmlink() {

0 commit comments

Comments
 (0)