Skip to content

Commit 1f8c908

Browse files
Exposes writeable filesystem as experimentalsys.FS (#1605)
Signed-off-by: Adrian Cole <[email protected]>
1 parent d88286b commit 1f8c908

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1058
-1000
lines changed

cmd/wazero/wazero.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/tetratelabs/wazero/experimental/gojs"
2222
"github.com/tetratelabs/wazero/experimental/logging"
2323
"github.com/tetratelabs/wazero/experimental/sock"
24+
"github.com/tetratelabs/wazero/experimental/sysfs"
2425
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
2526
"github.com/tetratelabs/wazero/internal/platform"
2627
internalsys "github.com/tetratelabs/wazero/internal/sys"
@@ -394,7 +395,7 @@ func validateMounts(mounts sliceFlag, stdErr logging.Writer) (rc int, rootPath s
394395
readOnly = true
395396
}
396397

397-
// TODO(anuraaga): Support wasm paths with colon in them.
398+
// TODO: Support wasm paths with colon in them.
398399
var dir, guestPath string
399400
if clnIdx := strings.LastIndexByte(mount, ':'); clnIdx != -1 {
400401
dir, guestPath = mount[:clnIdx], mount[clnIdx+1:]
@@ -418,12 +419,13 @@ func validateMounts(mounts sliceFlag, stdErr logging.Writer) (rc int, rootPath s
418419
fmt.Fprintf(stdErr, "invalid mount: path %q is not a directory\n", dir)
419420
}
420421

422+
root := sysfs.NewDirFS(dir)
421423
if readOnly {
422-
config = config.WithReadOnlyDirMount(dir, guestPath)
423-
} else {
424-
config = config.WithDirMount(dir, guestPath)
424+
root = sysfs.NewReadFS(root)
425425
}
426426

427+
config = config.(sysfs.FSConfig).WithSysFSMount(root, guestPath)
428+
427429
if internalsys.StripPrefixesAndTrailingSlash(guestPath) == "" {
428430
rootPath = dir
429431
}

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"time"
1212

1313
"github.com/tetratelabs/wazero/api"
14+
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
1415
"github.com/tetratelabs/wazero/internal/engine/compiler"
1516
"github.com/tetratelabs/wazero/internal/engine/interpreter"
1617
"github.com/tetratelabs/wazero/internal/filecache"
17-
"github.com/tetratelabs/wazero/internal/fsapi"
1818
"github.com/tetratelabs/wazero/internal/internalapi"
1919
"github.com/tetratelabs/wazero/internal/platform"
2020
internalsock "github.com/tetratelabs/wazero/internal/sock"
@@ -846,7 +846,7 @@ func (c *moduleConfig) toSysContext() (sysCtx *internalsys.Context, err error) {
846846
environ = append(environ, result)
847847
}
848848

849-
var fs []fsapi.FS
849+
var fs []experimentalsys.FS
850850
var guestPaths []string
851851
if f, ok := c.fsConfig.(*fsConfig); ok {
852852
fs, guestPaths = f.preopens()

internal/fsapi/dir.go renamed to experimental/sys/dir.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package fsapi
1+
package sys
22

33
import (
44
"fmt"
55
"io/fs"
66

7-
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
87
"github.com/tetratelabs/wazero/sys"
98
)
109

@@ -21,7 +20,7 @@ type FileType = fs.FileMode
2120
// - This extends `dirent` defined in POSIX with some fields defined by
2221
// Linux. See https://man7.org/linux/man-pages/man3/readdir.3.html and
2322
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html
24-
// - This has a subset of fields defined in Stat_t. Notably, there is no
23+
// - This has a subset of fields defined in sys.Stat_t. Notably, there is no
2524
// field corresponding to Stat_t.Dev because that value will be constant
2625
// for all files in a directory. To get the Dev value, call File.Stat on
2726
// the directory File.Readdir was called on.
@@ -58,8 +57,8 @@ func (DirFile) IsAppend() bool {
5857
}
5958

6059
// SetAppend implements File.SetAppend
61-
func (DirFile) SetAppend(bool) experimentalsys.Errno {
62-
return experimentalsys.EISDIR
60+
func (DirFile) SetAppend(bool) Errno {
61+
return EISDIR
6362
}
6463

6564
// IsNonblock implements File.IsNonblock
@@ -68,41 +67,41 @@ func (DirFile) IsNonblock() bool {
6867
}
6968

7069
// SetNonblock implements File.SetNonblock
71-
func (DirFile) SetNonblock(bool) experimentalsys.Errno {
72-
return experimentalsys.EISDIR
70+
func (DirFile) SetNonblock(bool) Errno {
71+
return EISDIR
7372
}
7473

7574
// IsDir implements File.IsDir
76-
func (DirFile) IsDir() (bool, experimentalsys.Errno) {
75+
func (DirFile) IsDir() (bool, Errno) {
7776
return true, 0
7877
}
7978

8079
// Read implements File.Read
81-
func (DirFile) Read([]byte) (int, experimentalsys.Errno) {
82-
return 0, experimentalsys.EISDIR
80+
func (DirFile) Read([]byte) (int, Errno) {
81+
return 0, EISDIR
8382
}
8483

8584
// Pread implements File.Pread
86-
func (DirFile) Pread([]byte, int64) (int, experimentalsys.Errno) {
87-
return 0, experimentalsys.EISDIR
85+
func (DirFile) Pread([]byte, int64) (int, Errno) {
86+
return 0, EISDIR
8887
}
8988

9089
// Poll implements File.Poll
91-
func (DirFile) Poll(Pflag, int32) (ready bool, errno experimentalsys.Errno) {
92-
return false, experimentalsys.ENOSYS
90+
func (DirFile) Poll(Pflag, int32) (ready bool, errno Errno) {
91+
return false, ENOSYS
9392
}
9493

9594
// Write implements File.Write
96-
func (DirFile) Write([]byte) (int, experimentalsys.Errno) {
97-
return 0, experimentalsys.EISDIR
95+
func (DirFile) Write([]byte) (int, Errno) {
96+
return 0, EISDIR
9897
}
9998

10099
// Pwrite implements File.Pwrite
101-
func (DirFile) Pwrite([]byte, int64) (int, experimentalsys.Errno) {
102-
return 0, experimentalsys.EISDIR
100+
func (DirFile) Pwrite([]byte, int64) (int, Errno) {
101+
return 0, EISDIR
103102
}
104103

105104
// Truncate implements File.Truncate
106-
func (DirFile) Truncate(int64) experimentalsys.Errno {
107-
return experimentalsys.EISDIR
105+
func (DirFile) Truncate(int64) Errno {
106+
return EISDIR
108107
}

0 commit comments

Comments
 (0)