Skip to content

Commit 154d9a0

Browse files
committed
nix::fcntl add FcntlArg::F_READAHEAD for freebsd.
Set/clear the amount of read ahead for the file descriptor.
1 parent 5ef78a8 commit 154d9a0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ 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 amount for sequential access or
829+
/// disable it with 0 or to system default for any value < 0.
830+
#[cfg(target_os = "freebsd")]
831+
F_READAHEAD(c_int),
828832
// TODO: Rest of flags
829833
}
830834

@@ -962,6 +966,10 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
962966
F_TRANSFEREXTENTS(rawfd) => {
963967
libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd)
964968
},
969+
#[cfg(target_os = "freebsd")]
970+
F_READAHEAD(val) => {
971+
libc::fcntl(fd, libc::F_READAHEAD, val)
972+
},
965973
}
966974
};
967975

test/test_fcntl.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,22 @@ 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+
// With TMPDIR set with UFS, the vnode name is not entered
816+
// into the name cache thus path is always empty.
817+
// Therefore, we reopen the tempfile a second time for the test
818+
// to pass.
819+
let tmp2 = File::open(tmp.path()).unwrap();
820+
let mut res = fcntl(&tmp2, FcntlArg::F_READAHEAD(1_000_000))
821+
.expect("read ahead failed");
822+
assert_ne!(res, -1);
823+
res =
824+
fcntl(&tmp2, FcntlArg::F_READAHEAD(-1024)).expect("read ahead failed");
825+
assert_ne!(res, -1);
826+
}

0 commit comments

Comments
 (0)