public interface IDesktopVolumes : IAsyncDisposable The desktop's storage volumes: listing, mounting, unmounting, ejecting and change notifications.
Remarks
Mounting and unmounting may ask the user for authorization, such as a Polkit password prompt on Linux. A refused authorization is PlatformFailureCode.PermissionDenied, a dismissed prompt PlatformFailureCode.UserDismissed, a volume in use PlatformFailureCode.ResourceBusy, a locked encrypted volume PlatformFailureCode.Locked, and an identifier of a volume that is not present PlatformFailureCode.NotFound. An operation the volume or platform does not offer, such as mounting on Windows, which mounts volumes itself, is PlatformUnavailableReason.BackendUnavailable.
Methods are safe to call from any thread; results and watch items arrive on the thread pool.
Methods
EjectAsync
ValueTask<PlatformResult<PlatformUnit>> EjectAsync(string volumeId, CancellationToken cancellationToken = default) Unmounts every volume of the volume's drive, then ejects its media or the drive itself.
Parameters
volumeIdThe
DesktopVolume.Idof any volume of the drive.cancellationTokenCancels waiting for the result.
ListAsync
ValueTask<PlatformResult<ImmutableArray<DesktopVolume>>> ListAsync(CancellationToken cancellationToken = default) Lists the present volumes.
MountAsync
ValueTask<PlatformResult<DesktopVolume>> MountAsync(string volumeId, CancellationToken cancellationToken = default) Mounts a volume and returns it with its mount path.
Parameters
volumeIdThe volume's
DesktopVolume.Id.cancellationTokenCancels waiting for the result; an authorization prompt the desktop already showed may stay open.
MountAsync
ValueTask<PlatformResult<DesktopVolume>> MountAsync(string volumeId, DesktopVolumeMountOptions options, CancellationToken cancellationToken) Mounts a volume with options and returns it with its mount path.
Parameters
volumeIdThe volume's
DesktopVolume.Id.optionsRead-only and platform mount options.
cancellationTokenCancels waiting for the result; an authorization prompt the desktop already showed may stay open.
Exceptions
ArgumentNullExceptionoptionsisnull.
Remarks
Linux passes the options to UDisks2 (ro for DesktopVolumeMountOptions.ReadOnly) and macOS to Disk Arbitration (rdonly). Windows mounts volumes itself and reports PlatformUnavailableReason.BackendUnavailable for any options but the default. The token is required so that MountAsync(id, default) keeps binding to IDesktopVolumes.MountAsync. The default implementation calls that overload for the default options and otherwise reports PlatformUnavailableReason.BackendUnavailable.
UnlockAsync
ValueTask<PlatformResult<DesktopVolume>> UnlockAsync(string volumeId, CancellationToken cancellationToken = default) Unlocks a locked encrypted volume through the operating system's own prompt and returns it unlocked.
Parameters
volumeIdThe volume's
DesktopVolume.Id; itsDesktopVolume.UnlockMethodisDesktopVolumeUnlockMethod.SystemPrompt.cancellationTokenCancels waiting for the result; a prompt the system already showed may stay open.
Returns
The unlocked volume; a volume that is not locked succeeds. A dismissed prompt, or one that leaves the volume locked, is PlatformFailureCode.UserDismissed. Where the system has no such prompt, such as on Linux and macOS, the result is PlatformUnavailableReason.BackendUnavailable, as the default implementation returns.
UnlockAsync
ValueTask<PlatformResult<DesktopVolume>> UnlockAsync(string volumeId, ReadOnlyMemory<char> passphrase, CancellationToken cancellationToken) Unlocks a locked encrypted volume with a passphrase and returns it unlocked.
Parameters
volumeIdThe volume's
DesktopVolume.Id; itsDesktopVolume.UnlockMethodisDesktopVolumeUnlockMethod.Passphrase.passphraseThe passphrase. Runic keeps no copy after the call: macOS writes it to
diskutil's standard input from a buffer Runic clears, Linux sends it to UDisks2 over the system bus. Clear your own copy once the call returns.cancellationTokenCancels waiting for the result; an authorization prompt the desktop already showed may stay open.
Returns
The unlocked volume. On Linux this is the cleartext filesystem, whose DesktopVolume.Id differs from the locked container's; a watch reports the container Removed and the filesystem Added. A wrong passphrase is PlatformFailureCode.Other with the native error, because UDisks2 and diskutil do not tell it apart from other failures; a refused authorization is PlatformFailureCode.PermissionDenied. Windows, which needs an administrator for a BitLocker passphrase, reports PlatformUnavailableReason.BackendUnavailable, as the default implementation does.
Exceptions
ArgumentExceptionpassphraseis empty.
UnmountAsync
ValueTask<PlatformResult<PlatformUnit>> UnmountAsync(string volumeId, CancellationToken cancellationToken = default) Unmounts a volume from every mount path. A volume that is not mounted succeeds.
Parameters
volumeIdThe volume's
DesktopVolume.Id.cancellationTokenCancels waiting for the result.
WatchAsync
IAsyncEnumerable<PlatformResult<DesktopVolumeChange>> WatchAsync(CancellationToken cancellationToken = default) Reports a Snapshot of every volume, then each change as it happens.
Remarks
When the volume service stops, the watch reports Unavailable and continues with a new snapshot once it is back. Without a volume service the watch reports Unavailable once and then waits.