Commit Graph

38 Commits

Author SHA1 Message Date
Crypt Keeper
2f2b6a9d2c sysfs: Makes ReadFS and AdaptFS embeddable (#1607)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-08-02 08:27:50 +08:00
Crypt Keeper
1f8c908f1c Exposes writeable filesystem as experimentalsys.FS (#1605)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-31 07:56:28 +08:00
Crypt Keeper
2382bbf730 sysfs: decouples FS and File from the syscall package (#1602)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-30 16:06:22 +08:00
Crypt Keeper
fb6147ca94 Emulates AT_SYMLINK_NOFOLLOW instead of sometimes implementing it (#1588)
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-22 08:03:47 +08:00
Crypt Keeper
b842d6cbfd fsapi: adds Oflag to decouple from syscall package (#1586)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-19 16:01:44 +08:00
Crypt Keeper
2f8dd23097 adds experimental sys.Errno to begin decoupling from the syscall package (#1582)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-17 08:13:29 +08:00
Crypt Keeper
0ec3c852d6 fs: pares down to functions used in wasip1 and wasip2 (#1563)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-07 07:58:36 +08:00
Crypt Keeper
d7193952e1 Allows wrapped filesystems to return dirent.ino except in windows (#1558)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-05 17:41:35 +08:00
Crypt Keeper
820685c4b2 Simplifies filesystem implementations (#1548)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-01 06:53:09 +08:00
Crypt Keeper
34324031cb extracts FS interfaces into fsapi package and consolidates impls (#1477)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-17 07:19:54 +03:00
Crypt Keeper
2ad2921eed Separates fs.File from os.File implementations of platform.File (#1455)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-15 13:42:20 +08:00
Crypt Keeper
16baeaab47 Adds Readdir to platform.File and removes internal use of fs.FS (#1454)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-11 10:04:34 +08:00
Crypt Keeper
29c7c7667b Adds IsDir and Seek to platform.File (#1441)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-09 07:47:25 +08:00
Adrian Cole
cf5ebf6f6b Use require.ErrnoEquals for more precise failures
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-03 13:54:12 +08:00
Crypt Keeper
493fe2d410 sysfs: stubs in approach to defining a new file type (#1290)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-01 12:33:40 +08:00
Crypt Keeper
36bf277534 sysfs: requires all methods to return syscall.Errno (#1264)
This forces all syscall functions, notably filesystem, to return numeric
codes as opposed to mapping in two different areas. The result of this
change is better consolidation in call sites of `sysfs.FS`, while
further refactoring is needed to address consolidation of file errors.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-22 07:47:57 +01:00
Adrian Cole
a43a0f11e4 Revert "sysfs: requires all methods to return syscall.Errno"
This reverts commit 4ea9d1a7b5.
2023-03-21 22:22:36 +08:00
Adrian Cole
4ea9d1a7b5 sysfs: requires all methods to return syscall.Errno
This forces all syscall functions, notably filesystem, to return numeric
codes as opposed to mapping in two different areas. The result of this
change is better consolidation in call sites of `sysfs.FS`, while
further refactoring is needed to address consolidation of file errors.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-21 22:20:28 +08:00
Crypt Keeper
c46a6eb4ae sysfs: return st instead of accepting it (#1261)
This returns stat as a value instead of a pointer param. This is both
more efficient and faster. It is also more efficient than returning a
pointer to a stat.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-21 10:57:19 +08:00
Crypt Keeper
f3c83dbd8d dirfs: corrects path joining bug when mounting root (#1228)
Before, we created invalid directory paths when the host directory was
"/", and now we don't!

This brings tests left failing on GOOS=js to 7
```bash
$ wazero run -mount=/:/ --experimental-workdir=$(go env GOROOT)/src/os os.wasm| grep '^--- FAIL'|wc -l
       7
```

See #1222

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-14 07:30:12 +08:00
Crypt Keeper
7e953d7483 gojs: introduces --experimental-workdir CLI arg (#1226)
When compiled to `GOOS=js`, wasm does not maintain the working
directory: it is defined by the host. While not explicitly documented,
`os.TestDirFSRootDir` in Go suggests the working directory must be valid
to pass (literally the directory holding the file).

This adds an experimental CLI flag that gives the initial working
directory. This is experimental because while GOOS=js uses this, current
WASI compilers will not, as they maintain working directory in code
managed by wasi-libc, or as a convention (e.g. in Zig).

It is not yet known if wasi-cli will maintain working directory
externally or not.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-13 15:43:45 +08:00
Crypt Keeper
41ef17c5c2 wasi: implements path_filestat_set_times (#1220)
This implements `path_filestat_set_times` which is the last remaining filesystem function in wasi we formerly stubbed.

Other minor changes:
* this removes all places we import alias path as pathutil, introducing a utility function `joinPath` where that was used to reduce name conflicts.
* this fixes places where we used different variable names for the same parameter between main and test source.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-13 09:46:17 +08:00
Crypt Keeper
4d90a5c364 platform: Allows sysfs to implement utimens natively (#1215)
platform: Allows sysfs to implement utimesns natively

This moves away from `syscall.UtimesNano` as it has intentionally
avoided common features in POSIX, such as handling UTIME_NOW and
UTIME_OMIT. When we eventually expose this API, users will be free to
override `UTIME_NOW` with a fake clock, possibly the same that was
supplied to wazero's `ModuleConfig`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-09 13:14:09 +08:00
Crypt Keeper
f5d194c43c wasi: implements platform.UtimesFile for fd_filestat_set_times (#1199)
This implements `platform.UtimesFile` which is similar to futimes.
Before, we were using path-based functionality even though the call site
was for a file descriptor.

Note: right now, there's no obvious code in Go to invoke the `futimens`
syscall. This means non-windows isn't implemented at nanos granularity,
so ends up falling back to the path based option.

Finally, this removes tests for the seldom supported updates with
negative epoch time. There's little impact to this as setting times on
files before 1970 isn't a typical use case.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-07 13:44:46 +08:00
Crypt Keeper
e77f24fe31 sysfs: drops os.File special casing for fs.FS to pass wasi-testsuite (#1174)
This adds a wazero adapter which passes wasi-testsuite 100pct on darwin,
linux and windows. While the main change was adding inodes to the wasi
`fd_readdir` dirents, there was a lot of incidental work needed.

Most of the work was troubleshooting in nature, around windows
specifically, but also wrapping of files. This backfills a lot of tests
and reworked how wrapping works, particularly around windows.

To accommodate this, we drop `os.File` special casing except for
`sysfs.DirFS`

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-01 13:28:57 +08:00
Crypt Keeper
3d5b6d609a implements lstat and fixes inode stat on windows go 1.20 (#1168)
gojs: implements lstat

This implements platform.Lstat and uses it in GOOS=js. Notably,
directory listings need to run lstat on their entries to get the correct
inodes back. In GOOS=js, directories are a fan-out of names, then lstat.

This also fixes stat for inodes on directories. We were missing a test
so we didn't know it was broken on windows. The approach used now is
reliable on go 1.20, and we should suggest anyone using windows to
compile with go 1.20.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-28 07:20:31 +08:00
Takeshi Yoneda
d955cd7a13 windows: fixes unlinking symlink to dir, rmdir on opened empty dir. (#1172)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-27 16:23:54 +09:00
Crypt Keeper
4ca0858e57 sysfs: adds FS.Stat and companions in platform (#1140)
This centralizes filestat logic by making our own `Stat_t` similar to
`syscall.Stat_t`. This exposes utilities in the platform package and
adds a new function `FS.Stat` which avoids having to use `fs.File` to
get the same info. Doing so at the FS abstraction allows us to optimize
how it is implemented internally using portable means (e.g.
`os.StatFile`) or OS-specific means where necessary, e.g. in windows.

This also ensures `platform.OpenFile` returns syscall.Errno and
centralizes error checking with a new `require.EqualErrno` test.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-21 10:13:37 +08:00
Crypt Keeper
e2ebce5d23 sysfs: adds chmod (#1135)
This adds `FS.Chmod` and implements it for `GOOS=js`. This function
isn't defined in WASI snapshot01, but it is in `wasi-filesystem`, e.g.
`change-file-permissions-at`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-17 20:55:03 +09:00
Crypt Keeper
882b764437 sysfs: consolidates errno coersion and maps EAGAIN and EINTR (#1113)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-10 14:50:05 +09:00
Crypt Keeper
8918d73020 ci: supports building with Go 1.20 and raises floor version to 1.18 (#1096)
This moves our floor version to the same we'll release 1.0 with: 1.18.
This is congruent with our version policy which is current-2.

Fixes #921

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-06 17:29:08 +02:00
Takeshi Yoneda
ebc2d97c2a wasi: implements link related system calls (#1057)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-01 12:06:44 +02:00
Takeshi Yoneda
e6cc2a1231 wasi(windows): fixes readdir on written-after-opened directories (#1087)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-01 17:24:09 +09:00
Crypt Keeper
f040753053 fs: handles windows edge cases on rename (#1086)
This handles edge cases on rename which were previously skipped in
testing. Notably, there are delete flags not possible to propagate in
current versions of go, which imply some copy/paste meanwhile.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-31 13:56:49 +02:00
Crypt Keeper
a60debc8d2 wasi: implements fd_filestat_set_size and fd_filestat_set_times (#1082)
This implements fd_filestat_set_size and fd_filestat_set_times, which
passes one more test in the rust wasi-testsuite.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-30 19:08:10 +02:00
Crypt Keeper
cc68f8ee12 fs: adds FSConfig to replace experimental writefs (#1061)
This adds a new top-level type FSConfig, which is configured via
`ModuleConfig.WithFSConfig(fcfg)`. This implements read-only and
read-write directory mounts, something not formally supported before. It
also implements `WithFS` which adapts a normal `fs.FS`. For convenience,
we retain the old `ModuleConfig.WithFS` signature so as to not affect
existing users much. A new configuration for our emerging raw
filesystem, `FSConfig.WithSysfs()` will happen later without breaking
this API.

Here's an example:
```
moduleConfig = wazero.NewModuleConfig().
	// Make the current directory read-only accessible to the guest.
	WithReadOnlyDirMount(".", "/")
	// Make "/tmp/wasm" accessible to the guest as "/tmp".
	WithDirMount("/tmp/wasm", "/tmp")
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-25 10:09:40 -10:00
Crypt Keeper
cb97d7a488 fs: decouples sysfs from fs.FS and consolidates guest path logic (#1058)
This decouples sysfs.FS from fs.FS by introducing a temporary type
FSHolder, which will be removed when we top-level FSConfig (shortly).

This further reduces complexity by consolidating guest path
configuration into the only type that uses it: CompositeFS.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-23 17:49:51 -10:00
Crypt Keeper
2a584a8937 fs: renames internal syscallfs package to sysfs and notes RATIONALE (#1056)
It will help for us to rename earlier vs later, and syscallfs will be
laborious, especially after we introduce an FSConfig type and need to
declare a method name that differentiates from normal fs.FS. e.g. WithFS
vs WithSysFS reads nicer than WithSyscallFS, and meanwhile sys is
already a public package.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-23 11:11:35 +08:00