Skip to content

Commit

Permalink
fcntl adding F_RDAHEAD for apple targets. (nix-rust#2482)
Browse files Browse the repository at this point in the history
Enable/disable read ahead globally on the file descriptor. When on,
 the os preemptively reads data in cache to anticipate future read
operations.
  • Loading branch information
devnexen authored Sep 5, 2024
1 parent e599223 commit 211f1ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/2482.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add fcntl constant `F_RDAHEAD` for Apple target
8 changes: 8 additions & 0 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ pub enum FcntlArg<'a> {
/// Issue an advisory read async with no copy to user
#[cfg(apple_targets)]
F_RDADVISE(libc::radvisory),
/// Turn read ahead off/on
#[cfg(apple_targets)]
F_RDAHEAD(bool)
// TODO: Rest of flags
}

Expand Down Expand Up @@ -912,6 +915,11 @@ pub fn fcntl<Fd: std::os::fd::AsFd>(fd: Fd, arg: FcntlArg) -> Result<c_int> {
F_RDADVISE(rad) => {
libc::fcntl(fd, libc::F_RDADVISE, &rad)
}
#[cfg(apple_targets)]
F_RDAHEAD(on) => {
let val = if on { 1 } else { 0 };
libc::fcntl(fd, libc::F_RDAHEAD, val)
}
}
};

Expand Down

0 comments on commit 211f1ab

Please sign in to comment.