Commit bfc32ae0 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

ole32: Add a helper function to return the file size and modify EnsureExists to use it.

parent cc7edbe3
...@@ -827,10 +827,12 @@ HRESULT BIGBLOCKFILE_WriteAt(BigBlockFile *This, ULARGE_INTEGER offset, ...@@ -827,10 +827,12 @@ HRESULT BIGBLOCKFILE_WriteAt(BigBlockFile *This, ULARGE_INTEGER offset,
* Sets the size of the file. * Sets the size of the file.
* *
*/ */
void BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
{ {
HRESULT hr = S_OK;
if (This->filesize.u.LowPart == newSize.u.LowPart) if (This->filesize.u.LowPart == newSize.u.LowPart)
return; return hr;
TRACE("from %u to %u\n", This->filesize.u.LowPart, newSize.u.LowPart); TRACE("from %u to %u\n", This->filesize.u.LowPart, newSize.u.LowPart);
...@@ -882,6 +884,20 @@ void BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -882,6 +884,20 @@ void BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
This->filesize.u.HighPart = newSize.u.HighPart; This->filesize.u.HighPart = newSize.u.HighPart;
BIGBLOCKFILE_RemapAllMappedPages(This); BIGBLOCKFILE_RemapAllMappedPages(This);
return hr;
}
/******************************************************************************
* BIGBLOCKFILE_GetSize
*
* Gets the size of the file.
*
*/
static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size)
{
HRESULT hr = S_OK;
*size = This->filesize;
return hr;
} }
/****************************************************************************** /******************************************************************************
...@@ -889,22 +905,27 @@ void BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -889,22 +905,27 @@ void BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
* *
* Grows the file if necessary to make sure the block is valid. * Grows the file if necessary to make sure the block is valid.
*/ */
void BIGBLOCKFILE_EnsureExists(BigBlockFile *This, ULONG index) HRESULT BIGBLOCKFILE_EnsureExists(BigBlockFile *This, ULONG index)
{ {
ULARGE_INTEGER size;
HRESULT hr;
/* Block index starts at -1 translate to zero based index */ /* Block index starts at -1 translate to zero based index */
if (index == 0xffffffff) if (index == 0xffffffff)
index = 0; index = 0;
else else
index++; index++;
hr = BIGBLOCKFILE_GetSize(This, &size);
if(FAILED(hr)) return hr;
/* make sure that the block physically exists */ /* make sure that the block physically exists */
if ((This->blocksize * (index + 1)) > This->filesize.u.LowPart) if ((This->blocksize * (index + 1)) > size.QuadPart)
{ {
ULARGE_INTEGER newSize; ULARGE_INTEGER newSize;
newSize.u.HighPart = 0; newSize.QuadPart = This->blocksize * (index + 1);
newSize.u.LowPart = This->blocksize * (index + 1); hr = BIGBLOCKFILE_SetSize(This, newSize);
BIGBLOCKFILE_SetSize(This, newSize);
} }
return hr;
} }
...@@ -164,8 +164,8 @@ BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile, ...@@ -164,8 +164,8 @@ BigBlockFile* BIGBLOCKFILE_Construct(HANDLE hFile,
ULONG blocksize, ULONG blocksize,
BOOL fileBased); BOOL fileBased);
void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This); void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This);
void BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index); HRESULT BIGBLOCKFILE_EnsureExists(LPBIGBLOCKFILE This, ULONG index);
void 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);
HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset, HRESULT BIGBLOCKFILE_WriteAt(LPBIGBLOCKFILE This, ULARGE_INTEGER offset,
......
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