github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/experimental/sysfs/sysfs.go (about) 1 // Package sysfs includes a low-level filesystem interface and utilities needed 2 // for WebAssembly host functions (ABI) such as WASI and runtime.GOOS=js. 3 // 4 // The name sysfs was chosen because wazero's public API has a "sys" package, 5 // which was named after https://github.com/golang/sys. 6 // 7 // This tracked in https://github.com/bananabytelabs/wazero/issues/1013 8 package sysfs 9 10 import ( 11 experimentalsys "github.com/bananabytelabs/wazero/experimental/sys" 12 "github.com/bananabytelabs/wazero/internal/sysfs" 13 ) 14 15 // AdaptFS adapts the input to sys.FS. Use DirFS instead of adapting an 16 // os.DirFS as it handles interop issues such as windows support. 17 // 18 // Note: This performs no flag verification on OpenFile. sys.FS cannot read 19 // flags as there is no parameter to pass them through with. Moreover, sys.FS 20 // documentation does not require the file to be present. In summary, we can't 21 // enforce flag behavior. 22 type AdaptFS = sysfs.AdaptFS 23 24 // DirFS is like os.DirFS except it returns sys.FS, which has more features. 25 func DirFS(dir string) experimentalsys.FS { 26 return sysfs.DirFS(dir) 27 } 28 29 // ReadFS is used to mask an existing sys.FS for reads. Notably, this allows 30 // the CLI to do read-only mounts of directories the host user can write, but 31 // doesn't want the guest wasm to. For example, Python libraries shouldn't be 32 // written to at runtime by the python wasm file. 33 // 34 // Note: This implements read-only by returning sys.EROFS or sys.EBADF, 35 // depending on the operation that require write access. 36 type ReadFS = sysfs.ReadFS