mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* DiscImageChef.Devices/Device/Constructor.cs:
Added support for USB on Linux. * DiscImageChef/Commands/DeviceInfo.cs: * DiscImageChef.Devices/Device/Variables.cs: Added support for USB detection and metadata. * DiscImageChef.Devices/Linux/Extern.cs: * DiscImageChef.Devices/Linux/Command.cs: Added readlink(3) support, for getting symlink destinations.
This commit is contained in:
@@ -1,3 +1,15 @@
|
|||||||
|
2015-12-31 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* Device/Constructor.cs:
|
||||||
|
Added support for USB on Linux.
|
||||||
|
|
||||||
|
* Device/Variables.cs:
|
||||||
|
Added support for USB detection and metadata.
|
||||||
|
|
||||||
|
* Linux/Extern.cs:
|
||||||
|
* Linux/Command.cs:
|
||||||
|
Added readlink(3) support, for getting symlink destinations.
|
||||||
|
|
||||||
2015-12-30 Natalia Portillo <claunia@claunia.com>
|
2015-12-30 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* Device/Variables.cs:
|
* Device/Variables.cs:
|
||||||
|
|||||||
@@ -102,6 +102,80 @@ namespace DiscImageChef.Devices
|
|||||||
|
|
||||||
bool scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
bool scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||||
|
|
||||||
|
#region USB
|
||||||
|
if(platformID == DiscImageChef.Interop.PlatformID.Linux)
|
||||||
|
{
|
||||||
|
if(devicePath.StartsWith("/dev/sd"))
|
||||||
|
{
|
||||||
|
string devPath = devicePath.Substring(5);
|
||||||
|
if(System.IO.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"))
|
||||||
|
{
|
||||||
|
System.IO.FileStream usbFs;
|
||||||
|
System.IO.StreamReader usbSr;
|
||||||
|
string usbTemp;
|
||||||
|
|
||||||
|
usbFs = new System.IO.FileStream(resolvedLink + "/descriptors", System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||||
|
byte[] usbBuf = new byte[65536];
|
||||||
|
int usbCount = usbFs.Read(usbBuf, 0, 65536);
|
||||||
|
usbDescriptors = new byte[usbCount];
|
||||||
|
Array.Copy(usbBuf, 0, usbDescriptors, 0, usbCount);
|
||||||
|
usbFs.Close();
|
||||||
|
|
||||||
|
usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct");
|
||||||
|
usbTemp = usbSr.ReadToEnd();
|
||||||
|
ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out usbProduct);
|
||||||
|
usbSr.Close();
|
||||||
|
|
||||||
|
usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor");
|
||||||
|
usbTemp = usbSr.ReadToEnd();
|
||||||
|
ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out usbVendor);
|
||||||
|
usbSr.Close();
|
||||||
|
|
||||||
|
if(System.IO.File.Exists(resolvedLink + "/manufacturer"))
|
||||||
|
{
|
||||||
|
usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer");
|
||||||
|
usbManufacturerString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(System.IO.File.Exists(resolvedLink + "/product"))
|
||||||
|
{
|
||||||
|
usbSr = new System.IO.StreamReader(resolvedLink + "/product");
|
||||||
|
usbProductString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(System.IO.File.Exists(resolvedLink + "/serial"))
|
||||||
|
{
|
||||||
|
usbSr = new System.IO.StreamReader(resolvedLink + "/serial");
|
||||||
|
usbSerialString = usbSr.ReadToEnd().Trim();
|
||||||
|
usbSr.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
usb = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Implement for other operating systems
|
||||||
|
else
|
||||||
|
usb = false;
|
||||||
|
#endregion USB
|
||||||
|
|
||||||
if (!scsiSense)
|
if (!scsiSense)
|
||||||
{
|
{
|
||||||
Decoders.SCSI.Inquiry.SCSIInquiry? Inquiry = Decoders.SCSI.Inquiry.Decode(inqBuf);
|
Decoders.SCSI.Inquiry.SCSIInquiry? Inquiry = Decoders.SCSI.Inquiry.Decode(inqBuf);
|
||||||
@@ -173,6 +247,24 @@ namespace DiscImageChef.Devices
|
|||||||
revision = null;
|
revision = null;
|
||||||
serial = null;
|
serial = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usb)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(manufacturer))
|
||||||
|
manufacturer = usbManufacturerString;
|
||||||
|
if (string.IsNullOrEmpty(model))
|
||||||
|
model = usbProductString;
|
||||||
|
if (string.IsNullOrEmpty(serial))
|
||||||
|
serial = usbSerialString;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (char c in serial)
|
||||||
|
{
|
||||||
|
if(Char.IsControl(c))
|
||||||
|
serial = usbSerialString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ namespace DiscImageChef.Devices
|
|||||||
readonly string serial;
|
readonly string serial;
|
||||||
readonly Decoders.SCSI.PeripheralDeviceTypes scsiType;
|
readonly Decoders.SCSI.PeripheralDeviceTypes scsiType;
|
||||||
readonly bool removable;
|
readonly bool removable;
|
||||||
|
readonly bool usb;
|
||||||
|
readonly ushort usbVendor;
|
||||||
|
readonly ushort usbProduct;
|
||||||
|
readonly byte[] usbDescriptors;
|
||||||
|
readonly string usbManufacturerString;
|
||||||
|
readonly string usbProductString;
|
||||||
|
readonly string usbSerialString;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Platform ID for this device
|
/// Gets the Platform ID for this device
|
||||||
@@ -172,6 +179,10 @@ namespace DiscImageChef.Devices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the device's SCSI peripheral device type
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The SCSI peripheral device type.</value>
|
||||||
public Decoders.SCSI.PeripheralDeviceTypes SCSIType
|
public Decoders.SCSI.PeripheralDeviceTypes SCSIType
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -180,6 +191,10 @@ namespace DiscImageChef.Devices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this device's media is removable.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if this device's media is removable; otherwise, <c>false</c>.</value>
|
||||||
public bool IsRemovable
|
public bool IsRemovable
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -187,6 +202,90 @@ namespace DiscImageChef.Devices
|
|||||||
return removable;
|
return removable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this device is attached via USB.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if this device is attached via USB; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsUSB
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB vendor ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB vendor ID.</value>
|
||||||
|
public ushort USBVendorID
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbVendor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB product ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB product ID.</value>
|
||||||
|
public ushort USBProductID
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbProduct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB descriptors.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB descriptors.</value>
|
||||||
|
public byte[] USBDescriptors
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbDescriptors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB manufacturer string.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB manufacturer string.</value>
|
||||||
|
public string USBManufacturerString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbManufacturerString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB product string.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB product string.</value>
|
||||||
|
public string USBProductString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbProductString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the USB serial string.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The USB serial string.</value>
|
||||||
|
public string USBSerialString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return usbSerialString;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -328,6 +328,34 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ReadLink(string path)
|
||||||
|
{
|
||||||
|
IntPtr buf = Marshal.AllocHGlobal(int.MaxValue);
|
||||||
|
int resultSize;
|
||||||
|
|
||||||
|
if (Interop.DetectOS.Is64Bit())
|
||||||
|
{
|
||||||
|
long result64 = Extern.readlink64(path, buf, (long)int.MaxValue);
|
||||||
|
if (result64 <= 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
resultSize = (int)result64;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int result = Extern.readlink(path, buf, int.MaxValue);
|
||||||
|
if (result <= 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
resultSize = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] resultString = new byte[resultSize];
|
||||||
|
Marshal.Copy(buf, resultString, 0, resultSize);
|
||||||
|
Marshal.FreeHGlobal(buf);
|
||||||
|
return System.Text.Encoding.ASCII.GetString(resultString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ namespace DiscImageChef.Devices.Linux
|
|||||||
|
|
||||||
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
|
||||||
internal static extern int ioctlSg(int fd, LinuxIoctl request, ref sg_io_hdr_t value);
|
internal static extern int ioctlSg(int fd, LinuxIoctl request, ref sg_io_hdr_t value);
|
||||||
|
|
||||||
|
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||||
|
internal static extern int readlink(string path, System.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
2015-12-31 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* Commands/DeviceInfo.cs:
|
||||||
|
Added support for USB detection and metadata.
|
||||||
|
|
||||||
2015-12-30 Natalia Portillo <claunia@claunia.com>
|
2015-12-30 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* Main.cs:
|
* Main.cs:
|
||||||
|
|||||||
@@ -68,6 +68,19 @@ namespace DiscImageChef.Commands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dev.IsUSB)
|
||||||
|
{
|
||||||
|
DicConsole.WriteLine("USB device");
|
||||||
|
if(dev.USBDescriptors != null)
|
||||||
|
DicConsole.WriteLine("USB descriptor is {0} bytes", dev.USBDescriptors.Length);
|
||||||
|
DicConsole.WriteLine("USB Vendor ID: {0:X4}", dev.USBVendorID);
|
||||||
|
DicConsole.WriteLine("USB Product ID: {0:X4}", dev.USBProductID);
|
||||||
|
DicConsole.WriteLine("USB Manufacturer: {0:X4}", dev.USBManufacturerString);
|
||||||
|
DicConsole.WriteLine("USB Product: {0:X4}", dev.USBProductString);
|
||||||
|
DicConsole.WriteLine("USB Serial number: {0:X4}", dev.USBSerialString);
|
||||||
|
DicConsole.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
switch (dev.Type)
|
switch (dev.Type)
|
||||||
{
|
{
|
||||||
case DeviceType.ATA:
|
case DeviceType.ATA:
|
||||||
|
|||||||
Reference in New Issue
Block a user