2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-12 06:39:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Command.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Direct device access.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// High level commands used to directly access devices.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
2017-12-20 02:08:37 +00:00
|
|
|
// it under the terms of the GNU Lesser General internal License as
|
2016-07-28 18:13:49 +01:00
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-12 06:39:31 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2017-12-20 02:08:37 +00:00
|
|
|
// Lesser General internal License for more details.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-12 06:39:31 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Decoders.ATA;
|
2015-10-12 19:55:00 +01:00
|
|
|
using DiscImageChef.Interop;
|
|
|
|
|
using Microsoft.Win32.SafeHandles;
|
2015-10-12 06:25:49 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Devices
|
|
|
|
|
{
|
2017-12-20 02:08:37 +00:00
|
|
|
static class Command
|
2015-10-12 06:25:49 +01:00
|
|
|
{
|
2015-10-12 20:08:56 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a SCSI command
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
|
|
|
|
/// <param name="fd">File handle</param>
|
|
|
|
|
/// <param name="cdb">SCSI CDB</param>
|
|
|
|
|
/// <param name="buffer">Buffer for SCSI command response</param>
|
|
|
|
|
/// <param name="senseBuffer">Buffer with the SCSI sense</param>
|
|
|
|
|
/// <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>
|
2017-12-20 02:08:37 +00:00
|
|
|
internal static int SendScsiCommand(object fd, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer,
|
2017-12-19 20:33:03 +00:00
|
|
|
uint timeout, ScsiDirection direction, out double duration, out bool sense)
|
2015-10-12 06:25:49 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
|
2015-10-12 19:55:00 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return SendScsiCommand(ptId, fd, cdb, ref buffer, out senseBuffer, timeout, direction, out duration,
|
2017-12-19 20:33:03 +00:00
|
|
|
out sense);
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-12 20:08:56 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sends a SCSI command
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 if no error occurred, otherwise, errno</returns>
|
2017-12-20 17:15:26 +00:00
|
|
|
/// <param name="ptId">Platform ID for executing the command</param>
|
2015-10-12 20:08:56 +01:00
|
|
|
/// <param name="fd">File handle</param>
|
|
|
|
|
/// <param name="cdb">SCSI CDB</param>
|
|
|
|
|
/// <param name="buffer">Buffer for SCSI command response</param>
|
|
|
|
|
/// <param name="senseBuffer">Buffer with the SCSI sense</param>
|
|
|
|
|
/// <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>
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static int SendScsiCommand(Interop.PlatformID ptId, object fd, byte[] cdb, ref byte[] buffer,
|
2017-12-19 20:33:03 +00:00
|
|
|
out byte[] senseBuffer, uint timeout, ScsiDirection direction,
|
|
|
|
|
out double duration, out bool sense)
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(ptId)
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
|
|
|
|
case Interop.PlatformID.Win32NT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
Windows.ScsiIoctlDirection dir;
|
2015-10-12 19:55:00 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
switch(direction)
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case ScsiDirection.In:
|
|
|
|
|
dir = Windows.ScsiIoctlDirection.In;
|
|
|
|
|
break;
|
|
|
|
|
case ScsiDirection.Out:
|
|
|
|
|
dir = Windows.ScsiIoctlDirection.Out;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
dir = Windows.ScsiIoctlDirection.Unspecified;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-12 19:55:00 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
return Windows.Command.SendScsiCommand((SafeFileHandle)fd, cdb, ref buffer, out senseBuffer,
|
|
|
|
|
timeout, dir, out duration, out sense);
|
|
|
|
|
}
|
|
|
|
|
case Interop.PlatformID.Linux:
|
|
|
|
|
{
|
|
|
|
|
Linux.ScsiIoctlDirection dir;
|
2015-10-12 19:55:00 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
switch(direction)
|
|
|
|
|
{
|
|
|
|
|
case ScsiDirection.In:
|
|
|
|
|
dir = Linux.ScsiIoctlDirection.In;
|
|
|
|
|
break;
|
|
|
|
|
case ScsiDirection.Out:
|
|
|
|
|
dir = Linux.ScsiIoctlDirection.Out;
|
|
|
|
|
break;
|
|
|
|
|
case ScsiDirection.Bidirectional:
|
|
|
|
|
dir = Linux.ScsiIoctlDirection.Unspecified;
|
|
|
|
|
break;
|
|
|
|
|
case ScsiDirection.None:
|
|
|
|
|
dir = Linux.ScsiIoctlDirection.None;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
dir = Linux.ScsiIoctlDirection.Unknown;
|
|
|
|
|
break;
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
return Linux.Command.SendScsiCommand((int)fd, cdb, ref buffer, out senseBuffer, timeout, dir,
|
|
|
|
|
out duration, out sense);
|
|
|
|
|
}
|
2017-12-10 21:00:20 +00:00
|
|
|
case Interop.PlatformID.FreeBSD:
|
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
FreeBSD.CcbFlags flags = 0;
|
2017-12-10 21:00:20 +00:00
|
|
|
|
|
|
|
|
switch(direction)
|
|
|
|
|
{
|
|
|
|
|
case ScsiDirection.In:
|
2017-12-20 17:15:26 +00:00
|
|
|
flags = FreeBSD.CcbFlags.CamDirIn;
|
2017-12-10 21:00:20 +00:00
|
|
|
break;
|
|
|
|
|
case ScsiDirection.Out:
|
2017-12-20 17:15:26 +00:00
|
|
|
flags = FreeBSD.CcbFlags.CamDirOut;
|
2017-12-10 21:00:20 +00:00
|
|
|
break;
|
|
|
|
|
case ScsiDirection.Bidirectional:
|
2017-12-20 17:15:26 +00:00
|
|
|
flags = FreeBSD.CcbFlags.CamDirBoth;
|
2017-12-10 21:00:20 +00:00
|
|
|
break;
|
|
|
|
|
case ScsiDirection.None:
|
2017-12-20 17:15:26 +00:00
|
|
|
flags = FreeBSD.CcbFlags.CamDirNone;
|
2017-12-10 21:00:20 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IntPtr.Size == 8
|
2017-12-19 20:33:03 +00:00
|
|
|
? FreeBSD.Command.SendScsiCommand64((IntPtr)fd, cdb, ref buffer, out senseBuffer,
|
|
|
|
|
timeout, flags, out duration, out sense)
|
2017-12-10 21:00:20 +00:00
|
|
|
: FreeBSD.Command.SendScsiCommand((IntPtr)fd, cdb, ref buffer, out senseBuffer, timeout,
|
|
|
|
|
flags, out duration, out sense);
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
default: throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", ptId));
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
2015-10-12 06:25:49 +01:00
|
|
|
}
|
2015-10-14 02:53:46 +01:00
|
|
|
|
2017-12-20 02:08:37 +00:00
|
|
|
internal static int SendAtaCommand(object fd, AtaRegistersCHS registers, out AtaErrorRegistersCHS errorRegisters,
|
2017-12-19 20:33:03 +00:00
|
|
|
AtaProtocol protocol, AtaTransferRegister transferRegister, ref byte[] buffer,
|
|
|
|
|
uint timeout, bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
|
2015-10-14 02:53:46 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
|
2017-12-19 20:33:03 +00:00
|
|
|
timeout, transferBlocks, out duration, out sense);
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersCHS registers,
|
2017-12-19 20:33:03 +00:00
|
|
|
out AtaErrorRegistersCHS errorRegisters, AtaProtocol protocol,
|
|
|
|
|
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
|
|
|
|
bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(ptId)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
|
|
|
|
case Interop.PlatformID.Win32NT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
if(( // Windows XP <= SP1
|
|
|
|
|
Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 1 &&
|
|
|
|
|
(Environment.OSVersion.ServicePack == "Service Pack 1" ||
|
|
|
|
|
Environment.OSVersion.ServicePack == "")) || ( // Windows 2000
|
|
|
|
|
Environment.OSVersion.Version.Major == 5 &&
|
|
|
|
|
Environment.OSVersion.Version.Minor == 0))
|
|
|
|
|
return Windows.Command.SendIdeCommand((SafeFileHandle)fd, registers, out errorRegisters,
|
2017-08-21 04:30:10 +01:00
|
|
|
protocol, ref buffer, timeout, out duration, out sense);
|
2017-12-19 20:33:03 +00:00
|
|
|
// Windows NT 4 or earlier, requires special ATA pass thru SCSI. But DiscImageChef cannot run there (or can it?)
|
|
|
|
|
if(Environment.OSVersion.Version.Major <= 4)
|
|
|
|
|
throw new InvalidOperationException("Windows NT 4.0 or earlier is not supported.");
|
|
|
|
|
|
|
|
|
|
return Windows.Command.SendAtaCommand((SafeFileHandle)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
ref buffer, timeout, out duration, out sense);
|
|
|
|
|
}
|
2015-10-14 02:53:46 +01:00
|
|
|
case Interop.PlatformID.Linux:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
transferRegister, ref buffer, timeout, transferBlocks,
|
|
|
|
|
out duration, out sense);
|
|
|
|
|
}
|
2017-12-11 00:23:13 +00:00
|
|
|
case Interop.PlatformID.FreeBSD:
|
|
|
|
|
{
|
|
|
|
|
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
ref buffer, timeout, out duration, out sense);
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
default: throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", ptId));
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 02:08:37 +00:00
|
|
|
internal static int SendAtaCommand(object fd, AtaRegistersLBA28 registers,
|
2017-12-19 20:33:03 +00:00
|
|
|
out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol,
|
|
|
|
|
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
|
|
|
|
bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
|
2015-10-14 02:53:46 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
|
2017-12-19 20:33:03 +00:00
|
|
|
timeout, transferBlocks, out duration, out sense);
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersLBA28 registers,
|
2017-12-19 20:33:03 +00:00
|
|
|
out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol,
|
|
|
|
|
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
|
|
|
|
bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(ptId)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
|
|
|
|
case Interop.PlatformID.Win32NT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
if(( // Windows XP <= SP1
|
|
|
|
|
Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 1 &&
|
|
|
|
|
(Environment.OSVersion.ServicePack == "Service Pack 1" ||
|
|
|
|
|
Environment.OSVersion.ServicePack == "")) || ( // Windows 2000
|
|
|
|
|
Environment.OSVersion.Version.Major == 5 &&
|
|
|
|
|
Environment.OSVersion.Version.Minor == 0))
|
|
|
|
|
return Windows.Command.SendIdeCommand((SafeFileHandle)fd, registers, out errorRegisters,
|
2017-08-21 04:30:10 +01:00
|
|
|
protocol, ref buffer, timeout, out duration, out sense);
|
2017-12-19 20:33:03 +00:00
|
|
|
// Windows NT 4 or earlier, requires special ATA pass thru SCSI. But DiscImageChef cannot run there (or can it?)
|
|
|
|
|
if(Environment.OSVersion.Version.Major <= 4)
|
|
|
|
|
throw new InvalidOperationException("Windows NT 4.0 or earlier is not supported.");
|
|
|
|
|
|
|
|
|
|
return Windows.Command.SendAtaCommand((SafeFileHandle)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
ref buffer, timeout, out duration, out sense);
|
|
|
|
|
}
|
2015-10-14 02:53:46 +01:00
|
|
|
case Interop.PlatformID.Linux:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
transferRegister, ref buffer, timeout, transferBlocks,
|
|
|
|
|
out duration, out sense);
|
|
|
|
|
}
|
2017-12-11 00:23:13 +00:00
|
|
|
case Interop.PlatformID.FreeBSD:
|
|
|
|
|
{
|
|
|
|
|
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
ref buffer, timeout, out duration, out sense);
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
default: throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", ptId));
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 02:08:37 +00:00
|
|
|
internal static int SendAtaCommand(object fd, AtaRegistersLBA48 registers,
|
2017-12-19 20:33:03 +00:00
|
|
|
out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol,
|
|
|
|
|
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
|
|
|
|
bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
|
2015-10-14 02:53:46 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return SendAtaCommand(ptId, fd, registers, out errorRegisters, protocol, transferRegister, ref buffer,
|
2017-12-19 20:33:03 +00:00
|
|
|
timeout, transferBlocks, out duration, out sense);
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static int SendAtaCommand(Interop.PlatformID ptId, object fd, AtaRegistersLBA48 registers,
|
2017-12-19 20:33:03 +00:00
|
|
|
out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol,
|
|
|
|
|
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
|
|
|
|
bool transferBlocks, out double duration, out bool sense)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(ptId)
|
2015-10-14 02:53:46 +01:00
|
|
|
{
|
|
|
|
|
case Interop.PlatformID.Win32NT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
2015-10-14 02:53:46 +01:00
|
|
|
case Interop.PlatformID.Linux:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
return Linux.Command.SendAtaCommand((int)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
transferRegister, ref buffer, timeout, transferBlocks,
|
|
|
|
|
out duration, out sense);
|
|
|
|
|
}
|
2017-12-11 00:23:13 +00:00
|
|
|
case Interop.PlatformID.FreeBSD:
|
|
|
|
|
{
|
|
|
|
|
return FreeBSD.Command.SendAtaCommand((IntPtr)fd, registers, out errorRegisters, protocol,
|
|
|
|
|
ref buffer, timeout, out duration, out sense);
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
default: throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", ptId));
|
2015-10-14 02:53:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-22 22:58:01 +01:00
|
|
|
|
2017-12-20 02:08:37 +00:00
|
|
|
internal static int SendMmcCommand(object fd, MmcCommands command, bool write, bool isApplication, MmcFlags flags,
|
2017-12-19 20:33:03 +00:00
|
|
|
uint argument, uint blockSize, uint blocks, ref byte[] buffer,
|
|
|
|
|
out uint[] response, out double duration, out bool sense, uint timeout = 0)
|
2016-10-22 22:58:01 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
Interop.PlatformID ptId = DetectOS.GetRealPlatformID();
|
2016-10-22 22:58:01 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
return SendMmcCommand(ptId, (int)fd, command, write, isApplication, flags, argument, blockSize, blocks,
|
2017-12-19 20:33:03 +00:00
|
|
|
ref buffer, out response, out duration, out sense, timeout);
|
2016-10-22 22:58:01 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
internal static int SendMmcCommand(Interop.PlatformID ptId, object fd, MmcCommands command, bool write,
|
2017-12-19 20:33:03 +00:00
|
|
|
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)
|
2016-10-22 22:58:01 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
switch(ptId)
|
2016-10-22 22:58:01 +01:00
|
|
|
{
|
|
|
|
|
case Interop.PlatformID.Win32NT:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
return Windows.Command.SendMmcCommand((SafeFileHandle)fd, command, write, isApplication, flags,
|
|
|
|
|
argument, blockSize, blocks, ref buffer, out response,
|
|
|
|
|
out duration, out sense, timeout);
|
|
|
|
|
}
|
2016-10-22 22:58:01 +01:00
|
|
|
case Interop.PlatformID.Linux:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
return Linux.Command.SendMmcCommand((int)fd, command, write, isApplication, flags, argument,
|
|
|
|
|
blockSize, blocks, ref buffer, out response, out duration,
|
|
|
|
|
out sense, timeout);
|
|
|
|
|
}
|
2017-12-20 17:15:26 +00:00
|
|
|
default: throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", ptId));
|
2016-10-22 22:58:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-12 06:25:49 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|