ChEXPORT SsrwOOStorage* SsrwOOStorage::openStorage(const ChCHAR1* in_name) { ChLOG_DEBUG_START_FN; for (size_t i = 0; i <= ChStrlen(in_name); i++) { m_pBuffer[i] = in_name[i]; } return openStorage(m_pBuffer); }
void ExecStreamTestBase::testCaseSetUp() { SegStorageTestBase::testCaseSetUp(); openStorage(DeviceMode::createNew); pScheduler.reset(newScheduler()); ExecStreamResourceKnobs knobSettings; knobSettings.cacheReservePercentage = DefaultCacheReservePercent; knobSettings.expectedConcurrentStatements = DefaultConcurrentStatements; ExecStreamResourceQuantity resourcesAvailable; resourcesAvailable.nCachePages = nMemPages; pResourceGovernor.reset( newResourceGovernor(knobSettings, resourcesAvailable)); }
/*============================================================================ Description: (API call) Removes a given storage or stream from the structured storage file. Arguments: io_pParent - storage containing the item to destroy in_pName - name of item to destroy Return: Status code ==========================================================================*/ int destroy( Storage* io_pParent, const wchar_t* in_pName) { SINT4 iRet = SSTG_OK; TOC* pTOC = NULL; DirectoryEntry* pParentEntry = NULL; DirectoryEntry* pChildEntry = NULL; StgInfo* pStgChildren = NULL; SINT4 childCount = 0; SINT4 i = 0; Storage* pStorage = 0; Header* pHeader = NULL; Fat* pRegFat = NULL; Fat* pSmallFat = NULL; ASSERT(io_pParent != NULL); ASSERT(in_pName != NULL); ASSERT(STG_CANWRITE(io_pParent->mode)); if ((io_pParent == NULL) || (in_pName == NULL)) { return SSTG_ERROR_ILLEGAL_CALL; } if (!STG_CANWRITE(io_pParent->mode)) { return SSTG_ERROR_ILLEGAL_ACCESS; } pRegFat = rootStorageGetFat(io_pParent->pRoot); pSmallFat = rootStorageGetSmallFat(io_pParent->pRoot); /* Get parent storage's directory entry */ pTOC = rootStorageGetTOC(io_pParent->pRoot); pParentEntry = tocGetEntryAtIndex(pTOC, io_pParent->ulDirIndex); if (pParentEntry == NULL) { return (int)SSTG_ERROR_CHILD_NOT_FOUND; } /* Find specified stream's directory entry */ iRet = tocFindChildEntry (pTOC, pParentEntry, in_pName, &pChildEntry); if (iRet != SSTG_OK) { return (int)iRet; } /* Ensure that the deletion operation is legal */ if ((directoryGetType(pChildEntry) != DIR_STREAM) && (directoryGetType(pChildEntry) != DIR_STORAGE)) { return SSTG_ERROR_ILLEGAL_ACCESS; } /* From this point on, any failures will cause an incomplete state in * the structured storage file. */ /* Mark all metadata as being dirty so it will be rewritten later */ iRet = rootStorageSetDirty(io_pParent->pRoot); if (iRet != SSTG_OK) { return (int)iRet; } if (directoryGetType(pChildEntry) == DIR_STREAM) { pHeader = rootStorageGetHeader(io_pParent->pRoot); if (directoryGetStreamLength(pChildEntry) < headerGetSmallStreamCutoff(pHeader)) { /* Merge the sectors of the stream into the free chain */ iRet = fatFreeChain(pSmallFat, directoryGetStartSector(pChildEntry)); if (iRet != SSTG_OK) { return iRet; } /* Recover as many sectors as possible from the small FAT's free * chain */ iRet = fatRecoverMiniFatFreeSectors(pSmallFat, pRegFat); if (iRet != SSTG_OK) { return iRet; } } else { /* Merge the sectors of the stream into the free chain */ iRet = fatFreeChain(pRegFat, directoryGetStartSector(pChildEntry)); if (iRet != SSTG_OK) { return iRet; } } } else if (directoryGetType(pChildEntry) == DIR_STORAGE) { /* Non-empty storages should be removed recursively */ iRet = openStorage(io_pParent, in_pName, &pStorage); if (iRet != SSTG_OK) { return iRet; } iRet = getChildrenInfo(pStorage, &pStgChildren, (int*)(void*)&childCount); if (iRet != SSTG_OK) { return iRet; } for (i = 0; i < childCount; i++) { iRet = destroy(pStorage, pStgChildren[i].sName); if (iRet != SSTG_OK) { return iRet; } } if (childCount > 0) { iRet = freeInfo(&pStgChildren, childCount); if (iRet != SSTG_OK) { return iRet; } } iRet = closeStorage(&pStorage); if (iRet != SSTG_OK) { return iRet; } } /* Remove the corresponding entry from the TOC */ iRet = tocRemoveEntry(pTOC, pParentEntry, pChildEntry); if (iRet != SSTG_OK) { return (int)iRet; } #ifdef DEBUG assertMiniStreamIntegrity(io_pParent->pRoot); #endif /* DEBUG */ return (int) iRet; }
SINT4 storageSelfTest1(StgMode in_stgModeOpen, StgMode in_stgModeCreate) { SINT4 iRet = SSTG_OK; RootStorage* pRoot = NULL; Storage* pStorage1 = NULL; Storage* pStorage2 = NULL; Storage* pStorage3 = NULL; Stream* pStream1 = NULL; Stream* pStream2 = NULL; Stream* pStream3 = NULL; Stream* pStream4 = NULL; int cch = 0; unsigned long cchL = 0; wchar_t pwchBuf[] = L"Stuff to write into streams"; wchar_t pwchBuf2[60]; /* The main thing being tested here is the open list. If the calling * application fails to close some streams and storages before closing * the structured storage file, the structured storage library is supposed * to clean everything up automatically. */ /* Create a bunch of streams and storages */ iRet = createStructuredStorageEx (WSZ_TEST_FILENAME, in_stgModeCreate, &pRoot, 0); ASSERT (iRet == SSTG_OK && pRoot != NULL); iRet = getStorageFromRoot (pRoot, &pStorage1); ASSERT (iRet == SSTG_OK && pStorage1 != NULL); iRet = createStream (pStorage1, WSZ_TEST_STREAM_1, &pStream1); ASSERT (iRet == SSTG_OK && pStream1 != NULL); cch = 0; ASSERT (writeLEwstring(pStream1, pwchBuf, &cch) == SSTG_OK && cch == 28); iRet = createStorage (pStorage1, WSZ_TEST_STORAGE_2, &pStorage2); ASSERT (iRet == SSTG_OK && pStorage2 != NULL); iRet = createStorage (pStorage2, WSZ_TEST_STORAGE_3, &pStorage3); ASSERT (iRet == SSTG_OK && pStorage3 != NULL); iRet = createStream (pStorage2, WSZ_TEST_STREAM_2, &pStream2); ASSERT (iRet == SSTG_OK && pStream2 != NULL); cch = 0; ASSERT (writeLEwstring(pStream2, pwchBuf, &cch) == SSTG_OK && cch == 28); cchL = 28 * sizeof(wchar_t); iRet = flushStream(pStorage2, WSZ_TEST_STREAM_3, pwchBuf, &cchL); ASSERT(iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t))); /* Test to ensure that destroying a mini stream works */ cchL = 28 * sizeof(wchar_t); iRet = flushStream(pStorage2, WSZ_TEST_STREAM_4, pwchBuf, &cchL); ASSERT(iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t))); iRet = destroy(pStorage2, WSZ_TEST_STREAM_4); ASSERT(iRet == SSTG_OK); /* Test to make sure duplicates are not allowed */ iRet = createStream(pStorage2, WSZ_TEST_STREAM_3, &pStream4); ASSERT (iRet != SSTG_OK && pStream4 == NULL); /* Now close the entire compound file without closing any of the open * children */ iRet = closeStructuredStorage(&pRoot); ASSERT (iRet == SSTG_OK && pRoot == NULL); pStorage1 = NULL; pStorage2 = NULL; pStorage3 = NULL; pStream1 = NULL; pStream2 = NULL; pStream3 = NULL; /* Now do the same thing for reading. */ /* Open a bunch of streams and storages for reading. */ iRet = openStructuredStorageEx (WSZ_TEST_FILENAME, in_stgModeOpen, &pRoot); ASSERT (iRet == SSTG_OK); iRet = getStorageFromRoot (pRoot, &pStorage1); ASSERT (iRet == SSTG_OK && pStorage1 != NULL); iRet = openStream (pStorage1, WSZ_TEST_STREAM_1, &pStream1); ASSERT (iRet == SSTG_OK && pStream1 != NULL); cch = 28; iRet = readLEwstring(pStream1, &cch, pwchBuf2); ASSERT (iRet == SSTG_OK && cch == 28); ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0); memset(pwchBuf2, 0, sizeof(pwchBuf2)); iRet = openStorage (pStorage1, WSZ_TEST_STORAGE_2, &pStorage2); ASSERT (iRet == SSTG_OK && pStorage2 != NULL); iRet = openStorage (pStorage2, WSZ_TEST_STORAGE_3, &pStorage3); ASSERT (iRet == SSTG_OK && pStorage3 != NULL); iRet = openStream (pStorage2, WSZ_TEST_STREAM_2, &pStream2); ASSERT (iRet == SSTG_OK && pStream2 != NULL); cch = 28; ASSERT (readLEwstring(pStream2, &cch, pwchBuf2) == SSTG_OK && cch == 28); ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0); memset(pwchBuf2, 0, sizeof(pwchBuf2)); iRet = openStream (pStorage2, WSZ_TEST_STREAM_3, &pStream3); ASSERT (iRet == SSTG_OK && pStream3 != NULL); cch = 28 * sizeof(wchar_t); iRet = streamRead(pStream3, pwchBuf2, &cchL); ASSERT (iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t))); ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0); memset(pwchBuf2, 0, sizeof(pwchBuf2)); /* Close the entire compound file without closing any of the open * children */ iRet = closeStructuredStorage(&pRoot); ASSERT (iRet == SSTG_OK && pRoot == NULL); /* Remove test file */ SSRW_WREMOVE (WSZ_TEST_FILENAME); return iRet; }