Skip to content

Commit aa17513

Browse files
committed
fcntl adding apple F_PREALLOCATE flag.
1 parent c5af4ad commit aa17513

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
@@ -626,6 +626,25 @@ fn test_f_get_path() {
626626
);
627627
}
628628

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

0 commit comments

Comments
 (0)