From bacf50104daa09cd90f8dc36c06a6982d91000af Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 11 Dec 2003 16:53:42 +0000 Subject: Linux ports --- lib/cdabstract.cpp | 144 ++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'lib/cdabstract.cpp') diff --git a/lib/cdabstract.cpp b/lib/cdabstract.cpp index 103be1a..ff438c4 100644 --- a/lib/cdabstract.cpp +++ b/lib/cdabstract.cpp @@ -17,17 +17,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdabstract.cpp,v 1.6 2003-12-04 01:55:15 pixel Exp $ */ +/* $Id: cdabstract.cpp,v 1.7 2003-12-11 16:53:43 pixel Exp $ */ #include "cdabstract.h" #include "Input.h" #include "cdreader.h" #ifdef __linux__ -#include -#include -#include -#include +#include +#include +#include +#include #endif #if defined (_MSC_VER) || defined (__MINGW32__) @@ -47,13 +47,13 @@ bool cdabstract::canprobe() { return true; #endif #ifdef _WIN32 - OSVERSIONINFO ov; - memset(&ov, 0, sizeof(OSVERSIONINFO)); - ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - GetVersionEx(&ov); - - return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)); + OSVERSIONINFO ov; + memset(&ov, 0, sizeof(OSVERSIONINFO)); + ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + GetVersionEx(&ov); + + return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)); #endif return false; } @@ -94,66 +94,66 @@ std::vector cdabstract::probe() throw (GeneralException) { } #ifdef _WIN32 -HANDLE cdabstract::OpenIOCTLFile(char cLetter) { - HANDLE hF; - char szFName[16]; - OSVERSIONINFO ov; - DWORD dwFlags; - DWORD dwIOCTLAttr = 0; - - memset(&ov, 0, sizeof(OSVERSIONINFO)); - ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&ov); - - if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)) - dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP - else dwFlags = GENERIC_READ; - - sprintf(szFName, "\\\\.\\%c:", cLetter); - - hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive - NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); - - if (hF == INVALID_HANDLE_VALUE) { // mmm... no success? - dwFlags ^= GENERIC_WRITE; // -> try write toggle - hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again - NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); - if (hF == INVALID_HANDLE_VALUE) - return NULL; - } - return hF; -} - -typedef struct { - ULONG Length; - UCHAR PortNumber; - UCHAR PathId; - UCHAR TargetId; - UCHAR Lun; -} SCSI_ADDRESS, *PSCSI_ADDRESS; - -void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) { - char szBuf[1024]; - PSCSI_ADDRESS pSA; - DWORD dwRet; - - *iDA = *iDT = *iDL = -1; - - if (hF == NULL) - return; - - memset(szBuf,0,1024); - - pSA = (PSCSI_ADDRESS)szBuf; - pSA->Length = sizeof(SCSI_ADDRESS); - - if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA, - sizeof(SCSI_ADDRESS), &dwRet, NULL)) - return; - - *iDA = pSA->PortNumber; - *iDT = pSA->TargetId; - *iDL = pSA->Lun; +HANDLE cdabstract::OpenIOCTLFile(char cLetter) { + HANDLE hF; + char szFName[16]; + OSVERSIONINFO ov; + DWORD dwFlags; + DWORD dwIOCTLAttr = 0; + + memset(&ov, 0, sizeof(OSVERSIONINFO)); + ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&ov); + + if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)) + dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP + else dwFlags = GENERIC_READ; + + sprintf(szFName, "\\\\.\\%c:", cLetter); + + hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive + NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); + + if (hF == INVALID_HANDLE_VALUE) { // mmm... no success? + dwFlags ^= GENERIC_WRITE; // -> try write toggle + hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again + NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); + if (hF == INVALID_HANDLE_VALUE) + return NULL; + } + return hF; +} + +typedef struct { + ULONG Length; + UCHAR PortNumber; + UCHAR PathId; + UCHAR TargetId; + UCHAR Lun; +} SCSI_ADDRESS, *PSCSI_ADDRESS; + +void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) { + char szBuf[1024]; + PSCSI_ADDRESS pSA; + DWORD dwRet; + + *iDA = *iDT = *iDL = -1; + + if (hF == NULL) + return; + + memset(szBuf,0,1024); + + pSA = (PSCSI_ADDRESS)szBuf; + pSA->Length = sizeof(SCSI_ADDRESS); + + if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA, + sizeof(SCSI_ADDRESS), &dwRet, NULL)) + return; + + *iDA = pSA->PortNumber; + *iDT = pSA->TargetId; + *iDL = pSA->Lun; } #endif -- cgit v1.2.3