WasiHostFileSystem Class
A file system whose files are the files of a directory of the disk, which the module cannot leave.
public sealed class WasiHostFileSystem : WasiFileSystemRemarks
WASI resolves the paths of the module before calling the file system: it follows the symbolic links itself, and rejects the paths and the links that leave the directory, the absolute paths and the absolute links. This file system also rejects the names that are not portable on Windows (\, :, *, ?, ", <, >, |, the control characters, the reserved names such as CON or NUL, and the names that end with a dot or a space) on Windows, and checks that the full path of each file is inside the directory.
The checks and the operations are not atomic: a process of the host that replaces a directory of the file system with a link between the check and the operation could make the module access the target of the link. Do not give the module a directory that untrusted processes can change.
The hard links are supported on Windows (NTFS, ReFS), Linux, macOS and FreeBSD: a hard link never follows a symbolic link, so that the module cannot link a file outside of the directory. The serial numbers of the files (which tell the hard links of a file) and their numbers of links come from the platform on Windows, Linux and macOS.
- Inheritance
WasiFileSystemWasiHostFileSystem
Constructors
| Name | Description |
|---|---|
| WasiHostFileSystem(string, bool) | Initializes a new instance of the WasiHostFileSystem class. |
WasiHostFileSystem(string, bool)
WasiHostFileSystem.csInitializes a new instance of the WasiHostFileSystem class.
Parameters
rootDirectorystring- The directory of the files. It must exist.
isReadOnlybool- Whether the module can only read the files.
Exceptions
DirectoryNotFoundException- The directory does not exist.
Properties
| Name | Description |
|---|---|
| IsReadOnly | Gets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem. |
| RootDirectory | Gets the full path of the directory of the files. |
IsReadOnly
WasiHostFileSystem.csGets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem.
public override bool IsReadOnly { get; }Property value
RootDirectory
WasiHostFileSystem.csMethods
| 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)
WasiHostFileSystem.csCreateHardLink(string, string)
WasiHostFileSystem.csCreates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
CreateSymbolicLink(string, string)
WasiHostFileSystem.csCreates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
DeleteDirectory(string)
WasiHostFileSystem.csDeleteFile(string)
WasiHostFileSystem.csEnumerateDirectory(string)
WasiHostFileSystem.csReturns the entries of a directory, without . and ...
public override IEnumerable<WasiDirectoryEntry> EnumerateDirectory(string path)GetStat(string)
WasiHostFileSystem.csReturns 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 override WasiFileStat? GetStat(string path)Move(string, string)
WasiHostFileSystem.csMoves a file, a directory or a symbolic link.
OpenFile(string, FileMode, FileAccess)
WasiHostFileSystem.csOpens a regular file. The stream of a regular file must be seekable.
public override 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)
WasiHostFileSystem.csReplace(string, string)
WasiHostFileSystem.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?)
WasiHostFileSystem.csChanges the times of a file or of a directory.
public override 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.