Index: src/ch/Device IO.h =================================================================== diff -u -rd5c3edd0d167db9b5d47d04248820fda49499a5e -r3716ae4c48568300cfdcebe705f9868a9dc8f3df --- src/ch/Device IO.h (.../Device IO.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) +++ src/ch/Device IO.h (.../Device IO.h) (revision 3716ae4c48568300cfdcebe705f9868a9dc8f3df) @@ -16,82 +16,23 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#define VWIN32_DIOC_DOS_IOCTL 1 - -typedef struct _DEVIOCTL_REGISTERS -{ - DWORD reg_EBX; - DWORD reg_EDX; - DWORD reg_ECX; - DWORD reg_EAX; - DWORD reg_EDI; - DWORD reg_ESI; - DWORD reg_Flags; -} DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS; +#ifndef __DEVICEIO_H__ +#define __DEVICEIO_H__ -#pragma pack(1) -typedef struct _DRIVE_MAP_INFO -{ - BYTE dmiAllocationLength; - BYTE dmiInfoLength; - BYTE dmiFlags; - BYTE dmiInt13Unit; - DWORD dmiAssociatedDriveMap; - ULONGLONG dmiPartitionStartRBA; -} DRIVE_MAP_INFO, *PDRIVE_MAP_INFO; -#pragma pack() - -// only 9x -BOOL GetDriveMapInfo(UINT nDrive, PDRIVE_MAP_INFO pdmi) -{ - DEVIOCTL_REGISTERS reg, *preg; - reg.reg_EAX = 0x440D; // IOCTL for block devices - reg.reg_EBX = nDrive; // zero-based drive ID - reg.reg_ECX = 0x086f; // Get Media ID command - reg.reg_EDX = (DWORD)pdmi; // receives media ID info - preg=® - - preg->reg_Flags = 0x8000; // assume error (carry flag set) - - HANDLE hDevice = CreateFile(_T("\\\\.\\vwin32"), - GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); - - if (hDevice == (HANDLE)INVALID_HANDLE_VALUE) - { - return FALSE; - } - else - { - DWORD cb; - BOOL fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL, - preg, sizeof(*preg), preg, sizeof(*preg), &cb, 0); - - if (!fResult) - { - CloseHandle(hDevice); - return FALSE; - } - } - - CloseHandle(hDevice); - - return TRUE; -} - // only NT bool GetSignature(LPCTSTR lpszDrive, LPTSTR lpszBuffer, int iSize) { - TCHAR szMapping[1024], szQuery[16384], szSymbolic[1024]; - + std::auto_ptr szMapping(new TCHAR[1024]); + std::auto_ptr szQuery(new TCHAR[16384]); + std::auto_ptr szSymbolic(new TCHAR[1024]); + // read mappings - if (QueryDosDevice(lpszDrive, szMapping, 1024) == 0) + if (QueryDosDevice(lpszDrive, szMapping.get(), 1024) == 0) return false; // search for all, to find out in which string is the signature int iCount, iCount2; - if ((iCount=QueryDosDevice(NULL, szQuery, 16384)) == 0) + if ((iCount=QueryDosDevice(NULL, szQuery.get(), 16384)) == 0) { TRACE("Encountered error #%lu @QueryDosDevice\n", GetLastError()); return false; @@ -102,22 +43,22 @@ TCHAR* pszOffset = NULL; while(iOffset < iCount) { - if(_tcsncmp(szQuery+iOffset, _T("STORAGE#Volume#"), _tcslen(_T("STORAGE#Volume#"))) == 0) + if(_tcsncmp(szQuery.get() + iOffset, _T("STORAGE#Volume#"), _tcslen(_T("STORAGE#Volume#"))) == 0) { - if((iCount2 = QueryDosDevice(szQuery+iOffset, szSymbolic, 1024)) == 0) + if((iCount2 = QueryDosDevice(szQuery.get() + iOffset, szSymbolic.get(), 1024)) == 0) return false; // now search for 'Signature' and extract (from szQuery+iOffset) - pszSignature=_tcsstr(szQuery+iOffset, _T("Signature")); + pszSignature=_tcsstr(szQuery.get() + iOffset, _T("Signature")); if (pszSignature == NULL) { - iOffset+=_tcslen(szQuery+iOffset)+1; + iOffset+=_tcslen(szQuery.get() + iOffset)+1; continue; } pszOffset=_tcsstr(pszSignature, _T("Offset")); if (pszOffset == NULL) { - iOffset+=_tcslen(szQuery+iOffset)+1; + iOffset+=_tcslen(szQuery.get() + iOffset)+1; continue; } @@ -129,19 +70,19 @@ while (iOffset2 < iCount2) { // compare szSymbolic+iOffset2 with szMapping - if (_tcscmp(szMapping, szSymbolic+iOffset2) == 0) + if (_tcscmp(szMapping.get(), szSymbolic.get() + iOffset2) == 0) { // found Signature & Offset - copy int iCnt=reinterpret_cast(pszOffset)-reinterpret_cast(pszSignature)+1; _tcsncpy(lpszBuffer, pszSignature, (iCnt > iSize) ? iSize : iCnt); return true; } - iOffset2+=_tcslen(szSymbolic)+1; + iOffset2+=_tcslen(szSymbolic.get())+1; } } - iOffset+=_tcslen(szQuery+iOffset)+1; + iOffset+=_tcslen(szQuery.get() + iOffset)+1; } return false; @@ -154,22 +95,8 @@ osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { - DRIVE_MAP_INFO dmi1, dmi2; - dmi1.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); - dmi1.dmiInt13Unit=0xff; - dmi2.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); - dmi2.dmiInt13Unit=0xff; - - // iDrvNum is 0-based, and we need 1-based - if (!GetDriveMapInfo(iDrvNum1+1, &dmi1) || !GetDriveMapInfo(iDrvNum2+1, &dmi2) || dmi1.dmiInt13Unit != dmi2.dmiInt13Unit || dmi1.dmiInt13Unit == 0xff) - return false; - else - return true; - } - else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) - { TCHAR drv1[3], drv2[3]; drv1[0]=static_cast(iDrvNum1+_T('A')); @@ -185,3 +112,5 @@ return false; } + +#endif