Remove NT device path calculation method as it doesn't work neither is it needed anywhere.

This commit is contained in:
2018-12-01 19:26:30 +00:00
parent e4f559e0de
commit ade74a57f5
4 changed files with 7 additions and 91 deletions

View File

@@ -34,7 +34,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.Decoders.ATA;
using Microsoft.Win32.SafeHandles;
@@ -457,84 +456,6 @@ namespace DiscImageChef.Devices.Windows
return (uint)sdn.deviceNumber;
}
/// <summary>
/// Gets the internal device path for a specified handle
/// </summary>
/// <param name="fd">Device handle</param>
/// <returns>Device path</returns>
internal static string GetDevicePath(SafeFileHandle fd)
{
uint devNumber = GetDeviceNumber(fd);
if(devNumber == uint.MaxValue) return null;
SafeFileHandle hDevInfo = Extern.SetupDiGetClassDevs(ref Consts.GuidDevinterfaceDisk, IntPtr.Zero,
IntPtr.Zero,
DeviceGetClassFlags.Present |
DeviceGetClassFlags.DeviceInterface);
if(hDevInfo.IsInvalid) return null;
uint index = 0;
DeviceInterfaceData spdid = new DeviceInterfaceData();
spdid.cbSize = Marshal.SizeOf(spdid);
while(true)
{
byte[] buffer = new byte[2048];
if(!Extern.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref Consts.GuidDevinterfaceDisk, index,
ref spdid)) break;
uint size = 0;
Extern.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref spdid, IntPtr.Zero, 0, ref size, IntPtr.Zero);
if(size > 0 && size < buffer.Length)
{
buffer[0] = (byte)(IntPtr.Size == 8
? IntPtr.Size
: IntPtr.Size + Marshal.SystemDefaultCharSize); // Funny...
IntPtr pspdidd = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, pspdidd, buffer.Length);
bool result =
Extern.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref spdid, pspdidd, size, ref size,
IntPtr.Zero);
buffer = new byte[size];
Marshal.Copy(pspdidd, buffer, 0, buffer.Length);
Marshal.FreeHGlobal(pspdidd);
if(result)
{
string devicePath = Encoding.Unicode.GetString(buffer, 4, (int)size - 4);
SafeFileHandle hDrive = Extern.CreateFile(devicePath, 0, FileShare.Read | FileShare.Write,
IntPtr.Zero, FileMode.OpenExisting, 0, IntPtr.Zero);
if(!hDrive.IsInvalid)
{
uint newDeviceNumber = GetDeviceNumber(hDrive);
if(newDeviceNumber == devNumber)
{
Extern.CloseHandle(hDrive);
return devicePath;
}
}
Extern.CloseHandle(hDrive);
}
}
index++;
}
Extern.SetupDiDestroyDeviceInfoList(hDevInfo);
return null;
}
/// <summary>
/// Returns true if the specified handle is controlled by a SFFDISK (aka SDHCI) driver
/// </summary>