Skip to content

Commit 08af3f8

Browse files
authored
nix::fcntl add FcntlArg::F_READAHEAD for freebsd. (#2569)
Set/clear the amount of read ahead for the file descriptor.
1 parent 5ef78a8 commit 08af3f8

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

changelog/2569.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `FcntlArg::F_READAHEAD` for FreeBSD target

src/fcntl.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,11 @@ pub enum FcntlArg<'a> {
825825
/// Both descriptors must reference regular files in the same volume.
826826
#[cfg(apple_targets)]
827827
F_TRANSFEREXTENTS(RawFd),
828+
/// Set or clear the read ahead (pre-fetch) amount for sequential access or
829+
/// disable it with 0 or to system default for any value < 0.
830+
/// It manages how the kernel caches file data.
831+
#[cfg(target_os = "freebsd")]
832+
F_READAHEAD(c_int),
828833
// TODO: Rest of flags
829834
}
830835

@@ -962,6 +967,10 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
962967
F_TRANSFEREXTENTS(rawfd) => {
963968
libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd)
964969
},
970+
#[cfg(target_os = "freebsd")]
971+
F_READAHEAD(val) => {
972+
libc::fcntl(fd, libc::F_READAHEAD, val)
973+
},
965974
}
966975
};
967976

test/test_fcntl.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,16 @@ fn test_f_transferextents() {
805805
.expect("transferextents failed");
806806
assert_ne!(res, -1);
807807
}
808+
809+
#[cfg(target_os = "freebsd")]
810+
#[test]
811+
fn test_f_readahead() {
812+
use nix::fcntl::*;
813+
814+
let tmp = NamedTempFile::new().unwrap();
815+
let mut res = fcntl(&tmp, FcntlArg::F_READAHEAD(1_000_000))
816+
.expect("read ahead failed");
817+
assert_ne!(res, -1);
818+
res = fcntl(&tmp, FcntlArg::F_READAHEAD(-1024)).expect("read ahead failed");
819+
assert_ne!(res, -1);
820+
}

0 commit comments

Comments
 (0)