From d48d19ff762382fe34c82dfdfa8aa6b54edbf912 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 27 Oct 2019 13:50:46 +0000 Subject: [PATCH] Check existence of NT DDK structures and create them otherwise. --- win32/CMakeLists.txt | 18 +++++++- win32/ata.c | 27 +---------- win32/ntioctl.h | 108 +++++++++++++++++++++++++++++++++++++++++++ win32/scsi.c | 23 +-------- 4 files changed, 129 insertions(+), 47 deletions(-) create mode 100644 win32/ntioctl.h diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index 5365bf7..ff2c8c6 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -4,7 +4,23 @@ if (NOT "${CMAKE_SYSTEM}" MATCHES "Windows") return() endif () -set(PLATFORM_SOURCES "win32.h" network.c hello.c "win32.c" list_devices.c ata.c device.c ieee1394.c pcmcia.c scsi.c sdhci.c usb.c) +CHECK_INCLUDE_FILES("ntddscsi.h" HAVE_NTDDSCSI_H) +CHECK_TYPE_SIZE(ATA_PASS_THROUGH_EX APTE) +CHECK_TYPE_SIZE(SCSI_PASS_THROUGH_DIRECT SPTD) + +if (HAVE_NTDDSCSI_H) + add_definitions(-DHAS_NTDDSCSI_H) +endif () + +if (HAVE_APTE) + add_definitions(-DHAS_APTE) +endif () + +if (HAVE_SPTD) + add_definitions(-DHAS_SPTD) +endif () + +set(PLATFORM_SOURCES "win32.h" network.c hello.c "win32.c" list_devices.c ata.c device.c ieee1394.c pcmcia.c scsi.c sdhci.c usb.c ntioctl.h) add_executable(dicremote ${PLATFORM_SOURCES}) diff --git a/win32/ata.c b/win32/ata.c index 8694665..493b9fb 100644 --- a/win32/ata.c +++ b/win32/ata.c @@ -16,35 +16,12 @@ */ #include "../dicmote.h" +#include "ntioctl.h" #include "win32.h" -#include +#include #include -#ifndef ATA_FLAGS_DRDY_REQUIRED -#define ATA_FLAGS_DRDY_REQUIRED (1 << 0) -#endif - -#ifndef ATA_FLAGS_DATA_IN -#define ATA_FLAGS_DATA_IN (1 << 1) -#endif - -#ifndef ATA_FLAGS_DATA_OUT -#define ATA_FLAGS_DATA_OUT (1 << 2) -#endif - -#ifndef ATA_FLAGS_48BIT_COMMAND -#define ATA_FLAGS_48BIT_COMMAND (1 << 3) -#endif - -#ifndef ATA_FLAGS_USE_DMA -#define ATA_FLAGS_USE_DMA (1 << 4) -#endif - -#ifndef IOCTL_ATA_PASS_THROUGH -#define IOCTL_ATA_PASS_THROUGH 0x4D02C -#endif - // TODO: Check if we can live without copying buffer in and out int32_t Win32SendAtaChsCommand(void* device_ctx, AtaRegistersChs registers, diff --git a/win32/ntioctl.h b/win32/ntioctl.h new file mode 100644 index 0000000..0f098ad --- /dev/null +++ b/win32/ntioctl.h @@ -0,0 +1,108 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DICREMOTE_WIN32_NTIOCTL_H_ +#define DICREMOTE_WIN32_NTIOCTL_H_ + +#include + +#ifdef HAS_NTDDSCSI_H +#include +#endif + +#ifndef ATA_FLAGS_DRDY_REQUIRED +#define ATA_FLAGS_DRDY_REQUIRED (1 << 0) +#endif + +#ifndef ATA_FLAGS_DATA_IN +#define ATA_FLAGS_DATA_IN (1 << 1) +#endif + +#ifndef ATA_FLAGS_DATA_OUT +#define ATA_FLAGS_DATA_OUT (1 << 2) +#endif + +#ifndef ATA_FLAGS_48BIT_COMMAND +#define ATA_FLAGS_48BIT_COMMAND (1 << 3) +#endif + +#ifndef ATA_FLAGS_USE_DMA +#define ATA_FLAGS_USE_DMA (1 << 4) +#endif + +#ifndef IOCTL_ATA_PASS_THROUGH +#define IOCTL_ATA_PASS_THROUGH 0x4D02C +#endif + +#ifndef SCSI_IOCTL_DATA_OUT +#define SCSI_IOCTL_DATA_OUT 0 +#endif + +#ifndef SCSI_IOCTL_DATA_IN +#define SCSI_IOCTL_DATA_IN 1 +#endif + +#ifndef SCSI_IOCTL_DATA_UNSPECIFIED +#define SCSI_IOCTL_DATA_UNSPECIFIED 2 +#endif + +#ifndef SCSI_IOCTL_DATA_BIDIRECTIONAL +#define SCSI_IOCTL_DATA_BIDIRECTIONAL 3 +#endif + +#ifndef IOCTL_SCSI_PASS_THROUGH_DIRECT +#define IOCTL_SCSI_PASS_THROUGH_DIRECT 0x4D014 +#endif + +#ifndef HAS_SPTD +typedef struct _SCSI_PASS_THROUGH_DIRECT +{ + USHORT Length; + UCHAR ScsiStatus; + UCHAR PathId; + UCHAR TargetId; + UCHAR Lun; + UCHAR CdbLength; + UCHAR SenseInfoLength; + UCHAR DataIn; + ULONG DataTransferLength; + ULONG TimeOutValue; + PVOID DataBuffer; + ULONG SenseInfoOffset; + UCHAR Cdb[16]; +} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT; +#endif + +#ifndef HAS_APTE +typedef struct _ATA_PASS_THROUGH_EX +{ + USHORT Length; + USHORT AtaFlags; + UCHAR PathId; + UCHAR TargetId; + UCHAR Lun; + UCHAR ReservedAsUchar; + ULONG DataTransferLength; + ULONG TimeOutValue; + ULONG ReservedAsUlong; + ULONG_PTR DataBufferOffset; + UCHAR PreviousTaskFile[8]; + UCHAR CurrentTaskFile[8]; +} ATA_PASS_THROUGH_EX, *PATA_PASS_THROUGH_EX; +#endif + +#endif // DICREMOTE_WIN32_NTIOCTL_H_ diff --git a/win32/scsi.c b/win32/scsi.c index 7784686..2c5f4fd 100644 --- a/win32/scsi.c +++ b/win32/scsi.c @@ -16,30 +16,11 @@ */ #include "../dicmote.h" +#include "ntioctl.h" #include "win32.h" -#include #include - -#ifndef SCSI_IOCTL_DATA_OUT -#define SCSI_IOCTL_DATA_OUT 0 -#endif - -#ifndef SCSI_IOCTL_DATA_IN -#define SCSI_IOCTL_DATA_IN 1 -#endif - -#ifndef SCSI_IOCTL_DATA_UNSPECIFIED -#define SCSI_IOCTL_DATA_UNSPECIFIED 2 -#endif - -#ifndef SCSI_IOCTL_DATA_BIDIRECTIONAL -#define SCSI_IOCTL_DATA_BIDIRECTIONAL 3 -#endif - -#ifndef IOCTL_SCSI_PASS_THROUGH_DIRECT -#define IOCTL_SCSI_PASS_THROUGH_DIRECT 0x4D014 -#endif +#include int32_t Win32SendScsiCommand(void* device_ctx, char* cdb,