FTK. Fix for bug 211880.

git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@985 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
ahodgkinson
2006-10-12 17:52:19 +00:00
parent e037ef167c
commit 8639be36eb
2 changed files with 118 additions and 26 deletions

View File

@@ -4019,7 +4019,7 @@ RCODE F_BTree::updateParentCounts(
FLMUINT uiCounts;
FLMBYTE * pucCounts;
f_assert( getBlockType( pucChildBlock) == F_BLK_TYPE_BT_NON_LEAF_COUNTS);
f_assert( getBlockType( *ppucParentBlock) == F_BLK_TYPE_BT_NON_LEAF_COUNTS);
uiCounts = countKeys( pucChildBlock);
if( RC_BAD( rc = m_pBlockMgr->prepareForUpdate( ppParentBlock,
@@ -4944,6 +4944,9 @@ RCODE F_BTree::moveEntriesToPrevBlock(
FLMUINT uiCount;
FLMUINT uiOffset;
f_assert( !(*ppPrevBlock));
f_assert( !(*ppucPrevBlock));
// Assume nothing to move.
*pbEntriesWereMoved = FALSE;
@@ -5042,7 +5045,6 @@ RCODE F_BTree::moveEntriesToPrevBlock(
// We will need to return this block.
f_assert( !(*ppPrevBlock));
*ppPrevBlock = pPrevBlock;
*ppucPrevBlock = pucPrevBlock;
@@ -5398,6 +5400,10 @@ RCODE F_BTree::moveEntriesToNextBlock(
pParentStack->pBlock = pParentBlock;
pParentStack->pucBlock = pucParentBlock;
pParentBlock = NULL;
pucParentBlock = NULL;
bCommonParent = TRUE;
}
else
@@ -6112,6 +6118,8 @@ RCODE F_BTree::findEntry(
goto Exit;
}
f_assert( pucBlock);
// We are building the stack inverted to make traversing it a bit easier.
uiLevel = getBlockLevel( pucBlock);
@@ -7512,7 +7520,7 @@ StartOver:
// Can we move entries around at all to make some room?
if( RC_BAD( rc = moveEntriesToPrevBlock( uiEntrySize, &pPrevBlock,
if( RC_BAD( rc = moveEntriesToPrevBlock( uiEntrySize, &pPrevBlock,
&pucPrevBlock, &bEntriesWereMoved)))
{
goto Exit;
@@ -7707,6 +7715,10 @@ StartOver:
goto Exit;
}
pPrevBlock->Release();
pPrevBlock = NULL;
pucPrevBlock = NULL;
// Increment so we point to one past the last entry.
m_pStack->uiCurOffset++;
@@ -12924,6 +12936,17 @@ RCODE FLMAPI FlmAllocBTree(
{
RCODE rc = NE_FLM_OK;
F_BTree * pBTree = NULL;
IF_BlockMgr * pTmpBlockMgr = NULL;
if( !pBlockMgr)
{
if( RC_BAD( rc = FlmAllocBlockMgr( 4096, &pTmpBlockMgr)))
{
goto Exit;
}
pBlockMgr = pTmpBlockMgr;
}
if( (pBTree = f_new F_BTree( pBlockMgr)) == NULL)
{
@@ -12941,5 +12964,10 @@ Exit:
pBTree->Release();
}
if( pTmpBlockMgr)
{
pTmpBlockMgr->Release();
}
return( rc);
}

View File

@@ -74,6 +74,8 @@ FSTATIC FLMBYTE ftkSlowPacketChecksum(
FSTATIC RCODE ftkTestText( void);
FSTATIC RCODE ftkTestBTree( void);
FSTATIC FLMBOOL flmCh6Brkcar(
FLMUINT16 ui16WpChar,
FLMUINT16 * pui16BaseChar,
@@ -4282,10 +4284,7 @@ int main( void)
RCODE rc = NE_FLM_OK;
IF_DirHdl * pDirHdl = NULL;
IF_FileSystem * pFileSystem = NULL;
IF_BlockMgr * pBlockMgr = NULL;
IF_BTree * pBTree = NULL;
FLMUINT * puiPacketSize;
FLMUINT32 ui32RootBlkId;
char szTmpBuf[ 128];
if( RC_BAD( rc = ftkStartup()))
@@ -4320,24 +4319,27 @@ int main( void)
pDirHdl->Release();
pDirHdl = NULL;
if( RC_BAD( rc = FlmAllocBlockMgr( 4096, &pBlockMgr)))
// B-Tree tests
f_printf( "Running B-Tree tests: ");
if( RC_BAD( rc = ftkTestBTree()))
{
goto Exit;
}
if( RC_BAD( rc = FlmAllocBTree( pBlockMgr, &pBTree)))
{
goto Exit;
}
if( RC_BAD( rc = pBTree->btCreate( 1, FALSE, TRUE, &ui32RootBlkId)))
{
goto Exit;
}
pBTree->btDeleteTree();
pBTree->Release();
f_printf( "Done.\n");
// Run a multi-threaded test to verify the proper operation of
// the atomic operations
if( RC_BAD( rc = ftkTestAtomics()))
{
goto Exit;
}
// sprintf tests
f_printf( "Running sprintf test: ");
f_sprintf( szTmpBuf, "Hello, World! (You're number %u)\n", 1);
f_printf( szTmpBuf);
@@ -4446,11 +4448,6 @@ Exit:
pFileSystem->Release();
}
if( pBlockMgr)
{
pBlockMgr->Release();
}
ftkShutdown();
return( (int)rc);
}
@@ -5988,7 +5985,6 @@ FLMUINT16 HanToZenkaku(
if (!ui16Zenkaku)
{
// Change return value
ui16CharsUsed = 0;
@@ -6152,3 +6148,71 @@ FLMUINT16 ZenToHankaku(
return (ui16Hankaku);
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE ftkTestBTree( void)
{
RCODE rc = NE_FLM_OK;
IF_BTree * pTree = NULL;
FLMUINT32 ui32RootId;
FLMUINT32 ui32Loop;
FLMBYTE ucKey[ 4];
FLMUINT uiKeyLen;
if( RC_BAD( rc = FlmAllocBTree( NULL, &pTree)))
{
goto Exit;
}
if( RC_BAD( rc = pTree->btCreate( 1, TRUE, TRUE, &ui32RootId)))
{
goto Exit;
}
for( ui32Loop = 0; ui32Loop < 10000; ui32Loop++)
{
f_UINT32ToBigEndian( ui32Loop, ucKey);
uiKeyLen = sizeof( ucKey);
if( RC_BAD( rc = pTree->btInsertEntry( ucKey,
uiKeyLen, uiKeyLen, NULL, 0, FALSE, TRUE, NULL, NULL)))
{
goto Exit;
}
}
for( ui32Loop = 0; ui32Loop < 10000; ui32Loop++)
{
uiKeyLen = sizeof( ucKey);
if( ui32Loop != 0)
{
if( RC_BAD( rc = pTree->btNextEntry( ucKey, uiKeyLen, &uiKeyLen)))
{
goto Exit;
}
}
else
{
if( RC_BAD( rc = pTree->btFirstEntry( ucKey, uiKeyLen, &uiKeyLen)))
{
goto Exit;
}
}
f_assert( uiKeyLen == sizeof( ucKey));
f_assert( ui32Loop == f_bigEndianToUINT32( ucKey));
}
Exit:
if( pTree)
{
pTree->btClose();
pTree->Release();
}
return( rc);
}