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;
}; };
/*********************************************************** /***********************************************************
...@@ -165,10 +163,7 @@ static inline void BIGBLOCKFILE_Zero(BlockBits *bb) ...@@ -165,10 +163,7 @@ 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,40 +199,22 @@ static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile) ...@@ -204,40 +199,22 @@ 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;
This->pLkbyt = plkbyt;
/* ILockBytes_AddRef(This->pLkbyt);
* 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;
/*
* Increment the reference count of the ILockByte object since
* we're keeping a reference to it.
*/
ILockBytes_AddRef(This->pLkbyt);
This->filesize.u.LowPart = GlobalSize(This->hbytearray);
This->filesize.u.HighPart = 0;
This->pbytearray = GlobalLock(This->hbytearray);
TRACE("mem on %p len %u\n", This->pbytearray, This->filesize.u.LowPart); /* We'll get the size directly with ILockBytes_Stat */
This->filesize.QuadPart = 0;
return TRUE; TRACE("ILockBytes %p\n", This->pLkbyt);
return TRUE;
} }
/****************************************************************************** /******************************************************************************
...@@ -277,34 +254,27 @@ static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page) ...@@ -277,34 +254,27 @@ 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;
DWORD numBytesToMap;
DWORD desired_access;
if (This->fileBased) assert(This->fileBased);
{
DWORD numBytesToMap;
DWORD desired_access;
if( !This->hfilemap )
return FALSE;
if (lowoffset + PAGE_SIZE > This->filesize.u.LowPart) if( !This->hfilemap )
numBytesToMap = This->filesize.u.LowPart - lowoffset; return FALSE;
else
numBytesToMap = PAGE_SIZE;
if (This->flProtect == PAGE_READONLY) if (lowoffset + PAGE_SIZE > This->filesize.u.LowPart)
desired_access = FILE_MAP_READ; numBytesToMap = This->filesize.u.LowPart - lowoffset;
else else
desired_access = FILE_MAP_WRITE; numBytesToMap = PAGE_SIZE;
page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0, if (This->flProtect == PAGE_READONLY)
lowoffset, numBytesToMap); desired_access = FILE_MAP_READ;
page->mapped_bytes = numBytesToMap;
}
else else
{ desired_access = FILE_MAP_WRITE;
page->lpBytes = (LPBYTE)This->pbytearray + lowoffset;
page->mapped_bytes = PAGE_SIZE; page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0,
} lowoffset, numBytesToMap);
page->mapped_bytes = numBytesToMap;
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,40 +825,19 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize) ...@@ -849,40 +825,19 @@ HRESULT BIGBLOCKFILE_SetSize(BigBlockFile *This, ULARGE_INTEGER newSize)
BIGBLOCKFILE_UnmapAllMappedPages(This); BIGBLOCKFILE_UnmapAllMappedPages(This);
if (This->fileBased) newpos.QuadPart = newSize.QuadPart;
if (SetFilePointerEx(This->hfile, newpos, NULL, FILE_BEGIN))
{ {
LARGE_INTEGER newpos; if( This->hfilemap ) CloseHandle(This->hfilemap);
newpos.QuadPart = newSize.QuadPart; SetEndOfFile(This->hfile);
if (SetFilePointerEx(This->hfile, newpos, NULL, FILE_BEGIN))
{
if( This->hfilemap ) CloseHandle(This->hfilemap);
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 = newSize;
This->filesize.u.HighPart = newSize.u.HighPart;
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;
*size = This->filesize; if(This->fileBased)
*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