diff --git a/changelog/2569.added.md b/changelog/2569.added.md new file mode 100644 index 0000000000..c9539d74b5 --- /dev/null +++ b/changelog/2569.added.md @@ -0,0 +1 @@ +Added `FcntlArg::F_READAHEAD` for FreeBSD target diff --git a/src/fcntl.rs b/src/fcntl.rs index 3a4c41926f..4bebe9c457 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -825,6 +825,11 @@ pub enum FcntlArg<'a> { /// Both descriptors must reference regular files in the same volume. #[cfg(apple_targets)] F_TRANSFEREXTENTS(RawFd), + /// Set or clear the read ahead (pre-fetch) amount for sequential access or + /// disable it with 0 or to system default for any value < 0. + /// It manages how the kernel caches file data. + #[cfg(target_os = "freebsd")] + F_READAHEAD(c_int), // TODO: Rest of flags } @@ -962,6 +967,10 @@ pub fn fcntl(fd: Fd, arg: FcntlArg) -> Result { F_TRANSFEREXTENTS(rawfd) => { libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd) }, + #[cfg(target_os = "freebsd")] + F_READAHEAD(val) => { + libc::fcntl(fd, libc::F_READAHEAD, val) + }, } }; diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 2068435b98..76c3b9f2dc 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -805,3 +805,16 @@ fn test_f_transferextents() { .expect("transferextents failed"); assert_ne!(res, -1); } + +#[cfg(target_os = "freebsd")] +#[test] +fn test_f_readahead() { + use nix::fcntl::*; + + let tmp = NamedTempFile::new().unwrap(); + let mut res = fcntl(&tmp, FcntlArg::F_READAHEAD(1_000_000)) + .expect("read ahead failed"); + assert_ne!(res, -1); + res = fcntl(&tmp, FcntlArg::F_READAHEAD(-1024)).expect("read ahead failed"); + assert_ne!(res, -1); +}