WasiFileSystem Class
A file system that a WASI module reads and writes through a preopened directory (see WasiPreopenedDirectory): WasiHostFileSystem for a directory of the disk, or WasiInMemoryFileSystem for files in memory.
public abstract class WasiFileSystemRemarks
The paths are relative to the root of the file system, separated by /, without empty, . or .. segments; the root is the empty string. WASI resolves the paths of the module before calling the file system: it follows the symbolic links (WasiFileSystem.ReadSymbolicLink) and rejects the paths that leave the directory they are relative to, so that the module cannot reach the files outside of the file system.
WASI checks the preconditions of the operations before calling the methods (the type of the file, an existing destination, a directory that is not empty, ...). The methods throw a WasiException to report an error with a precise code; the other exceptions of the file system (IOException, UnauthorizedAccessException, ...) are converted to the closest code.
Constructors
| Name | Description |
|---|---|
| WasiFileSystem() | Initializes a new instance of the WasiFileSystem class. |
WasiFileSystem()
WasiFileSystem.csInitializes a new instance of the WasiFileSystem class.
protected WasiFileSystem()Properties
| Name | Description |
|---|---|
| IsReadOnly | Gets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem. |
IsReadOnly
WasiFileSystem.csGets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem.
public virtual bool IsReadOnly { get; }Property value
Methods
| Name | Description |
|---|---|
| CreateDirectory(string) | Creates a directory. |
| CreateHardLink(string, string) | Creates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported. |
| CreateSymbolicLink(string, string) | Creates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported. |
| DeleteDirectory(string) | Deletes a directory. |
| DeleteFile(string) | Deletes a file or a symbolic link (not its target). |
| EnumerateDirectory(string) | Returns the entries of a directory, without . and ... |
| GetStat(string) | Returns the status of a file, of a directory or of a symbolic link (not of its target), or null when it does not exist. |
| Move(string, string) | Moves a file, a directory or a symbolic link. |
| OpenFile(string, FileMode, FileAccess) | Opens a regular file. The stream of a regular file must be seekable. |
| ReadSymbolicLink(string) | Returns the target of a symbolic link, with / separators. A target that starts with / is absolute: WASI does not follow it. |
| Replace(string, string) | Moves a file or a symbolic link over an existing file or symbolic link, which it replaces (a rename of POSIX). The default implementation deletes the destination, then moves the source: override it to replace the destination in one operation, so that a move that fails does not lose the destination. |
| SetTimes(string, DateTimeOffset?, DateTimeOffset?) | Changes the times of a file or of a directory. |
CreateDirectory(string)
CreateHardLink(string, string)
WasiFileSystem.csCreates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
CreateSymbolicLink(string, string)
WasiFileSystem.csCreates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
DeleteDirectory(string)
DeleteFile(string)
EnumerateDirectory(string)
Returns the entries of a directory, without . and ...
public abstract IEnumerable<WasiDirectoryEntry> EnumerateDirectory(string path)GetStat(string)
Returns the status of a file, of a directory or of a symbolic link (not of its target), or null when it does not exist.
public abstract WasiFileStat? GetStat(string path)Move(string, string)
Moves a file, a directory or a symbolic link.
OpenFile(string, FileMode, FileAccess)
Opens a regular file. The stream of a regular file must be seekable.
public abstract Stream OpenFile(string path, FileMode mode, FileAccess access)Parameters
pathstring- The path of the file. Its parent is an existing directory.
modeFileMode- How the file is opened, or created.
accessFileAccess- The access to the file.
Returns
ReadSymbolicLink(string)
Replace(string, string)
WasiFileSystem.csMoves a file or a symbolic link over an existing file or symbolic link, which it replaces (a rename of POSIX). The default implementation deletes the destination, then moves the source: override it to replace the destination in one operation, so that a move that fails does not lose the destination.
SetTimes(string, DateTimeOffset?, DateTimeOffset?)
Changes the times of a file or of a directory.
public abstract void SetTimes(string path, DateTimeOffset? lastAccessTime, DateTimeOffset? lastWriteTime)Parameters
pathstring- The path of an existing file or directory.
lastAccessTimeDateTimeOffset?- The new time of the last access, or null to keep it.
lastWriteTimeDateTimeOffset?- The new time of the last write, or null to keep it.