-
Notifications
You must be signed in to change notification settings - Fork 13.9k
minimal dirfd implementation (1/4) #146341
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
base: master
Are you sure you want to change the base?
Conversation
c3278f6
to
6982a46
Compare
This comment has been minimized.
This comment has been minimized.
6982a46
to
313c731
Compare
This comment has been minimized.
This comment has been minimized.
313c731
to
1b3d7d6
Compare
This comment has been minimized.
This comment has been minimized.
1b3d7d6
to
be0d761
Compare
@ChrisDenton I'll need your help for the Windows review |
be0d761
to
3083d58
Compare
@rustbot ready |
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.
Looks pretty good to me, just a few mechanical things here. There are a couple left over from the previous review, #146341 (comment), #146341 (comment), and (newly) #146341 (comment).
let mut handle = ptr::null_mut(); | ||
let mut io_status = c::IO_STATUS_BLOCK::PENDING; | ||
let access = opts.get_access_mode()? | c::SYNCHRONIZE; | ||
let options = create_options | c::FILE_SYNCHRONOUS_IO_NONALERT; |
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.
Could you add a note about why this flag is set?
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 no longer remember why I chose this one, and looking at it now, I'm not sure whether we should set this one, FILE_SYNCHRONOUS_IO_ALERT
, or neither. Maybe @ChrisDenton has thoughts?
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.
Update, using neither causes an error, so I've added back FILE_SYNCHRONOUS_IO_NONALERT
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.
Yeah, passing this flag is equivalent to not passing FILE_FLAG_OVERLAPPED to CreateFile. So if you don't pass this flag, other APIs using the handle need to follow the usual overlapped rules, otherwise they may behave improperly.
From the top post:
I think it would be fine to include the
That is quite alright, there is no hurry :) For reference, the |
This comment was marked as outdated.
This comment was marked as outdated.
minimal dirfd implementation (1/4) try-job: aarch64-apple try-job: dist-various* try-job: test-various* try-job: x86_64-msvc* try-job: x86_64-mingw
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
minimal dirfd implementation (1/4) try-job: aarch64-apple try-job: dist-various* try-job: test-various* try-job: x86_64-msvc* try-job: x86_64-mingw*
minimal dirfd implementation (1/4) try-job: aarch64-apple try-job: dist-various* try-job: test-various* try-job: x86_64-msvc-1 try-job: x86_64-mingw*
a37578d
to
cfbcd8b
Compare
library/std/src/fs/tests.rs
Outdated
use crate::test_helpers::{TempDir, tmpdir}; | ||
use crate::time::{Duration, Instant, SystemTime}; | ||
use crate::{env, str, thread}; | ||
use crate::{env, io, str, thread}; |
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.
io
needs the cfg(not(miri))
gate as well
Status update: the current implementation looks pretty good to me, but I'd Chris or somebody more familiar with Windows to take a look at that bit. It would still be good to add comments about the flags used to make the incantation a bit less magic without referring to the docs (e.g. FILE_SYNCHRONOUS_IO_NONALERT, FILE_FLAG_BACKUP_SEMANTICS). |
cfbcd8b
to
18a93b3
Compare
@ChrisDenton would you be able to take a look at the windows impl here? Feel free to punt this bit to somebody else as well, just needs a second set of eyes since I'm not super familiar here. |
@ChrisDenton friendly ping |
Heya @wesleywiser or @dpaoliello would one of you mind giving a quick look at the Windows bits here? To me it looks pretty reasonable, but I'm not very familiar with the winternl APIs so would appreciate a sanity check. |
I'll see if I can find an expert to help. I'm not familiar enough with these APIs to have any confidence reviewing. |
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.
Looks reasonable.
windows_targets::link!("ntdll.dll" "system" fn NtCreateFile(filehandle : *mut HANDLE, desiredaccess : FILE_ACCESS_RIGHTS, objectattributes : *const OBJECT_ATTRIBUTES, iostatusblock : *mut IO_STATUS_BLOCK, allocationsize : *const i64, fileattributes : FILE_FLAGS_AND_ATTRIBUTES, shareaccess : FILE_SHARE_MODE, createdisposition : NTCREATEFILE_CREATE_DISPOSITION, createoptions : NTCREATEFILE_CREATE_OPTIONS, eabuffer : *const core::ffi::c_void, ealength : u32) -> NTSTATUS); | ||
windows_targets::link!("ntdll.dll" "system" fn NtOpenFile(filehandle : *mut HANDLE, desiredaccess : u32, objectattributes : *const OBJECT_ATTRIBUTES, iostatusblock : *mut IO_STATUS_BLOCK, shareaccess : u32, openoptions : u32) -> NTSTATUS); | ||
windows_targets::link!("ntdll.dll" "system" fn NtReadFile(filehandle : HANDLE, event : HANDLE, apcroutine : PIO_APC_ROUTINE, apccontext : *const core::ffi::c_void, iostatusblock : *mut IO_STATUS_BLOCK, buffer : *mut core::ffi::c_void, length : u32, byteoffset : *const i64, key : *const u32) -> NTSTATUS); | ||
windows_targets::link!("ntdll.dll" "system" fn NtSetInformationFile(filehandle : HANDLE, iostatusblock : *mut IO_STATUS_BLOCK, fileinformation : *const core::ffi::c_void, length : u32, fileinformationclass : FILE_INFORMATION_CLASS) -> NTSTATUS); |
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.
nit: These changes to expose the NT rename APIs don't seem to be necessary for this PR. They probably should go in a later PR in the series.
☔ The latest upstream changes (presumably #147838) made this pull request unmergeable. Please resolve the merge conflicts. |
For the suggestion above and a rebase, @rustbot author |
Reminder, once the PR becomes ready for a review, use |
18a93b3
to
70ea0df
Compare
This comment has been minimized.
This comment has been minimized.
70ea0df
to
fedd376
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
fedd376
to
1624481
Compare
@rustbot ready |
@bors2 try |
minimal dirfd implementation (1/4) try-job: aarch64-apple try-job: dist-various* try-job: test-various* try-job: x86_64-msvc-1 try-job: x86_64-mingw*
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test for 7d804a8 failed: CI. Failed jobs:
|
This is the first of four smaller PRs that will eventually be equivalent to #139514.
A few notes:
new
toopen
becauseopen_dir
takes&self
and opens a subdirectory.open
toopen_file
.impl AsRawFd
and friends because thecommon
implementation usesPathBuf
s. How should I proceed here?The other PRs will be based on this one, so I'll make drafts and mark them ready as their predecessors get merged. They might take a bit though; I've never done this particular thing with git before.
Tracking issue: #120426
r? @tgross35
try-job: aarch64-apple
try-job: dist-various*
try-job: test-various*
try-job: x86_64-msvc-1
try-job: x86_64-mingw*