Skip to content
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

Exposes writeable filesystem as experimentalsys.FS #1605

Merged
merged 2 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/wazero/wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/tetratelabs/wazero/experimental/gojs"
"github.com/tetratelabs/wazero/experimental/logging"
"github.com/tetratelabs/wazero/experimental/sock"
"github.com/tetratelabs/wazero/experimental/sysfs"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/platform"
internalsys "github.com/tetratelabs/wazero/internal/sys"
Expand Down Expand Up @@ -394,7 +395,7 @@ func validateMounts(mounts sliceFlag, stdErr logging.Writer) (rc int, rootPath s
readOnly = true
}

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

root := sysfs.NewDirFS(dir)
if readOnly {
config = config.WithReadOnlyDirMount(dir, guestPath)
} else {
config = config.WithDirMount(dir, guestPath)
root = sysfs.NewReadFS(root)
}

config = config.(sysfs.FSConfig).WithSysFSMount(root, guestPath)

if internalsys.StripPrefixesAndTrailingSlash(guestPath) == "" {
rootPath = dir
}
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"time"

"github.com/tetratelabs/wazero/api"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/engine/compiler"
"github.com/tetratelabs/wazero/internal/engine/interpreter"
"github.com/tetratelabs/wazero/internal/filecache"
"github.com/tetratelabs/wazero/internal/fsapi"
"github.com/tetratelabs/wazero/internal/internalapi"
"github.com/tetratelabs/wazero/internal/platform"
internalsock "github.com/tetratelabs/wazero/internal/sock"
Expand Down Expand Up @@ -846,7 +846,7 @@ func (c *moduleConfig) toSysContext() (sysCtx *internalsys.Context, err error) {
environ = append(environ, result)
}

var fs []fsapi.FS
var fs []experimentalsys.FS
var guestPaths []string
if f, ok := c.fsConfig.(*fsConfig); ok {
fs, guestPaths = f.preopens()
Expand Down
39 changes: 19 additions & 20 deletions internal/fsapi/dir.go → experimental/sys/dir.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package fsapi
package sys

import (
"fmt"
"io/fs"

experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)

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

// SetAppend implements File.SetAppend
func (DirFile) SetAppend(bool) experimentalsys.Errno {
return experimentalsys.EISDIR
func (DirFile) SetAppend(bool) Errno {
return EISDIR
}

// IsNonblock implements File.IsNonblock
Expand All @@ -68,41 +67,41 @@ func (DirFile) IsNonblock() bool {
}

// SetNonblock implements File.SetNonblock
func (DirFile) SetNonblock(bool) experimentalsys.Errno {
return experimentalsys.EISDIR
func (DirFile) SetNonblock(bool) Errno {
return EISDIR
}

// IsDir implements File.IsDir
func (DirFile) IsDir() (bool, experimentalsys.Errno) {
func (DirFile) IsDir() (bool, Errno) {
return true, 0
}

// Read implements File.Read
func (DirFile) Read([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
func (DirFile) Read([]byte) (int, Errno) {
return 0, EISDIR
}

// Pread implements File.Pread
func (DirFile) Pread([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
func (DirFile) Pread([]byte, int64) (int, Errno) {
return 0, EISDIR
}

// Poll implements File.Poll
func (DirFile) Poll(Pflag, int32) (ready bool, errno experimentalsys.Errno) {
return false, experimentalsys.ENOSYS
func (DirFile) Poll(Pflag, int32) (ready bool, errno Errno) {
return false, ENOSYS
}

// Write implements File.Write
func (DirFile) Write([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
func (DirFile) Write([]byte) (int, Errno) {
return 0, EISDIR
}

// Pwrite implements File.Pwrite
func (DirFile) Pwrite([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
func (DirFile) Pwrite([]byte, int64) (int, Errno) {
return 0, EISDIR
}

// Truncate implements File.Truncate
func (DirFile) Truncate(int64) experimentalsys.Errno {
return experimentalsys.EISDIR
func (DirFile) Truncate(int64) Errno {
return EISDIR
}
Loading