AlphaOmega.DeviceIoControl
1.2.4
dotnet add package AlphaOmega.DeviceIoControl --version 1.2.4
NuGet\Install-Package AlphaOmega.DeviceIoControl -Version 1.2.4
<PackageReference Include="AlphaOmega.DeviceIoControl" Version="1.2.4" />
<PackageVersion Include="AlphaOmega.DeviceIoControl" Version="1.2.4" />
<PackageReference Include="AlphaOmega.DeviceIoControl" />
paket add AlphaOmega.DeviceIoControl --version 1.2.4
#r "nuget: AlphaOmega.DeviceIoControl, 1.2.4"
#:package AlphaOmega.DeviceIoControl@1.2.4
#addin nuget:?package=AlphaOmega.DeviceIoControl&version=1.2.4
#tool nuget:?package=AlphaOmega.DeviceIoControl&version=1.2.4
DeviceIoControl assembly
Wrapper around the Windows DeviceIoControl Win32 API providing strongly-typed access to common IOCTL and FSCTL control codes (volume, disk, storage, SMART, filesystem statistics, etc.). Primary purpose is reading S.M.A.R.T. data and low-level device characteristics from physical drives.
Original SMART C++ source (by Andrew I. Reshin, 11.02.2001) is preserved in S.M.A.R.T.rar.
Install
NuGet:
dotnet add package AlphaOmega.DeviceIoControl
Targets: .NET 8, .NET Standard 2.0, .NET Framework 3.5
Quick usage
using AlphaOmega.DeviceIoControl;
using(var device = new DeviceIoControl(@"c:\")) // Path to a logical drive or volume root
{
bool isOn = device.IsDeviceOn;
Console.WriteLine($"Device is {(isOn ? "on" : "off")}");
// DISC SMART version & capabilities
var version = device.Disc.Version?.Value;
if(version != null)
{
Console.WriteLine("Capabilities: " +
string.Join(", ", new [] {
version.IsAtaSupported ? "ATA" : null,
version.IsAtapiSupported ? "ATAPI" : null,
version.IsSmartSupported ? "SMART" : null,
}.Where(x => x != null)));
}
// SMART data
var smart = device.Disc.Smart;
if(smart != null)
{
Console.WriteLine("=== INFO ===");
Console.WriteLine($"Model: {smart.SystemParams.ModelNumber}\n" +
$"Serial: {smart.SystemParams.SerialNumber}\n" +
$"Firmware: {smart.SystemParams.FirmwareRev}\n" +
$"User LBA capacity: {smart.SystemParams.ulTotalAddressableSectors:n0} sectors");
}
}
Additional examples
Enumerate disk extents of a volume:
using(var device = new DeviceIoControl(@"c:\"))
{
var extents = device.Volume.DiskExtents; // IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
foreach(var e in extents.Extents)
Console.WriteLine($"Disk #{e.DiskNumber} offset {e.StartingOffset} length {e.ExtentLength}");
}
Query storage device number:
using(var device = new DeviceIoControl(@"c:\"))
{
var devNum = device.Storage.DeviceNumber; // IOCTL_STORAGE_GET_DEVICE_NUMBER
Console.WriteLine($"DeviceType={devNum.DeviceType} Number={devNum.DeviceNumber} Partition={devNum.PartitionNumber}");
}
Safely eject removable media:
using(var device = new DeviceIoControl(@"e:\"))
{
device.Storage.MediaRemoval(true); // Prevent removal lock
device.Storage.EjectMedia(); // IOCTL_STORAGE_EJECT_MEDIA
}
Supported structures / control codes
- IOCTL_VOLUME
- GET_VOLUME_DISK_EXTENTS
- IS_CLUSTERED
- IOCTL_DISC
- PERFORMANCE / PERFORMANCE_OFF
- IS_WRITABLE
- SMART_GET_VERSION
- SMART_SEND_DRIVE_COMMAND
- SMART_RCV_DRIVE_DATA
- GET_DRIVE_GEOMETRY_EX
- IOCTL_STORAGE
- CHECK_VERIFY / CHECK_VERIFY2
- MEDIA_REMOVAL / EJECT_MEDIA
- GET_MEDIA_TYPES_EX
- GET_MEDIA_SERIAL_NUMBER
- GET_HOTPLUG_INFO
- GET_DEVICE_NUMBER
- PREDICT_FAILURE
- QUERY_PROPERTY
- FSCTL
- LOCK_VOLUME / UNLOCK_VOLUME / DISMOUNT_VOLUME
- IS_VOLUME_MOUNTED
- FILESYSTEM_GET_STATISTICS
- GET_NTFS_VOLUME_DATA
- GET_VOLUME_BITMAP
Error handling
Each property method internally calls DeviceIoControl. If the underlying API returns an error (GetLastError) it surfaces via thrown IOException / Win32Exception. Some properties can be null when not supported by device / OS.
Security / permissions
Most queries require only read access. Operations like locking, dismounting, media removal or eject need elevated privileges and exclusive access. Always ensure handles are disposed before performing sensitive tasks.
Performance notes
SMART queries may spin up sleeping disks. Cache results externally if invoked frequently. Methods avoid unnecessary allocations and pinvoke marshaling is minimized.
Building
Clone and build with .NET SDK 8+ (for multi-targeting). Legacy .NET Framework 3.5 build may require VS with older targeting packs installed.
Disclaimer
Low-level device operations can cause data loss if misused (e.g. improper locking/eject). Use read-only APIs unless you understand the implications.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net35 is compatible. net40 was computed. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 3.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.4 | 218 | 10/28/2025 |
| 1.2.2 | 351 | 12/5/2023 |
| 1.0.8418.35733 | 345 | 1/18/2023 |