diff --git a/ole/stg_bigblockfile.c b/ole/stg_bigblockfile.c index 13d52e7d9e2..ffd6776501f 100644 --- a/ole/stg_bigblockfile.c +++ b/ole/stg_bigblockfile.c @@ -86,6 +86,8 @@ static BigBlock* BIGBLOCKFILE_AddBigBlock(LPBIGBLOCKFILE This, ULONG index); static BigBlock* BIGBLOCKFILE_CreateBlock(ULONG index); +static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags); + /****************************************************************************** * BIGBLOCKFILE_Construct * @@ -95,6 +97,7 @@ static BigBlock* BIGBLOCKFILE_CreateBlock(ULONG index); */ BigBlockFile * BIGBLOCKFILE_Construct( HANDLE32 hFile, + DWORD openFlags, ULONG blocksize) { LPBIGBLOCKFILE This; @@ -112,11 +115,13 @@ BigBlockFile * BIGBLOCKFILE_Construct( return NULL; } + This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags); + /* create the file mapping object */ This->hfilemap = CreateFileMapping32A(This->hfile, NULL, - PAGE_READWRITE, + This->flProtect, 0, 0, NULL); @@ -327,7 +332,7 @@ void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize) */ This->hfilemap = CreateFileMapping32A(This->hfile, NULL, - PAGE_READWRITE, + This->flProtect, 0, 0, NULL); @@ -826,3 +831,26 @@ static void BIGBLOCKFILE_FreeAllMappedPages( } } +/**************************************************************************** + * BIGBLOCKFILE_GetProtectMode + * + * This function will return a protection mode flag for a file-mapping object + * from the open flags of a file. + */ +static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags) +{ + DWORD flProtect = PAGE_READONLY; + BOOL32 bSTGM_WRITE = ((openFlags & STGM_WRITE) == STGM_WRITE); + BOOL32 bSTGM_READWRITE = ((openFlags & STGM_READWRITE) == STGM_READWRITE); + BOOL32 bSTGM_READ = ! (bSTGM_WRITE || bSTGM_READWRITE); + + if (bSTGM_READ) + flProtect = PAGE_READONLY; + + if ((bSTGM_WRITE) || (bSTGM_READWRITE)) + flProtect = PAGE_READWRITE; + + return flProtect; +} + + diff --git a/ole/storage32.c b/ole/storage32.c index 0a0887d7c13..4ea9da1a416 100644 --- a/ole/storage32.c +++ b/ole/storage32.c @@ -1866,7 +1866,12 @@ HRESULT Storage32Impl_Construct( */ This->bigBlockSize = DEF_BIG_BLOCK_SIZE; This->smallBlockSize = DEF_SMALL_BLOCK_SIZE; - This->bigBlockFile = BIGBLOCKFILE_Construct(hFile, This->bigBlockSize); + This->bigBlockFile = BIGBLOCKFILE_Construct(hFile, + openFlags, + This->bigBlockSize); + + if (This->bigBlockFile == 0) + return E_FAIL; if (openFlags & STGM_CREATE) { diff --git a/ole/storage32.h b/ole/storage32.h index 1a196a2b034..c3803cab22c 100644 --- a/ole/storage32.h +++ b/ole/storage32.h @@ -138,6 +138,7 @@ struct BigBlockFile ULONG blocksize; HANDLE32 hfile; HANDLE32 hfilemap; + DWORD flProtect; MappedPage *headmap_ro; MappedPage *headmap_w; BigBlock *headblock; @@ -147,7 +148,9 @@ struct BigBlockFile * Declaration of the functions used to manipulate the BigBlockFile * data structure. */ -BigBlockFile* BIGBLOCKFILE_Construct(HANDLE32 hFile, ULONG blocksize); +BigBlockFile* BIGBLOCKFILE_Construct(HANDLE32 hFile, + DWORD openFlags, + ULONG blocksize); void BIGBLOCKFILE_Destructor(LPBIGBLOCKFILE This); void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index); void* BIGBLOCKFILE_GetROBigBlock(LPBIGBLOCKFILE This, ULONG index);