//--------------------------------------------------------------------------------------------------- Ptr<DataStore> DataStore::Open(LPCTSTR Filename) { DataStore* pStore = new DataStore(); pStore->m_pFile = MemoryMappedFile::Open(Filename, FileMode::OPEN); pStore->m_pView = pStore->m_pFile->CreateView(); pStore->m_pHeader = (STOREHEADER*)pStore->m_pView->GetBasePointer(); if (pStore->m_pHeader->DataStoreVersion != DATASTOREVERSION) throw DataStoreException(pStore, "The DataStore version number is unknown"); pStore->m_pBlockAllocationIndex0 = (BLOCKADDRESS*)pStore->GetBlock(pStore->m_pHeader->BlockAllocationIndex0); pStore->m_pBlockBitmaps = new DWORD*[pStore->m_pHeader->BlockSize / sizeof(BLOCKADDRESS)]; for (SIZE_T i=0; i<pStore->m_pHeader->BlockSize / sizeof(BLOCKADDRESS); i++) { if (pStore->m_pBlockAllocationIndex0[i] != 0) pStore->m_pBlockBitmaps[i] = (DWORD*)pStore->GetBlock(pStore->m_pBlockAllocationIndex0[i]); else pStore->m_pBlockBitmaps[i] = 0; } return pStore; }
//--------------------------------------------------------------------------------------------------- Ptr<DataStore> DataStore::Create(LPCTSTR Filename, BLOCKADDRESS BlockSize) { DataStore* pStore = new DataStore(); if (BlockSize < sizeof(STOREHEADER)) throw DataStoreException(pStore, "The BlockSize must be at least as large as the size of the header"); pStore->m_pFile = MemoryMappedFile::Open(Filename, FileMode::CREATE); pStore->m_pFile->Resize(10 * BlockSize); pStore->m_pView = pStore->m_pFile->CreateView(); pStore->m_pHeader = (STOREHEADER*)pStore->m_pView->GetBasePointer(); ZeroMemory(pStore->m_pHeader, sizeof(STOREHEADER)); pStore->m_pHeader->DataStoreVersion = DATASTOREVERSION; pStore->m_pHeader->BlockAllocationIndex0 = 1; pStore->m_pHeader->BlockCount = 10; pStore->m_pHeader->BlockSize = BlockSize; pStore->m_pHeader->FreeBlockCount = 6; //pStore->m_pHeader->MetaDataTable.BlockCount = 0; //pStore->m_pHeader->MetaDataTable.BlockDirectory = 0; pStore->m_pBlockAllocationIndex0 = (BLOCKADDRESS*)pStore->GetBlock(1); pStore->m_pBlockBitmaps = new DWORD*[BlockSize / sizeof(BLOCKADDRESS)]; ZeroMemory(pStore->m_pBlockBitmaps, sizeof(DWORD*) * BlockSize / sizeof(BLOCKADDRESS)); pStore->m_pBlockAllocationIndex0[0] = 2; pStore->m_pBlockBitmaps[0] = (DWORD*)pStore->GetBlock(2); pStore->m_pBlockAllocationIndex0[1] = 3; pStore->m_pBlockBitmaps[1] = (DWORD*)pStore->GetBlock(3); pStore->m_pBlockBitmaps[0][0] = 0xf; return pStore; }