REFACTOR: Remove unneeded code.

This commit is contained in:
2017-12-21 14:30:38 +00:00
parent 35ce7db892
commit dcd053b20d
343 changed files with 2842 additions and 2588 deletions

View File

@@ -32,8 +32,11 @@
using System;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Devices.FreeBSD;
using DiscImageChef.Devices.Windows;
using DiscImageChef.Interop;
using Microsoft.Win32.SafeHandles;
using PlatformID = DiscImageChef.Interop.PlatformID;
namespace DiscImageChef.Devices
{
@@ -54,7 +57,7 @@ namespace DiscImageChef.Devices
internal static int SendScsiCommand(object fd, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer,
uint timeout, ScsiDirection direction, out double duration, out bool sense)
{
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
return SendScsiCommand(ptId, fd, cdb, ref buffer, out senseBuffer, timeout, direction, out duration,
out sense);
@@ -73,33 +76,33 @@ namespace DiscImageChef.Devices
/// <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>
internal static int SendScsiCommand(Interop.PlatformID ptId, object fd, byte[] cdb, ref byte[] buffer,
internal static int SendScsiCommand(PlatformID ptId, object fd, byte[] cdb, ref byte[] buffer,
out byte[] senseBuffer, uint timeout, ScsiDirection direction,
out double duration, out bool sense)
{
switch(ptId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
Windows.ScsiIoctlDirection dir;
ScsiIoctlDirection dir;
switch(direction)
{
case ScsiDirection.In:
dir = Windows.ScsiIoctlDirection.In;
dir = ScsiIoctlDirection.In;
break;
case ScsiDirection.Out:
dir = Windows.ScsiIoctlDirection.Out;
dir = ScsiIoctlDirection.Out;
break;
default:
dir = Windows.ScsiIoctlDirection.Unspecified;
dir = ScsiIoctlDirection.Unspecified;
break;
}
return Windows.Command.SendScsiCommand((SafeFileHandle)fd, cdb, ref buffer, out senseBuffer,
timeout, dir, out duration, out sense);
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
Linux.ScsiIoctlDirection dir;
@@ -125,23 +128,23 @@ namespace DiscImageChef.Devices
return Linux.Command.SendScsiCommand((int)fd, cdb, ref buffer, out senseBuffer, timeout, dir,
out duration, out sense);
}
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
{
FreeBSD.CcbFlags flags = 0;
CcbFlags flags = 0;
switch(direction)
{
case ScsiDirection.In:
flags = FreeBSD.CcbFlags.CamDirIn;
flags = CcbFlags.CamDirIn;
break;
case ScsiDirection.Out:
flags = FreeBSD.CcbFlags.CamDirOut;
flags = CcbFlags.CamDirOut;
break;
case ScsiDirection.Bidirectional:
flags = FreeBSD.CcbFlags.CamDirBoth;
flags = CcbFlags.CamDirBoth;
break;
case ScsiDirection.None:
flags = FreeBSD.CcbFlags.CamDirNone;
flags = CcbFlags.CamDirNone;
break;
}
@@ -159,20 +162,20 @@ namespace DiscImageChef.Devices
AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer,
uint timeout, bool transferBlocks, out double duration, out bool sense)
{
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
timeout, transferBlocks, out duration, out sense);
}
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersCHS registers,
internal static int SendAtaCommand(PlatformID ptId, object fd, AtaRegistersCHS registers,
out AtaErrorRegistersCHS errorRegisters, AtaProtocol protocol,
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
bool transferBlocks, out double duration, out bool sense)
{
switch(ptId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
if(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 1 &&
(Environment.OSVersion.ServicePack == "Service Pack 1" ||
@@ -187,13 +190,13 @@ namespace DiscImageChef.Devices
return Windows.Command.SendAtaCommand((SafeFileHandle)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
transferRegister, ref buffer, timeout, transferBlocks,
out duration, out sense);
}
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
{
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
@@ -207,20 +210,20 @@ namespace DiscImageChef.Devices
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
bool transferBlocks, out double duration, out bool sense)
{
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
timeout, transferBlocks, out duration, out sense);
}
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersLBA28 registers,
internal static int SendAtaCommand(PlatformID ptId, object fd, AtaRegistersLBA28 registers,
out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol,
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
bool transferBlocks, out double duration, out bool sense)
{
switch(ptId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
if(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 1 &&
(Environment.OSVersion.ServicePack == "Service Pack 1" ||
@@ -235,13 +238,13 @@ namespace DiscImageChef.Devices
return Windows.Command.SendAtaCommand((SafeFileHandle)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
transferRegister, ref buffer, timeout, transferBlocks,
out duration, out sense);
}
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
{
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
@@ -255,32 +258,32 @@ namespace DiscImageChef.Devices
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
bool transferBlocks, out double duration, out bool sense)
{
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
timeout, transferBlocks, out duration, out sense);
}
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersLBA48 registers,
internal static int SendAtaCommand(PlatformID ptId, object fd, AtaRegistersLBA48 registers,
out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol,
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
bool transferBlocks, out double duration, out bool sense)
{
switch(ptId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
// No check for Windows version. A 48-bit ATA disk simply does not work on earlier systems
return Windows.Command.SendAtaCommand((SafeFileHandle)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
transferRegister, ref buffer, timeout, transferBlocks,
out duration, out sense);
}
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
{
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
ref buffer, timeout, out duration, out sense);
@@ -293,26 +296,26 @@ namespace DiscImageChef.Devices
uint argument, uint blockSize, uint blocks, ref byte[] buffer,
out uint[] response, out double duration, out bool sense, uint timeout = 0)
{
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
PlatformID ptId = DetectOS.GetRealPlatformID();
return SendMmcCommand(ptId, (int)fd, command, write, isApplication, flags, argument, blockSize, blocks,
ref buffer, out response, out duration, out sense, timeout);
}
internal static int SendMmcCommand(Interop.PlatformID ptId, object fd, MmcCommands command, bool write,
internal static int SendMmcCommand(PlatformID ptId, object fd, MmcCommands command, bool write,
bool isApplication, MmcFlags flags, uint argument, uint blockSize, uint blocks,
ref byte[] buffer, out uint[] response, out double duration, out bool sense,
uint timeout = 0)
{
switch(ptId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
return Windows.Command.SendMmcCommand((SafeFileHandle)fd, command, write, isApplication, flags,
argument, blockSize, blocks, ref buffer, out response,
out duration, out sense, timeout);
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
return Linux.Command.SendMmcCommand((int)fd, command, write, isApplication, flags, argument,
blockSize, blocks, ref buffer, out response, out duration,

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Decoders.ATA;
namespace DiscImageChef.Devices
@@ -140,34 +141,34 @@ namespace DiscImageChef.Devices
switch(command) {
case MmcCommands.SendCid when cachedCid != null:
{
System.DateTime start = System.DateTime.Now;
DateTime start = DateTime.Now;
buffer = new byte[cachedCid.Length];
System.Array.Copy(cachedCid, buffer, buffer.Length);
Array.Copy(cachedCid, buffer, buffer.Length);
response = new uint[4];
sense = false;
System.DateTime end = System.DateTime.Now;
DateTime end = DateTime.Now;
duration = (end - start).TotalMilliseconds;
return 0;
}
case MmcCommands.SendCsd when cachedCid != null:
{
System.DateTime start = System.DateTime.Now;
DateTime start = DateTime.Now;
buffer = new byte[cachedCsd.Length];
System.Array.Copy(cachedCsd, buffer, buffer.Length);
Array.Copy(cachedCsd, buffer, buffer.Length);
response = new uint[4];
sense = false;
System.DateTime end = System.DateTime.Now;
DateTime end = DateTime.Now;
duration = (end - start).TotalMilliseconds;
return 0;
}
case (MmcCommands)SecureDigitalCommands.SendScr when cachedScr != null:
{
System.DateTime start = System.DateTime.Now;
DateTime start = DateTime.Now;
buffer = new byte[cachedScr.Length];
System.Array.Copy(cachedScr, buffer, buffer.Length);
Array.Copy(cachedScr, buffer, buffer.Length);
response = new uint[4];
sense = false;
System.DateTime end = System.DateTime.Now;
DateTime end = DateTime.Now;
duration = (end - start).TotalMilliseconds;
return 0;
}
@@ -179,12 +180,12 @@ namespace DiscImageChef.Devices
blocks, ref buffer, out response, out duration, out sense, timeout);
{
System.DateTime start = System.DateTime.Now;
DateTime start = DateTime.Now;
buffer = new byte[cachedOcr.Length];
System.Array.Copy(cachedOcr, buffer, buffer.Length);
Array.Copy(cachedOcr, buffer, buffer.Length);
response = new uint[4];
sense = false;
System.DateTime end = System.DateTime.Now;
DateTime end = DateTime.Now;
duration = (end - start).TotalMilliseconds;
return 0;
}

View File

@@ -31,11 +31,26 @@
// ****************************************************************************/
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Decoders.SCSI;
using DiscImageChef.Decoders.SecureDigital;
using DiscImageChef.Devices.FreeBSD;
using DiscImageChef.Devices.Windows;
using DiscImageChef.Interop;
using Microsoft.Win32.SafeHandles;
using Extern = DiscImageChef.Devices.Windows.Extern;
using FileAccess = DiscImageChef.Devices.Windows.FileAccess;
using FileAttributes = DiscImageChef.Devices.Windows.FileAttributes;
using FileFlags = DiscImageChef.Devices.Linux.FileFlags;
using FileMode = DiscImageChef.Devices.Windows.FileMode;
using FileShare = DiscImageChef.Devices.Windows.FileShare;
using PlatformID = DiscImageChef.Interop.PlatformID;
using VendorString = DiscImageChef.Decoders.SecureDigital.VendorString;
namespace DiscImageChef.Devices
{
@@ -47,19 +62,19 @@ namespace DiscImageChef.Devices
/// <param name="devicePath">Device path</param>
public Device(string devicePath)
{
PlatformId = Interop.DetectOS.GetRealPlatformID();
PlatformId = DetectOS.GetRealPlatformID();
Timeout = 15;
Error = false;
IsRemovable = false;
switch(PlatformId)
{
case Interop.PlatformID.Win32NT:
case PlatformID.Win32NT:
{
FileHandle = Windows.Extern.CreateFile(devicePath,
Windows.FileAccess.GenericRead | Windows.FileAccess.GenericWrite,
Windows.FileShare.Read | Windows.FileShare.Write, IntPtr.Zero,
Windows.FileMode.OpenExisting, Windows.FileAttributes.Normal,
FileHandle = Extern.CreateFile(devicePath,
FileAccess.GenericRead | FileAccess.GenericWrite,
FileShare.Read | FileShare.Write, IntPtr.Zero,
FileMode.OpenExisting, FileAttributes.Normal,
IntPtr.Zero);
if(((SafeFileHandle)FileHandle).IsInvalid)
@@ -70,9 +85,9 @@ namespace DiscImageChef.Devices
break;
}
case Interop.PlatformID.Linux:
case PlatformID.Linux:
{
FileHandle = Linux.Extern.open(devicePath, Linux.FileFlags.Readonly | Linux.FileFlags.NonBlocking);
FileHandle = Linux.Extern.open(devicePath, FileFlags.Readonly | FileFlags.NonBlocking);
if((int)FileHandle < 0)
{
@@ -82,7 +97,7 @@ namespace DiscImageChef.Devices
break;
}
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
{
FileHandle = FreeBSD.Extern.cam_open_device(devicePath, FreeBSD.FileFlags.ReadWrite);
@@ -92,8 +107,8 @@ namespace DiscImageChef.Devices
LastError = Marshal.GetLastWin32Error();
}
FreeBSD.CamDevice camDevice =
(FreeBSD.CamDevice)Marshal.PtrToStructure((IntPtr)FileHandle, typeof(FreeBSD.CamDevice));
CamDevice camDevice =
(CamDevice)Marshal.PtrToStructure((IntPtr)FileHandle, typeof(CamDevice));
if(StringHandlers.CToString(camDevice.SimName) == "ata")
throw new
@@ -108,7 +123,7 @@ namespace DiscImageChef.Devices
if(Error) throw new SystemException(string.Format("Error {0} opening device.", LastError));
Type = DeviceType.Unknown;
ScsiType = Decoders.SCSI.PeripheralDeviceTypes.UnknownDevice;
ScsiType = PeripheralDeviceTypes.UnknownDevice;
AtaErrorRegistersCHS errorRegisters;
@@ -123,10 +138,10 @@ namespace DiscImageChef.Devices
// Windows is answering SCSI INQUIRY for all device types so it needs to be detected first
switch(PlatformId) {
case Interop.PlatformID.Win32NT:
Windows.StoragePropertyQuery query = new Windows.StoragePropertyQuery();
query.PropertyId = Windows.StoragePropertyId.Device;
query.QueryType = Windows.StorageQueryType.Standard;
case PlatformID.Win32NT:
StoragePropertyQuery query = new StoragePropertyQuery();
query.PropertyId = StoragePropertyId.Device;
query.QueryType = StorageQueryType.Standard;
query.AdditionalParameters = new byte[1];
IntPtr descriptorPtr = Marshal.AllocHGlobal(1000);
@@ -135,8 +150,8 @@ namespace DiscImageChef.Devices
uint returned = 0;
int error = 0;
bool hasError = !Windows.Extern.DeviceIoControlStorageQuery((SafeFileHandle)FileHandle,
Windows.WindowsIoctl
bool hasError = !Extern.DeviceIoControlStorageQuery((SafeFileHandle)FileHandle,
WindowsIoctl
.IoctlStorageQueryProperty,
ref query, (uint)Marshal.SizeOf(query),
descriptorPtr, 1000, ref returned,
@@ -148,7 +163,7 @@ namespace DiscImageChef.Devices
if(!hasError && error == 0)
{
Windows.StorageDeviceDescriptor descriptor = new Windows.StorageDeviceDescriptor();
StorageDeviceDescriptor descriptor = new StorageDeviceDescriptor();
descriptor.Version = BitConverter.ToUInt32(descriptorB, 0);
descriptor.Size = BitConverter.ToUInt32(descriptorB, 4);
descriptor.DeviceType = descriptorB[8];
@@ -159,42 +174,42 @@ namespace DiscImageChef.Devices
descriptor.ProductIdOffset = BitConverter.ToInt32(descriptorB, 16);
descriptor.ProductRevisionOffset = BitConverter.ToInt32(descriptorB, 20);
descriptor.SerialNumberOffset = BitConverter.ToInt32(descriptorB, 24);
descriptor.BusType = (Windows.StorageBusType)BitConverter.ToUInt32(descriptorB, 28);
descriptor.BusType = (StorageBusType)BitConverter.ToUInt32(descriptorB, 28);
descriptor.RawPropertiesLength = BitConverter.ToUInt32(descriptorB, 32);
descriptor.RawDeviceProperties = new byte[descriptor.RawPropertiesLength];
Array.Copy(descriptorB, 36, descriptor.RawDeviceProperties, 0, descriptor.RawPropertiesLength);
switch(descriptor.BusType)
{
case Windows.StorageBusType.SCSI:
case Windows.StorageBusType.SSA:
case Windows.StorageBusType.Fibre:
case Windows.StorageBusType.iSCSI:
case Windows.StorageBusType.SAS:
case StorageBusType.SCSI:
case StorageBusType.SSA:
case StorageBusType.Fibre:
case StorageBusType.iSCSI:
case StorageBusType.SAS:
Type = DeviceType.SCSI;
break;
case Windows.StorageBusType.FireWire:
case StorageBusType.FireWire:
IsFireWire = true;
Type = DeviceType.SCSI;
break;
case Windows.StorageBusType.USB:
case StorageBusType.USB:
IsUsb = true;
Type = DeviceType.SCSI;
break;
case Windows.StorageBusType.ATAPI:
case StorageBusType.ATAPI:
Type = DeviceType.ATAPI;
break;
case Windows.StorageBusType.ATA:
case Windows.StorageBusType.SATA:
case StorageBusType.ATA:
case StorageBusType.SATA:
Type = DeviceType.ATA;
break;
case Windows.StorageBusType.MultiMediaCard:
case StorageBusType.MultiMediaCard:
Type = DeviceType.MMC;
break;
case Windows.StorageBusType.SecureDigital:
case StorageBusType.SecureDigital:
Type = DeviceType.SecureDigital;
break;
case Windows.StorageBusType.NVMe:
case StorageBusType.NVMe:
Type = DeviceType.NVMe;
break;
}
@@ -304,7 +319,7 @@ namespace DiscImageChef.Devices
}
}
break;
case Interop.PlatformID.Linux:
case PlatformID.Linux:
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
@@ -313,22 +328,22 @@ namespace DiscImageChef.Devices
else if(devicePath.StartsWith("/dev/mmcblk", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.File.Exists("/sys/block/" + devPath + "/device/csd"))
if(File.Exists("/sys/block/" + devPath + "/device/csd"))
{
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/csd", out cachedCsd);
if(len == 0) cachedCsd = null;
}
if(System.IO.File.Exists("/sys/block/" + devPath + "/device/cid"))
if(File.Exists("/sys/block/" + devPath + "/device/cid"))
{
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/cid", out cachedCid);
if(len == 0) cachedCid = null;
}
if(System.IO.File.Exists("/sys/block/" + devPath + "/device/scr"))
if(File.Exists("/sys/block/" + devPath + "/device/scr"))
{
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/scr", out cachedScr);
if(len == 0) cachedScr = null;
}
if(System.IO.File.Exists("/sys/block/" + devPath + "/device/ocr"))
if(File.Exists("/sys/block/" + devPath + "/device/ocr"))
{
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/ocr", out cachedOcr);
if(len == 0) cachedOcr = null;
@@ -342,14 +357,14 @@ namespace DiscImageChef.Devices
#region SecureDigital / MultiMediaCard
if(cachedCid != null)
{
ScsiType = Decoders.SCSI.PeripheralDeviceTypes.DirectAccess;
ScsiType = PeripheralDeviceTypes.DirectAccess;
IsRemovable = false;
if(cachedScr != null)
{
Type = DeviceType.SecureDigital;
Decoders.SecureDigital.CID decoded = Decoders.SecureDigital.Decoders.DecodeCID(cachedCid);
Manufacturer = Decoders.SecureDigital.VendorString.Prettify(decoded.Manufacturer);
CID decoded = Decoders.SecureDigital.Decoders.DecodeCID(cachedCid);
Manufacturer = VendorString.Prettify(decoded.Manufacturer);
Model = decoded.ProductName;
Revision = string.Format("{0:X2}.{1:X2}", (decoded.ProductRevision & 0xF0) >> 4,
decoded.ProductRevision & 0x0F);
@@ -370,29 +385,29 @@ namespace DiscImageChef.Devices
#region USB
switch(PlatformId) {
case Interop.PlatformID.Linux:
case PlatformID.Linux:
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.Directory.Exists("/sys/block/" + devPath))
if(Directory.Exists("/sys/block/" + devPath))
{
string resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
resolvedLink = "/sys" + resolvedLink.Substring(2);
if(!string.IsNullOrEmpty(resolvedLink))
while(resolvedLink.Contains("usb"))
{
resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink);
if(!System.IO.File.Exists(resolvedLink + "/descriptors") ||
!System.IO.File.Exists(resolvedLink + "/idProduct") ||
!System.IO.File.Exists(resolvedLink + "/idVendor")) continue;
resolvedLink = Path.GetDirectoryName(resolvedLink);
if(!File.Exists(resolvedLink + "/descriptors") ||
!File.Exists(resolvedLink + "/idProduct") ||
!File.Exists(resolvedLink + "/idVendor")) continue;
System.IO.FileStream usbFs;
System.IO.StreamReader usbSr;
FileStream usbFs;
StreamReader usbSr;
string usbTemp;
usbFs = new System.IO.FileStream(resolvedLink + "/descriptors",
usbFs = new FileStream(resolvedLink + "/descriptors",
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
byte[] usbBuf = new byte[65536];
@@ -401,35 +416,35 @@ namespace DiscImageChef.Devices
Array.Copy(usbBuf, 0, UsbDescriptors, 0, usbCount);
usbFs.Close();
usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct");
usbSr = new StreamReader(resolvedLink + "/idProduct");
usbTemp = usbSr.ReadToEnd();
ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture, out usbProduct);
ushort.TryParse(usbTemp, NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out usbProduct);
usbSr.Close();
usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor");
usbSr = new StreamReader(resolvedLink + "/idVendor");
usbTemp = usbSr.ReadToEnd();
ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture, out usbVendor);
ushort.TryParse(usbTemp, NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out usbVendor);
usbSr.Close();
if(System.IO.File.Exists(resolvedLink + "/manufacturer"))
if(File.Exists(resolvedLink + "/manufacturer"))
{
usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer");
usbSr = new StreamReader(resolvedLink + "/manufacturer");
UsbManufacturerString = usbSr.ReadToEnd().Trim();
usbSr.Close();
}
if(System.IO.File.Exists(resolvedLink + "/product"))
if(File.Exists(resolvedLink + "/product"))
{
usbSr = new System.IO.StreamReader(resolvedLink + "/product");
usbSr = new StreamReader(resolvedLink + "/product");
UsbProductString = usbSr.ReadToEnd().Trim();
usbSr.Close();
}
if(System.IO.File.Exists(resolvedLink + "/serial"))
if(File.Exists(resolvedLink + "/serial"))
{
usbSr = new System.IO.StreamReader(resolvedLink + "/serial");
usbSr = new StreamReader(resolvedLink + "/serial");
UsbSerialString = usbSr.ReadToEnd().Trim();
usbSr.Close();
}
@@ -441,17 +456,17 @@ namespace DiscImageChef.Devices
}
break;
case Interop.PlatformID.Win32NT:
Windows.Usb.UsbDevice usbDevice = null;
case PlatformID.Win32NT:
Usb.UsbDevice usbDevice = null;
// I have to search for USB disks, floppies and CD-ROMs as separate device types
foreach(string devGuid in new[]
{
Windows.Usb.GuidDevinterfaceFloppy, Windows.Usb.GuidDevinterfaceCdrom,
Windows.Usb.GuidDevinterfaceDisk
Usb.GuidDevinterfaceFloppy, Usb.GuidDevinterfaceCdrom,
Usb.GuidDevinterfaceDisk
})
{
usbDevice = Windows.Usb.FindDrivePath(devicePath, devGuid);
usbDevice = Usb.FindDrivePath(devicePath, devGuid);
if(usbDevice != null) break;
}
@@ -472,57 +487,57 @@ namespace DiscImageChef.Devices
#endregion USB
#region FireWire
if(PlatformId == Interop.PlatformID.Linux)
if(PlatformId == PlatformID.Linux)
{
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.Directory.Exists("/sys/block/" + devPath))
if(Directory.Exists("/sys/block/" + devPath))
{
string resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
resolvedLink = "/sys" + resolvedLink.Substring(2);
if(!string.IsNullOrEmpty(resolvedLink))
while(resolvedLink.Contains("firewire"))
{
resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink);
if(!System.IO.File.Exists(resolvedLink + "/model") ||
!System.IO.File.Exists(resolvedLink + "/vendor") ||
!System.IO.File.Exists(resolvedLink + "/guid")) continue;
resolvedLink = Path.GetDirectoryName(resolvedLink);
if(!File.Exists(resolvedLink + "/model") ||
!File.Exists(resolvedLink + "/vendor") ||
!File.Exists(resolvedLink + "/guid")) continue;
System.IO.StreamReader fwSr;
StreamReader fwSr;
string fwTemp;
fwSr = new System.IO.StreamReader(resolvedLink + "/model");
fwSr = new StreamReader(resolvedLink + "/model");
fwTemp = fwSr.ReadToEnd();
uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture, out firewireModel);
uint.TryParse(fwTemp, NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out firewireModel);
fwSr.Close();
fwSr = new System.IO.StreamReader(resolvedLink + "/vendor");
fwSr = new StreamReader(resolvedLink + "/vendor");
fwTemp = fwSr.ReadToEnd();
uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture,
uint.TryParse(fwTemp, NumberStyles.HexNumber,
CultureInfo.InvariantCulture,
out firewireVendor);
fwSr.Close();
fwSr = new System.IO.StreamReader(resolvedLink + "/guid");
fwSr = new StreamReader(resolvedLink + "/guid");
fwTemp = fwSr.ReadToEnd();
ulong.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber,
System.Globalization.CultureInfo.InvariantCulture, out firewireGuid);
ulong.TryParse(fwTemp, NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out firewireGuid);
fwSr.Close();
if(System.IO.File.Exists(resolvedLink + "/model_name"))
if(File.Exists(resolvedLink + "/model_name"))
{
fwSr = new System.IO.StreamReader(resolvedLink + "/model_name");
fwSr = new StreamReader(resolvedLink + "/model_name");
FireWireModelName = fwSr.ReadToEnd().Trim();
fwSr.Close();
}
if(System.IO.File.Exists(resolvedLink + "/vendor_name"))
if(File.Exists(resolvedLink + "/vendor_name"))
{
fwSr = new System.IO.StreamReader(resolvedLink + "/vendor_name");
fwSr = new StreamReader(resolvedLink + "/vendor_name");
FireWireVendorName = fwSr.ReadToEnd().Trim();
fwSr.Close();
}
@@ -538,38 +553,38 @@ namespace DiscImageChef.Devices
#endregion FireWire
#region PCMCIA
if(PlatformId == Interop.PlatformID.Linux)
if(PlatformId == PlatformID.Linux)
{
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.Directory.Exists("/sys/block/" + devPath))
if(Directory.Exists("/sys/block/" + devPath))
{
string resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
resolvedLink = "/sys" + resolvedLink.Substring(2);
if(!string.IsNullOrEmpty(resolvedLink))
while(resolvedLink.Contains("/sys/devices"))
{
resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink);
if(!System.IO.Directory.Exists(resolvedLink + "/pcmcia_socket")) continue;
resolvedLink = Path.GetDirectoryName(resolvedLink);
if(!Directory.Exists(resolvedLink + "/pcmcia_socket")) continue;
string[] subdirs =
System.IO.Directory.GetDirectories(resolvedLink + "/pcmcia_socket",
Directory.GetDirectories(resolvedLink + "/pcmcia_socket",
"pcmcia_socket*",
System.IO.SearchOption.TopDirectoryOnly);
SearchOption.TopDirectoryOnly);
if(subdirs.Length <= 0) continue;
string possibleDir =
System.IO.Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]);
if(!System.IO.File.Exists(possibleDir + "/card_type") ||
!System.IO.File.Exists(possibleDir + "/cis")) continue;
Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]);
if(!File.Exists(possibleDir + "/card_type") ||
!File.Exists(possibleDir + "/cis")) continue;
System.IO.FileStream cisFs;
FileStream cisFs;
cisFs = new System.IO.FileStream(possibleDir + "/cis",
cisFs = new FileStream(possibleDir + "/cis",
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
byte[] cisBuf = new byte[65536];
@@ -590,11 +605,11 @@ namespace DiscImageChef.Devices
if(!scsiSense)
{
Decoders.SCSI.Inquiry.SCSIInquiry? inquiry = Decoders.SCSI.Inquiry.Decode(inqBuf);
Inquiry.SCSIInquiry? inquiry = Inquiry.Decode(inqBuf);
Type = DeviceType.SCSI;
bool serialSense = ScsiInquiry(out inqBuf, out senseBuf, 0x80);
if(!serialSense) Serial = Decoders.SCSI.EVPD.DecodePage80(inqBuf);
if(!serialSense) Serial = EVPD.DecodePage80(inqBuf);
if(inquiry.HasValue)
{
@@ -606,7 +621,7 @@ namespace DiscImageChef.Devices
if(tmp != null) Manufacturer = tmp.Trim();
IsRemovable = inquiry.Value.RMB;
ScsiType = (Decoders.SCSI.PeripheralDeviceTypes)inquiry.Value.PeripheralDeviceType;
ScsiType = (PeripheralDeviceTypes)inquiry.Value.PeripheralDeviceType;
}
bool atapiSense = AtapiIdentify(out ataBuf, out errorRegisters);
@@ -647,7 +662,7 @@ namespace DiscImageChef.Devices
Revision = ataid.Value.FirmwareRevision;
Serial = ataid.Value.SerialNumber;
ScsiType = Decoders.SCSI.PeripheralDeviceTypes.DirectAccess;
ScsiType = PeripheralDeviceTypes.DirectAccess;
if((ushort)ataid.Value.GeneralConfiguration != 0x848A)
IsRemovable |=
@@ -684,7 +699,7 @@ namespace DiscImageChef.Devices
static int ConvertFromHexAscii(string file, out byte[] outBuf)
{
System.IO.StreamReader sr = new System.IO.StreamReader(file);
StreamReader sr = new StreamReader(file);
string ins = sr.ReadToEnd().Trim();
outBuf = new byte[ins.Length / 2];
int count = 0;

View File

@@ -31,7 +31,9 @@
// ****************************************************************************/
using System;
using DiscImageChef.Devices.Windows;
using Microsoft.Win32.SafeHandles;
using PlatformID = DiscImageChef.Interop.PlatformID;
namespace DiscImageChef.Devices
{
@@ -47,13 +49,13 @@ namespace DiscImageChef.Devices
switch(PlatformId)
{
case Interop.PlatformID.Win32NT:
Windows.Extern.CloseHandle((SafeFileHandle)FileHandle);
case PlatformID.Win32NT:
Extern.CloseHandle((SafeFileHandle)FileHandle);
break;
case Interop.PlatformID.Linux:
case PlatformID.Linux:
Linux.Extern.close((int)FileHandle);
break;
case Interop.PlatformID.FreeBSD:
case PlatformID.FreeBSD:
FreeBSD.Extern.cam_close_device((IntPtr)FileHandle);
break;
}

View File

@@ -31,6 +31,8 @@
// ****************************************************************************/
using System;
using DiscImageChef.Interop;
using PlatformID = DiscImageChef.Interop.PlatformID;
namespace DiscImageChef.Devices
{
@@ -48,14 +50,14 @@ namespace DiscImageChef.Devices
{
public static DeviceInfo[] ListDevices()
{
switch(Interop.DetectOS.GetRealPlatformID())
switch(DetectOS.GetRealPlatformID())
{
case Interop.PlatformID.Win32NT: return Windows.ListDevices.GetList();
case Interop.PlatformID.Linux: return Linux.ListDevices.GetList();
case Interop.PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList();
case PlatformID.Win32NT: return Windows.ListDevices.GetList();
case PlatformID.Linux: return Linux.ListDevices.GetList();
case PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList();
default:
throw new InvalidOperationException(string.Format("Platform {0} not yet supported.",
Interop.DetectOS.GetRealPlatformID()));
DetectOS.GetRealPlatformID()));
}
}
}

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System;
using System.Text;
using DiscImageChef.Console;
namespace DiscImageChef.Devices
@@ -51,12 +52,12 @@ namespace DiscImageChef.Devices
if(!string.IsNullOrWhiteSpace(firstHalf))
{
tmp = System.Text.Encoding.ASCII.GetBytes(firstHalf);
tmp = Encoding.ASCII.GetBytes(firstHalf);
Array.Copy(tmp, 0, firstHalfBytes, 0, 8);
}
if(!string.IsNullOrWhiteSpace(secondHalf))
{
tmp = System.Text.Encoding.ASCII.GetBytes(secondHalf);
tmp = Encoding.ASCII.GetBytes(secondHalf);
Array.Copy(tmp, 0, secondHalfBytes, 0, 8);
}

View File

@@ -100,7 +100,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort confLength = (ushort)(((int)buffer[2] << 8) + buffer[3] + 4);
ushort confLength = (ushort)((buffer[2] << 8) + buffer[3] + 4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[confLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
@@ -157,7 +157,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort strctLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
ushort strctLength = (ushort)((buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
@@ -319,7 +319,7 @@ namespace DiscImageChef.Devices
Error = LastError != 0;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
uint strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
@@ -382,7 +382,7 @@ namespace DiscImageChef.Devices
Error = LastError != 0;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
uint strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
Array.Copy(tmpBuffer, 0, buffer, 0, buffer.Length);

View File

@@ -81,7 +81,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint attrLen = (uint)(((int)buffer[0] << 24) + ((int)buffer[1] << 16) + ((int)buffer[2] << 8) + buffer[3] +
uint attrLen = (uint)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] +
4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[attrLen];

View File

@@ -32,6 +32,7 @@
using System;
using DiscImageChef.Console;
using PlatformID = DiscImageChef.Interop.PlatformID;
namespace DiscImageChef.Devices
{
@@ -367,7 +368,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort modeLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
ushort modeLength = (ushort)((buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[modeLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
@@ -598,7 +599,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)buffer[0] << 24) + ((int)buffer[1] << 16) + ((int)buffer[2] << 8) +
uint strctLength = (uint)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) +
buffer[3] + 4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
@@ -738,10 +739,10 @@ namespace DiscImageChef.Devices
// Prevent overflows
if(buffer.Length > 255)
{
if(PlatformId != Interop.PlatformID.Win32NT && PlatformId != Interop.PlatformID.Win32S &&
PlatformId != Interop.PlatformID.Win32Windows && PlatformId != Interop.PlatformID.WinCE &&
PlatformId != Interop.PlatformID.WindowsPhone &&
PlatformId != Interop.PlatformID.Xbox) LastError = 75;
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
PlatformId != PlatformID.WindowsPhone &&
PlatformId != PlatformID.Xbox) LastError = 75;
else LastError = 111;
Error = true;
duration = 0;
@@ -781,10 +782,10 @@ namespace DiscImageChef.Devices
// Prevent overflows
if(buffer.Length > 65535)
{
if(PlatformId != Interop.PlatformID.Win32NT && PlatformId != Interop.PlatformID.Win32S &&
PlatformId != Interop.PlatformID.Win32Windows && PlatformId != Interop.PlatformID.WinCE &&
PlatformId != Interop.PlatformID.WindowsPhone &&
PlatformId != Interop.PlatformID.Xbox) LastError = 75;
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
PlatformId != PlatformID.WindowsPhone &&
PlatformId != PlatformID.Xbox) LastError = 75;
else LastError = 111;
Error = true;
duration = 0;

View File

@@ -918,7 +918,7 @@ namespace DiscImageChef.Devices
if(sense) return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort availableLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
ushort availableLength = (ushort)((buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[availableLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);

View File

@@ -30,6 +30,9 @@
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using DiscImageChef.Decoders.SCSI;
using DiscImageChef.Interop;
namespace DiscImageChef.Devices
{
public partial class Device
@@ -51,7 +54,7 @@ namespace DiscImageChef.Devices
/// Gets the Platform ID for this device
/// </summary>
/// <value>The Platform ID</value>
public Interop.PlatformID PlatformId { get; }
public PlatformID PlatformId { get; }
/// <summary>
/// Gets the file handle representing this device
@@ -111,7 +114,7 @@ namespace DiscImageChef.Devices
/// Gets the device's SCSI peripheral device type
/// </summary>
/// <value>The SCSI peripheral device type.</value>
public Decoders.SCSI.PeripheralDeviceTypes ScsiType { get; }
public PeripheralDeviceTypes ScsiType { get; }
/// <summary>
/// Gets a value indicating whether this device's media is removable.

View File

@@ -452,8 +452,8 @@ namespace DiscImageChef.Devices.FreeBSD
errorRegisters = new AtaErrorRegistersLBA48();
// 48-bit ATA CAM commands can crash FreeBSD < 9.2-RELEASE
if(System.Environment.Version.Major == 9 && System.Environment.Version.Minor < 2 ||
System.Environment.Version.Major < 9) return -1;
if(Environment.Version.Major == 9 && Environment.Version.Minor < 2 ||
Environment.Version.Major < 9) return -1;
if(buffer == null) return -1;

View File

@@ -35,6 +35,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Decoders.SCSI;
using static DiscImageChef.Devices.FreeBSD.Extern;
namespace DiscImageChef.Devices.FreeBSD
@@ -96,7 +98,7 @@ namespace DiscImageChef.Devices.FreeBSD
atadTneid[aIndex + 1] = cgd.ident_data[aIndex];
}
Decoders.ATA.Identify.IdentifyDevice? idt = Decoders.ATA.Identify.Decode(atadTneid);
Identify.IdentifyDevice? idt = Identify.Decode(atadTneid);
if(idt.HasValue)
{
string[] separated = idt.Value.Model.Split(' ');
@@ -121,7 +123,7 @@ namespace DiscImageChef.Devices.FreeBSD
}
case CamProto.ProtoScsi:
{
Decoders.SCSI.Inquiry.SCSIInquiry? inq = Decoders.SCSI.Inquiry.Decode(cgd.inq_data);
Inquiry.SCSIInquiry? inq = Inquiry.Decode(cgd.inq_data);
if(inq.HasValue)
{
deviceInfo.Vendor = StringHandlers.CToString(inq.Value.VendorIdentification).Trim();

View File

@@ -33,7 +33,9 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Interop;
namespace DiscImageChef.Devices.Linux
{
@@ -382,7 +384,7 @@ namespace DiscImageChef.Devices.Linux
IntPtr buf = Marshal.AllocHGlobal(4096);
int resultSize;
if(Interop.DetectOS.Is64Bit())
if(DetectOS.Is64Bit())
{
long result64 = Extern.readlink64(path, buf, 4096);
if(result64 <= 0) return null;
@@ -400,7 +402,7 @@ namespace DiscImageChef.Devices.Linux
byte[] resultString = new byte[resultSize];
Marshal.Copy(buf, resultString, 0, resultSize);
Marshal.FreeHGlobal(buf);
return System.Text.Encoding.ASCII.GetString(resultString);
return Encoding.ASCII.GetString(resultString);
}
}
}

View File

@@ -54,10 +54,10 @@ namespace DiscImageChef.Devices.Linux
internal static extern int ioctlMmc(int fd, LinuxIoctl request, ref MmcIocCmd value);
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int readlink(string path, System.IntPtr buf, int bufsize);
internal static extern int readlink(string path, IntPtr buf, int bufsize);
[DllImport("libc", CharSet = CharSet.Ansi, EntryPoint = "readlink", SetLastError = true)]
internal static extern long readlink64(string path, System.IntPtr buf, long bufsize);
internal static extern long readlink64(string path, IntPtr buf, long bufsize);
[DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern IntPtr udev_new();

View File

@@ -136,19 +136,19 @@ namespace DiscImageChef.Devices.Windows
if(descriptor.VendorIdOffset > 0)
info.Vendor =
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.VendorIdOffset);
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: descriptor.VendorIdOffset);
if(descriptor.ProductIdOffset > 0)
info.Model =
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: (int)descriptor.ProductIdOffset);
StringHandlers.CToString(descriptorB, Encoding.ASCII, start: descriptor.ProductIdOffset);
// TODO: Get serial number of SCSI and USB devices, probably also FireWire (untested)
if(descriptor.SerialNumberOffset > 0)
{
info.Serial =
StringHandlers.CToString(descriptorB, Encoding.ASCII,
start: (int)descriptor.SerialNumberOffset);
start: descriptor.SerialNumberOffset);
// fix any serial numbers that are returned as hex-strings
if(Array.TrueForAll(info.Serial.ToCharArray(), (char c) => "0123456789abcdef".IndexOf(c) >= 0)
if(Array.TrueForAll(info.Serial.ToCharArray(), c => "0123456789abcdef".IndexOf(c) >= 0)
&& info.Serial.Length == 40) info.Serial = HexStringToString(info.Serial).Trim();
}

View File

@@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
@@ -486,7 +487,7 @@ namespace DiscImageChef.Devices.Windows
//
// Return a list of USB Host Controllers
//
static internal System.Collections.ObjectModel.ReadOnlyCollection<UsbController> GetHostControllers()
static internal ReadOnlyCollection<UsbController> GetHostControllers()
{
List<UsbController> hostList = new List<UsbController>();
Guid hostGuid = new Guid(GUID_DEVINTERFACE_HUBCONTROLLER);
@@ -495,7 +496,7 @@ namespace DiscImageChef.Devices.Windows
// devices that match the interface GUID of a Hub Controller
IntPtr h = SetupDiGetClassDevs(ref hostGuid, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(h.ToInt32() == INVALID_HANDLE_VALUE)
return new System.Collections.ObjectModel.ReadOnlyCollection<UsbController>(hostList);
return new ReadOnlyCollection<UsbController>(hostList);
IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE);
bool success;
@@ -547,7 +548,7 @@ namespace DiscImageChef.Devices.Windows
SetupDiDestroyDeviceInfoList(h);
// convert it into a Collection
return new System.Collections.ObjectModel.ReadOnlyCollection<UsbController>(hostList);
return new ReadOnlyCollection<UsbController>(hostList);
}
//
@@ -732,7 +733,7 @@ namespace DiscImageChef.Devices.Windows
}
// return a list of the down stream ports
internal System.Collections.ObjectModel.ReadOnlyCollection<UsbPort> GetPorts()
internal ReadOnlyCollection<UsbPort> GetPorts()
{
List<UsbPort> portList = new List<UsbPort>();
@@ -740,7 +741,7 @@ namespace DiscImageChef.Devices.Windows
IntPtr h = CreateFile(HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,
IntPtr.Zero);
if(h.ToInt32() == INVALID_HANDLE_VALUE)
return new System.Collections.ObjectModel.ReadOnlyCollection<UsbPort>(portList);
return new ReadOnlyCollection<UsbPort>(portList);
int nBytes = Marshal.SizeOf(typeof(UsbNodeConnectionInformationEx));
IntPtr ptrNodeConnection = Marshal.AllocHGlobal(nBytes);
@@ -783,7 +784,7 @@ namespace DiscImageChef.Devices.Windows
Marshal.FreeHGlobal(ptrNodeConnection);
CloseHandle(h);
// convert it into a Collection
return new System.Collections.ObjectModel.ReadOnlyCollection<UsbPort>(portList);
return new ReadOnlyCollection<UsbPort>(portList);
}
}
@@ -956,7 +957,7 @@ namespace DiscImageChef.Devices.Windows
// build a request for configuration descriptor
UsbDescriptorRequest dcrRequest = new UsbDescriptorRequest();
dcrRequest.ConnectionIndex = PortPortNumber;
dcrRequest.SetupPacket.wValue = (short)(USB_CONFIGURATION_DESCRIPTOR_TYPE << 8);
dcrRequest.SetupPacket.wValue = USB_CONFIGURATION_DESCRIPTOR_TYPE << 8;
dcrRequest.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(dcrRequest));
dcrRequest.SetupPacket.wIndex = 0;
// Geez, I wish C# had a Marshal.MemSet() method