2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-12 06:39:31 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Extern.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 : Windows direct device access.
|
2015-10-12 06:39:31 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains the P/Invoke definitions of Windows syscalls used to directly
|
|
|
|
|
// interface 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
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// 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
|
|
|
|
|
// Lesser General Public 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-05-19 20:28:49 +01:00
|
|
|
// Copyright © 2011-2017 Natalia Portillo
|
2015-10-12 06:39:31 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-10-12 06:39:31 +01:00
|
|
|
|
|
|
|
|
using System;
|
2015-10-05 21:20:25 +01:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Devices.Windows
|
|
|
|
|
{
|
|
|
|
|
static class Extern
|
|
|
|
|
{
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
|
|
|
internal static extern SafeFileHandle CreateFile(
|
|
|
|
|
[MarshalAs(UnmanagedType.LPTStr)] string filename,
|
2015-10-06 18:27:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAccess access,
|
|
|
|
|
[MarshalAs(UnmanagedType.U4)] FileShare share,
|
2015-10-05 21:20:25 +01:00
|
|
|
IntPtr securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
|
2015-10-06 18:28:06 +01:00
|
|
|
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
|
2015-10-06 18:27:38 +01:00
|
|
|
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
|
2015-10-05 21:20:25 +01:00
|
|
|
IntPtr templateFile);
|
|
|
|
|
|
2017-08-21 04:28:26 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2015-10-12 06:25:49 +01:00
|
|
|
internal static extern bool DeviceIoControlScsi(
|
2015-10-05 21:20:25 +01:00
|
|
|
SafeFileHandle hDevice,
|
2015-10-12 06:25:49 +01:00
|
|
|
WindowsIoctl IoControlCode,
|
2015-10-06 18:29:15 +01:00
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer InBuffer,
|
2015-10-05 21:20:25 +01:00
|
|
|
uint nInBufferSize,
|
2015-10-06 18:29:15 +01:00
|
|
|
ref ScsiPassThroughDirectAndSenseBuffer OutBuffer,
|
2015-10-05 21:20:25 +01:00
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr Overlapped
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-21 04:28:26 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
2015-10-12 06:25:49 +01:00
|
|
|
internal static extern bool DeviceIoControlAta(
|
2015-10-07 02:15:31 +01:00
|
|
|
SafeFileHandle hDevice,
|
2015-10-12 06:25:49 +01:00
|
|
|
WindowsIoctl IoControlCode,
|
2017-09-07 16:48:25 +01:00
|
|
|
ref AtaPassThroughDirectWithBuffer InBuffer,
|
2015-10-07 02:15:31 +01:00
|
|
|
uint nInBufferSize,
|
2017-09-07 16:48:25 +01:00
|
|
|
ref AtaPassThroughDirectWithBuffer OutBuffer,
|
2015-10-07 02:15:31 +01:00
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr Overlapped
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-22 03:40:43 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
|
|
|
|
internal static extern bool DeviceIoControlStorageQuery(
|
|
|
|
|
SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl IoControlCode,
|
|
|
|
|
ref StoragePropertyQuery InBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
IntPtr OutBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr Overlapped
|
2017-09-10 23:20:59 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, EntryPoint = "DeviceIoControl", CharSet = CharSet.Auto)]
|
|
|
|
|
internal static extern bool DeviceIoControlIde(
|
|
|
|
|
SafeFileHandle hDevice,
|
|
|
|
|
WindowsIoctl IoControlCode,
|
|
|
|
|
ref IdePassThroughDirect InBuffer,
|
|
|
|
|
uint nInBufferSize,
|
|
|
|
|
ref IdePassThroughDirect OutBuffer,
|
|
|
|
|
uint nOutBufferSize,
|
|
|
|
|
ref uint pBytesReturned,
|
|
|
|
|
IntPtr Overlapped
|
|
|
|
|
);
|
2017-08-22 03:40:43 +01:00
|
|
|
|
2015-10-05 21:20:25 +01:00
|
|
|
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
2015-10-12 06:25:49 +01:00
|
|
|
internal static extern bool CloseHandle(SafeFileHandle hDevice);
|
2015-10-05 21:20:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|