adds experimental sys.Errno to begin decoupling from the syscall package (#1582)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-07-17 08:13:29 +08:00
committed by GitHub
parent 1dafce0b2a
commit 2f8dd23097
94 changed files with 1591 additions and 1374 deletions

View File

@@ -3,9 +3,9 @@ package fsapi
import (
"fmt"
"io/fs"
"syscall"
"time"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)
@@ -59,8 +59,8 @@ func (DirFile) IsAppend() bool {
}
// SetAppend implements File.SetAppend
func (DirFile) SetAppend(bool) syscall.Errno {
return syscall.EISDIR
func (DirFile) SetAppend(bool) experimentalsys.Errno {
return experimentalsys.EISDIR
}
// IsNonblock implements File.IsNonblock
@@ -69,41 +69,41 @@ func (DirFile) IsNonblock() bool {
}
// SetNonblock implements File.SetNonblock
func (DirFile) SetNonblock(bool) syscall.Errno {
return syscall.EISDIR
func (DirFile) SetNonblock(bool) experimentalsys.Errno {
return experimentalsys.EISDIR
}
// IsDir implements File.IsDir
func (DirFile) IsDir() (bool, syscall.Errno) {
func (DirFile) IsDir() (bool, experimentalsys.Errno) {
return true, 0
}
// Read implements File.Read
func (DirFile) Read([]byte) (int, syscall.Errno) {
return 0, syscall.EISDIR
func (DirFile) Read([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
}
// Pread implements File.Pread
func (DirFile) Pread([]byte, int64) (int, syscall.Errno) {
return 0, syscall.EISDIR
func (DirFile) Pread([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
}
// PollRead implements File.PollRead
func (DirFile) PollRead(*time.Duration) (ready bool, errno syscall.Errno) {
return false, syscall.ENOSYS
func (DirFile) PollRead(*time.Duration) (ready bool, errno experimentalsys.Errno) {
return false, experimentalsys.ENOSYS
}
// Write implements File.Write
func (DirFile) Write([]byte) (int, syscall.Errno) {
return 0, syscall.EISDIR
func (DirFile) Write([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
}
// Pwrite implements File.Pwrite
func (DirFile) Pwrite([]byte, int64) (int, syscall.Errno) {
return 0, syscall.EISDIR
func (DirFile) Pwrite([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.EISDIR
}
// Truncate implements File.Truncate
func (DirFile) Truncate(int64) syscall.Errno {
return syscall.EISDIR
func (DirFile) Truncate(int64) experimentalsys.Errno {
return experimentalsys.EISDIR
}

View File

@@ -4,6 +4,7 @@ import (
"syscall"
"time"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)
@@ -11,14 +12,14 @@ import (
// including WASI and runtime.GOOS=js.
//
// Implementations should embed UnimplementedFile for forward compatability. Any
// unsupported method or parameter should return syscall.ENOSYS.
// unsupported method or parameter should return ENOSYS.
//
// # Errors
//
// All methods that can return an error return a syscall.Errno, which is zero
// All methods that can return an error return a Errno, which is zero
// on success.
//
// Restricting to syscall.Errno matches current WebAssembly host functions,
// Restricting to Errno matches current WebAssembly host functions,
// which are constrained to well-known error codes. For example, `GOOS=js` maps
// hard coded values and panics otherwise. More commonly, WASI maps syscall
// errors to u32 numeric values.
@@ -36,41 +37,41 @@ type File interface {
//
// # Errors
//
// Possible errors are those from Stat, except syscall.ENOSYS should not
// Possible errors are those from Stat, except ENOSYS should not
// be returned. Zero should be returned if there is no implementation.
//
// # Notes
//
// - Implementations should cache this result.
// - This combined with Ino can implement os.SameFile.
Dev() (uint64, syscall.Errno)
Dev() (uint64, experimentalsys.Errno)
// Ino returns the serial number (Stat_t.Ino) of this file, zero if unknown
// or an error retrieving it.
//
// # Errors
//
// Possible errors are those from Stat, except syscall.ENOSYS should not
// Possible errors are those from Stat, except ENOSYS should not
// be returned. Zero should be returned if there is no implementation.
//
// # Notes
//
// - Implementations should cache this result.
// - This combined with Dev can implement os.SameFile.
Ino() (sys.Inode, syscall.Errno)
Ino() (sys.Inode, experimentalsys.Errno)
// IsDir returns true if this file is a directory or an error there was an
// error retrieving this information.
//
// # Errors
//
// Possible errors are those from Stat, except syscall.ENOSYS should not
// Possible errors are those from Stat, except ENOSYS should not
// be returned. false should be returned if there is no implementation.
//
// # Notes
//
// - Implementations should cache this result.
IsDir() (bool, syscall.Errno)
IsDir() (bool, experimentalsys.Errno)
// IsNonblock returns true if the file was opened with O_NONBLOCK, or
// SetNonblock was successfully enabled on this file.
@@ -85,15 +86,15 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed.
//
// # Notes
//
// - This is like syscall.SetNonblock and `fcntl` with O_NONBLOCK in
// POSIX. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
SetNonblock(enable bool) syscall.Errno
SetNonblock(enable bool) experimentalsys.Errno
// IsAppend returns true if the file was opened with syscall.O_APPEND, or
// SetAppend was successfully enabled on this file.
@@ -108,24 +109,24 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed.
//
// # Notes
//
// - There is no `O_APPEND` for `fcntl` in POSIX, so implementations may
// have to re-open the underlying file to apply this. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
SetAppend(enable bool) syscall.Errno
SetAppend(enable bool) experimentalsys.Errno
// Stat is similar to syscall.Fstat.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed.
//
// # Notes
//
@@ -134,17 +135,17 @@ type File interface {
// - A fs.FileInfo backed implementation sets atim, mtim and ctim to the
// same value.
// - Windows allows you to stat a closed directory.
Stat() (sys.Stat_t, syscall.Errno)
Stat() (sys.Stat_t, experimentalsys.Errno)
// Read attempts to read all bytes in the file into `buf`, and returns the
// count read even on error.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed or not readable.
// - syscall.EISDIR: the file was a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed or not readable.
// - EISDIR: the file was a directory.
//
// # Notes
//
@@ -152,18 +153,18 @@ type File interface {
// io.Reader. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
// - Unlike io.Reader, there is no io.EOF returned on end-of-file. To
// read the file completely, the caller must repeat until `n` is zero.
Read(buf []byte) (n int, errno syscall.Errno)
Read(buf []byte) (n int, errno experimentalsys.Errno)
// Pread attempts to read all bytes in the file into `p`, starting at the
// offset `off`, and returns the count read even on error.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed or not readable.
// - syscall.EINVAL: the offset was negative.
// - syscall.EISDIR: the file was a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed or not readable.
// - EINVAL: the offset was negative.
// - EISDIR: the file was a directory.
//
// # Notes
//
@@ -171,7 +172,7 @@ type File interface {
// of io.ReaderAt. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html
// - Unlike io.ReaderAt, there is no io.EOF returned on end-of-file. To
// read the file completely, the caller must repeat until `n` is zero.
Pread(buf []byte, off int64) (n int, errno syscall.Errno)
Pread(buf []byte, off int64) (n int, errno experimentalsys.Errno)
// Seek attempts to set the next offset for Read or Write and returns the
// resulting absolute offset or an error.
@@ -194,16 +195,16 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed or not readable.
// - syscall.EINVAL: the offset was negative.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed or not readable.
// - EINVAL: the offset was negative.
//
// # Notes
//
// - This is like io.Seeker and `fseek` in POSIX, preferring semantics
// of io.Seeker. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
Seek(offset int64, whence int) (newOffset int64, errno syscall.Errno)
Seek(offset int64, whence int) (newOffset int64, errno experimentalsys.Errno)
// PollRead returns if the file has data ready to be read or an error.
//
@@ -213,8 +214,8 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
//
// # Notes
//
@@ -223,7 +224,7 @@ type File interface {
// - No-op files, such as those which read from /dev/null, should return
// immediately true to avoid hangs (because data will never become
// available).
PollRead(timeout *time.Duration) (ready bool, errno syscall.Errno)
PollRead(timeout *time.Duration) (ready bool, errno experimentalsys.Errno)
// Readdir reads the contents of the directory associated with file and
// returns a slice of up to n Dirent values in an arbitrary order. This is
@@ -234,10 +235,10 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file was closed or not a directory.
// - syscall.ENOENT: the directory could not be read (e.g. deleted).
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file was closed or not a directory.
// - ENOENT: the directory could not be read (e.g. deleted).
//
// # Notes
//
@@ -247,88 +248,88 @@ type File interface {
// read the directory completely, the caller must repeat until the
// count read (`len(dirents)`) is less than `n`.
// - See /RATIONALE.md for design notes.
Readdir(n int) (dirents []Dirent, errno syscall.Errno)
Readdir(n int) (dirents []Dirent, errno experimentalsys.Errno)
// Write attempts to write all bytes in `p` to the file, and returns the
// count written even on error.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file was closed, not writeable, or a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file was closed, not writeable, or a directory.
//
// # Notes
//
// - This is like io.Writer and `write` in POSIX, preferring semantics of
// io.Writer. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
Write(buf []byte) (n int, errno syscall.Errno)
Write(buf []byte) (n int, errno experimentalsys.Errno)
// Pwrite attempts to write all bytes in `p` to the file at the given
// offset `off`, and returns the count written even on error.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed or not writeable.
// - syscall.EINVAL: the offset was negative.
// - syscall.EISDIR: the file was a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed or not writeable.
// - EINVAL: the offset was negative.
// - EISDIR: the file was a directory.
//
// # Notes
//
// - This is like io.WriterAt and `pwrite` in POSIX, preferring semantics
// of io.WriterAt. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html
Pwrite(buf []byte, off int64) (n int, errno syscall.Errno)
Pwrite(buf []byte, off int64) (n int, errno experimentalsys.Errno)
// Truncate truncates a file to a specified length.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed.
// - syscall.EINVAL: the `size` is negative.
// - syscall.EISDIR: the file was a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed.
// - EINVAL: the `size` is negative.
// - EISDIR: the file was a directory.
//
// # Notes
//
// - This is like syscall.Ftruncate and `ftruncate` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
// - Windows does not error when calling Truncate on a closed file.
Truncate(size int64) syscall.Errno
Truncate(size int64) experimentalsys.Errno
// Sync synchronizes changes to the file.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - EBADF: the file or directory was closed.
//
// # Notes
//
// - This is like syscall.Fsync and `fsync` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html
// - This returns with no error instead of syscall.ENOSYS when
// - This returns with no error instead of ENOSYS when
// unimplemented. This prevents fake filesystems from erring.
// - Windows does not error when calling Sync on a closed file.
Sync() syscall.Errno
Sync() experimentalsys.Errno
// Datasync synchronizes the data of a file.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - EBADF: the file or directory was closed.
//
// # Notes
//
// - This is like syscall.Fdatasync and `fdatasync` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html
// - This returns with no error instead of syscall.ENOSYS when
// - This returns with no error instead of ENOSYS when
// unimplemented. This prevents fake filesystems from erring.
// - As this is commonly missing, some implementations dispatch to Sync.
Datasync() syscall.Errno
Datasync() experimentalsys.Errno
// Utimens set file access and modification times of this file, at
// nanosecond precision.
@@ -342,25 +343,25 @@ type File interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EBADF: the file or directory was closed.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EBADF: the file or directory was closed.
//
// # Notes
//
// - This is like syscall.UtimesNano and `futimens` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html
// - Windows requires files to be open with syscall.O_RDWR, which means you
// cannot use this to update timestamps on a directory (syscall.EPERM).
Utimens(times *[2]syscall.Timespec) syscall.Errno
// cannot use this to update timestamps on a directory (EPERM).
Utimens(times *[2]syscall.Timespec) experimentalsys.Errno
// Close closes the underlying file.
//
// A zero syscall.Errno is returned if unimplemented or success.
// A zero Errno is returned if unimplemented or success.
//
// # Notes
//
// - This is like syscall.Close and `close` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
Close() syscall.Errno
Close() experimentalsys.Errno
}

View File

@@ -4,6 +4,7 @@ import (
"io/fs"
"syscall"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)
@@ -11,14 +12,14 @@ import (
// including WASI and runtime.GOOS=js.
//
// Implementations should embed UnimplementedFS for forward compatability. Any
// unsupported method or parameter should return syscall.ENO
// unsupported method or parameter should return ENO
//
// # Errors
//
// All methods that can return an error return a syscall.Errno, which is zero
// All methods that can return an error return a Errno, which is zero
// on success.
//
// Restricting to syscall.Errno matches current WebAssembly host functions,
// Restricting to Errno matches current WebAssembly host functions,
// which are constrained to well-known error codes. For example, `GOOS=js` maps
// hard coded values and panics otherwise. More commonly, WASI maps syscall
// errors to u32 numeric values.
@@ -32,12 +33,12 @@ type FS interface {
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` or `flag` is invalid.
// - syscall.EISDIR: the path was a directory, but flag included
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` or `flag` is invalid.
// - EISDIR: the path was a directory, but flag included
// syscall.O_RDWR or syscall.O_WRONLY
// - syscall.ENOENT: `path` doesn't exist and `flag` doesn't contain
// - ENOENT: `path` doesn't exist and `flag` doesn't contain
// os.O_CREATE.
//
// # Constraints on the returned file
@@ -45,7 +46,7 @@ type FS interface {
// Implementations that can read flags should enforce them regardless of
// the type returned. For example, while os.File implements io.Writer,
// attempts to write to a directory or a file opened with os.O_RDONLY fail
// with a syscall.EBADF.
// with a EBADF.
//
// Some implementations choose whether to enforce read-only opens, namely
// fs.FS. While fs.FS is supported (Adapt), wazero cannot runtime enforce
@@ -55,21 +56,22 @@ type FS interface {
// # Notes
//
// - This is like os.OpenFile, except the path is relative to this file
// system, and syscall.Errno is returned instead of os.PathError.
// system, and Errno is returned instead of os.PathError.
// - flag are the same as os.OpenFile, for example, os.O_CREATE.
// - Implications of permissions when os.O_CREATE are described in Chmod
// notes.
// - This is like `open` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
OpenFile(path string, flag int, perm fs.FileMode) (File, syscall.Errno)
OpenFile(path string, flag int, perm fs.FileMode) (File, experimentalsys.Errno)
// TODO: make sure all flags are not in the syscall package
// Lstat gets file status without following symbolic links.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.ENOENT: `path` doesn't exist.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - ENOENT: `path` doesn't exist.
//
// # Notes
//
@@ -81,15 +83,15 @@ type FS interface {
// same value.
// - When the path is a symbolic link, the stat returned is for the link,
// not the file it refers to.
Lstat(path string) (sys.Stat_t, syscall.Errno)
Lstat(path string) (sys.Stat_t, experimentalsys.Errno)
// Stat gets file status.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.ENOENT: `path` doesn't exist.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - ENOENT: `path` doesn't exist.
//
// # Notes
//
@@ -101,17 +103,17 @@ type FS interface {
// same value.
// - When the path is a symbolic link, the stat returned is for the file
// it refers to.
Stat(path string) (sys.Stat_t, syscall.Errno)
Stat(path string) (sys.Stat_t, experimentalsys.Errno)
// Mkdir makes a directory.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// - syscall.EEXIST: `path` exists and is a directory.
// - syscall.ENOTDIR: `path` exists and is a file.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
// - EEXIST: `path` exists and is a directory.
// - ENOTDIR: `path` exists and is a file.
//
// # Notes
//
@@ -120,16 +122,16 @@ type FS interface {
// - This is like `mkdir` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html
// - Implications of permissions are described in Chmod notes.
Mkdir(path string, perm fs.FileMode) syscall.Errno
Mkdir(path string, perm fs.FileMode) experimentalsys.Errno
// Chmod changes the mode of the file.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// - syscall.ENOENT: `path` does not exist.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
// - ENOENT: `path` does not exist.
//
// # Notes
//
@@ -140,19 +142,19 @@ type FS interface {
// - Windows ignores the execute bit, and any permissions come back as
// group and world. For example, chmod of 0400 reads back as 0444, and
// 0700 0666. Also, permissions on directories aren't supported at all.
Chmod(path string, perm fs.FileMode) syscall.Errno
Chmod(path string, perm fs.FileMode) experimentalsys.Errno
// Rename renames file or directory.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `from` or `to` is invalid.
// - syscall.ENOENT: `from` or `to` don't exist.
// - syscall.ENOTDIR: `from` is a directory and `to` exists as a file.
// - syscall.EISDIR: `from` is a file and `to` exists as a directory.
// - syscall.ENOTEMPTY: `both from` and `to` are existing directory, but
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `from` or `to` is invalid.
// - ENOENT: `from` or `to` don't exist.
// - ENOTDIR: `from` is a directory and `to` exists as a file.
// - EISDIR: `from` is a file and `to` exists as a directory.
// - ENOTEMPTY: `both from` and `to` are existing directory, but
// `to` is not empty.
//
// # Notes
@@ -162,18 +164,18 @@ type FS interface {
// - This is like `rename` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
// - Windows doesn't let you overwrite an existing directory.
Rename(from, to string) syscall.Errno
Rename(from, to string) experimentalsys.Errno
// Rmdir removes a directory.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// - syscall.ENOENT: `path` doesn't exist.
// - syscall.ENOTDIR: `path` exists, but isn't a directory.
// - syscall.ENOTEMPTY: `path` exists, but isn't empty.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
// - ENOENT: `path` doesn't exist.
// - ENOTDIR: `path` exists, but isn't a directory.
// - ENOTEMPTY: `path` exists, but isn't empty.
//
// # Notes
//
@@ -181,18 +183,18 @@ type FS interface {
// file system.
// - This is like `rmdir` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html
// - As of Go 1.19, Windows maps syscall.ENOTDIR to syscall.ENOENT.
Rmdir(path string) syscall.Errno
// - As of Go 1.19, Windows maps ENOTDIR to ENOENT.
Rmdir(path string) experimentalsys.Errno
// Unlink removes a directory entry.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// - syscall.ENOENT: `path` doesn't exist.
// - syscall.EISDIR: `path` exists, but is a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
// - ENOENT: `path` doesn't exist.
// - EISDIR: `path` exists, but is a directory.
//
// # Notes
//
@@ -203,18 +205,18 @@ type FS interface {
// - On Windows, syscall.Unlink doesn't delete symlink to directory unlike other platforms. Implementations might
// want to combine syscall.RemoveDirectory with syscall.Unlink in order to delete such links on Windows.
// See https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya
Unlink(path string) syscall.Errno
Unlink(path string) experimentalsys.Errno
// Link creates a "hard" link from oldPath to newPath, in contrast to a
// soft link (via Symlink).
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EPERM: `oldPath` is invalid.
// - syscall.ENOENT: `oldPath` doesn't exist.
// - syscall.EISDIR: `newPath` exists, but is a directory.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EPERM: `oldPath` is invalid.
// - ENOENT: `oldPath` doesn't exist.
// - EISDIR: `newPath` exists, but is a directory.
//
// # Notes
//
@@ -222,17 +224,17 @@ type FS interface {
// file system.
// - This is like `link` in POSIX. See
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
Link(oldPath, newPath string) syscall.Errno
Link(oldPath, newPath string) experimentalsys.Errno
// Symlink creates a "soft" link from oldPath to newPath, in contrast to a
// hard link (via Link).
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EPERM: `oldPath` or `newPath` is invalid.
// - syscall.EEXIST: `newPath` exists.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EPERM: `oldPath` or `newPath` is invalid.
// - EEXIST: `newPath` exists.
//
// # Notes
//
@@ -246,17 +248,17 @@ type FS interface {
// See https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
// for how others implement this.
// - Symlinks in Windows requires `SeCreateSymbolicLinkPrivilege`.
// Otherwise, syscall.EPERM results.
// Otherwise, EPERM results.
// See https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links
Symlink(oldPath, linkName string) syscall.Errno
Symlink(oldPath, linkName string) experimentalsys.Errno
// Readlink reads the contents of a symbolic link.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
//
// # Notes
//
@@ -267,7 +269,7 @@ type FS interface {
// - On Windows, the path separator is different from other platforms,
// but to provide consistent results to Wasm, this normalizes to a "/"
// separator.
Readlink(path string) (string, syscall.Errno)
Readlink(path string) (string, experimentalsys.Errno)
// Utimens set file access and modification times on a path relative to
// this file system, at nanosecond precision.
@@ -275,25 +277,26 @@ type FS interface {
// # Parameters
//
// The `times` parameter includes the access and modification timestamps to
// assign. Special syscall.Timespec NSec values platform.UTIME_NOW and
// platform.UTIME_OMIT may be specified instead of real timestamps. A nil
// `times` parameter behaves the same as if both were set to
// platform.UTIME_NOW.
// assign. Special syscall.Timespec NSec values UTIME_NOW and UTIME_OMIT
// may be specified instead of real timestamps. A nil `times` parameter
// behaves the same as if both were set to UTIME_NOW.
//
// When the `symlinkFollow` parameter is true and the path is a symbolic link,
// the target of expanding that link is updated.
//
// # Errors
//
// A zero syscall.Errno is success. The below are expected otherwise:
// - syscall.ENOSYS: the implementation does not support this function.
// - syscall.EINVAL: `path` is invalid.
// - syscall.EEXIST: `path` exists and is a directory.
// - syscall.ENOTDIR: `path` exists and is a file.
// A zero Errno is success. The below are expected otherwise:
// - ENOSYS: the implementation does not support this function.
// - EINVAL: `path` is invalid.
// - EEXIST: `path` exists and is a directory.
// - ENOTDIR: `path` exists and is a file.
//
// # Notes
//
// - This is like syscall.UtimesNano and `utimensat` with `AT_FDCWD` in
// POSIX. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html
Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) syscall.Errno
Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) experimentalsys.Errno
// TODO: change impl to not use syscall package,
// possibly by being just a pair of int64s..
}

View File

@@ -5,10 +5,11 @@ import (
"syscall"
"time"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)
// UnimplementedFS is an FS that returns syscall.ENOSYS for all functions,
// UnimplementedFS is an FS that returns ENOSYS for all functions,
// This should be embedded to have forward compatible implementations.
type UnimplementedFS struct{}
@@ -19,92 +20,92 @@ func (UnimplementedFS) String() string {
// Open implements the same method as documented on fs.FS
func (UnimplementedFS) Open(name string) (fs.File, error) {
return nil, &fs.PathError{Op: "open", Path: name, Err: syscall.ENOSYS}
return nil, &fs.PathError{Op: "open", Path: name, Err: experimentalsys.ENOSYS}
}
// OpenFile implements FS.OpenFile
func (UnimplementedFS) OpenFile(path string, flag int, perm fs.FileMode) (File, syscall.Errno) {
return nil, syscall.ENOSYS
func (UnimplementedFS) OpenFile(path string, flag int, perm fs.FileMode) (File, experimentalsys.Errno) {
return nil, experimentalsys.ENOSYS
}
// Lstat implements FS.Lstat
func (UnimplementedFS) Lstat(path string) (sys.Stat_t, syscall.Errno) {
return sys.Stat_t{}, syscall.ENOSYS
func (UnimplementedFS) Lstat(path string) (sys.Stat_t, experimentalsys.Errno) {
return sys.Stat_t{}, experimentalsys.ENOSYS
}
// Stat implements FS.Stat
func (UnimplementedFS) Stat(path string) (sys.Stat_t, syscall.Errno) {
return sys.Stat_t{}, syscall.ENOSYS
func (UnimplementedFS) Stat(path string) (sys.Stat_t, experimentalsys.Errno) {
return sys.Stat_t{}, experimentalsys.ENOSYS
}
// Readlink implements FS.Readlink
func (UnimplementedFS) Readlink(path string) (string, syscall.Errno) {
return "", syscall.ENOSYS
func (UnimplementedFS) Readlink(path string) (string, experimentalsys.Errno) {
return "", experimentalsys.ENOSYS
}
// Mkdir implements FS.Mkdir
func (UnimplementedFS) Mkdir(path string, perm fs.FileMode) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Mkdir(path string, perm fs.FileMode) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Chmod implements FS.Chmod
func (UnimplementedFS) Chmod(path string, perm fs.FileMode) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Rename implements FS.Rename
func (UnimplementedFS) Rename(from, to string) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Rename(from, to string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Rmdir implements FS.Rmdir
func (UnimplementedFS) Rmdir(path string) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Rmdir(path string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Link implements FS.Link
func (UnimplementedFS) Link(_, _ string) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Link(_, _ string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Symlink implements FS.Symlink
func (UnimplementedFS) Symlink(_, _ string) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Symlink(_, _ string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Unlink implements FS.Unlink
func (UnimplementedFS) Unlink(path string) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Unlink(path string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Utimens implements FS.Utimens
func (UnimplementedFS) Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Truncate implements FS.Truncate
func (UnimplementedFS) Truncate(string, int64) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFS) Truncate(string, int64) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// UnimplementedFile is a File that returns syscall.ENOSYS for all functions,
// UnimplementedFile is a File that returns ENOSYS for all functions,
// except where no-op are otherwise documented.
//
// This should be embedded to have forward compatible implementations.
type UnimplementedFile struct{}
// Dev implements File.Dev
func (UnimplementedFile) Dev() (uint64, syscall.Errno) {
func (UnimplementedFile) Dev() (uint64, experimentalsys.Errno) {
return 0, 0
}
// Ino implements File.Ino
func (UnimplementedFile) Ino() (sys.Inode, syscall.Errno) {
func (UnimplementedFile) Ino() (sys.Inode, experimentalsys.Errno) {
return 0, 0
}
// IsDir implements File.IsDir
func (UnimplementedFile) IsDir() (bool, syscall.Errno) {
func (UnimplementedFile) IsDir() (bool, experimentalsys.Errno) {
return false, 0
}
@@ -114,8 +115,8 @@ func (UnimplementedFile) IsAppend() bool {
}
// SetAppend implements File.SetAppend
func (UnimplementedFile) SetAppend(bool) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFile) SetAppend(bool) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// IsNonblock implements File.IsNonblock
@@ -124,69 +125,69 @@ func (UnimplementedFile) IsNonblock() bool {
}
// SetNonblock implements File.SetNonblock
func (UnimplementedFile) SetNonblock(bool) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFile) SetNonblock(bool) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Stat implements File.Stat
func (UnimplementedFile) Stat() (sys.Stat_t, syscall.Errno) {
return sys.Stat_t{}, syscall.ENOSYS
func (UnimplementedFile) Stat() (sys.Stat_t, experimentalsys.Errno) {
return sys.Stat_t{}, experimentalsys.ENOSYS
}
// Read implements File.Read
func (UnimplementedFile) Read([]byte) (int, syscall.Errno) {
return 0, syscall.ENOSYS
func (UnimplementedFile) Read([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.ENOSYS
}
// Pread implements File.Pread
func (UnimplementedFile) Pread([]byte, int64) (int, syscall.Errno) {
return 0, syscall.ENOSYS
func (UnimplementedFile) Pread([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.ENOSYS
}
// Seek implements File.Seek
func (UnimplementedFile) Seek(int64, int) (int64, syscall.Errno) {
return 0, syscall.ENOSYS
func (UnimplementedFile) Seek(int64, int) (int64, experimentalsys.Errno) {
return 0, experimentalsys.ENOSYS
}
// Readdir implements File.Readdir
func (UnimplementedFile) Readdir(int) (dirents []Dirent, errno syscall.Errno) {
return nil, syscall.ENOSYS
func (UnimplementedFile) Readdir(int) (dirents []Dirent, errno experimentalsys.Errno) {
return nil, experimentalsys.ENOSYS
}
// PollRead implements File.PollRead
func (UnimplementedFile) PollRead(*time.Duration) (ready bool, errno syscall.Errno) {
return false, syscall.ENOSYS
func (UnimplementedFile) PollRead(*time.Duration) (ready bool, errno experimentalsys.Errno) {
return false, experimentalsys.ENOSYS
}
// Write implements File.Write
func (UnimplementedFile) Write([]byte) (int, syscall.Errno) {
return 0, syscall.ENOSYS
func (UnimplementedFile) Write([]byte) (int, experimentalsys.Errno) {
return 0, experimentalsys.ENOSYS
}
// Pwrite implements File.Pwrite
func (UnimplementedFile) Pwrite([]byte, int64) (int, syscall.Errno) {
return 0, syscall.ENOSYS
func (UnimplementedFile) Pwrite([]byte, int64) (int, experimentalsys.Errno) {
return 0, experimentalsys.ENOSYS
}
// Truncate implements File.Truncate
func (UnimplementedFile) Truncate(int64) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFile) Truncate(int64) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Sync implements File.Sync
func (UnimplementedFile) Sync() syscall.Errno {
return 0 // not syscall.ENOSYS
func (UnimplementedFile) Sync() experimentalsys.Errno {
return 0 // not ENOSYS
}
// Datasync implements File.Datasync
func (UnimplementedFile) Datasync() syscall.Errno {
return 0 // not syscall.ENOSYS
func (UnimplementedFile) Datasync() experimentalsys.Errno {
return 0 // not ENOSYS
}
// Utimens implements File.Utimens
func (UnimplementedFile) Utimens(*[2]syscall.Timespec) syscall.Errno {
return syscall.ENOSYS
func (UnimplementedFile) Utimens(*[2]syscall.Timespec) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Close implements File.Close
func (UnimplementedFile) Close() (errno syscall.Errno) { return }
func (UnimplementedFile) Close() (errno experimentalsys.Errno) { return }