unimplemented.go

  1package sys
  2
  3import (
  4	"io/fs"
  5
  6	"github.com/tetratelabs/wazero/sys"
  7)
  8
  9// UnimplementedFS is an FS that returns ENOSYS for all functions,
 10// This should be embedded to have forward compatible implementations.
 11type UnimplementedFS struct{}
 12
 13// OpenFile implements FS.OpenFile
 14func (UnimplementedFS) OpenFile(path string, flag Oflag, perm fs.FileMode) (File, Errno) {
 15	return nil, ENOSYS
 16}
 17
 18// Lstat implements FS.Lstat
 19func (UnimplementedFS) Lstat(path string) (sys.Stat_t, Errno) {
 20	return sys.Stat_t{}, ENOSYS
 21}
 22
 23// Stat implements FS.Stat
 24func (UnimplementedFS) Stat(path string) (sys.Stat_t, Errno) {
 25	return sys.Stat_t{}, ENOSYS
 26}
 27
 28// Readlink implements FS.Readlink
 29func (UnimplementedFS) Readlink(path string) (string, Errno) {
 30	return "", ENOSYS
 31}
 32
 33// Mkdir implements FS.Mkdir
 34func (UnimplementedFS) Mkdir(path string, perm fs.FileMode) Errno {
 35	return ENOSYS
 36}
 37
 38// Chmod implements FS.Chmod
 39func (UnimplementedFS) Chmod(path string, perm fs.FileMode) Errno {
 40	return ENOSYS
 41}
 42
 43// Rename implements FS.Rename
 44func (UnimplementedFS) Rename(from, to string) Errno {
 45	return ENOSYS
 46}
 47
 48// Rmdir implements FS.Rmdir
 49func (UnimplementedFS) Rmdir(path string) Errno {
 50	return ENOSYS
 51}
 52
 53// Link implements FS.Link
 54func (UnimplementedFS) Link(_, _ string) Errno {
 55	return ENOSYS
 56}
 57
 58// Symlink implements FS.Symlink
 59func (UnimplementedFS) Symlink(_, _ string) Errno {
 60	return ENOSYS
 61}
 62
 63// Unlink implements FS.Unlink
 64func (UnimplementedFS) Unlink(path string) Errno {
 65	return ENOSYS
 66}
 67
 68// Utimens implements FS.Utimens
 69func (UnimplementedFS) Utimens(path string, atim, mtim int64) Errno {
 70	return ENOSYS
 71}
 72
 73// UnimplementedFile is a File that returns ENOSYS for all functions,
 74// except where no-op are otherwise documented.
 75//
 76// This should be embedded to have forward compatible implementations.
 77type UnimplementedFile struct{}
 78
 79// Dev implements File.Dev
 80func (UnimplementedFile) Dev() (uint64, Errno) {
 81	return 0, 0
 82}
 83
 84// Ino implements File.Ino
 85func (UnimplementedFile) Ino() (sys.Inode, Errno) {
 86	return 0, 0
 87}
 88
 89// IsDir implements File.IsDir
 90func (UnimplementedFile) IsDir() (bool, Errno) {
 91	return false, 0
 92}
 93
 94// IsAppend implements File.IsAppend
 95func (UnimplementedFile) IsAppend() bool {
 96	return false
 97}
 98
 99// SetAppend implements File.SetAppend
100func (UnimplementedFile) SetAppend(bool) Errno {
101	return ENOSYS
102}
103
104// Stat implements File.Stat
105func (UnimplementedFile) Stat() (sys.Stat_t, Errno) {
106	return sys.Stat_t{}, ENOSYS
107}
108
109// Read implements File.Read
110func (UnimplementedFile) Read([]byte) (int, Errno) {
111	return 0, ENOSYS
112}
113
114// Pread implements File.Pread
115func (UnimplementedFile) Pread([]byte, int64) (int, Errno) {
116	return 0, ENOSYS
117}
118
119// Seek implements File.Seek
120func (UnimplementedFile) Seek(int64, int) (int64, Errno) {
121	return 0, ENOSYS
122}
123
124// Readdir implements File.Readdir
125func (UnimplementedFile) Readdir(int) (dirents []Dirent, errno Errno) {
126	return nil, ENOSYS
127}
128
129// Write implements File.Write
130func (UnimplementedFile) Write([]byte) (int, Errno) {
131	return 0, ENOSYS
132}
133
134// Pwrite implements File.Pwrite
135func (UnimplementedFile) Pwrite([]byte, int64) (int, Errno) {
136	return 0, ENOSYS
137}
138
139// Truncate implements File.Truncate
140func (UnimplementedFile) Truncate(int64) Errno {
141	return ENOSYS
142}
143
144// Sync implements File.Sync
145func (UnimplementedFile) Sync() Errno {
146	return 0 // not ENOSYS
147}
148
149// Datasync implements File.Datasync
150func (UnimplementedFile) Datasync() Errno {
151	return 0 // not ENOSYS
152}
153
154// Utimens implements File.Utimens
155func (UnimplementedFile) Utimens(int64, int64) Errno {
156	return ENOSYS
157}
158
159// Close implements File.Close
160func (UnimplementedFile) Close() (errno Errno) { return }