CreateFile returns Incorrect function
I get a list of physical disks with wmic diskdrive list command. There are two internal SSDs, one USB flash drive and one external SSD connected to USB-C port. CreateFile works for all of them except for external SSD, I get ERROR_INVALID_FUNCTION. When I connect the same SSD to USB port, it works as expected. What could be the problem?
I found some suggestions to look into IRP_MJ_CREATE, but there is no info how to use in VB.NET.
Code:
Dim result = CreateFile("\\.\PHYSICALDRIVE2", EFileAccess.GenericRead Or EFileAccess.GenericWrite, EFileShare.Read Or EFileShare.Write, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Normal, IntPtr.Zero)
If result.IsInvalid Then
Console.WriteLine(New Win32Exception(Marshal.GetLastWin32Error()).Message)
End If
Re: CreateFile returns Incorrect function
When it's mounted does GetDriveType return DRIVE_FIXED? If not the physical drive number isn't valid and you'd get low level access from "\\.\D:" or whatever letter it's on.
IRP_MJ_CREATE is something handled inside drivers, you have no access to it.