ole32: Convert the *_{Read,Write}At structured storage functions to

return HRESULTs instead of BOOLs so that errors can be properly
propagated from lower levels.
This commit is contained in:
Robert Shearman 2006-09-11 11:13:47 +01:00 committed by Alexandre Julliard
parent bfc1bdc3bb
commit 79f7318a11
3 changed files with 67 additions and 62 deletions

View File

@ -302,15 +302,11 @@ static HRESULT WINAPI StgStreamImpl_Read(
} }
else if (This->bigBlockChain!=0) else if (This->bigBlockChain!=0)
{ {
BOOL success = BlockChainStream_ReadAt(This->bigBlockChain, res = BlockChainStream_ReadAt(This->bigBlockChain,
This->currentPosition, This->currentPosition,
bytesToReadFromBuffer, bytesToReadFromBuffer,
pv, pv,
pcbRead); pcbRead);
if (success)
res = S_OK;
else
res = STG_E_READFAULT;
} }
else else
{ {
@ -363,6 +359,7 @@ static HRESULT WINAPI StgStreamImpl_Write(
ULARGE_INTEGER newSize; ULARGE_INTEGER newSize;
ULONG bytesWritten = 0; ULONG bytesWritten = 0;
HRESULT res;
TRACE("(%p, %p, %ld, %p)\n", TRACE("(%p, %p, %ld, %p)\n",
iface, pv, cb, pcbWritten); iface, pv, cb, pcbWritten);
@ -427,7 +424,7 @@ static HRESULT WINAPI StgStreamImpl_Write(
*/ */
if (This->smallBlockChain!=0) if (This->smallBlockChain!=0)
{ {
SmallBlockChainStream_WriteAt(This->smallBlockChain, res = SmallBlockChainStream_WriteAt(This->smallBlockChain,
This->currentPosition, This->currentPosition,
cb, cb,
pv, pv,
@ -436,13 +433,15 @@ static HRESULT WINAPI StgStreamImpl_Write(
} }
else if (This->bigBlockChain!=0) else if (This->bigBlockChain!=0)
{ {
BlockChainStream_WriteAt(This->bigBlockChain, res = BlockChainStream_WriteAt(This->bigBlockChain,
This->currentPosition, This->currentPosition,
cb, cb,
pv, pv,
pcbWritten); pcbWritten);
} }
else else
/* this should never happen because the IStream_SetSize call above will
* make sure a big or small block chain is created */
assert(FALSE); assert(FALSE);
/* /*
@ -451,7 +450,7 @@ static HRESULT WINAPI StgStreamImpl_Write(
This->currentPosition.u.LowPart += *pcbWritten; This->currentPosition.u.LowPart += *pcbWritten;
TRACE("<-- S_OK, written %lu\n", *pcbWritten); TRACE("<-- S_OK, written %lu\n", *pcbWritten);
return S_OK; return res;
} }
/*** /***

View File

@ -3303,20 +3303,20 @@ BOOL StorageImpl_ReadProperty(
{ {
BYTE currentProperty[PROPSET_BLOCK_SIZE]; BYTE currentProperty[PROPSET_BLOCK_SIZE];
ULARGE_INTEGER offsetInPropSet; ULARGE_INTEGER offsetInPropSet;
BOOL readSuccessful; HRESULT readRes;
ULONG bytesRead; ULONG bytesRead;
offsetInPropSet.u.HighPart = 0; offsetInPropSet.u.HighPart = 0;
offsetInPropSet.u.LowPart = index * PROPSET_BLOCK_SIZE; offsetInPropSet.u.LowPart = index * PROPSET_BLOCK_SIZE;
readSuccessful = BlockChainStream_ReadAt( readRes = BlockChainStream_ReadAt(
This->rootBlockChain, This->rootBlockChain,
offsetInPropSet, offsetInPropSet,
PROPSET_BLOCK_SIZE, PROPSET_BLOCK_SIZE,
currentProperty, currentProperty,
&bytesRead); &bytesRead);
if (readSuccessful) if (SUCCEEDED(readRes))
{ {
/* replace the name of root entry (often "Root Entry") by the file name */ /* replace the name of root entry (often "Root Entry") by the file name */
WCHAR *propName = (index == This->base.rootPropertySetIndex) ? WCHAR *propName = (index == This->base.rootPropertySetIndex) ?
@ -3389,7 +3389,7 @@ BOOL StorageImpl_ReadProperty(
buffer->size.u.HighPart = 0; buffer->size.u.HighPart = 0;
} }
return readSuccessful; return SUCCEEDED(readRes) ? TRUE : FALSE;
} }
/********************************************************************* /*********************************************************************
@ -3402,7 +3402,7 @@ BOOL StorageImpl_WriteProperty(
{ {
BYTE currentProperty[PROPSET_BLOCK_SIZE]; BYTE currentProperty[PROPSET_BLOCK_SIZE];
ULARGE_INTEGER offsetInPropSet; ULARGE_INTEGER offsetInPropSet;
BOOL writeSuccessful; HRESULT writeRes;
ULONG bytesWritten; ULONG bytesWritten;
offsetInPropSet.u.HighPart = 0; offsetInPropSet.u.HighPart = 0;
@ -3472,12 +3472,12 @@ BOOL StorageImpl_WriteProperty(
OFFSET_PS_SIZE, OFFSET_PS_SIZE,
buffer->size.u.LowPart); buffer->size.u.LowPart);
writeSuccessful = BlockChainStream_WriteAt(This->rootBlockChain, writeRes = BlockChainStream_WriteAt(This->rootBlockChain,
offsetInPropSet, offsetInPropSet,
PROPSET_BLOCK_SIZE, PROPSET_BLOCK_SIZE,
currentProperty, currentProperty,
&bytesWritten); &bytesWritten);
return writeSuccessful; return SUCCEEDED(writeRes) ? TRUE : FALSE;
} }
static BOOL StorageImpl_ReadBigBlock( static BOOL StorageImpl_ReadBigBlock(
@ -3557,8 +3557,8 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
ULARGE_INTEGER size, offset; ULARGE_INTEGER size, offset;
ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten; ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten;
ULONG propertyIndex; ULONG propertyIndex;
BOOL successWrite; HRESULT resWrite;
HRESULT successRead; HRESULT resRead;
StgProperty chainProperty; StgProperty chainProperty;
BYTE *buffer; BYTE *buffer;
BlockChainStream *bbTempChain = NULL; BlockChainStream *bbTempChain = NULL;
@ -3591,25 +3591,25 @@ BlockChainStream* Storage32Impl_SmallBlocksToBigBlocks(
buffer = HeapAlloc(GetProcessHeap(),0,DEF_SMALL_BLOCK_SIZE); buffer = HeapAlloc(GetProcessHeap(),0,DEF_SMALL_BLOCK_SIZE);
do do
{ {
successRead = SmallBlockChainStream_ReadAt(*ppsbChain, resRead = SmallBlockChainStream_ReadAt(*ppsbChain,
offset, offset,
DEF_SMALL_BLOCK_SIZE, DEF_SMALL_BLOCK_SIZE,
buffer, buffer,
&cbRead); &cbRead);
if (FAILED(successRead)) if (FAILED(resRead))
break; break;
if (cbRead > 0) if (cbRead > 0)
{ {
cbTotalRead += cbRead; cbTotalRead += cbRead;
successWrite = BlockChainStream_WriteAt(bbTempChain, resWrite = BlockChainStream_WriteAt(bbTempChain,
offset, offset,
cbRead, cbRead,
buffer, buffer,
&cbWritten); &cbWritten);
if (!successWrite) if (FAILED(resWrite))
break; break;
cbTotalWritten += cbWritten; cbTotalWritten += cbWritten;
@ -4516,7 +4516,7 @@ static ULONG BlockChainStream_GetCount(BlockChainStream* This)
* bytesRead may be NULL. * bytesRead may be NULL.
* Failure will be returned if the specified number of bytes has not been read. * Failure will be returned if the specified number of bytes has not been read.
*/ */
BOOL BlockChainStream_ReadAt(BlockChainStream* This, HRESULT BlockChainStream_ReadAt(BlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,
void* buffer, void* buffer,
@ -4551,12 +4551,12 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
{ {
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex))) if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex)))
return FALSE; return STG_E_DOCFILECORRUPT;
blockNoInSequence--; blockNoInSequence--;
} }
if ((blockNoInSequence > 0) && (blockIndex == BLOCK_END_OF_CHAIN)) if ((blockNoInSequence > 0) && (blockIndex == BLOCK_END_OF_CHAIN))
return FALSE; /* We failed to find the starting block */ return STG_E_DOCFILECORRUPT; /* We failed to find the starting block */
This->lastBlockNoInSequenceIndex = blockIndex; This->lastBlockNoInSequenceIndex = blockIndex;
@ -4580,7 +4580,7 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
bigBlockBuffer = bigBlockBuffer =
StorageImpl_GetROBigBlock(This->parentStorage, blockIndex); StorageImpl_GetROBigBlock(This->parentStorage, blockIndex);
if (!bigBlockBuffer) if (!bigBlockBuffer)
return FALSE; return STG_E_READFAULT;
memcpy(bufferWalker, bigBlockBuffer + offsetInBlock, bytesToReadInBuffer); memcpy(bufferWalker, bigBlockBuffer + offsetInBlock, bytesToReadInBuffer);
@ -4590,7 +4590,7 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
* Step to the next big block. * Step to the next big block.
*/ */
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex))) if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, &blockIndex)))
return FALSE; return STG_E_DOCFILECORRUPT;
bufferWalker += bytesToReadInBuffer; bufferWalker += bytesToReadInBuffer;
size -= bytesToReadInBuffer; size -= bytesToReadInBuffer;
@ -4599,7 +4599,7 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
} }
return (size == 0); return (size == 0) ? S_OK : STG_E_READFAULT;
} }
/****************************************************************************** /******************************************************************************
@ -4609,7 +4609,7 @@ BOOL BlockChainStream_ReadAt(BlockChainStream* This,
* bytesWritten may be NULL. * bytesWritten may be NULL.
* Will fail if not all specified number of bytes have been written. * Will fail if not all specified number of bytes have been written.
*/ */
BOOL BlockChainStream_WriteAt(BlockChainStream* This, HRESULT BlockChainStream_WriteAt(BlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,
const void* buffer, const void* buffer,
@ -4645,7 +4645,7 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This,
{ {
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
&blockIndex))) &blockIndex)))
return FALSE; return STG_E_DOCFILECORRUPT;
blockNoInSequence--; blockNoInSequence--;
} }
@ -4680,14 +4680,14 @@ BOOL BlockChainStream_WriteAt(BlockChainStream* This,
*/ */
if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex, if(FAILED(StorageImpl_GetNextBlockInChain(This->parentStorage, blockIndex,
&blockIndex))) &blockIndex)))
return FALSE; return STG_E_DOCFILECORRUPT;
bufferWalker += bytesToWrite; bufferWalker += bytesToWrite;
size -= bytesToWrite; size -= bytesToWrite;
*bytesWritten += bytesToWrite; *bytesWritten += bytesToWrite;
offsetInBlock = 0; /* There is no offset on the next block */ offsetInBlock = 0; /* There is no offset on the next block */
} }
return (size == 0); return (size == 0) ? S_OK : STG_E_WRITEFAULT;
} }
/****************************************************************************** /******************************************************************************
@ -5010,7 +5010,7 @@ static HRESULT SmallBlockChainStream_GetNextBlockInChain(
ULARGE_INTEGER offsetOfBlockInDepot; ULARGE_INTEGER offsetOfBlockInDepot;
DWORD buffer; DWORD buffer;
ULONG bytesRead; ULONG bytesRead;
BOOL success; HRESULT res;
*nextBlockInChain = BLOCK_END_OF_CHAIN; *nextBlockInChain = BLOCK_END_OF_CHAIN;
@ -5020,20 +5020,20 @@ static HRESULT SmallBlockChainStream_GetNextBlockInChain(
/* /*
* Read those bytes in the buffer from the small block file. * Read those bytes in the buffer from the small block file.
*/ */
success = BlockChainStream_ReadAt( res = BlockChainStream_ReadAt(
This->parentStorage->smallBlockDepotChain, This->parentStorage->smallBlockDepotChain,
offsetOfBlockInDepot, offsetOfBlockInDepot,
sizeof(DWORD), sizeof(DWORD),
&buffer, &buffer,
&bytesRead); &bytesRead);
if (success) if (SUCCEEDED(res))
{ {
StorageUtl_ReadDWord((BYTE *)&buffer, 0, nextBlockInChain); StorageUtl_ReadDWord((BYTE *)&buffer, 0, nextBlockInChain);
return S_OK; return S_OK;
} }
return STG_E_READFAULT; return res;
} }
/****************************************************************************** /******************************************************************************
@ -5096,7 +5096,7 @@ static ULONG SmallBlockChainStream_GetNextFreeBlock(
ULONG bytesRead; ULONG bytesRead;
ULONG blockIndex = 0; ULONG blockIndex = 0;
ULONG nextBlockIndex = BLOCK_END_OF_CHAIN; ULONG nextBlockIndex = BLOCK_END_OF_CHAIN;
BOOL success = TRUE; HRESULT res = S_OK;
ULONG smallBlocksPerBigBlock; ULONG smallBlocksPerBigBlock;
offsetOfBlockInDepot.u.HighPart = 0; offsetOfBlockInDepot.u.HighPart = 0;
@ -5108,7 +5108,7 @@ static ULONG SmallBlockChainStream_GetNextFreeBlock(
{ {
offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG); offsetOfBlockInDepot.u.LowPart = blockIndex * sizeof(ULONG);
success = BlockChainStream_ReadAt( res = BlockChainStream_ReadAt(
This->parentStorage->smallBlockDepotChain, This->parentStorage->smallBlockDepotChain,
offsetOfBlockInDepot, offsetOfBlockInDepot,
sizeof(DWORD), sizeof(DWORD),
@ -5118,7 +5118,7 @@ static ULONG SmallBlockChainStream_GetNextFreeBlock(
/* /*
* If we run out of space for the small block depot, enlarge it * If we run out of space for the small block depot, enlarge it
*/ */
if (success) if (SUCCEEDED(res))
{ {
StorageUtl_ReadDWord((BYTE *)&buffer, 0, &nextBlockIndex); StorageUtl_ReadDWord((BYTE *)&buffer, 0, &nextBlockIndex);
@ -5310,12 +5310,14 @@ HRESULT SmallBlockChainStream_ReadAt(
* The small block has already been identified so it shouldn't fail * The small block has already been identified so it shouldn't fail
* unless the file is corrupt. * unless the file is corrupt.
*/ */
if (!BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain, rc = BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain,
offsetInBigBlockFile, offsetInBigBlockFile,
bytesToReadInBuffer, bytesToReadInBuffer,
bufferWalker, bufferWalker,
&bytesReadFromBigBlockFile)) &bytesReadFromBigBlockFile);
return STG_E_DOCFILECORRUPT;
if (FAILED(rc))
return rc;
assert(bytesReadFromBigBlockFile == bytesToReadInBuffer); assert(bytesReadFromBigBlockFile == bytesToReadInBuffer);
@ -5324,7 +5326,7 @@ HRESULT SmallBlockChainStream_ReadAt(
*/ */
rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex); rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex);
if(FAILED(rc)) if(FAILED(rc))
return rc; return STG_E_DOCFILECORRUPT;
bufferWalker += bytesToReadInBuffer; bufferWalker += bytesToReadInBuffer;
size -= bytesToReadInBuffer; size -= bytesToReadInBuffer;
@ -5332,7 +5334,7 @@ HRESULT SmallBlockChainStream_ReadAt(
offsetInBlock = 0; /* There is no offset on the next block */ offsetInBlock = 0; /* There is no offset on the next block */
} }
return rc; return (size == 0) ? S_OK : STG_E_READFAULT;
} }
/****************************************************************************** /******************************************************************************
@ -5342,7 +5344,7 @@ HRESULT SmallBlockChainStream_ReadAt(
* bytesWritten may be NULL. * bytesWritten may be NULL.
* Will fail if not all specified number of bytes have been written. * Will fail if not all specified number of bytes have been written.
*/ */
BOOL SmallBlockChainStream_WriteAt( HRESULT SmallBlockChainStream_WriteAt(
SmallBlockChainStream* This, SmallBlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,
@ -5358,6 +5360,7 @@ BOOL SmallBlockChainStream_WriteAt(
ULONG blockIndex; ULONG blockIndex;
ULONG bytesWrittenFromBigBlockFile; ULONG bytesWrittenFromBigBlockFile;
const BYTE* bufferWalker; const BYTE* bufferWalker;
HRESULT res;
/* /*
* This should never happen on a small block file. * This should never happen on a small block file.
@ -5372,7 +5375,7 @@ BOOL SmallBlockChainStream_WriteAt(
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN)) while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
{ {
if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex))) if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex)))
return FALSE; return STG_E_DOCFILECORRUPT;
blockNoInSequence--; blockNoInSequence--;
} }
@ -5404,11 +5407,14 @@ BOOL SmallBlockChainStream_WriteAt(
/* /*
* Write those bytes in the buffer to the small block file. * Write those bytes in the buffer to the small block file.
*/ */
BlockChainStream_WriteAt(This->parentStorage->smallBlockRootChain, res = BlockChainStream_WriteAt(
This->parentStorage->smallBlockRootChain,
offsetInBigBlockFile, offsetInBigBlockFile,
bytesToWriteInBuffer, bytesToWriteInBuffer,
bufferWalker, bufferWalker,
&bytesWrittenFromBigBlockFile); &bytesWrittenFromBigBlockFile);
if (FAILED(res))
return res;
assert(bytesWrittenFromBigBlockFile == bytesToWriteInBuffer); assert(bytesWrittenFromBigBlockFile == bytesToWriteInBuffer);
@ -5424,7 +5430,7 @@ BOOL SmallBlockChainStream_WriteAt(
offsetInBlock = 0; /* There is no offset on the next block */ offsetInBlock = 0; /* There is no offset on the next block */
} }
return (size == 0); return (size == 0) ? S_OK : STG_E_WRITEFAULT;
} }
/****************************************************************************** /******************************************************************************

View File

@ -455,14 +455,14 @@ BlockChainStream* BlockChainStream_Construct(
void BlockChainStream_Destroy( void BlockChainStream_Destroy(
BlockChainStream* This); BlockChainStream* This);
BOOL BlockChainStream_ReadAt( HRESULT BlockChainStream_ReadAt(
BlockChainStream* This, BlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,
void* buffer, void* buffer,
ULONG* bytesRead); ULONG* bytesRead);
BOOL BlockChainStream_WriteAt( HRESULT BlockChainStream_WriteAt(
BlockChainStream* This, BlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,
@ -502,7 +502,7 @@ HRESULT SmallBlockChainStream_ReadAt(
void* buffer, void* buffer,
ULONG* bytesRead); ULONG* bytesRead);
BOOL SmallBlockChainStream_WriteAt( HRESULT SmallBlockChainStream_WriteAt(
SmallBlockChainStream* This, SmallBlockChainStream* This,
ULARGE_INTEGER offset, ULARGE_INTEGER offset,
ULONG size, ULONG size,