diff --git a/Makefile b/Makefile index 7fbfc22d..bf4351a0 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... diff --git a/cmd/wazero/wazero.go b/cmd/wazero/wazero.go index a51b821c..71734108 100644 --- a/cmd/wazero/wazero.go +++ b/cmd/wazero/wazero.go @@ -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 diff --git a/experimental/writefs/writefs.go b/experimental/writefs/writefs.go index bd6bf948..b48d67c2 100644 --- a/experimental/writefs/writefs.go +++ b/experimental/writefs/writefs.go @@ -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, "/") } diff --git a/imports/wasi_snapshot_preview1/fs.go b/imports/wasi_snapshot_preview1/fs.go index 087b11c4..a77244f6 100644 --- a/imports/wasi_snapshot_preview1/fs.go +++ b/imports/wasi_snapshot_preview1/fs.go @@ -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) } diff --git a/imports/wasi_snapshot_preview1/fs_test.go b/imports/wasi_snapshot_preview1/fs_test.go index 7b34897d..65c30839 100644 --- a/imports/wasi_snapshot_preview1/fs_test.go +++ b/imports/wasi_snapshot_preview1/fs_test.go @@ -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)) diff --git a/imports/wasi_snapshot_preview1/wasi_stdlib_test.go b/imports/wasi_snapshot_preview1/wasi_stdlib_test.go index 803edec5..32a5a3ba 100644 --- a/imports/wasi_snapshot_preview1/wasi_stdlib_test.go +++ b/imports/wasi_snapshot_preview1/wasi_stdlib_test.go @@ -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, ` diff --git a/internal/fstest/fstest.go b/internal/fstest/fstest.go index dd9bca17..03310309 100644 --- a/internal/fstest/fstest.go +++ b/internal/fstest/fstest.go @@ -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. diff --git a/internal/gojs/fs.go b/internal/gojs/fs.go index 6182c4cb..287b9409 100644 --- a/internal/gojs/fs.go +++ b/internal/gojs/fs.go @@ -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) } diff --git a/internal/gojs/fs_test.go b/internal/gojs/fs_test.go index a6c1ecc4..204a58e1 100644 --- a/internal/gojs/fs_test.go +++ b/internal/gojs/fs_test.go @@ -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)) diff --git a/internal/sys/fs.go b/internal/sys/fs.go index dd5cf7c0..47d11a84 100644 --- a/internal/sys/fs.go +++ b/internal/sys/fs.go @@ -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 } diff --git a/internal/sys/fs_test.go b/internal/sys/fs_test.go index 5beb9b39..74873206 100644 --- a/internal/sys/fs_test.go +++ b/internal/sys/fs_test.go @@ -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) diff --git a/internal/sys/sys.go b/internal/sys/sys.go index b0d6e3be..0fa9b252 100644 --- a/internal/sys/sys.go +++ b/internal/sys/sys.go @@ -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 diff --git a/internal/sys/sys_test.go b/internal/sys/sys_test.go index 50b26f45..c24c7fdf 100644 --- a/internal/sys/sys_test.go +++ b/internal/sys/sys_test.go @@ -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{} diff --git a/internal/syscallfs/adapter.go b/internal/sysfs/adapter.go similarity index 98% rename from internal/syscallfs/adapter.go rename to internal/sysfs/adapter.go index a1474eb1..7433ec3b 100644 --- a/internal/syscallfs/adapter.go +++ b/internal/sysfs/adapter.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "fmt" diff --git a/internal/syscallfs/adapter_test.go b/internal/sysfs/adapter_test.go similarity index 98% rename from internal/syscallfs/adapter_test.go rename to internal/sysfs/adapter_test.go index 5824e9d0..df6fcfb8 100644 --- a/internal/syscallfs/adapter_test.go +++ b/internal/sysfs/adapter_test.go @@ -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 diff --git a/internal/syscallfs/dirfs.go b/internal/sysfs/dirfs.go similarity index 99% rename from internal/syscallfs/dirfs.go rename to internal/sysfs/dirfs.go index 57daea42..7ec4353a 100644 --- a/internal/syscallfs/dirfs.go +++ b/internal/sysfs/dirfs.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "errors" diff --git a/internal/syscallfs/dirfs_test.go b/internal/sysfs/dirfs_test.go similarity index 99% rename from internal/syscallfs/dirfs_test.go rename to internal/sysfs/dirfs_test.go index b6bd1b9a..0e5b13ae 100644 --- a/internal/syscallfs/dirfs_test.go +++ b/internal/sysfs/dirfs_test.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "errors" diff --git a/internal/syscallfs/readfs.go b/internal/sysfs/readfs.go similarity index 99% rename from internal/syscallfs/readfs.go rename to internal/sysfs/readfs.go index e99b954d..ee09c688 100644 --- a/internal/syscallfs/readfs.go +++ b/internal/sysfs/readfs.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "io" diff --git a/internal/syscallfs/readfs_test.go b/internal/sysfs/readfs_test.go similarity index 99% rename from internal/syscallfs/readfs_test.go rename to internal/sysfs/readfs_test.go index dcc4a27d..8ee12fcd 100644 --- a/internal/syscallfs/readfs_test.go +++ b/internal/sysfs/readfs_test.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "io/fs" diff --git a/internal/syscallfs/rootfs.go b/internal/sysfs/rootfs.go similarity index 99% rename from internal/syscallfs/rootfs.go rename to internal/sysfs/rootfs.go index 8bcafd87..3c767a43 100644 --- a/internal/syscallfs/rootfs.go +++ b/internal/sysfs/rootfs.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "fmt" diff --git a/internal/syscallfs/rootfs_test.go b/internal/sysfs/rootfs_test.go similarity index 99% rename from internal/syscallfs/rootfs_test.go rename to internal/sysfs/rootfs_test.go index 3d865a4d..9c373adf 100644 --- a/internal/syscallfs/rootfs_test.go +++ b/internal/sysfs/rootfs_test.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "errors" diff --git a/internal/syscallfs/syscall.go b/internal/sysfs/syscall.go similarity index 95% rename from internal/syscallfs/syscall.go rename to internal/sysfs/syscall.go index ed4e4083..b9ecc951 100644 --- a/internal/syscallfs/syscall.go +++ b/internal/sysfs/syscall.go @@ -1,6 +1,6 @@ //go:build !windows -package syscallfs +package sysfs import "syscall" diff --git a/internal/syscallfs/syscall_windows.go b/internal/sysfs/syscall_windows.go similarity index 99% rename from internal/syscallfs/syscall_windows.go rename to internal/sysfs/syscall_windows.go index 303b08fd..863dc456 100644 --- a/internal/syscallfs/syscall_windows.go +++ b/internal/sysfs/syscall_windows.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "errors" diff --git a/internal/syscallfs/syscallfs.go b/internal/sysfs/sysfs.go similarity index 96% rename from internal/syscallfs/syscallfs.go rename to internal/sysfs/sysfs.go index bcd36c10..5227ae8e 100644 --- a/internal/syscallfs/syscallfs.go +++ b/internal/sysfs/sysfs.go @@ -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" diff --git a/internal/syscallfs/syscallfs_bench_test.go b/internal/sysfs/sysfs_bench_test.go similarity index 98% rename from internal/syscallfs/syscallfs_bench_test.go rename to internal/sysfs/sysfs_bench_test.go index 6f1a0cb8..bf43390b 100644 --- a/internal/syscallfs/syscallfs_bench_test.go +++ b/internal/sysfs/sysfs_bench_test.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "io" diff --git a/internal/syscallfs/syscallfs_test.go b/internal/sysfs/sysfs_test.go similarity index 99% rename from internal/syscallfs/syscallfs_test.go rename to internal/sysfs/sysfs_test.go index d22a9f4d..389b231f 100644 --- a/internal/syscallfs/syscallfs_test.go +++ b/internal/sysfs/sysfs_test.go @@ -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 { diff --git a/internal/syscallfs/testdata/empty.txt b/internal/sysfs/testdata/empty.txt similarity index 100% rename from internal/syscallfs/testdata/empty.txt rename to internal/sysfs/testdata/empty.txt diff --git a/internal/syscallfs/testdata/wazero.txt b/internal/sysfs/testdata/wazero.txt similarity index 100% rename from internal/syscallfs/testdata/wazero.txt rename to internal/sysfs/testdata/wazero.txt diff --git a/internal/syscallfs/unsupported.go b/internal/sysfs/unsupported.go similarity index 98% rename from internal/syscallfs/unsupported.go rename to internal/sysfs/unsupported.go index 991bb155..fd386434 100644 --- a/internal/syscallfs/unsupported.go +++ b/internal/sysfs/unsupported.go @@ -1,4 +1,4 @@ -package syscallfs +package sysfs import ( "fmt"