mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Final cleanup of DiscImageChef.Devices.
This commit is contained in:
@@ -44,7 +44,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
static class Command
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a SCSI command
|
||||
/// Sends a SCSI command
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -54,7 +54,10 @@ namespace DiscImageChef.Devices.Windows
|
||||
/// <param name="timeout">Timeout in seconds</param>
|
||||
/// <param name="direction">SCSI command transfer direction</param>
|
||||
/// <param name="duration">Time it took to execute the command in milliseconds</param>
|
||||
/// <param name="sense"><c>True</c> if SCSI error returned non-OK status and <paramref name="senseBuffer"/> contains SCSI sense</param>
|
||||
/// <param name="sense">
|
||||
/// <c>True</c> if SCSI error returned non-OK status and <paramref name="senseBuffer" /> contains SCSI
|
||||
/// sense
|
||||
/// </param>
|
||||
internal static int SendScsiCommand(SafeFileHandle fd, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer,
|
||||
uint timeout, ScsiIoctlDirection direction, out double duration,
|
||||
out bool sense)
|
||||
@@ -111,7 +114,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an ATA command in CHS mode
|
||||
/// Sends an ATA command in CHS mode
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -157,13 +160,16 @@ namespace DiscImageChef.Devices.Windows
|
||||
dataBuffer = new byte[64 * 512]
|
||||
};
|
||||
|
||||
switch(protocol) {
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
case AtaProtocol.Dma:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -212,7 +218,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an ATA command in 28-bit LBA mode
|
||||
/// Sends an ATA command in 28-bit LBA mode
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -258,13 +264,16 @@ namespace DiscImageChef.Devices.Windows
|
||||
dataBuffer = new byte[64 * 512]
|
||||
};
|
||||
|
||||
switch(protocol) {
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
case AtaProtocol.Dma:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -313,7 +322,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an ATA command in 48-bit LBA mode
|
||||
/// Sends an ATA command in 48-bit LBA mode
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -367,13 +376,16 @@ namespace DiscImageChef.Devices.Windows
|
||||
dataBuffer = new byte[64 * 512]
|
||||
};
|
||||
|
||||
switch(protocol) {
|
||||
switch(protocol)
|
||||
{
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
case AtaProtocol.Dma: aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
case AtaProtocol.Dma:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataIn;
|
||||
break;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut: aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
case AtaProtocol.UDmaOut:
|
||||
aptdBuf.aptd.AtaFlags = AtaFlags.DataOut;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -426,7 +438,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an ATA command in CHS mode using undocumented Windows XP ioctl
|
||||
/// Sends an ATA command in CHS mode using undocumented Windows XP ioctl
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -495,7 +507,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an ATA command in 28-bit LBA mode using undocumented Windows XP ioctl
|
||||
/// Sends an ATA command in 28-bit LBA mode using undocumented Windows XP ioctl
|
||||
/// </summary>
|
||||
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -564,7 +576,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device number for a specified handle
|
||||
/// Gets the device number for a specified handle
|
||||
/// </summary>
|
||||
/// <param name="deviceHandle">Device handle</param>
|
||||
/// <returns>Device number</returns>
|
||||
@@ -580,7 +592,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the internal device path for a specified handle
|
||||
/// Gets the internal device path for a specified handle
|
||||
/// </summary>
|
||||
/// <param name="fd">Device handle</param>
|
||||
/// <returns>Device path</returns>
|
||||
@@ -658,7 +670,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified handle is controlled by a SFFDISK (aka SDHCI) driver
|
||||
/// Returns true if the specified handle is controlled by a SFFDISK (aka SDHCI) driver
|
||||
/// </summary>
|
||||
/// <param name="fd">Device handle</param>
|
||||
/// <returns><c>true</c> if SDHCI, false otherwise</returns>
|
||||
@@ -672,7 +684,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a MMC/SD command
|
||||
/// Sends a MMC/SD command
|
||||
/// </summary>
|
||||
/// <returns>The result of the command.</returns>
|
||||
/// <param name="fd">File handle</param>
|
||||
@@ -722,7 +734,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
if(flags.HasFlag(MmcFlags.ResponseR6)) commandDescriptor.responseType = SdResponseType.R6;
|
||||
|
||||
byte[] commandB = new byte[commandData.size + commandData.protocolArgumentSize +
|
||||
commandData.deviceDataBufferSize];
|
||||
commandData.deviceDataBufferSize];
|
||||
IntPtr hBuf = Marshal.AllocHGlobal(commandB.Length);
|
||||
Marshal.StructureToPtr(commandData, hBuf, true);
|
||||
IntPtr descriptorOffset = new IntPtr(hBuf.ToInt32() + commandData.size);
|
||||
@@ -732,9 +744,8 @@ namespace DiscImageChef.Devices.Windows
|
||||
|
||||
int error = 0;
|
||||
DateTime start = DateTime.Now;
|
||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB,
|
||||
(uint)commandB.Length, commandB, (uint)commandB.Length,
|
||||
out _, IntPtr.Zero);
|
||||
sense = !Extern.DeviceIoControl(fd, WindowsIoctl.IoctlSffdiskDeviceCommand, commandB, (uint)commandB.Length,
|
||||
commandB, (uint)commandB.Length, out _, IntPtr.Zero);
|
||||
DateTime end = DateTime.Now;
|
||||
|
||||
if(sense) error = Marshal.GetLastWin32Error();
|
||||
|
||||
@@ -40,142 +40,142 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum FileAttributes : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_ARCHIVE
|
||||
/// FILE_ATTRIBUTE_ARCHIVE
|
||||
/// </summary>
|
||||
Archive = 0x20,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_COMPRESSED
|
||||
/// FILE_ATTRIBUTE_COMPRESSED
|
||||
/// </summary>
|
||||
Compressed = 0x800,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_DEVICE
|
||||
/// FILE_ATTRIBUTE_DEVICE
|
||||
/// </summary>
|
||||
Device = 0x40,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_DIRECTORY
|
||||
/// FILE_ATTRIBUTE_DIRECTORY
|
||||
/// </summary>
|
||||
Directory = 0x10,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_ENCRYPTED
|
||||
/// FILE_ATTRIBUTE_ENCRYPTED
|
||||
/// </summary>
|
||||
Encrypted = 0x4000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_HIDDEN
|
||||
/// FILE_ATTRIBUTE_HIDDEN
|
||||
/// </summary>
|
||||
Hidden = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_INTEGRITY_STREAM
|
||||
/// FILE_ATTRIBUTE_INTEGRITY_STREAM
|
||||
/// </summary>
|
||||
IntegrityStream = 0x8000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_NORMAL
|
||||
/// FILE_ATTRIBUTE_NORMAL
|
||||
/// </summary>
|
||||
Normal = 0x80,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
|
||||
/// FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
|
||||
/// </summary>
|
||||
NotContentIndexed = 0x2000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_NO_SCRUB_DATA
|
||||
/// FILE_ATTRIBUTE_NO_SCRUB_DATA
|
||||
/// </summary>
|
||||
NoScrubData = 0x20000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_OFFLINE
|
||||
/// FILE_ATTRIBUTE_OFFLINE
|
||||
/// </summary>
|
||||
Offline = 0x1000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_READONLY
|
||||
/// FILE_ATTRIBUTE_READONLY
|
||||
/// </summary>
|
||||
Readonly = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_REPARSE_POINT
|
||||
/// FILE_ATTRIBUTE_REPARSE_POINT
|
||||
/// </summary>
|
||||
ReparsePoint = 0x400,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_SPARSE_FILE
|
||||
/// FILE_ATTRIBUTE_SPARSE_FILE
|
||||
/// </summary>
|
||||
SparseFile = 0x200,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_SYSTEM
|
||||
/// FILE_ATTRIBUTE_SYSTEM
|
||||
/// </summary>
|
||||
System = 0x04,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_TEMPORARY
|
||||
/// FILE_ATTRIBUTE_TEMPORARY
|
||||
/// </summary>
|
||||
Temporary = 0x100,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_ATTRIBUTE_VIRTUAL
|
||||
/// FILE_ATTRIBUTE_VIRTUAL
|
||||
/// </summary>
|
||||
Virtual = 0x10000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_BACKUP_SEMANTICS
|
||||
/// FILE_FLAG_BACKUP_SEMANTICS
|
||||
/// </summary>
|
||||
BackupSemantics = 0x02000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_DELETE_ON_CLOSE
|
||||
/// FILE_FLAG_DELETE_ON_CLOSE
|
||||
/// </summary>
|
||||
DeleteOnClose = 0x04000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_NO_BUFFERING
|
||||
/// FILE_FLAG_NO_BUFFERING
|
||||
/// </summary>
|
||||
NoBuffering = 0x20000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_OPEN_NO_RECALL
|
||||
/// FILE_FLAG_OPEN_NO_RECALL
|
||||
/// </summary>
|
||||
OpenNoRecall = 0x00100000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_OPEN_REPARSE_POINT
|
||||
/// FILE_FLAG_OPEN_REPARSE_POINT
|
||||
/// </summary>
|
||||
OpenReparsePoint = 0x00200000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_OVERLAPPED
|
||||
/// FILE_FLAG_OVERLAPPED
|
||||
/// </summary>
|
||||
Overlapped = 0x40000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_POSIX_SEMANTICS
|
||||
/// FILE_FLAG_POSIX_SEMANTICS
|
||||
/// </summary>
|
||||
PosixSemantics = 0x0100000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_RANDOM_ACCESS
|
||||
/// FILE_FLAG_RANDOM_ACCESS
|
||||
/// </summary>
|
||||
RandomAccess = 0x10000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_SESSION_AWARE
|
||||
/// FILE_FLAG_SESSION_AWARE
|
||||
/// </summary>
|
||||
SessionAware = 0x00800000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_SEQUENTIAL_SCAN
|
||||
/// FILE_FLAG_SEQUENTIAL_SCAN
|
||||
/// </summary>
|
||||
SequentialScan = 0x08000000,
|
||||
|
||||
/// <summary>
|
||||
/// FILE_FLAG_WRITE_THROUGH
|
||||
/// FILE_FLAG_WRITE_THROUGH
|
||||
/// </summary>
|
||||
WriteThrough = 0x80000000
|
||||
}
|
||||
@@ -184,75 +184,75 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum FileAccess : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// FILE_READ_DATA
|
||||
/// FILE_READ_DATA
|
||||
/// </summary>
|
||||
ReadData = 0x0001,
|
||||
/// <summary>
|
||||
/// FILE_LIST_DIRECTORY
|
||||
/// FILE_LIST_DIRECTORY
|
||||
/// </summary>
|
||||
ListDirectory = ReadData,
|
||||
/// <summary>
|
||||
/// FILE_WRITE_DATA
|
||||
/// FILE_WRITE_DATA
|
||||
/// </summary>
|
||||
WriteData = 0x0002,
|
||||
/// <summary>
|
||||
/// FILE_ADD_FILE
|
||||
/// FILE_ADD_FILE
|
||||
/// </summary>
|
||||
AddFile = WriteData,
|
||||
/// <summary>
|
||||
/// FILE_APPEND_DATA
|
||||
/// FILE_APPEND_DATA
|
||||
/// </summary>
|
||||
AppendData = 0x0004,
|
||||
/// <summary>
|
||||
/// FILE_ADD_SUBDIRECTORY
|
||||
/// FILE_ADD_SUBDIRECTORY
|
||||
/// </summary>
|
||||
AddSubdirectory = AppendData,
|
||||
/// <summary>
|
||||
/// FILE_CREATE_PIPE_INSTANCE
|
||||
/// FILE_CREATE_PIPE_INSTANCE
|
||||
/// </summary>
|
||||
CreatePipeInstance = AppendData,
|
||||
/// <summary>
|
||||
/// FILE_READ_EA
|
||||
/// FILE_READ_EA
|
||||
/// </summary>
|
||||
ReadEa = 0x0008,
|
||||
/// <summary>
|
||||
/// FILE_WRITE_EA
|
||||
/// FILE_WRITE_EA
|
||||
/// </summary>
|
||||
WriteEa = 0x0010,
|
||||
/// <summary>
|
||||
/// FILE_EXECUTE
|
||||
/// FILE_EXECUTE
|
||||
/// </summary>
|
||||
Execute = 0x0020,
|
||||
/// <summary>
|
||||
/// FILE_TRAVERSE
|
||||
/// FILE_TRAVERSE
|
||||
/// </summary>
|
||||
Traverse = Execute,
|
||||
/// <summary>
|
||||
/// FILE_DELETE_CHILD
|
||||
/// FILE_DELETE_CHILD
|
||||
/// </summary>
|
||||
DeleteChild = 0x0040,
|
||||
/// <summary>
|
||||
/// FILE_READ_ATTRIBUTES
|
||||
/// FILE_READ_ATTRIBUTES
|
||||
/// </summary>
|
||||
ReadAttributes = 0x0080,
|
||||
/// <summary>
|
||||
/// FILE_WRITE_ATTRIBUTES
|
||||
/// FILE_WRITE_ATTRIBUTES
|
||||
/// </summary>
|
||||
WriteAttributes = 0x0100,
|
||||
/// <summary>
|
||||
/// GENERIC_READ
|
||||
/// GENERIC_READ
|
||||
/// </summary>
|
||||
GenericRead = 0x80000000,
|
||||
/// <summary>
|
||||
/// GENERIC_WRITE
|
||||
/// GENERIC_WRITE
|
||||
/// </summary>
|
||||
GenericWrite = 0x40000000,
|
||||
/// <summary>
|
||||
/// GENERIC_EXECUTE
|
||||
/// GENERIC_EXECUTE
|
||||
/// </summary>
|
||||
GenericExecute = 0x20000000,
|
||||
/// <summary>
|
||||
/// GENERIC_ALL
|
||||
/// GENERIC_ALL
|
||||
/// </summary>
|
||||
GenericAll = 0x10000000
|
||||
}
|
||||
@@ -261,19 +261,19 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum FileShare : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// FILE_SHARE_NONE
|
||||
/// FILE_SHARE_NONE
|
||||
/// </summary>
|
||||
None = 0x00,
|
||||
/// <summary>
|
||||
/// FILE_SHARE_READ
|
||||
/// FILE_SHARE_READ
|
||||
/// </summary>
|
||||
Read = 0x01,
|
||||
/// <summary>
|
||||
/// FILE_SHARE_WRITE
|
||||
/// FILE_SHARE_WRITE
|
||||
/// </summary>
|
||||
Write = 0x02,
|
||||
/// <summary>
|
||||
/// FILE_SHARE_DELETE
|
||||
/// FILE_SHARE_DELETE
|
||||
/// </summary>
|
||||
Delete = 0x03
|
||||
}
|
||||
@@ -282,45 +282,45 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum FileMode : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// NEW
|
||||
/// NEW
|
||||
/// </summary>
|
||||
New = 0x01,
|
||||
/// <summary>
|
||||
/// CREATE_ALWAYS
|
||||
/// CREATE_ALWAYS
|
||||
/// </summary>
|
||||
CreateAlways = 0x02,
|
||||
/// <summary>
|
||||
/// OPEN_EXISTING
|
||||
/// OPEN_EXISTING
|
||||
/// </summary>
|
||||
OpenExisting = 0x03,
|
||||
/// <summary>
|
||||
/// OPEN_ALWAYS
|
||||
/// OPEN_ALWAYS
|
||||
/// </summary>
|
||||
OpenAlways = 0x04,
|
||||
/// <summary>
|
||||
/// TRUNCATE_EXISTING
|
||||
/// TRUNCATE_EXISTING
|
||||
/// </summary>
|
||||
TruncateExisting = 0x05
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Direction of SCSI transfer
|
||||
/// Direction of SCSI transfer
|
||||
/// </summary>
|
||||
enum ScsiIoctlDirection : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// From host to device
|
||||
/// SCSI_IOCTL_DATA_OUT
|
||||
/// From host to device
|
||||
/// SCSI_IOCTL_DATA_OUT
|
||||
/// </summary>
|
||||
Out = 0,
|
||||
/// <summary>
|
||||
/// From device to host
|
||||
/// SCSI_IOCTL_DATA_IN
|
||||
/// From device to host
|
||||
/// SCSI_IOCTL_DATA_IN
|
||||
/// </summary>
|
||||
In = 1,
|
||||
/// <summary>
|
||||
/// Unspecified direction, or bidirectional, or no data
|
||||
/// SCSI_IOCTL_DATA_UNSPECIFIED
|
||||
/// Unspecified direction, or bidirectional, or no data
|
||||
/// SCSI_IOCTL_DATA_UNSPECIFIED
|
||||
/// </summary>
|
||||
Unspecified = 2
|
||||
}
|
||||
@@ -330,15 +330,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
IoctlAtaPassThrough = 0x4D02C,
|
||||
IoctlAtaPassThroughDirect = 0x4D030,
|
||||
/// <summary>
|
||||
/// ScsiPassThrough
|
||||
/// ScsiPassThrough
|
||||
/// </summary>
|
||||
IoctlScsiPassThrough = 0x4D004,
|
||||
/// <summary>
|
||||
/// ScsiPassThroughDirect
|
||||
/// ScsiPassThroughDirect
|
||||
/// </summary>
|
||||
IoctlScsiPassThroughDirect = 0x4D014,
|
||||
/// <summary>
|
||||
/// ScsiGetAddress
|
||||
/// ScsiGetAddress
|
||||
/// </summary>
|
||||
IoctlScsiGetAddress = 0x41018,
|
||||
IoctlStorageQueryProperty = 0x2D1400,
|
||||
@@ -352,27 +352,27 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum AtaFlags : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_DRDY_REQUIRED
|
||||
/// ATA_FLAGS_DRDY_REQUIRED
|
||||
/// </summary>
|
||||
DrdyRequired = 0x01,
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_DATA_IN
|
||||
/// ATA_FLAGS_DATA_IN
|
||||
/// </summary>
|
||||
DataIn = 0x02,
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_DATA_OUT
|
||||
/// ATA_FLAGS_DATA_OUT
|
||||
/// </summary>
|
||||
DataOut = 0x04,
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_48BIT_COMMAND
|
||||
/// ATA_FLAGS_48BIT_COMMAND
|
||||
/// </summary>
|
||||
ExtendedCommand = 0x08,
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_USE_DMA
|
||||
/// ATA_FLAGS_USE_DMA
|
||||
/// </summary>
|
||||
Dma = 0x10,
|
||||
/// <summary>
|
||||
/// ATA_FLAGS_NO_MULTIPLE
|
||||
/// ATA_FLAGS_NO_MULTIPLE
|
||||
/// </summary>
|
||||
NoMultiple = 0x20
|
||||
}
|
||||
@@ -430,23 +430,23 @@ namespace DiscImageChef.Devices.Windows
|
||||
enum DeviceGetClassFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// DIGCF_DEFAULT
|
||||
/// DIGCF_DEFAULT
|
||||
/// </summary>
|
||||
Default = 0x01,
|
||||
/// <summary>
|
||||
/// DIGCF_PRESENT
|
||||
/// DIGCF_PRESENT
|
||||
/// </summary>
|
||||
Present = 0x02,
|
||||
/// <summary>
|
||||
/// DIGCF_ALLCLASSES
|
||||
/// DIGCF_ALLCLASSES
|
||||
/// </summary>
|
||||
AllClasses = 0x04,
|
||||
/// <summary>
|
||||
/// DIGCF_PROFILE
|
||||
/// DIGCF_PROFILE
|
||||
/// </summary>
|
||||
Profile = 0x08,
|
||||
/// <summary>
|
||||
/// DIGCF_DEVICEINTERFACE
|
||||
/// DIGCF_DEVICEINTERFACE
|
||||
/// </summary>
|
||||
DeviceInterface = 0x10
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
static class ListDevices
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a hex dump string to the ASCII string it represents
|
||||
/// Converts a hex dump string to the ASCII string it represents
|
||||
/// </summary>
|
||||
/// <param name="hex">Hex dump</param>
|
||||
/// <returns>Decoded string</returns>
|
||||
@@ -53,13 +53,14 @@ namespace DiscImageChef.Devices.Windows
|
||||
StringBuilder result = new StringBuilder();
|
||||
const string HEXTABLE = "0123456789abcdef";
|
||||
|
||||
for(int i = 0; i < hex.Length / 2; i++) result.Append((char)(16 * HEXTABLE.IndexOf(hex[2 * i]) + HEXTABLE.IndexOf(hex[2 * i + 1])));
|
||||
for(int i = 0; i < hex.Length / 2; i++)
|
||||
result.Append((char)(16 * HEXTABLE.IndexOf(hex[2 * i]) + HEXTABLE.IndexOf(hex[2 * i + 1])));
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all known storage devices on Windows
|
||||
/// Gets a list of all known storage devices on Windows
|
||||
/// </summary>
|
||||
/// <returns>List of devices</returns>
|
||||
[SuppressMessage("ReSharper", "RedundantCatchClause")]
|
||||
@@ -159,12 +160,11 @@ namespace DiscImageChef.Devices.Windows
|
||||
if(descriptor.SerialNumberOffset > 0)
|
||||
{
|
||||
info.Serial =
|
||||
StringHandlers.CToString(descriptorB, Encoding.ASCII,
|
||||
start: descriptor.SerialNumberOffset);
|
||||
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: descriptor.SerialNumberOffset);
|
||||
|
||||
// fix any serial numbers that are returned as hex-strings
|
||||
if(Array.TrueForAll(info.Serial.ToCharArray(), c => "0123456789abcdef".IndexOf(c) >= 0)
|
||||
&& info.Serial.Length == 40) info.Serial = HexStringToString(info.Serial).Trim();
|
||||
if(Array.TrueForAll(info.Serial.ToCharArray(), c => "0123456789abcdef".IndexOf(c) >= 0) &&
|
||||
info.Serial.Length == 40) info.Serial = HexStringToString(info.Serial).Trim();
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(info.Vendor) || info.Vendor == "ATA")
|
||||
|
||||
@@ -68,51 +68,51 @@ namespace DiscImageChef.Devices.Windows
|
||||
struct AtaPassThroughDirect
|
||||
{
|
||||
/// <summary>
|
||||
/// Length in bytes of this structure
|
||||
/// Length in bytes of this structure
|
||||
/// </summary>
|
||||
public ushort Length;
|
||||
/// <summary>
|
||||
/// Indicates transfer direction and kind of operation
|
||||
/// Indicates transfer direction and kind of operation
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.U2)] public AtaFlags AtaFlags;
|
||||
/// <summary>
|
||||
/// Indicates IDE port or bus, set by driver
|
||||
/// Indicates IDE port or bus, set by driver
|
||||
/// </summary>
|
||||
public byte PathId;
|
||||
/// <summary>
|
||||
/// Indicates target device on bus, set by driver
|
||||
/// Indicates target device on bus, set by driver
|
||||
/// </summary>
|
||||
public byte TargetId;
|
||||
/// <summary>
|
||||
/// Indicates logical unit number of device, set by driver
|
||||
/// Indicates logical unit number of device, set by driver
|
||||
/// </summary>
|
||||
public byte Lun;
|
||||
/// <summary>
|
||||
/// Reserved
|
||||
/// Reserved
|
||||
/// </summary>
|
||||
public byte ReservedAsUchar;
|
||||
/// <summary>
|
||||
/// Data transfer length in bytes
|
||||
/// Data transfer length in bytes
|
||||
/// </summary>
|
||||
public uint DataTransferLength;
|
||||
/// <summary>
|
||||
/// Timeout value in seconds
|
||||
/// Timeout value in seconds
|
||||
/// </summary>
|
||||
public uint TimeOutValue;
|
||||
/// <summary>
|
||||
/// Reserved
|
||||
/// Reserved
|
||||
/// </summary>
|
||||
public uint ReservedAsUlong;
|
||||
/// <summary>
|
||||
/// Pointer to data buffer relative to start of this structure
|
||||
/// Pointer to data buffer relative to start of this structure
|
||||
/// </summary>
|
||||
public IntPtr DataBuffer;
|
||||
/// <summary>
|
||||
/// Previous ATA registers, for LBA48
|
||||
/// Previous ATA registers, for LBA48
|
||||
/// </summary>
|
||||
public AtaTaskFile PreviousTaskFile;
|
||||
/// <summary>
|
||||
/// ATA registers
|
||||
/// ATA registers
|
||||
/// </summary>
|
||||
public AtaTaskFile CurrentTaskFile;
|
||||
}
|
||||
@@ -185,15 +185,15 @@ namespace DiscImageChef.Devices.Windows
|
||||
struct IdePassThroughDirect
|
||||
{
|
||||
/// <summary>
|
||||
/// ATA registers
|
||||
/// ATA registers
|
||||
/// </summary>
|
||||
public AtaTaskFile CurrentTaskFile;
|
||||
/// <summary>
|
||||
/// Size of data buffer
|
||||
/// Size of data buffer
|
||||
/// </summary>
|
||||
public uint DataBufferSize;
|
||||
/// <summary>
|
||||
/// Data buffer
|
||||
/// Data buffer
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] public byte[] DataBuffer;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,12 +43,17 @@ namespace DiscImageChef.Devices.Windows
|
||||
//
|
||||
// TODO: Even after cleaning, refactoring and xml-documenting, this code needs some love
|
||||
/// <summary>
|
||||
/// Implements functions for getting and accesing information from the USB bus
|
||||
/// Implements functions for getting and accesing information from the USB bus
|
||||
/// </summary>
|
||||
static partial class Usb
|
||||
{
|
||||
const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
|
||||
internal const string GuidDevinterfaceDisk = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
internal const string GuidDevinterfaceCdrom = "53f56308-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
internal const string GuidDevinterfaceFloppy = "53f56311-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all connected devices
|
||||
/// Get a list of all connected devices
|
||||
/// </summary>
|
||||
/// <returns>List of usb devices</returns>
|
||||
internal static List<UsbDevice> GetConnectedDevices()
|
||||
@@ -61,7 +66,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// private routine for enumerating a hub
|
||||
/// private routine for enumerating a hub
|
||||
/// </summary>
|
||||
/// <param name="hub">Hub</param>
|
||||
/// <param name="devList">Device list</param>
|
||||
@@ -73,7 +78,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a device based upon it's DriverKeyName
|
||||
/// Find a device based upon it's DriverKeyName
|
||||
/// </summary>
|
||||
/// <param name="driverKeyName">DriverKeyName</param>
|
||||
/// <returns>USB device</returns>
|
||||
@@ -91,7 +96,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a device connected to a specified hub by it's DriverKeyName
|
||||
/// Finds a device connected to a specified hub by it's DriverKeyName
|
||||
/// </summary>
|
||||
/// <param name="hub">Hub</param>
|
||||
/// <param name="foundDevice">UsbDevice</param>
|
||||
@@ -113,7 +118,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a device based upon it's Instance ID
|
||||
/// Find a device based upon it's Instance ID
|
||||
/// </summary>
|
||||
/// <param name="instanceId">Device instance ID</param>
|
||||
/// <returns>USB device</returns>
|
||||
@@ -131,7 +136,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// private routine for enumerating a hub
|
||||
/// private routine for enumerating a hub
|
||||
/// </summary>
|
||||
/// <param name="hub">Hub</param>
|
||||
/// <param name="foundDevice">USB device</param>
|
||||
@@ -152,19 +157,6 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
}
|
||||
|
||||
const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
|
||||
internal const string GuidDevinterfaceDisk = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
internal const string GuidDevinterfaceCdrom = "53f56308-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
internal const string GuidDevinterfaceFloppy = "53f56311-b6bf-11d0-94f2-00a0c91efb8b";
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct StorageDeviceNumber
|
||||
{
|
||||
internal int DeviceType;
|
||||
internal int DeviceNumber;
|
||||
internal int PartitionNumber;
|
||||
}
|
||||
|
||||
[DllImport("setupapi.dll")]
|
||||
static extern int CM_Get_Parent(out IntPtr pdnDevInst, IntPtr dnDevInst, int ulFlags);
|
||||
|
||||
@@ -172,7 +164,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
static extern int CM_Get_Device_ID(IntPtr dnDevInst, IntPtr buffer, int bufferLen, int ulFlags);
|
||||
|
||||
/// <summary>
|
||||
/// Find a device based upon a Drive Letter
|
||||
/// Find a device based upon a Drive Letter
|
||||
/// </summary>
|
||||
/// <param name="driveLetter">Drive letter</param>
|
||||
/// <param name="deviceGuid">Device GUID</param>
|
||||
@@ -187,7 +179,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a device based upon a Drive Path
|
||||
/// Find a device based upon a Drive Path
|
||||
/// </summary>
|
||||
/// <param name="drivePath">Drive path</param>
|
||||
/// <param name="deviceGuid">Device GUID</param>
|
||||
@@ -202,7 +194,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a device based upon a Device Number
|
||||
/// Find a device based upon a Device Number
|
||||
/// </summary>
|
||||
/// <param name="devNum">Device Number</param>
|
||||
/// <param name="deviceGuid">Device GUID</param>
|
||||
@@ -267,12 +259,13 @@ namespace DiscImageChef.Devices.Windows
|
||||
}
|
||||
|
||||
// Did we find an InterfaceID of a USB device?
|
||||
if(instanceId?.StartsWith("USB\\", StringComparison.Ordinal) == true) foundDevice = FindDeviceByInstanceId(instanceId);
|
||||
if(instanceId?.StartsWith("USB\\", StringComparison.Ordinal) == true)
|
||||
foundDevice = FindDeviceByInstanceId(instanceId);
|
||||
return foundDevice;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return a unique device number for the given device path
|
||||
/// return a unique device number for the given device path
|
||||
/// </summary>
|
||||
/// <param name="devicePath">Device path</param>
|
||||
/// <returns>Device number</returns>
|
||||
@@ -287,8 +280,7 @@ namespace DiscImageChef.Devices.Windows
|
||||
int nBytes = Marshal.SizeOf(sdn);
|
||||
IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes);
|
||||
|
||||
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out _,
|
||||
IntPtr.Zero))
|
||||
if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out _, IntPtr.Zero))
|
||||
{
|
||||
sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber));
|
||||
// just my way of combining the relevant parts of the
|
||||
@@ -299,5 +291,13 @@ namespace DiscImageChef.Devices.Windows
|
||||
CloseHandle(h);
|
||||
return ans;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct StorageDeviceNumber
|
||||
{
|
||||
internal int DeviceType;
|
||||
internal int DeviceNumber;
|
||||
internal int PartitionNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user