Bool32 CRIControl::OpenDestinationDIBfromSource(char* cDIBName) { Handle hDIBIn; pvoid pDIB; if ( mpSourceDIB != NULL ) return FALSE; if ( !ReadDIB(cDIBName, &hDIBIn) ) { SetReturnCode_rimage(IDS_RIMAGE_NO_IMAGE_FOUND); return FALSE; } if ( !(pDIB = RIMAGELock(hDIBIn) ) ) { SetReturnCode_rimage(IDS_RIMAGE_INTERNAL_MODULE_ERROR); return FALSE; } mpDestinationDIB = new CTDIB(hDIBIn); if ( !mpDestinationDIB->SetDIBbyPtr(pDIB) ) { delete mpSourceDIB; mpDestinationDIB = NULL; SetReturnCode_rimage(IDS_RIMAGE_DIB_NOT_ATTACHED); return FALSE; } DIBOpeningType = TRUE; return TRUE; }
// Bitmaps einlesen und Paletten initialisieren bool CBildObjekt :: InitDIB (const char *pcFullName) { int fh; /* Dateihandle (evtl. komprimiertes File) */ OFSTRUCT of; /* Dateistruktur */ HPALETTE hPalCurrent; /* PaletteStruct */ HBITMAP hDIBCurrent; /* DIB */ HBITMAP hBMCurrent; /* DDB */ // alte DIB freigeben FreeDIB (); // Datei eröffnen, Speicherplatz anlegen fh = OpenFile (pcFullName, (OFSTRUCT *)&of, OF_READ); if (fh < 0) return false; hDIBCurrent = ReadDIBitmapInfo (fh); // Farbtabelle lesen // Gültigkeit der DIB-Datei prüfen if (hDIBCurrent == NULL) { _lclose (fh); return false; } m_hDIB = hDIBCurrent; // im Objekt merken // PaletteSetup hPalCurrent = CreateDIBPalette (); // Palette bilden if (hPalCurrent == NULL) { _lclose (fh); return false; } m_hPal = hPalCurrent; // DIB einlesen hDIBCurrent = ReadDIB (fh); if (!hDIBCurrent) { _lclose (fh); return false; } m_hDIB = hDIBCurrent; _lclose (fh); // DDB bilden hBMCurrent = DIBToBitmap(); if (!hBMCurrent) return false; m_hDDB = hBMCurrent; return true; }
CNdasUnitDevice* CNdasUnitDeviceCreator::CreateUnitDiskDevice() { // // Read DIB // // Read DIB should success, even if the unit disk does not contain // the DIB. If it fails, there should be some communication error. // XTL::AutoProcessHeapPtr<NDAS_DIB_V2> pDIBv2; XTL::AutoProcessHeapPtr<BLOCK_ACCESS_CONTROL_LIST> pBACL; // // ReadDIB is to allocate pDIBv2 // BOOL fSuccess = ReadDIB(&pDIBv2); // attach to auto heap if (!fSuccess) { XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "ReadDIB failed, error=0x%X\n", GetLastError()); XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Creating unit disk device instance failed.\n"); return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_READ_FAILURE); } if(0 != pDIBv2->BACLSize) { fSuccess = ReadBACL(&pBACL, pDIBv2->BACLSize); if (!fSuccess) { XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "ReadBACL failed, error=0x%X\n", GetLastError()); XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Creating unit disk device instance failed.\n"); return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_READ_FAILURE); } } NDAS_UNITDEVICE_DISK_TYPE diskType = pGetNdasUnitDiskTypeFromDIBv2(pDIBv2); if (NDAS_UNITDEVICE_DISK_TYPE_UNKNOWN == diskType) { // // Error! Invalid media type // XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Media type in DIBv2 is invalid, mediaType=0x%X\n", pDIBv2->iMediaType); // // we should create generic unknown unit disk device // return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_UNKNOWN_LDTYPE); } // return NULL; LPVOID pAddTargetInfo = NULL; NDAS_RAID_META_DATA Rmd = {0}; if (NMT_RAID1 == pDIBv2->iMediaType || NMT_RAID4 == pDIBv2->iMediaType) { // // These types are not used anymore, however, // for compatibility reasons, we retain these codes // pAddTargetInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NDAS_LURN_RAID_INFO_V1)); PNDAS_LURN_RAID_INFO_V1 raidInfo = static_cast<PNDAS_LURN_RAID_INFO_V1>(pAddTargetInfo); raidInfo->SectorsPerBit = pDIBv2->iSectorsPerBit; raidInfo->SectorBitmapStart = m_udinfo.SectorCount.QuadPart - 0x0f00; raidInfo->SectorInfo = m_udinfo.SectorCount.QuadPart - 0x0002; raidInfo->SectorLastWrittenSector = m_udinfo.SectorCount.QuadPart - 0x1000; } else if (NMT_RAID1R2 == pDIBv2->iMediaType || NMT_RAID4R2 == pDIBv2->iMediaType || NMT_RAID1R3 == pDIBv2->iMediaType || NMT_RAID4R3 == pDIBv2->iMediaType) { // // do not allocate with "new INFO_RAID" // destructor will delete with "HeapFree" // pAddTargetInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NDAS_LURN_RAID_INFO_V2)); PNDAS_LURN_RAID_INFO_V2 pIR = reinterpret_cast<PNDAS_LURN_RAID_INFO_V2>(pAddTargetInfo); fSuccess = m_devComm.ReadDiskBlock( reinterpret_cast<PBYTE>(&Rmd), NDAS_BLOCK_LOCATION_RMD, 1); if (!fSuccess) { XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Reading RMD failed: "); XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Creating unit disk device instance failed.\n"); return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_READ_FAILURE); } if (Rmd.Signature != NDAS_RAID_META_DATA_SIGNATURE) { XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "RMD signature mismatch."); XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Creating unit disk device instance failed.\n"); return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_UNKNOWN_LDTYPE); } pIR->SectorsPerBit = pDIBv2->iSectorsPerBit; pIR->nSpareDisk = pDIBv2->nSpareCount; // To fix: Use RaidSetId and ConfigSetId from NdasOpGetRaidInfo ::CopyMemory(&pIR->RaidSetId, &Rmd.RaidSetId, sizeof(pIR->RaidSetId)); ::CopyMemory(&pIR->ConfigSetId, &Rmd.ConfigSetId, sizeof(pIR->ConfigSetId)); } UINT64 ulUserBlocks = static_cast<UINT64>(pDIBv2->sizeUserSpace); DWORD ldSequence = pDIBv2->iSequence; NDAS_LOGICALDEVICE_GROUP ldGroup = {0}; ldGroup.Type = pGetNdasLogicalDeviceTypeFromDIBv2(pDIBv2); ldGroup.nUnitDevices = pDIBv2->nDiskCount + pDIBv2->nSpareCount; ldGroup.nUnitDevicesSpare = pDIBv2->nSpareCount; // ::CopyMemory(&ldGroup.RaidSetId, &Rmd.RaidSetId, sizeof(GUID)); // ::CopyMemory(&ldGroup.ConfigSetId, &Rmd.ConfigSetId, sizeof(GUID)); for(DWORD i=0; i<MAX_NDAS_LOGICALDEVICE_GROUP_MEMBER; i++) { ldGroup.DeviceHwVersions[i] = pDIBv2->UnitDiskInfos[i].HwVersion; } // // Consistency check for DIB // // 1. DIB should contain an entry for this unit device // wich m_pDevice->GetDeviceId() and m_dwUnitNo; // // Otherwise, DIB is invalid and reported as Single // for(DWORD i = 0; i < ldGroup.nUnitDevices; i++) { CopyMemory( &ldGroup.UnitDevices[i].DeviceId, pDIBv2->UnitDisks[i].MACAddr, sizeof(NDAS_DEVICE_ID)); ldGroup.UnitDevices[i].UnitNo = pDIBv2->UnitDisks[i].UnitNumber; } // // Read CONTENT_ENCRYPT // // Read CONTENT_ENCRYPT should success, even if the unit disk does not contain // the CONTENT_ENCRYPT. If it fails, there should be some communication error. // NDAS_CONTENT_ENCRYPT_BLOCK ceb = {0}; NDAS_CONTENT_ENCRYPT ce = {0}; fSuccess = ReadContentEncryptBlock(&ceb); if (!fSuccess) { XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "ReadContentEncryptBlock failed, error=0x%X\n", GetLastError()); XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, "Creating unit disk device instance failed.\n"); (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_CEB_READ_FAILURE); return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_READ_FAILURE); } UINT uiRet = ::NdasEncVerifyContentEncryptBlock(&ceb); if (NDASENC_ERROR_CEB_INVALID_SIGNATURE == uiRet) { // No Content Encryption // Safe to ignore ce.Method = NDAS_CONTENT_ENCRYPT_METHOD_NONE; } else if (NDASENC_ERROR_CEB_INVALID_CRC == uiRet) { // No Content Encryption // Safe to ignore ce.Method = NDAS_CONTENT_ENCRYPT_METHOD_NONE; } else if (NDASENC_ERROR_CEB_UNSUPPORTED_REVISION == uiRet) { // Error ! (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_CEB_UNSUPPORTED_REVISION, uiRet); // return NULL; return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_ECKEY_FAILURE); } else if (NDASENC_ERROR_CEB_INVALID_KEY_LENGTH == uiRet) { // No Content Encryption (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_CEB_INVALID_KEY_LENGTH, uiRet); ce.Method = NDAS_CONTENT_ENCRYPT_METHOD_NONE; } else if (ERROR_SUCCESS != uiRet) { // No Content Encryption ce.Method = NDAS_CONTENT_ENCRYPT_METHOD_NONE; } else { // // We consider the case that ENCRYPTION is not NONE. // if (NDAS_CONTENT_ENCRYPT_METHOD_NONE != ceb.Method) { BYTE SysKey[16] = {0}; DWORD cbSysKey = sizeof(SysKey); uiRet = ::NdasEncGetSysKey(cbSysKey, SysKey, &cbSysKey); if (ERROR_SUCCESS != uiRet) { (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_GET_SYS_KEY, uiRet); // return NULL; return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_ECKEY_FAILURE); } uiRet = ::NdasEncVerifyFingerprintCEB(SysKey, cbSysKey, &ceb); if (ERROR_SUCCESS != uiRet) { (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_SYS_KEY_MISMATCH, uiRet); // return NULL; return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_ECKEY_FAILURE); } // // Create Content Encrypt // ce.Method = ceb.Method; ce.KeyLength = ceb.KeyLength; ce.Key; uiRet = ::NdasEncCreateContentEncryptKey( SysKey, cbSysKey, ceb.Key, ceb.KeyLength, ce.Key, sizeof(ce.Key)); if (ERROR_SUCCESS != uiRet) { (VOID) ::NdasLogEventError2(EVT_NDASSVC_ERROR_KEY_GENERATION_FAILURE, uiRet); // return NULL; return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_HDD_ECKEY_FAILURE); } } } CNdasUnitDiskDevice* pUnitDiskDevice = new CNdasUnitDiskDevice( m_pDevice, m_dwUnitNo, diskType, m_udinfo, ldGroup, ldSequence, ulUserBlocks, pAddTargetInfo, ce, pDIBv2, pBACL); if (NULL == pUnitDiskDevice) { return NULL; } // We should detach pDIBv2 from being freeed here // pUnitDiskDevice will take care of it at dtor pDIBv2.Detach(); pBACL.Detach(); return pUnitDiskDevice; }