-
Notifications
You must be signed in to change notification settings - Fork 259
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
[1/3] Proper path resolution: add openat functionality #2254
base: main
Are you sure you want to change the base?
Conversation
c4eb9c5
to
63aac67
Compare
26f2ef6
to
6debef3
Compare
This commit adds the `openat` functionality to `sys.FS`. On UNIX-like platforms, this is done with the `openat(2)` syscall. On Windows, this is done with [`NtCreateFile`][1]. This is the first in a series of commit that overhauls how paths are resolved. The wasi-filesystem spec now [describes][2] a path resolution implementation that uses `openat`. [1]: https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntcreatefile [2]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md Signed-off-by: Yage Hu <[email protected]>
6debef3
to
ea28b4d
Compare
Signed-off-by: Yage Hu <[email protected]>
Signed-off-by: Yage Hu <[email protected]>
1c64d11
to
107be03
Compare
Signed-off-by: Yage Hu <[email protected]>
Signed-off-by: Yage Hu <[email protected]>
a960173
to
7f90143
Compare
Signed-off-by: Yage Hu <[email protected]>
7f90143
to
2dd5cda
Compare
796b45e
to
8b8f220
Compare
Signed-off-by: Yage Hu <[email protected]>
8b8f220
to
00f22bb
Compare
4071412
to
00f22bb
Compare
FYI I can't stack PRs on top of this one because I can't push branches to this repo. |
@@ -71,7 +72,7 @@ func (r *ReadFS) Utimens(path string, atim, mtim int64) experimentalsys.Errno { | |||
} | |||
|
|||
// compile-time check to ensure readFile implements api.File. | |||
var _ experimentalsys.File = (*readFile)(nil) | |||
var _ fsapi.File = (*readFile)(nil) |
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.
this was intentionally implementing only the experimental public VFS API. In fact I think this experimental VFS should not expose OpenAt
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.
Thanks for the context! I had thought it was an oversight.
OpenAt( | ||
fs experimentalsys.FS, | ||
path string, | ||
flag experimentalsys.Oflag, | ||
mode fs.FileMode, | ||
) (experimentalsys.File, experimentalsys.Errno) |
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 we really need to expose this at this level?
the reason I am asking is that this obviously only applies to hierarchical FSs, but it won't work (as you can see later) on other types of file descriptors such as sockets or stdin/err/out. Could it be possible to keep this internal and limited to tree-like file systems?
Essentially, the final goal of this (series of) PR is to introduce an API that will reproduce the correct behavior when resolving paths, so it would great if we can scope it only to files for which "paths" make sense.
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.
It definitely doesn't need to be exposed at this level. I misunderstood your last comment and thought you wanted the method moved from the public interface to a private one.
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.
well, that was a fair assumption, but I was wondering if we could keep it as an implementation detail of Open for those FSs that need hierarchical file access 🤔
Quick update: I'm on a cross-country move at the moment. Will get around to this again after mid-August. Thanks for the speedy reviews @evacchi |
This PR is the first in a series that will implement the path resolution algorithm described by wasi-filesystem. Since this new path resolution implementation requires the use of
openat
, this PR first introducesopenat(2)
and its Windows equivalentNtCreateFile
to Wazero.openat(2)
openat(2)
NtCreateFile
internal/sysfs/dirfs_test.go
The next PR will stack on this one and use the
openat
functionality to implement path resolution.