{
BOOL fileBased;
ULARGE_INTEGER filesize;
- ULONG blocksize;
HANDLE hfile;
HANDLE hfilemap;
DWORD flProtect;
* and the blocks in use list.
*/
BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD openFlags,
- ULONG blocksize, BOOL fileBased)
+ BOOL fileBased)
{
BigBlockFile *This;
This->fileBased = fileBased;
This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags);
- This->blocksize = blocksize;
This->maplist = NULL;
This->victimhead = NULL;
}
/******************************************************************************
- * 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;
HRESULT hr;
- /* Block index starts at -1 translate to zero based index */
- if (index == 0xffffffff)
- index = 0;
- else
- index++;
-
hr = BIGBLOCKFILE_GetSize(This, &size);
if(FAILED(hr)) return hr;
- /* make sure that the block physically exists */
- if ((This->blocksize * (index + 1)) > size.QuadPart)
- {
- ULARGE_INTEGER newSize;
-
- newSize.QuadPart = This->blocksize * (index + 1);
+ if (newSize.QuadPart > size.QuadPart)
hr = BIGBLOCKFILE_SetSize(This, newSize);
- }
return hr;
}
This->bigBlockFile = BIGBLOCKFILE_Construct(hFile,
pLkbyt,
openFlags,
- This->bigBlockSize,
fileBased);
if (This->bigBlockFile == 0)
ULONG nextBlockIndex = BLOCK_SPECIAL;
int depotIndex = 0;
ULONG freeBlock = BLOCK_UNUSED;
+ ULARGE_INTEGER neededSize;
depotIndex = This->prevFreeBlock / blocksPerDepot;
depotBlockOffset = (This->prevFreeBlock % blocksPerDepot) * sizeof(ULONG);
/*
* 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;
BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
ILockBytes* pLkByt,
DWORD openFlags,
- ULONG blocksize,
BOOL fileBased);
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_ReadAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
void* buffer, ULONG size, ULONG* bytesRead);