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 WasiFileSystem

Remarks

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

NameDescription
WasiFileSystem()Initializes a new instance of the WasiFileSystem class.

WasiFileSystem()

WasiFileSystem.cs

Initializes a new instance of the WasiFileSystem class.

protected WasiFileSystem()

Properties

NameDescription
IsReadOnlyGets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem.

Gets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem.

public virtual bool IsReadOnly { get; }

Property value

bool

Methods

NameDescription
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)

Creates a directory.

public abstract void CreateDirectory(string path)

Parameters

path string
The path of the directory, which does not exist. Its parent is an existing directory.

CreateHardLink(string, string)

WasiFileSystem.cs

Creates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.

public virtual void CreateHardLink(string path, string existingPath)

Parameters

path string
The path of the link, which does not exist. Its parent is an existing directory.
existingPath string
The path of an existing regular file.

CreateSymbolicLink(string, string)

WasiFileSystem.cs

Creates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.

public virtual void CreateSymbolicLink(string path, string target)

Parameters

path string
The path of the link, which does not exist. Its parent is an existing directory.
target string
The target of the link, relative to the directory of the link, with / separators.

DeleteDirectory(string)

Deletes a directory.

public abstract void DeleteDirectory(string path)

Parameters

path string
The path of an existing empty directory, which is not the root.

DeleteFile(string)

Deletes a file or a symbolic link (not its target).

public abstract void DeleteFile(string path)

Parameters

path string
The path of an existing file or symbolic link.

EnumerateDirectory(string)

Returns the entries of a directory, without . and ...

public abstract IEnumerable<WasiDirectoryEntry> EnumerateDirectory(string path)

Parameters

path string
The path of an existing directory.

Returns

IEnumerable<WasiDirectoryEntry>

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)

Parameters

path string
The path of the file.

Returns

WasiFileStat?

Move(string, string)

Moves a file, a directory or a symbolic link.

public abstract void Move(string sourcePath, string destinationPath)

Parameters

sourcePath string
The path of the existing file, which is not the root.
destinationPath string
The new path of the file, which does not exist. Its parent is an existing directory, which is not inside sourcePath.

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

path string
The path of the file. Its parent is an existing directory.
mode FileMode
How the file is opened, or created.
access FileAccess
The access to the file.

Returns

Stream

ReadSymbolicLink(string)

Returns the target of a symbolic link, with / separators. A target that starts with / is absolute: WASI does not follow it.

public abstract string ReadSymbolicLink(string path)

Parameters

path string
The path of the symbolic link.

Returns

string

Replace(string, string)

WasiFileSystem.cs

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.

public virtual void Replace(string sourcePath, string destinationPath)

Parameters

sourcePath string
The path of the existing file or symbolic link, which is not the root.
destinationPath string
The path of the existing file or symbolic link to replace.

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

path string
The path of an existing file or directory.
lastAccessTime DateTimeOffset?
The new time of the last access, or null to keep it.
lastWriteTime DateTimeOffset?
The new time of the last write, or null to keep it.