...
1 package sysfs
2
3 import (
4 "fmt"
5 "io/fs"
6 "path"
7
8 experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
9 "github.com/tetratelabs/wazero/sys"
10 )
11
12 type AdaptFS struct {
13 FS fs.FS
14 }
15
16
17 func (a *AdaptFS) String() string {
18 return fmt.Sprintf("%v", a.FS)
19 }
20
21
22 func (a *AdaptFS) OpenFile(path string, flag experimentalsys.Oflag, perm fs.FileMode) (experimentalsys.File, experimentalsys.Errno) {
23 return OpenFSFile(a.FS, cleanPath(path), flag, perm)
24 }
25
26
27 func (a *AdaptFS) Lstat(path string) (sys.Stat_t, experimentalsys.Errno) {
28
29
30
31
32
33
34
35
36 return a.Stat(path)
37 }
38
39
40 func (a *AdaptFS) Stat(path string) (sys.Stat_t, experimentalsys.Errno) {
41 f, errno := a.OpenFile(path, experimentalsys.O_RDONLY, 0)
42 if errno != 0 {
43 return sys.Stat_t{}, errno
44 }
45 defer f.Close()
46 return f.Stat()
47 }
48
49
50 func (a *AdaptFS) Readlink(string) (string, experimentalsys.Errno) {
51 return "", experimentalsys.ENOSYS
52 }
53
54
55 func (a *AdaptFS) Mkdir(string, fs.FileMode) experimentalsys.Errno {
56 return experimentalsys.ENOSYS
57 }
58
59
60 func (a *AdaptFS) Chmod(string, fs.FileMode) experimentalsys.Errno {
61 return experimentalsys.ENOSYS
62 }
63
64
65 func (a *AdaptFS) Rename(string, string) experimentalsys.Errno {
66 return experimentalsys.ENOSYS
67 }
68
69
70 func (a *AdaptFS) Rmdir(string) experimentalsys.Errno {
71 return experimentalsys.ENOSYS
72 }
73
74
75 func (a *AdaptFS) Link(string, string) experimentalsys.Errno {
76 return experimentalsys.ENOSYS
77 }
78
79
80 func (a *AdaptFS) Symlink(string, string) experimentalsys.Errno {
81 return experimentalsys.ENOSYS
82 }
83
84
85 func (a *AdaptFS) Unlink(string) experimentalsys.Errno {
86 return experimentalsys.ENOSYS
87 }
88
89
90 func (a *AdaptFS) Utimens(string, int64, int64) experimentalsys.Errno {
91 return experimentalsys.ENOSYS
92 }
93
94 func cleanPath(name string) string {
95 if len(name) == 0 {
96 return name
97 }
98
99 cleaned := name
100 if name[0] == '/' {
101 cleaned = name[1:]
102 }
103 cleaned = path.Clean(cleaned)
104 return cleaned
105 }
106
View as plain text