Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix::fcntl add FcntlArg::F_READAHEAD for freebsd. #2569

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2569.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `FcntlArg::F_READAHEAD` for FreeBSD target
9 changes: 9 additions & 0 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something related to the kernel page cache, something used to control the pre-fetch strategy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it manages file data caching yes. will adjust the comment.

// TODO: Rest of flags
}

Expand Down Expand Up @@ -962,6 +967,10 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
F_TRANSFEREXTENTS(rawfd) => {
libc::fcntl(fd, libc::F_TRANSFEREXTENTS, rawfd)
},
#[cfg(target_os = "freebsd")]
F_READAHEAD(val) => {
libc::fcntl(fd, libc::F_READAHEAD, val)
},
}
};

Expand Down
13 changes: 13 additions & 0 deletions test/test_fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading