Commit 5ceb003a authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

ole32: Remove knowledge of block sizes from the BigBlockFile object.

We can't determine the correct block size until we read the header, and we can't create the BigBlockFile until we know the correct block size. To solve this dilemma, have StorageImpl calculate the file size it needs instead of asking the BigBlockFile to "ensure a big block exists".
parent 92666974
...@@ -93,7 +93,6 @@ struct BigBlockFile ...@@ -93,7 +93,6 @@ struct BigBlockFile
{ {
BOOL fileBased; BOOL fileBased;
ULARGE_INTEGER filesize; ULARGE_INTEGER filesize;
ULONG blocksize;
HANDLE hfile; HANDLE hfile;
HANDLE hfilemap; HANDLE hfilemap;
DWORD flProtect; DWORD flProtect;
...@@ -658,7 +657,7 @@ static HRESULT ImplBIGBLOCKFILE_WriteAt( ...@@ -658,7 +657,7 @@ static HRESULT ImplBIGBLOCKFILE_WriteAt(
* and the blocks in use list. * and the blocks in use list.
*/ */
BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD openFlags, BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD openFlags,
ULONG blocksize, BOOL fileBased) BOOL fileBased)
{ {
BigBlockFile *This; BigBlockFile *This;
...@@ -669,7 +668,6 @@ BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD ope ...@@ -669,7 +668,6 @@ BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD ope
This->fileBased = fileBased; This->fileBased = fileBased;
This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags); This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags);
This->blocksize = blocksize;
This->maplist = NULL; This->maplist = NULL;
This->victimhead = NULL; This->victimhead = NULL;
...@@ -812,31 +810,19 @@ static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size) ...@@ -812,31 +810,19 @@ static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size)
} }
/****************************************************************************** /******************************************************************************
* BIGBLOCKFILE_EnsureExists * BIGBLOCKFILE_Expand
* *
* Grows the file if necessary to make sure the block is valid. * Grows the file to the specified size if necessary.
*/ */
HRESULT BIGBLOCKFILE_EnsureExists(BigBlockFile *This, ULONG index) HRESULT BIGBLOCKFILE_Expand(BigBlockFile *This, ULARGE_INTEGER newSize)
{ {
ULARGE_INTEGER size; ULARGE_INTEGER size;
HRESULT hr; HRESULT hr;
/* Block index starts at -1 translate to zero based index */
if (index == 0xffffffff)
index = 0;
else
index++;
hr = BIGBLOCKFILE_GetSize(This, &size); hr = BIGBLOCKFILE_GetSize(This, &size);
if(FAILED(hr)) return hr; if(FAILED(hr)) return hr;
/* make sure that the block physically exists */ if (newSize.QuadPart > size.QuadPart)
if ((This->blocksize * (index + 1)) > size.QuadPart)
{
ULARGE_INTEGER newSize;
newSize.QuadPart = This->blocksize * (index + 1);
hr = BIGBLOCKFILE_SetSize(This, newSize); hr = BIGBLOCKFILE_SetSize(This, newSize);
}
return hr; return hr;
} }
...@@ -2639,7 +2639,6 @@ static HRESULT StorageImpl_Construct( ...@@ -2639,7 +2639,6 @@ static HRESULT StorageImpl_Construct(
This->bigBlockFile = BIGBLOCKFILE_Construct(hFile, This->bigBlockFile = BIGBLOCKFILE_Construct(hFile,
pLkbyt, pLkbyt,
openFlags, openFlags,
This->bigBlockSize,
fileBased); fileBased);
if (This->bigBlockFile == 0) if (This->bigBlockFile == 0)
...@@ -2855,6 +2854,7 @@ static ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2855,6 +2854,7 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
ULONG nextBlockIndex = BLOCK_SPECIAL; ULONG nextBlockIndex = BLOCK_SPECIAL;
int depotIndex = 0; int depotIndex = 0;
ULONG freeBlock = BLOCK_UNUSED; ULONG freeBlock = BLOCK_UNUSED;
ULARGE_INTEGER neededSize;
depotIndex = This->prevFreeBlock / blocksPerDepot; depotIndex = This->prevFreeBlock / blocksPerDepot;
depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG); depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
...@@ -2968,7 +2968,8 @@ static ULONG StorageImpl_GetNextFreeBigBlock( ...@@ -2968,7 +2968,8 @@ static ULONG StorageImpl_GetNextFreeBigBlock(
/* /*
* make sure that the block physically exists before using it * make sure that the block physically exists before using it
*/ */
BIGBLOCKFILE_EnsureExists(This->bigBlockFile, freeBlock); neededSize.QuadPart = StorageImpl_GetBigBlockOffset(This, freeBlock)+This->bigBlockSize;
BIGBLOCKFILE_Expand(This->bigBlockFile, neededSize);
This->prevFreeBlock = freeBlock; This->prevFreeBlock = freeBlock;
......
...@@ -161,10 +161,9 @@ typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE; ...@@ -161,10 +161,9 @@ typedef struct BigBlockFile BigBlockFile,*LPBIGBLOCKFILE;
BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile, BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
ILockBytes* pLkByt, ILockBytes* pLkByt,
DWORD openFlags, DWORD openFlags,
ULONG blocksize,
BOOL fileBased); BOOL fileBased);
void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This); void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
HRESULT BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index); HRESULT BIGBLOCKFILE_Expand(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize); HRESULT BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize);
HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset, HRESULT BIGBLOCKFILE_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
void* buffer, ULONG size, ULONG* bytesRead); void* buffer, ULONG size, ULONG* bytesRead);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment