Skip to content

Conversation

Qelxiros
Copy link
Contributor

@Qelxiros Qelxiros commented Sep 8, 2025

This is the first of four smaller PRs that will eventually be equivalent to #139514.

A few notes:

  • I renamed new to open because open_dir takes &self and opens a subdirectory.
    • I also renamed open to open_file.
  • I'm not sure how to impl AsRawFd and friends because the common implementation uses PathBufs. 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*

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 8, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 10, 2025
@tgross35
Copy link
Contributor

@ChrisDenton I'll need your help for the Windows review

@Qelxiros
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 10, 2025
Copy link
Contributor

@tgross35 tgross35 left a 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).

View changes since this review

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

@tgross35
Copy link
Contributor

From the top post:

* I'm not sure how to `impl AsRawFd` and friends because the `common` implementation uses `PathBuf`s. How should I proceed here?

I think it would be fine to include the impl AsRawFd only in unix/dir so it's only implemented if we have dirfd. I'll add an unresolved question to the tracking issue.

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.

That is quite alright, there is no hurry :) For reference, the --update-refs rebase flag can be pretty useful when you're working with a stack (e.g. https://andrewlock.net/working-with-stacked-branches-in-git-is-easier-with-update-refs/)

@tgross35

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Sep 10, 2025
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
@rust-bors

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment was marked as outdated.

@tgross35

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Sep 10, 2025
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*
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Sep 11, 2025

💔 Test for ba4037e failed: CI. Failed jobs:

@@ -1,5 +1,6 @@
use rand::RngCore;

use super::Dir;
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a gate on miri to not be unused

@tgross35
Copy link
Contributor

@bors2 try

rust-bors bot added a commit that referenced this pull request Sep 11, 2025
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*
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Sep 11, 2025

💔 Test for 26d8112 failed: CI. Failed jobs:

@Qelxiros Qelxiros force-pushed the dirfd-minimum branch 2 times, most recently from 1f8f886 to 109188b Compare September 11, 2025 17:15
@tgross35
Copy link
Contributor

@bors2 try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 11, 2025
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*
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Sep 11, 2025

💔 Test for d36ef83 failed: CI. Failed jobs:

Comment on lines +61 to +65
if path.is_absolute() {
return File::open(path, opts);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does nt_create_file not accept absolute paths if a root is specified? A comment about why this is needed would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the check is removed (and add the check shown in the error message), I get this error.

thread 'fs::tests::test_dir_read_file' (6364) panicked at library\std\src\fs\tests.rs:2251:17:
dir.open_file(tmpdir.join("foo.txt")) failed with: The filename, directory name, or volume label syntax is incorrect. (os error 123)

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, does calling maybe_verbatim make a difference? Speculating, but maybe it doesn't like the Unix path join. Could you maybe debug dump the buffer from object_attributes.ObjectName in nt_create_file to see what it's trying to open?

and add the check shown in the error message

Which check is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dir.open_file(tmpdir.join("foo.txt"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by unix path join. TempDir::join calls out to Path::join, which uses PathBuf::push, which appears to have lots of Windows-specific logic (although it's largely not cfg-gated, so I could be wrong).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed that the path it's attempting to open is consistent with tmpdir path + "foo.txt".

For reference (from https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntcreatefile describing RootDirectory):
If this value is non-NULL, the ObjectName member specifies a file name relative to this directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking that .join() used a forward slash separator even on Windows - but I guess that's not accurate, looks like MAIN_SEP_STR is used. It would still be good to print it if you're able, to make sure it looks like a valid path, and to try to repro in C.

The error condition still seems weird - I don't see any mention of absolute paths at https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntcreatefile. We should at least be able to explain what's going on before adding our own check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you see my last message? I haven't reproduced in C, but I'm not sure I want to in a VM. The quote in my previous message seems ambiguous to me, so I'm not super surprised that it's a hard error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed I did not thanks. GH never seems to let me know if a new message appears while I'm typing.

Started some scratch work to test this out (not yet working for relative paths either though) https://godbolt.org/z/x81M1jdvf.

@tgross35
Copy link
Contributor

@bors2 try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 15, 2025
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*
@rust-bors
Copy link

rust-bors bot commented Sep 15, 2025

☀️ Try build successful (CI)
Build commit: 6864db0 (6864db0e62c9a69c5b6b3a45634c65cedb96ff25, parent: f3fd3efe4f698ad9dc2ccd6b46a3b07e1bc911da)

use crate::test_helpers::{TempDir, tmpdir};
use crate::time::{Duration, Instant, SystemTime};
use crate::{env, str, thread};
use crate::{env, io, str, thread};
Copy link
Contributor

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

@tgross35
Copy link
Contributor

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).

@tgross35
Copy link
Contributor

@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.

@Qelxiros
Copy link
Contributor Author

Qelxiros commented Oct 6, 2025

@ChrisDenton friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants