REFACTOR: Fixed MOST name inconsistencies.

This commit is contained in:
2017-12-20 17:15:26 +00:00
parent 542520f5cd
commit a4650c61aa
428 changed files with 16205 additions and 16320 deletions

View File

@@ -60,42 +60,42 @@ namespace DiscImageChef.Devices.Linux
if(buffer == null) return -1;
sg_io_hdr_t io_hdr = new sg_io_hdr_t();
SgIoHdrT ioHdr = new SgIoHdrT();
senseBuffer = new byte[32];
io_hdr.interface_id = 'S';
io_hdr.cmd_len = (byte)cdb.Length;
io_hdr.mx_sb_len = (byte)senseBuffer.Length;
io_hdr.dxfer_direction = direction;
io_hdr.dxfer_len = (uint)buffer.Length;
io_hdr.dxferp = Marshal.AllocHGlobal(buffer.Length);
io_hdr.cmdp = Marshal.AllocHGlobal(cdb.Length);
io_hdr.sbp = Marshal.AllocHGlobal(senseBuffer.Length);
io_hdr.timeout = timeout * 1000;
ioHdr.interface_id = 'S';
ioHdr.cmd_len = (byte)cdb.Length;
ioHdr.mx_sb_len = (byte)senseBuffer.Length;
ioHdr.dxfer_direction = direction;
ioHdr.dxfer_len = (uint)buffer.Length;
ioHdr.dxferp = Marshal.AllocHGlobal(buffer.Length);
ioHdr.cmdp = Marshal.AllocHGlobal(cdb.Length);
ioHdr.sbp = Marshal.AllocHGlobal(senseBuffer.Length);
ioHdr.timeout = timeout * 1000;
Marshal.Copy(buffer, 0, io_hdr.dxferp, buffer.Length);
Marshal.Copy(cdb, 0, io_hdr.cmdp, cdb.Length);
Marshal.Copy(senseBuffer, 0, io_hdr.sbp, senseBuffer.Length);
Marshal.Copy(buffer, 0, ioHdr.dxferp, buffer.Length);
Marshal.Copy(cdb, 0, ioHdr.cmdp, cdb.Length);
Marshal.Copy(senseBuffer, 0, ioHdr.sbp, senseBuffer.Length);
DateTime start = DateTime.UtcNow;
int error = Extern.ioctlSg(fd, LinuxIoctl.SG_IO, ref io_hdr);
int error = Extern.ioctlSg(fd, LinuxIoctl.SgIo, ref ioHdr);
DateTime end = DateTime.UtcNow;
if(error < 0) error = Marshal.GetLastWin32Error();
Marshal.Copy(io_hdr.dxferp, buffer, 0, buffer.Length);
Marshal.Copy(io_hdr.cmdp, cdb, 0, cdb.Length);
Marshal.Copy(io_hdr.sbp, senseBuffer, 0, senseBuffer.Length);
Marshal.Copy(ioHdr.dxferp, buffer, 0, buffer.Length);
Marshal.Copy(ioHdr.cmdp, cdb, 0, cdb.Length);
Marshal.Copy(ioHdr.sbp, senseBuffer, 0, senseBuffer.Length);
sense |= (io_hdr.info & SgInfo.OkMask) != SgInfo.Ok;
sense |= (ioHdr.info & SgInfo.OkMask) != SgInfo.Ok;
if(io_hdr.duration > 0) duration = io_hdr.duration;
if(ioHdr.duration > 0) duration = ioHdr.duration;
else duration = (end - start).TotalMilliseconds;
Marshal.FreeHGlobal(io_hdr.dxferp);
Marshal.FreeHGlobal(io_hdr.cmdp);
Marshal.FreeHGlobal(io_hdr.sbp);
Marshal.FreeHGlobal(ioHdr.dxferp);
Marshal.FreeHGlobal(ioHdr.cmdp);
Marshal.FreeHGlobal(ioHdr.sbp);
return error;
}
@@ -339,28 +339,28 @@ namespace DiscImageChef.Devices.Linux
if(buffer == null) return -1;
mmc_ioc_cmd io_cmd = new mmc_ioc_cmd();
MmcIocCmd ioCmd = new MmcIocCmd();
IntPtr bufPtr = Marshal.AllocHGlobal(buffer.Length);
io_cmd.write_flag = write;
io_cmd.is_ascmd = isApplication;
io_cmd.opcode = (uint)command;
io_cmd.arg = argument;
io_cmd.flags = flags;
io_cmd.blksz = blockSize;
io_cmd.blocks = blocks;
ioCmd.write_flag = write;
ioCmd.is_ascmd = isApplication;
ioCmd.opcode = (uint)command;
ioCmd.arg = argument;
ioCmd.flags = flags;
ioCmd.blksz = blockSize;
ioCmd.blocks = blocks;
if(timeout > 0)
{
io_cmd.data_timeout_ns = timeout * 1000000000;
io_cmd.cmd_timeout_ms = timeout * 1000;
ioCmd.data_timeout_ns = timeout * 1000000000;
ioCmd.cmd_timeout_ms = timeout * 1000;
}
io_cmd.data_ptr = (ulong)bufPtr;
ioCmd.data_ptr = (ulong)bufPtr;
Marshal.Copy(buffer, 0, bufPtr, buffer.Length);
DateTime start = DateTime.UtcNow;
int error = Extern.ioctlMmc(fd, LinuxIoctl.MMC_IOC_CMD, ref io_cmd);
int error = Extern.ioctlMmc(fd, LinuxIoctl.MmcIocCmd, ref ioCmd);
DateTime end = DateTime.UtcNow;
sense |= error < 0;
@@ -369,7 +369,7 @@ namespace DiscImageChef.Devices.Linux
Marshal.Copy(bufPtr, buffer, 0, buffer.Length);
response = io_cmd.response;
response = ioCmd.response;
duration = (end - start).TotalMilliseconds;
Marshal.FreeHGlobal(bufPtr);

View File

@@ -61,7 +61,7 @@ namespace DiscImageChef.Devices.Linux
/// <summary>
/// O_NOCTTY
/// </summary>
NoControlTTY = 00000400,
NoControlTty = 00000400,
/// <summary>
/// O_TRUNC
/// </summary>
@@ -143,10 +143,10 @@ namespace DiscImageChef.Devices.Linux
enum LinuxIoctl : uint
{
// SCSI IOCtls
SG_GET_VERSION_NUM = 0x2282,
SG_IO = 0x2285,
SgGetVersionNum = 0x2282,
SgIo = 0x2285,
// MMC IOCtl
MMC_IOC_CMD = 0xC048B300
MmcIocCmd = 0xC048B300
}
[Flags]

View File

@@ -48,10 +48,10 @@ namespace DiscImageChef.Devices.Linux
internal static extern int ioctlInt(int fd, LinuxIoctl request, out int value);
[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 SgIoHdrT value);
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]
internal static extern int ioctlMmc(int fd, LinuxIoctl request, ref mmc_ioc_cmd value);
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);
@@ -67,6 +67,6 @@ namespace DiscImageChef.Devices.Linux
IntPtr udev, string subsystem, string sysname);
[DllImport("libudev", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern string udev_device_get_property_value(IntPtr udev_device, string key);
internal static extern string udev_device_get_property_value(IntPtr udevDevice, string key);
}
}

View File

@@ -60,70 +60,70 @@ namespace DiscImageChef.Devices.Linux
for(int i = 0; i < sysdevs.Length; i++)
{
devices[i] = new DeviceInfo();
devices[i].path = "/dev/" + Path.GetFileName(sysdevs[i]);
devices[i].Path = "/dev/" + Path.GetFileName(sysdevs[i]);
if(hasUdev)
{
udevDev = Extern.udev_device_new_from_subsystem_sysname(udev, "block",
Path.GetFileName(sysdevs[i]));
devices[i].vendor = Extern.udev_device_get_property_value(udevDev, "ID_VENDOR");
devices[i].model = Extern.udev_device_get_property_value(udevDev, "ID_MODEL");
if(!string.IsNullOrEmpty(devices[i].model)) devices[i].model = devices[i].model.Replace('_', ' ');
devices[i].serial = Extern.udev_device_get_property_value(udevDev, "ID_SCSI_SERIAL");
if(string.IsNullOrEmpty(devices[i].serial))
devices[i].serial = Extern.udev_device_get_property_value(udevDev, "ID_SERIAL_SHORT");
devices[i].bus = Extern.udev_device_get_property_value(udevDev, "ID_BUS");
devices[i].Vendor = Extern.udev_device_get_property_value(udevDev, "ID_VENDOR");
devices[i].Model = Extern.udev_device_get_property_value(udevDev, "ID_MODEL");
if(!string.IsNullOrEmpty(devices[i].Model)) devices[i].Model = devices[i].Model.Replace('_', ' ');
devices[i].Serial = Extern.udev_device_get_property_value(udevDev, "ID_SCSI_SERIAL");
if(string.IsNullOrEmpty(devices[i].Serial))
devices[i].Serial = Extern.udev_device_get_property_value(udevDev, "ID_SERIAL_SHORT");
devices[i].Bus = Extern.udev_device_get_property_value(udevDev, "ID_BUS");
}
if(File.Exists(Path.Combine(sysdevs[i], "device/vendor")) && string.IsNullOrEmpty(devices[i].vendor))
if(File.Exists(Path.Combine(sysdevs[i], "device/vendor")) && string.IsNullOrEmpty(devices[i].Vendor))
{
sr = new StreamReader(Path.Combine(sysdevs[i], "device/vendor"), Encoding.ASCII);
devices[i].vendor = sr.ReadLine().Trim();
devices[i].Vendor = sr.ReadLine().Trim();
}
else if(devices[i].path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].vendor = "Linux";
else if(devices[i].Path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].Vendor = "Linux";
if(File.Exists(Path.Combine(sysdevs[i], "device/model")) &&
(string.IsNullOrEmpty(devices[i].model) || devices[i].bus == "ata"))
(string.IsNullOrEmpty(devices[i].Model) || devices[i].Bus == "ata"))
{
sr = new StreamReader(Path.Combine(sysdevs[i], "device/model"), Encoding.ASCII);
devices[i].model = sr.ReadLine().Trim();
devices[i].Model = sr.ReadLine().Trim();
}
else if(devices[i].path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].model = "Linux";
else if(devices[i].Path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].Model = "Linux";
if(File.Exists(Path.Combine(sysdevs[i], "device/serial")) && string.IsNullOrEmpty(devices[i].serial))
if(File.Exists(Path.Combine(sysdevs[i], "device/serial")) && string.IsNullOrEmpty(devices[i].Serial))
{
sr = new StreamReader(Path.Combine(sysdevs[i], "device/serial"), Encoding.ASCII);
devices[i].serial = sr.ReadLine().Trim();
devices[i].Serial = sr.ReadLine().Trim();
}
if(string.IsNullOrEmpty(devices[i].vendor) || devices[i].vendor == "ATA")
if(string.IsNullOrEmpty(devices[i].Vendor) || devices[i].Vendor == "ATA")
{
if(devices[i].model != null)
if(devices[i].Model != null)
{
string[] pieces = devices[i].model.Split(' ');
string[] pieces = devices[i].Model.Split(' ');
if(pieces.Length > 1)
{
devices[i].vendor = pieces[0];
devices[i].model = devices[i].model.Substring(pieces[0].Length + 1);
devices[i].Vendor = pieces[0];
devices[i].Model = devices[i].Model.Substring(pieces[0].Length + 1);
}
}
}
// TODO: Get better device type from sysfs paths
if(string.IsNullOrEmpty(devices[i].bus))
if(string.IsNullOrEmpty(devices[i].Bus))
{
if(devices[i].path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].bus = "loop";
else if(devices[i].path.StartsWith("/dev/nvme", StringComparison.CurrentCulture))
devices[i].bus = "NVMe";
else if(devices[i].path.StartsWith("/dev/mmc", StringComparison.CurrentCulture))
devices[i].bus = "MMC/SD";
if(devices[i].Path.StartsWith("/dev/loop", StringComparison.CurrentCulture))
devices[i].Bus = "loop";
else if(devices[i].Path.StartsWith("/dev/nvme", StringComparison.CurrentCulture))
devices[i].Bus = "NVMe";
else if(devices[i].Path.StartsWith("/dev/mmc", StringComparison.CurrentCulture))
devices[i].Bus = "MMC/SD";
}
else devices[i].bus = devices[i].bus.ToUpper();
else devices[i].Bus = devices[i].Bus.ToUpper();
switch(devices[i].bus)
switch(devices[i].Bus)
{
case "ATA":
case "ATAPI":
@@ -132,7 +132,7 @@ namespace DiscImageChef.Devices.Linux
case "PCMCIA":
case "FireWire":
case "MMC/SD":
devices[i].supported = true;
devices[i].Supported = true;
break;
}
}

View File

@@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
namespace DiscImageChef.Devices.Linux
{
[StructLayout(LayoutKind.Sequential)]
struct sg_io_hdr_t
struct SgIoHdrT
{
/// <summary>
/// Always 'S' for SG v3
@@ -67,7 +67,7 @@ namespace DiscImageChef.Devices.Linux
}
[StructLayout(LayoutKind.Sequential)]
struct mmc_ioc_cmd
struct MmcIocCmd
{
/// <summary>
/// Implies direction of data. true = write, false = read