-
Notifications
You must be signed in to change notification settings - Fork 683
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
fcntl adding apple F_PREALLOCATE flag. #2393
Conversation
I am working on the CI issues, they are not related to this PR Update: CI fixed in #2394, you can rebase your branch now:) |
Gentle ping on this PR, would you like to rebase and finish it? |
seems libc 0.2.154 not yet available (just the tag on the repo but not yet published maybe) ? |
Right, it has been yanked, we have to wait for rust-lang/libc#3682 |
The issue has been fixed, please rebase your branch:) |
src/fcntl.rs
Outdated
@@ -692,6 +692,9 @@ pub enum FcntlArg<'a> { | |||
/// Return the full path without firmlinks of the fd. | |||
#[cfg(apple_targets)] | |||
F_GETPATH_NOFIRMLINK(&'a mut PathBuf), | |||
/// Pre-allocate storage with different policies on fd. | |||
#[cfg(apple_targets)] | |||
F_PREALLOCATE(&'a libc::fstore_t), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The associated buffer has an OUT
field:
typedef struct fstore {
u_int32_t fst_flags; /* IN: flags word */
int fst_posmode; /* IN: indicates offset field */
off_t fst_offset; /* IN: start of the region */
off_t fst_length; /* IN: size of the region */
off_t fst_bytesalloc; /* OUT: number of bytes allocated */
} fstore_t;
i.e., the buffer can be written, if we use an immutable reference here, then UB could happen
Ref: https://keith.github.io/xcode-man-pages/fcntl.2.html#F_PREALLOCATE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried implementing this on my mac, I think we should create a helper type for those IN
fields, and return the OUT
field through fcntl()
.
For that fst_falgs
field, we would create a bitflags struct, for fst_posmode
, a Rust enum would suffice.
And F_ALLOCATEPERSIST is not available in libc, we should add it first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libc PR filed: rust-lang/libc#3713
Update: PR merged
6a30505
to
d5c26cc
Compare
@@ -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), | |||
/// Pre-allocate storage with different policies on fd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we shoud document the reason why a mutable reference is needed here? i.e., there is a OUT field in the associated sturcutre🤔
d5c26cc
to
c924b1b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Looks like you need to resolve the conflict in |
c924b1b
to
208c1da
Compare
208c1da
to
7d355e3
Compare
What does this PR do
Checklist:
CONTRIBUTING.md