Is there any class in the .NET framework that provides access to the \. \ G: - path. (i.e. raw volumes)?
Currently, we are doing this without problems using p / invoked ReadFile and WriteFile, which is not difficult for synchronous access, but it is tedious to add async read / write because of all the care you need to take on and handling the OVERLAPPED structure and management the lifetime of the event object, etc. (i.e. all the tedious things we would have to do in Win32 code ...)
It's hard to prove that you also have interaction with the GC, with any simple testing technique.
The FileStream class contains all of this code, no doubt a completely safe and sophisticated mod, and uses many internal helpers that we cannot use. Unfortunately, FileStream explicitly stops opening the original volume, so we cannot use it.
Is there anything else in the framework that helps to avoid writing such code from scratch? I spoke in the Reference Source, but nothing pops up.
Update - we have already tried this sentence to avoid checking the type of path by opening the device ourselves and passing it to the descriptor. When we try to do this, it explodes with the following error (note that this trace passes through the FileStream counter-constructor - that is, we do not have the ability to interact with the stream at all):
System.IO.IOException: The parameter is incorrect.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.SeekCore(Int64 offset, SeekOrigin origin)
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
at OurApp.USBComms.UsbDevice..ctor(Char driveLetter) in
For reference, our CreateFile call looks like this:
var deviceName = String.Format(@"\\.\{0}:", driveLetter);
var handle = SafeNativeMethods.CreateFile(deviceName,
0x80000000 | 0x40000000,
FileShare.ReadWrite,
0,
FileMode.Open,
(uint)FileOptions.Asynchronous | 0x20000000,
IntPtr.Zero);
if (handle.IsInvalid)
{
throw new IOException("CreateFile Error: " + Marshal.GetLastWin32Error());
}
Update3: , ( ) SetFilePointer , FILE_FLAG_OVERLAPPED. , SetFilePointer , . , FileStream, -, - (- , ), .