package sysfs
import "github.com/tetratelabs/wazero/internal/sysfs"
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.
Index ¶
- func FileDatasync(f fs.File) (err error)
- func ReaderAtOffset(f fs.File, offset int64) io.Reader
- func StripPrefixesAndTrailingSlash(path string) string
- func WriterAtOffset(f fs.File, offset int64) io.Writer
- type CompositeFS
- func (c *CompositeFS) Chmod(path string, perm fs.FileMode) error
- func (c *CompositeFS) Chown(path string, uid, gid int) error
- func (c *CompositeFS) FS() (fs []FS)
- func (c *CompositeFS) GuestPaths() (guestPaths []string)
- func (c *CompositeFS) Lchown(path string, uid, gid int) error
- func (c *CompositeFS) Link(oldName, newName string) error
- func (c *CompositeFS) Lstat(path string, stat *platform.Stat_t) error
- func (c *CompositeFS) Mkdir(path string, perm fs.FileMode) error
- func (c *CompositeFS) Open(name string) (fs.File, error)
- func (c *CompositeFS) OpenFile(path string, flag int, perm fs.FileMode) (f fs.File, err error)
- func (c *CompositeFS) Readlink(path string) (string, error)
- func (c *CompositeFS) Rename(from, to string) error
- func (c *CompositeFS) Rmdir(path string) error
- func (c *CompositeFS) Stat(path string, stat *platform.Stat_t) error
- func (c *CompositeFS) String() string
- func (c *CompositeFS) Symlink(oldName, link string) (err error)
- func (c *CompositeFS) Truncate(path string, size int64) error
- func (c *CompositeFS) Unlink(path string) error
- func (c *CompositeFS) Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) error
- type FS
- func Adapt(fs fs.FS) FS
- func NewDirFS(dir string) FS
- func NewReadFS(fs FS) FS
- func NewRootFS(fs []FS, guestPaths []string) (FS, error)
- type UnimplementedFS
- func (UnimplementedFS) Chmod(path string, perm fs.FileMode) error
- func (UnimplementedFS) Chown(path string, uid, gid int) error
- func (UnimplementedFS) Lchown(path string, uid, gid int) error
- func (UnimplementedFS) Link(_, _ string) error
- func (UnimplementedFS) Lstat(path string, stat *platform.Stat_t) error
- func (UnimplementedFS) Mkdir(path string, perm fs.FileMode) error
- func (UnimplementedFS) Open(name string) (fs.File, error)
- func (UnimplementedFS) OpenFile(path string, flag int, perm fs.FileMode) (fs.File, error)
- func (UnimplementedFS) Readlink(path string) (string, error)
- func (UnimplementedFS) Rename(from, to string) error
- func (UnimplementedFS) Rmdir(path string) error
- func (UnimplementedFS) Stat(path string, stat *platform.Stat_t) error
- func (UnimplementedFS) String() string
- func (UnimplementedFS) Symlink(_, _ string) error
- func (UnimplementedFS) Truncate(string, int64) error
- func (UnimplementedFS) Unlink(path string) error
- func (UnimplementedFS) Utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) error
Functions ¶
func FileDatasync ¶
FileDatasync is like syscall.Fdatasync except that's only defined in linux.
func ReaderAtOffset ¶
ReaderAtOffset gets an io.Reader from a fs.File that reads from an offset, yet doesn't affect the underlying position. This is used to implement syscall.Pread.
Note: The file accessed shouldn't be used concurrently, but wasm isn't safe to use concurrently anyway. Hence, we don't do any locking against parallel reads.
func StripPrefixesAndTrailingSlash ¶
func WriterAtOffset ¶
WriterAtOffset gets an io.Writer from a fs.File that writes to an offset, yet doesn't affect the underlying position. This is used to implement syscall.Pwrite.
Types ¶
type CompositeFS ¶
type CompositeFS struct { UnimplementedFS // contains filtered or unexported fields }
func (*CompositeFS) Chmod ¶
func (c *CompositeFS) Chmod(path string, perm fs.FileMode) error
Chmod implements FS.Chmod
func (*CompositeFS) Chown ¶
func (c *CompositeFS) Chown(path string, uid, gid int) error
Chown implements FS.Chown
func (*CompositeFS) FS ¶
func (c *CompositeFS) FS() (fs []FS)
FS returns the underlying filesystems in original order.
func (*CompositeFS) GuestPaths ¶
func (c *CompositeFS) GuestPaths() (guestPaths []string)
GuestPaths returns the underlying pre-open paths in original order.
func (*CompositeFS) Lchown ¶
func (c *CompositeFS) Lchown(path string, uid, gid int) error
Lchown implements FS.Lchown
func (*CompositeFS) Link ¶
func (c *CompositeFS) Link(oldName, newName string) error
Link implements FS.Link.
func (*CompositeFS) Lstat ¶
func (c *CompositeFS) Lstat(path string, stat *platform.Stat_t) error
Lstat implements FS.Lstat
func (*CompositeFS) Mkdir ¶
func (c *CompositeFS) Mkdir(path string, perm fs.FileMode) error
Mkdir implements FS.Mkdir
func (*CompositeFS) Open ¶
func (c *CompositeFS) Open(name string) (fs.File, error)
Open implements the same method as documented on fs.FS
func (*CompositeFS) OpenFile ¶
OpenFile implements FS.OpenFile
func (*CompositeFS) Readlink ¶
func (c *CompositeFS) Readlink(path string) (string, error)
Readlink implements FS.Readlink
func (*CompositeFS) Rename ¶
func (c *CompositeFS) Rename(from, to string) error
Rename implements FS.Rename
func (*CompositeFS) Rmdir ¶
func (c *CompositeFS) Rmdir(path string) error
Rmdir implements FS.Rmdir
func (*CompositeFS) Stat ¶
func (c *CompositeFS) Stat(path string, stat *platform.Stat_t) error
Stat implements FS.Stat
func (*CompositeFS) String ¶
func (c *CompositeFS) String() string
String implements fmt.Stringer
func (*CompositeFS) Symlink ¶
func (c *CompositeFS) Symlink(oldName, link string) (err error)
Symlink implements FS.Symlink
func (*CompositeFS) Truncate ¶
func (c *CompositeFS) Truncate(path string, size int64) error
Truncate implements FS.Truncate
func (*CompositeFS) Unlink ¶
func (c *CompositeFS) Unlink(path string) error
Unlink implements FS.Unlink
func (*CompositeFS) Utimens ¶
Utimens implements FS.Utimens
type FS ¶
type FS interface { // String should return a human-readable format of the filesystem // // For example, if this filesystem is backed by the real directory // "/tmp/wasm", the expected value is "/tmp/wasm". // // When the host filesystem isn't a real filesystem, substitute a symbolic, // human-readable name. e.g. "virtual" String() string // OpenFile is similar to os.OpenFile, except the path is relative to this // file system, and syscall.Errno are returned instead of a os.PathError. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` or `flag` is invalid. // - syscall.ENOENT: `path` doesn't exist and `flag` doesn't contain // os.O_CREATE. // // # Constraints on the returned file // // 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. // // Some implementations choose whether to enforce read-only opens, namely // fs.FS. While fs.FS is supported (Adapt), wazero cannot runtime enforce // open flags. Instead, we encourage good behavior and test our built-in // implementations. // // # Notes // // - flag are the same as OpenFile, for example, os.O_CREATE. // - Implications of permissions when os.O_CREATE are described in Chmod // notes. OpenFile(path string, flag int, perm fs.FileMode) (fs.File, error) // Lstat is similar to syscall.Lstat, except the path is relative to this // file system. // // # Errors // // The following errors are expected: // - syscall.ENOENT: `path` doesn't exist. // // # Notes // // - An fs.FileInfo backed implementation sets atim, mtim and ctim to the // 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, stat *platform.Stat_t) error // Stat is similar to syscall.Stat, except the path is relative to this // file system. // // # Errors // // The following errors are expected: // - syscall.ENOENT: `path` doesn't exist. // // # Notes // // - An fs.FileInfo backed implementation sets atim, mtim and ctim to the // same value. // - When the path is a symbolic link, the stat returned is for the file // it refers to. Stat(path string, stat *platform.Stat_t) error // Mkdir is similar to os.Mkdir, except the path is relative to this file // system, and syscall.Errno are returned instead of a os.PathError. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.EEXIST: `path` exists and is a directory. // - syscall.ENOTDIR: `path` exists and is a file. // // # Notes // // - Implications of permissions are described in Chmod notes. Mkdir(path string, perm fs.FileMode) error // Chmod is similar to os.Chmod, except the path is relative to this file // system, and syscall.Errno are returned instead of a os.PathError. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.ENOENT: `path` does not exist. // // # Notes // // - 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) error // Chown is like os.Chown except the path is relative to this file // system, and syscall.Errno are returned instead of an os.PathError. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.ENOENT: `path` does not exist. // // # Notes // // - Windows will always return syscall.ENOSYS // - This is similar to https://linux.die.net/man/3/chown Chown(path string, uid, gid int) error // Lchown is like os.Lchown except the path is relative to this file // system, and syscall.Errno are returned instead of a os.PathError. // See https://linux.die.net/man/3/lchown // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.ENOENT: `path` does not exist. // // # Notes // // - Windows will always return syscall.ENOSYS // - This is similar to https://linux.die.net/man/3/lchown Lchown(path string, uid, gid int) error // Rename is similar to syscall.Rename, except the path is relative to this // file system. // // # Errors // // The following errors are expected: // - 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 // `to` is not empty. // // # Notes // // - Windows doesn't let you overwrite an existing directory. Rename(from, to string) error // Rmdir is similar to syscall.Rmdir, except the path is relative to this // file system. // // # Errors // // The following errors are expected: // - 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. // // # Notes // // - As of Go 1.19, Windows maps syscall.ENOTDIR to syscall.ENOENT. Rmdir(path string) error // Unlink is similar to syscall.Unlink, except the path is relative to this // file system. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.ENOENT: `path` doesn't exist. // - syscall.EISDIR: `path` exists, but is a directory. // // # Notes // // - 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) error // Link is similar to syscall.Link, except the path is relative to this // file system. This creates "hard" link from oldPath to newPath, in // contrast to soft link as in Symlink. // // # Errors // // The following errors are expected: // - syscall.EPERM: `oldPath` is invalid. // - syscall.ENOENT: `oldPath` doesn't exist. // - syscall.EISDIR: `newPath` exists, but is a directory. Link(oldPath, newPath string) error // Symlink is similar to syscall.Symlink, except the `oldPath` is relative // to this file system. This creates "soft" link from oldPath to newPath, // in contrast to hard link as in Link. // // # Errors // // The following errors are expected: // - syscall.EPERM: `oldPath` or `newPath` is invalid. // - syscall.EEXIST: `newPath` exists. // // # Notes // // - Only `newPath` is relative to this file system and `oldPath` is kept // as-is. That is because the link is only resolved relative to the // directory when dereferencing it (e.g. ReadLink). // 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. // See https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links Symlink(oldPath, linkName string) error // Readlink is similar to syscall.Readlink, except the path is relative to // this file system. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // // # Notes // - 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, error) // Truncate is similar to syscall.Truncate, except the path is relative to // this file system. // // # Errors // // The following errors are expected: // - syscall.EINVAL: `path` is invalid or size is negative. // - syscall.ENOENT: `path` doesn't exist // - syscall.EACCES: `path` doesn't have write access. Truncate(path string, size int64) error // Utimens set file access and modification times on a path relative to // this file system, at nanosecond precision. // // # Parameters // // The `times` parameter includes the access and modification timestamps to // 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 // // The following errors are expected: // - syscall.EINVAL: `path` is invalid. // - syscall.EEXIST: `path` exists and is a directory. // - syscall.ENOTDIR: `path` exists and is a file. // // # Notes // // - This is similar to syscall.Utimens, except that doesn't have flags to // control expansion of symbolic links. It also doesn't support special // values UTIME_NOW or UTIME_NOW. // - This is like `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) error }
FS is a writeable fs.FS bridge backed by syscall functions needed for ABI including WASI and runtime.GOOS=js.
Implementations should embed UnimplementedFS for forward compatability. Any unsupported method or parameter should return syscall.ENOSYS.
See https://github.com/golang/go/issues/45757
func Adapt ¶
Adapt adapts the input to FS unless it is already one. Use NewDirFS instead of os.DirFS as it handles interop issues such as windows support.
Note: This performs no flag verification on FS.OpenFile. fs.FS cannot read flags as there is no parameter to pass them through with. Moreover, fs.FS documentation does not require the file to be present. In summary, we can't enforce flag behavior.
func NewDirFS ¶
func NewReadFS ¶
NewReadFS is used to mask an existing FS for reads. Notably, this allows the CLI to do read-only mounts of directories the host user can write, but doesn't want the guest wasm to. For example, Python libraries shouldn't be written to at runtime by the python wasm file.
func NewRootFS ¶
type UnimplementedFS ¶
type UnimplementedFS struct{}
UnimplementedFS is an FS that returns syscall.ENOSYS for all functions, This should be embedded to have forward compatible implementations.
func (UnimplementedFS) Chmod ¶
func (UnimplementedFS) Chmod(path string, perm fs.FileMode) error
Chmod implements FS.Chmod
func (UnimplementedFS) Chown ¶
func (UnimplementedFS) Chown(path string, uid, gid int) error
Chown implements FS.Chown
func (UnimplementedFS) Lchown ¶
func (UnimplementedFS) Lchown(path string, uid, gid int) error
Lchown implements FS.Lchown
func (UnimplementedFS) Link ¶
func (UnimplementedFS) Link(_, _ string) error
Link implements FS.Link
func (UnimplementedFS) Lstat ¶
func (UnimplementedFS) Lstat(path string, stat *platform.Stat_t) error
Lstat implements FS.Lstat
func (UnimplementedFS) Mkdir ¶
func (UnimplementedFS) Mkdir(path string, perm fs.FileMode) error
Mkdir implements FS.Mkdir
func (UnimplementedFS) Open ¶
func (UnimplementedFS) Open(name string) (fs.File, error)
Open implements the same method as documented on fs.FS
func (UnimplementedFS) OpenFile ¶
OpenFile implements FS.OpenFile
func (UnimplementedFS) Readlink ¶
func (UnimplementedFS) Readlink(path string) (string, error)
Readlink implements FS.Readlink
func (UnimplementedFS) Rename ¶
func (UnimplementedFS) Rename(from, to string) error
Rename implements FS.Rename
func (UnimplementedFS) Rmdir ¶
func (UnimplementedFS) Rmdir(path string) error
Rmdir implements FS.Rmdir
func (UnimplementedFS) Stat ¶
func (UnimplementedFS) Stat(path string, stat *platform.Stat_t) error
Stat implements FS.Stat
func (UnimplementedFS) String ¶
func (UnimplementedFS) String() string
String implements fmt.Stringer
func (UnimplementedFS) Symlink ¶
func (UnimplementedFS) Symlink(_, _ string) error
Symlink implements FS.Symlink
func (UnimplementedFS) Truncate ¶
func (UnimplementedFS) Truncate(string, int64) error
Truncate implements FS.Truncate
func (UnimplementedFS) Unlink ¶
func (UnimplementedFS) Unlink(path string) error
Unlink implements FS.Unlink
func (UnimplementedFS) Utimens ¶
Utimens implements FS.Utimens
Source Files ¶
adapter.go dirfs.go readfs.go rootfs.go sysfs.go unsupported.go
- Version
- v1.0.0-rc.2
- Published
- Mar 16, 2023
- Platform
- windows/amd64
- Imports
- 10 packages
- Last checked
- 7 hours ago –
Tools for package owners.