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

ole32: The bigblockfile on ILockBytes implementation should work on any…

ole32: The bigblockfile on ILockBytes implementation should work on any ILockBytes not just those based on HGLOBAL.
parent bfc32ae0
...@@ -113,8 +113,6 @@ struct BigBlockFile ...@@ -113,8 +113,6 @@ struct BigBlockFile
MappedPage *victimhead, *victimtail; MappedPage *victimhead, *victimtail;
ULONG num_victim_pages; ULONG num_victim_pages;
ILockBytes *pLkbyt; ILockBytes *pLkbyt;
HGLOBAL hbytearray;
LPVOID pbytearray;
}; };
/*********************************************************** /***********************************************************
...@@ -166,9 +164,6 @@ static inline void BIGBLOCKFILE_Zero(BlockBits *bb) ...@@ -166,9 +164,6 @@ static inline void BIGBLOCKFILE_Zero(BlockBits *bb)
static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile) static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile)
{ {
This->pLkbyt = NULL; This->pLkbyt = NULL;
This->hbytearray = 0;
This->pbytearray = NULL;
This->hfile = hFile; This->hfile = hFile;
if (This->hfile == INVALID_HANDLE_VALUE) if (This->hfile == INVALID_HANDLE_VALUE)
...@@ -204,39 +199,21 @@ static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile) ...@@ -204,39 +199,21 @@ static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile)
} }
/****************************************************************************** /******************************************************************************
* BIGBLOCKFILE_MemInit * BIGBLOCKFILE_LockBytesInit
* *
* Initialize a big block object supported by an ILockBytes on HGLOABL. * Initialize a big block object supported by an ILockBytes.
*/ */
static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt) static BOOL BIGBLOCKFILE_LockBytesInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt)
{ {
This->hfile = 0; This->hfile = 0;
This->hfilemap = 0; This->hfilemap = 0;
/*
* Retrieve the handle to the byte array from the LockByte object.
*/
if (GetHGlobalFromILockBytes(plkbyt, &(This->hbytearray)) != S_OK)
{
FIXME("May not be an ILockBytes on HGLOBAL\n");
return FALSE;
}
This->pLkbyt = plkbyt; This->pLkbyt = plkbyt;
/*
* Increment the reference count of the ILockByte object since
* we're keeping a reference to it.
*/
ILockBytes_AddRef(This->pLkbyt); ILockBytes_AddRef(This->pLkbyt);
This->filesize.u.LowPart = GlobalSize(This->hbytearray); /* We'll get the size directly with ILockBytes_Stat */
This->filesize.u.HighPart = 0; This->filesize.QuadPart = 0;
This->pbytearray = GlobalLock(This->hbytearray);
TRACE("mem on %p len %u\n", This->pbytearray, This->filesize.u.LowPart);
TRACE("ILockBytes %p\n", This->pLkbyt);
return TRUE; return TRUE;
} }
...@@ -277,12 +254,11 @@ static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page) ...@@ -277,12 +254,11 @@ static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page)
static BOOL BIGBLOCKFILE_MapPage(BigBlockFile *This, MappedPage *page) static BOOL BIGBLOCKFILE_MapPage(BigBlockFile *This, MappedPage *page)
{ {
DWORD lowoffset = PAGE_SIZE * page->page_index; DWORD lowoffset = PAGE_SIZE * page->page_index;
if (This->fileBased)
{
DWORD numBytesToMap; DWORD numBytesToMap;
DWORD desired_access; DWORD desired_access;
assert(This->fileBased);
if( !This->hfilemap ) if( !This->hfilemap )
return FALSE; return FALSE;
...@@ -299,12 +275,6 @@ static BOOL BIGBLOCKFILE_MapPage(BigBlockFile *This, MappedPage *page) ...@@ -299,12 +275,6 @@ static BOOL BIGBLOCKFILE_MapPage(BigBlockFile *This, MappedPage *page)
page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0, page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0,
lowoffset, numBytesToMap); lowoffset, numBytesToMap);
page->mapped_bytes = numBytesToMap; page->mapped_bytes = numBytesToMap;
}
else
{
page->lpBytes = (LPBYTE)This->pbytearray + lowoffset;
page->mapped_bytes = PAGE_SIZE;
}
TRACE("mapped page %u to %p\n", page->page_index, page->lpBytes); TRACE("mapped page %u to %p\n", page->page_index, page->lpBytes);
...@@ -392,10 +362,13 @@ static void * BIGBLOCKFILE_GetMappedView( ...@@ -392,10 +362,13 @@ static void * BIGBLOCKFILE_GetMappedView(
static void BIGBLOCKFILE_UnmapPage(LPBIGBLOCKFILE This, MappedPage *page) static void BIGBLOCKFILE_UnmapPage(LPBIGBLOCKFILE This, MappedPage *page)
{ {
TRACE("%d at %p\n", page->page_index, page->lpBytes); TRACE("%d at %p\n", page->page_index, page->lpBytes);
assert(This->fileBased);
if (page->refcnt > 0) if (page->refcnt > 0)
ERR("unmapping inuse page %p\n", page->lpBytes); ERR("unmapping inuse page %p\n", page->lpBytes);
if (This->fileBased && page->lpBytes) if (page->lpBytes)
UnmapViewOfFile(page->lpBytes); UnmapViewOfFile(page->lpBytes);
page->lpBytes = NULL; page->lpBytes = NULL;
...@@ -764,7 +737,7 @@ BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD ope ...@@ -764,7 +737,7 @@ BigBlockFile *BIGBLOCKFILE_Construct(HANDLE hFile, ILockBytes* pLkByt, DWORD ope
} }
else else
{ {
if (!BIGBLOCKFILE_MemInit(This, pLkByt)) if (!BIGBLOCKFILE_LockBytesInit(This, pLkByt))
{ {
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return NULL; return NULL;
...@@ -790,7 +763,6 @@ void BIGBLOCKFILE_Destructor(BigBlockFile *This) ...@@ -790,7 +763,6 @@ void BIGBLOCKFILE_Destructor(BigBlockFile *This)
} }
else else
{ {
GlobalUnlock(This->hbytearray);
ILockBytes_Release(This->pLkbyt); ILockBytes_Release(This->pLkbyt);
} }
...@@ -830,6 +802,10 @@ HRESULT BIGBLOCKFILE_WriteAt(BigBlockFile *This, ULARGE_INTEGER offset, ...@@ -830,6 +802,10 @@ HRESULT BIGBLOCKFILE_WriteAt(BigBlockFile *This, ULARGE_INTEGER offset,
HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
LARGE_INTEGER newpos;
if (!This->fileBased)
return ILockBytes_SetSize(This->pLkbyt, newSize);
if (This->filesize.u.LowPart == newSize.u.LowPart) if (This->filesize.u.LowPart == newSize.u.LowPart)
return hr; return hr;
...@@ -849,10 +825,6 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -849,10 +825,6 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
BIGBLOCKFILE_UnmapAllMappedPages(This); BIGBLOCKFILE_UnmapAllMappedPages(This);
if (This->fileBased)
{
LARGE_INTEGER newpos;
newpos.QuadPart = newSize.QuadPart; newpos.QuadPart = newSize.QuadPart;
if (SetFilePointerEx(This->hfile, newpos, NULL, FILE_BEGIN)) if (SetFilePointerEx(This->hfile, newpos, NULL, FILE_BEGIN))
{ {
...@@ -861,28 +833,11 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -861,28 +833,11 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
SetEndOfFile(This->hfile); SetEndOfFile(This->hfile);
/* re-create the file mapping object */ /* re-create the file mapping object */
This->hfilemap = CreateFileMappingA(This->hfile, This->hfilemap = CreateFileMappingA(This->hfile, NULL, This->flProtect,
NULL, 0, 0, NULL);
This->flProtect,
0, 0,
NULL);
}
} }
else
{
GlobalUnlock(This->hbytearray);
/* Resize the byte array object. */
ILockBytes_SetSize(This->pLkbyt, newSize);
/* Re-acquire the handle, it may have changed */
GetHGlobalFromILockBytes(This->pLkbyt, &This->hbytearray);
This->pbytearray = GlobalLock(This->hbytearray);
}
This->filesize.u.LowPart = newSize.u.LowPart;
This->filesize.u.HighPart = newSize.u.HighPart;
This->filesize = newSize;
BIGBLOCKFILE_RemapAllMappedPages(This); BIGBLOCKFILE_RemapAllMappedPages(This);
return hr; return hr;
} }
...@@ -896,7 +851,14 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -896,7 +851,14 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size) static HRESULT BIGBLOCKFILE_GetSize(BigBlockFile *This, ULARGE_INTEGER *size)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if(This->fileBased)
*size = This->filesize; *size = This->filesize;
else
{
STATSTG stat;
hr = ILockBytes_Stat(This->pLkbyt, &stat, STATFLAG_NONAME);
if(SUCCEEDED(hr)) *size = stat.cbSize;
}
return hr; return hr;
} }
......
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