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>
This commit is contained in:
Crypt Keeper
2023-01-23 11:11:35 +08:00
committed by GitHub
parent 3838757dda
commit 2a584a8937
29 changed files with 103 additions and 98 deletions

View File

@@ -218,7 +218,7 @@ check:
# The following checks help ensure our platform-specific code used for system
# calls safely falls back on a platform unsupported by the compiler engine.
# This makes sure the intepreter can be used. Most often the package that can
# drift here is "platform" or "syscallfs":
# drift here is "platform" or "sysfs":
#
# Ensure we build on an arbitrary operating system
@GOARCH=amd64 GOOS=dragonfly go build ./...

View File

@@ -16,7 +16,7 @@ import (
"github.com/tetratelabs/wazero/experimental/logging"
gojs "github.com/tetratelabs/wazero/imports/go"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/internal/version"
"github.com/tetratelabs/wazero/sys"
)
@@ -227,8 +227,8 @@ func doRun(args []string, stdOut io.Writer, stdErr logging.Writer, exit func(cod
exit(0)
}
func validateMounts(mounts sliceFlag, stdErr logging.Writer, exit func(code int)) syscallfs.FS {
fs := make([]syscallfs.FS, 0, len(mounts))
func validateMounts(mounts sliceFlag, stdErr logging.Writer, exit func(code int)) sysfs.FS {
fs := make([]sysfs.FS, 0, len(mounts))
for _, mount := range mounts {
if len(mount) == 0 {
fmt.Fprintln(stdErr, "invalid mount: empty string")
@@ -261,18 +261,18 @@ func validateMounts(mounts sliceFlag, stdErr logging.Writer, exit func(code int)
host = abs
}
next, err := syscallfs.NewDirFS(host, guest)
next, err := sysfs.NewDirFS(host, guest)
if err != nil {
fmt.Fprintf(stdErr, "invalid mount: %v\n", err)
exit(1)
} else {
if readOnly {
next = syscallfs.NewReadFS(next)
next = sysfs.NewReadFS(next)
}
fs = append(fs, next)
}
}
if fs, err := syscallfs.NewRootFS(fs...); err != nil {
if fs, err := sysfs.NewRootFS(fs...); err != nil {
fmt.Fprintf(stdErr, "invalid mounts %v: %v\n", fs, err)
exit(1)
return nil

View File

@@ -10,7 +10,7 @@ package writefs
import (
"io/fs"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
)
// NewDirFS creates a writeable filesystem at the given path on the host
@@ -35,6 +35,6 @@ import (
// Do not attempt to use the result as a fs.FS, as it will panic. This is a
// bridge to a future filesystem abstraction made for wazero.
func NewDirFS(hostDir string) (fs.FS, error) {
// syscallfs.DirFS is intentionally internal as it is still evolving
return syscallfs.NewDirFS(hostDir, "/")
// sysfs.DirFS is intentionally internal as it is still evolving
return sysfs.NewDirFS(hostDir, "/")
}

View File

@@ -12,7 +12,7 @@ import (
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
. "github.com/tetratelabs/wazero/internal/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/wasm"
)
@@ -513,7 +513,7 @@ func fdReadOrPread(mod api.Module, params []uint64, isPread bool) Errno {
var resultNread uint32
if isPread {
offset := int64(params[3])
reader = syscallfs.ReaderAtOffset(r.File, offset)
reader = sysfs.ReaderAtOffset(r.File, offset)
resultNread = uint32(params[4])
} else {
resultNread = uint32(params[3])
@@ -1039,7 +1039,7 @@ func fdWriteOrPwrite(mod api.Module, params []uint64, isPwrite bool) Errno {
return ErrnoBadf
} else if isPwrite {
offset := int64(params[3])
writer = syscallfs.WriterAtOffset(f.File, offset)
writer = sysfs.WriterAtOffset(f.File, offset)
resultNwritten = uint32(params[4])
} else {
writer = f.File.(io.Writer)
@@ -1180,7 +1180,7 @@ func pathFilestatGetFn(_ context.Context, mod api.Module, params []uint64) Errno
resultBuf := uint32(params[4])
// Stat the file without allocating a file descriptor
stat, err := syscallfs.StatPath(fsc.FS(), pathName)
stat, err := sysfs.StatPath(fsc.FS(), pathName)
if err != nil {
return ToErrno(err)
}

View File

@@ -17,7 +17,7 @@ import (
"github.com/tetratelabs/wazero/internal/fstest"
"github.com/tetratelabs/wazero/internal/leb128"
"github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/internal/testing/require"
. "github.com/tetratelabs/wazero/internal/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/wasm"
@@ -719,7 +719,7 @@ func Test_fdPread_Errors(t *testing.T) {
}
func Test_fdPrestatGet(t *testing.T) {
testfs, err := syscallfs.NewDirFS(t.TempDir(), "/")
testfs, err := sysfs.NewDirFS(t.TempDir(), "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(testfs))
@@ -806,7 +806,7 @@ func Test_fdPrestatGet_Errors(t *testing.T) {
}
func Test_fdPrestatDirName(t *testing.T) {
testfs, err := syscallfs.NewDirFS(t.TempDir(), "/")
testfs, err := sysfs.NewDirFS(t.TempDir(), "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(testfs))
@@ -2283,7 +2283,7 @@ func Test_fdWrite_Errors(t *testing.T) {
func Test_pathCreateDirectory(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -2314,7 +2314,7 @@ func Test_pathCreateDirectory(t *testing.T) {
func Test_pathCreateDirectory_Errors(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -2602,9 +2602,9 @@ func Test_pathLink(t *testing.T) {
func Test_pathOpen(t *testing.T) {
dir := t.TempDir() // open before loop to ensure no locking problems.
writeFS, err := syscallfs.NewDirFS(dir, "/")
writeFS, err := sysfs.NewDirFS(dir, "/")
require.NoError(t, err)
readFS := syscallfs.NewReadFS(writeFS)
readFS := sysfs.NewReadFS(writeFS)
fileName := "file"
fileContents := []byte("012")
@@ -2638,7 +2638,7 @@ func Test_pathOpen(t *testing.T) {
expectedLog string
}{
{
name: "syscallfs.ReadFS",
name: "sysfs.ReadFS",
fs: readFS,
path: func(*testing.T) string { return fileName },
expected: func(t *testing.T, fsc *sys.FSContext) {
@@ -2650,7 +2650,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS",
name: "sysfs.DirFS",
fs: writeFS,
path: func(*testing.T) string { return fileName },
expected: func(t *testing.T, fsc *sys.FSContext) {
@@ -2662,7 +2662,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.ReadFS FD_APPEND",
name: "sysfs.ReadFS FD_APPEND",
fs: readFS,
fdflags: FD_APPEND,
path: func(t *testing.T) (file string) { return appendName },
@@ -2673,7 +2673,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS FD_APPEND",
name: "sysfs.DirFS FD_APPEND",
fs: writeFS,
path: func(t *testing.T) (file string) { return appendName },
fdflags: FD_APPEND,
@@ -2693,7 +2693,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.ReadFS O_CREAT",
name: "sysfs.ReadFS O_CREAT",
fs: readFS,
oflags: O_CREAT,
expectedErrno: ErrnoNosys,
@@ -2704,7 +2704,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS O_CREAT",
name: "sysfs.DirFS O_CREAT",
fs: writeFS,
path: func(t *testing.T) (file string) { return "creat" },
oflags: O_CREAT,
@@ -2725,7 +2725,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.ReadFS O_CREAT O_TRUNC",
name: "sysfs.ReadFS O_CREAT O_TRUNC",
fs: readFS,
oflags: O_CREAT | O_TRUNC,
expectedErrno: ErrnoNosys,
@@ -2736,7 +2736,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS O_CREAT O_TRUNC",
name: "sysfs.DirFS O_CREAT O_TRUNC",
fs: writeFS,
path: func(t *testing.T) (file string) { return path.Join(dirName, "O_CREAT-O_TRUNC") },
oflags: O_CREAT | O_TRUNC,
@@ -2757,7 +2757,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.ReadFS O_DIRECTORY",
name: "sysfs.ReadFS O_DIRECTORY",
fs: readFS,
oflags: O_DIRECTORY,
path: func(*testing.T) string { return dirName },
@@ -2772,7 +2772,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS O_DIRECTORY",
name: "sysfs.DirFS O_DIRECTORY",
fs: writeFS,
path: func(*testing.T) string { return dirName },
oflags: O_DIRECTORY,
@@ -2787,7 +2787,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.ReadFS O_TRUNC",
name: "sysfs.ReadFS O_TRUNC",
fs: readFS,
oflags: O_TRUNC,
expectedErrno: ErrnoNosys,
@@ -2798,7 +2798,7 @@ func Test_pathOpen(t *testing.T) {
`,
},
{
name: "syscallfs.DirFS O_TRUNC",
name: "sysfs.DirFS O_TRUNC",
fs: writeFS,
path: func(t *testing.T) (file string) { return "trunc" },
oflags: O_TRUNC,
@@ -2893,7 +2893,7 @@ func writeFile(t *testing.T, tmpDir, file string, contents []byte) {
func Test_pathOpen_Errors(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3037,7 +3037,7 @@ func Test_pathReadlink(t *testing.T) {
func Test_pathRemoveDirectory(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3070,7 +3070,7 @@ func Test_pathRemoveDirectory(t *testing.T) {
func Test_pathRemoveDirectory_Errors(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3208,7 +3208,7 @@ func Test_pathSymlink(t *testing.T) {
func Test_pathRename(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3252,7 +3252,7 @@ func Test_pathRename(t *testing.T) {
func Test_pathRename_Errors(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3428,7 +3428,7 @@ func Test_pathRename_Errors(t *testing.T) {
func Test_pathUnlinkFile(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3461,7 +3461,7 @@ func Test_pathUnlinkFile(t *testing.T) {
func Test_pathUnlinkFile_Errors(t *testing.T) {
tmpDir := t.TempDir() // open before loop to ensure no locking problems.
fs, err := syscallfs.NewDirFS(tmpDir, "/")
fs, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(fs))
@@ -3572,13 +3572,13 @@ func requireOpenFile(t *testing.T, tmpDir string, pathName string, data []byte,
require.NoError(t, os.WriteFile(realPath, data, 0o600))
}
writeFS, err := syscallfs.NewDirFS(tmpDir, "/")
writeFS, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
testFS := writeFS
if readOnly {
oflags = os.O_RDONLY
testFS = syscallfs.NewReadFS(testFS)
testFS = sysfs.NewReadFS(testFS)
}
mod, r, log := requireProxyModule(t, wazero.NewModuleConfig().WithFS(testFS))

View File

@@ -11,7 +11,7 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/sys"
)
@@ -51,7 +51,7 @@ func Test_fdReaddir_ls(t *testing.T) {
func testFdReaddirLs(t *testing.T, bin []byte) {
// TODO: make a subfs
moduleConfig := wazero.NewModuleConfig().
WithFS(syscallfs.Adapt(fstest.MapFS{
WithFS(sysfs.Adapt(fstest.MapFS{
"-": {},
"a-": {Mode: fs.ModeDir},
"ab-": {},
@@ -87,7 +87,7 @@ ENOTDIR
for i := 0; i < count; i++ {
testFS[strconv.Itoa(i)] = &fstest.MapFile{}
}
config := wazero.NewModuleConfig().WithFS(syscallfs.Adapt(testFS, "/")).WithArgs("wasi", "ls", ".")
config := wazero.NewModuleConfig().WithFS(sysfs.Adapt(testFS, "/")).WithArgs("wasi", "ls", ".")
console := compileAndRun(t, config, bin)
lines := strings.Split(console, "\n")
@@ -112,7 +112,7 @@ func Test_fdReaddir_stat(t *testing.T) {
func testFdReaddirStat(t *testing.T, bin []byte) {
moduleConfig := wazero.NewModuleConfig().WithArgs("wasi", "stat")
console := compileAndRun(t, moduleConfig.WithFS(syscallfs.Adapt(fstest.MapFS{}, "/")), bin)
console := compileAndRun(t, moduleConfig.WithFS(sysfs.Adapt(fstest.MapFS{}, "/")), bin)
// TODO: switch this to a real stat test
require.Equal(t, `

View File

@@ -12,7 +12,7 @@
// }
//
// Failures found here should result in new tests in the appropriate package,
// for example, gojs, syscallfs or wasi_snapshot_preview1.
// for example, gojs, sysfs or wasi_snapshot_preview1.
//
// This package must have no dependencies. Otherwise, compiling this with
// TinyGo or `GOARCH=wasm GOOS=js` can become bloated or complicated.

View File

@@ -13,7 +13,7 @@ import (
"github.com/tetratelabs/wazero/internal/gojs/goos"
"github.com/tetratelabs/wazero/internal/platform"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/internal/wasm"
)
@@ -117,7 +117,7 @@ func (jsfsStat) invoke(ctx context.Context, mod api.Module, args ...interface{})
func syscallStat(mod api.Module, path string) (*jsSt, error) {
fsc := mod.(*wasm.CallContext).Sys.FS()
if stat, err := syscallfs.StatPath(fsc.FS(), path); err != nil {
if stat, err := sysfs.StatPath(fsc.FS(), path); err != nil {
return nil, err
} else {
return newJsSt(stat), nil
@@ -278,7 +278,7 @@ func syscallRead(mod api.Module, fd uint32, offset interface{}, p []byte) (n uin
var reader io.Reader = f.File
if offset != nil {
reader = syscallfs.ReaderAtOffset(f.File, toInt64(offset))
reader = sysfs.ReaderAtOffset(f.File, toInt64(offset))
}
if nRead, e := reader.Read(p); e == nil || e == io.EOF {
@@ -324,7 +324,7 @@ func syscallWrite(mod api.Module, fd uint32, offset interface{}, p []byte) (n ui
if f, ok := fsc.LookupFile(fd); !ok {
err = syscall.EBADF
} else if offset != nil {
writer = syscallfs.WriterAtOffset(f.File, toInt64(offset))
writer = sysfs.WriterAtOffset(f.File, toInt64(offset))
} else {
writer = f.File.(io.Writer)
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/tetratelabs/wazero/experimental/writefs"
"github.com/tetratelabs/wazero/internal/fstest"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/internal/testing/require"
)
@@ -45,7 +45,7 @@ func Test_testfs(t *testing.T) {
require.NoError(t, os.Mkdir(testfsDir, 0o700))
require.NoError(t, fstest.WriteTestFiles(testfsDir))
rootFS, err := syscallfs.NewDirFS(tmpDir, "/")
rootFS, err := sysfs.NewDirFS(tmpDir, "/")
require.NoError(t, err)
stdout, stderr, err := compileAndRun(testCtx, "testfs", wazero.NewModuleConfig().WithFS(rootFS))

View File

@@ -10,7 +10,7 @@ import (
"time"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
)
const (
@@ -108,7 +108,7 @@ func (stdioFileInfo) IsDir() bool { return false }
func (stdioFileInfo) Sys() interface{} { return nil }
type lazyDir struct {
fs syscallfs.FS
fs sysfs.FS
f fs.File
}
@@ -199,7 +199,7 @@ type ReadDir struct {
type FSContext struct {
// fs is the root ("/") mount.
fs syscallfs.FS
fs sysfs.FS
// openedFiles is a map of file descriptor numbers (>=FdPreopen) to open files
// (or directories) and defaults to empty.
@@ -210,15 +210,15 @@ type FSContext struct {
// NewFSContext creates a FSContext with stdio streams and an optional
// pre-opened filesystem.
//
// If `preopened` is not syscallfs.UnimplementedFS, it is inserted into
// If `preopened` is not sysfs.UnimplementedFS, it is inserted into
// the file descriptor table as FdPreopen.
func NewFSContext(stdin io.Reader, stdout, stderr io.Writer, preopened syscallfs.FS) (fsc *FSContext, err error) {
func NewFSContext(stdin io.Reader, stdout, stderr io.Writer, preopened sysfs.FS) (fsc *FSContext, err error) {
fsc = &FSContext{fs: preopened}
fsc.openedFiles.Insert(stdinReader(stdin))
fsc.openedFiles.Insert(stdioWriter(stdout, noopStdoutStat))
fsc.openedFiles.Insert(stdioWriter(stderr, noopStderrStat))
if _, ok := preopened.(syscallfs.UnimplementedFS); ok {
if _, ok := preopened.(sysfs.UnimplementedFS); ok {
return fsc, nil
}
@@ -267,7 +267,7 @@ func (s fileModeStat) IsDir() bool { return false }
// FS returns the underlying filesystem. Any files that should be added to the
// table should be inserted via InsertFile.
func (c *FSContext) FS() syscallfs.FS {
func (c *FSContext) FS() sysfs.FS {
return c.fs
}

View File

@@ -10,7 +10,7 @@ import (
"testing"
"testing/fstest"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
testfs "github.com/tetratelabs/wazero/internal/testing/fs"
"github.com/tetratelabs/wazero/internal/testing/require"
)
@@ -31,31 +31,31 @@ func TestNewFSContext(t *testing.T) {
embedFS, err := fs.Sub(testdata, "testdata")
require.NoError(t, err)
dirfs, err := syscallfs.NewDirFS(".", "/")
dirfs, err := sysfs.NewDirFS(".", "/")
require.NoError(t, err)
// Test various usual configuration for the file system.
tests := []struct {
name string
fs syscallfs.FS
fs sysfs.FS
}{
{
name: "embed.FS",
fs: syscallfs.Adapt(embedFS, "/"),
fs: sysfs.Adapt(embedFS, "/"),
},
{
name: "syscallfs.NewDirFS",
name: "sysfs.NewDirFS",
// Don't use "testdata" because it may not be present in
// cross-architecture (a.k.a. scratch) build containers.
fs: dirfs,
},
{
name: "syscallfs.NewReadFS",
fs: syscallfs.NewReadFS(dirfs),
name: "sysfs.NewReadFS",
fs: sysfs.NewReadFS(dirfs),
},
{
name: "fstest.MapFS",
fs: syscallfs.Adapt(fstest.MapFS{}, "/"),
fs: sysfs.Adapt(fstest.MapFS{}, "/"),
},
}
@@ -96,10 +96,10 @@ func TestNewFSContext(t *testing.T) {
}
func TestUnimplementedFSContext(t *testing.T) {
testFS, err := NewFSContext(nil, nil, nil, syscallfs.UnimplementedFS{})
testFS, err := NewFSContext(nil, nil, nil, sysfs.UnimplementedFS{})
require.NoError(t, err)
expected := &FSContext{fs: syscallfs.UnimplementedFS{}}
expected := &FSContext{fs: sysfs.UnimplementedFS{}}
expected.openedFiles.Insert(noopStdin)
expected.openedFiles.Insert(noopStdout)
expected.openedFiles.Insert(noopStderr)
@@ -109,12 +109,12 @@ func TestUnimplementedFSContext(t *testing.T) {
require.NoError(t, err)
// Closes opened files
require.Equal(t, &FSContext{fs: syscallfs.UnimplementedFS{}}, testFS)
require.Equal(t, &FSContext{fs: sysfs.UnimplementedFS{}}, testFS)
})
}
func TestContext_Close(t *testing.T) {
testFS := syscallfs.Adapt(testfs.FS{"foo": &testfs.File{}}, "/")
testFS := sysfs.Adapt(testfs.FS{"foo": &testfs.File{}}, "/")
fsc, err := NewFSContext(nil, nil, nil, testFS)
require.NoError(t, err)
@@ -139,7 +139,7 @@ func TestContext_Close(t *testing.T) {
func TestContext_Close_Error(t *testing.T) {
file := &testfs.File{CloseErr: errors.New("error closing")}
testFS := syscallfs.Adapt(testfs.FS{"foo": file}, "/")
testFS := sysfs.Adapt(testfs.FS{"foo": file}, "/")
fsc, err := NewFSContext(nil, nil, nil, testFS)
require.NoError(t, err)

View File

@@ -8,7 +8,7 @@ import (
"time"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
"github.com/tetratelabs/wazero/sys"
)
@@ -88,7 +88,7 @@ func (c *Context) Nanosleep(ns int64) {
(*(c.nanosleep))(ns)
}
// FS returns the possibly empty (syscallfs.UnimplementedFS) file system context.
// FS returns the possibly empty (sysfs.UnimplementedFS) file system context.
func (c *Context) FS() *FSContext {
return c.fsc
}
@@ -182,9 +182,9 @@ func NewContext(
}
if fs != nil {
sysCtx.fsc, err = NewFSContext(stdin, stdout, stderr, syscallfs.Adapt(fs, "/"))
sysCtx.fsc, err = NewFSContext(stdin, stdout, stderr, sysfs.Adapt(fs, "/"))
} else {
sysCtx.fsc, err = NewFSContext(stdin, stdout, stderr, syscallfs.UnimplementedFS{})
sysCtx.fsc, err = NewFSContext(stdin, stdout, stderr, sysfs.UnimplementedFS{})
}
return

View File

@@ -6,16 +6,16 @@ import (
"time"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/syscallfs"
"github.com/tetratelabs/wazero/internal/sysfs"
testfs "github.com/tetratelabs/wazero/internal/testing/fs"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/sys"
)
func TestContext_FS(t *testing.T) {
sysCtx := DefaultContext(syscallfs.UnimplementedFS{})
sysCtx := DefaultContext(sysfs.UnimplementedFS{})
fsc, err := NewFSContext(nil, nil, nil, syscallfs.UnimplementedFS{})
fsc, err := NewFSContext(nil, nil, nil, sysfs.UnimplementedFS{})
require.NoError(t, err)
require.Equal(t, fsc, sysCtx.FS())
@@ -51,7 +51,7 @@ func TestDefaultSysContext(t *testing.T) {
require.Equal(t, &ns, sysCtx.nanosleep)
require.Equal(t, platform.NewFakeRandSource(), sysCtx.RandSource())
testFS := syscallfs.Adapt(testfs.FS{}, "/")
testFS := sysfs.Adapt(testfs.FS{}, "/")
expectedFS, _ := NewFSContext(nil, nil, nil, testFS)
expectedOpenedFiles := FileTable{}

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"errors"
@@ -155,7 +155,7 @@ func TestAdapt_TestFS(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// Adapt a normal fs.FS to syscallfs.FS
// Adapt a normal fs.FS to sysfs.FS
testFS := Adapt(tc.fs, "/")
// Adapt it back to fs.FS and run the tests

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"errors"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"errors"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"io"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"io/fs"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"errors"

View File

@@ -1,6 +1,6 @@
//go:build !windows
package syscallfs
package sysfs
import "syscall"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"errors"

View File

@@ -1,4 +1,9 @@
package syscallfs
// Package sysfs includes a low-level filesystem interface and utilities needed
// for WebAssembly host functions (ABI) such as WASI and runtime.GOOS=js.
//
// The name sysfs was chosen because wazero's public API has a "sys" package,
// which was named after https://github.com/golang/sys.
package sysfs
import (
"io"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"io"

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"embed"
@@ -423,7 +423,7 @@ func TestWriterAtOffset(t *testing.T) {
name string
fs FS
}{
{name: "syscallfs.dirFS", fs: dirFS},
{name: "sysfs.dirFS", fs: dirFS},
}
for _, tc := range tests {
@@ -490,7 +490,7 @@ func TestWriterAtOffset_empty(t *testing.T) {
name string
fs FS
}{
{name: "syscallfs.dirFS", fs: dirFS},
{name: "sysfs.dirFS", fs: dirFS},
}
for _, tc := range tests {

View File

@@ -1,4 +1,4 @@
package syscallfs
package sysfs
import (
"fmt"