1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* BigBlockFile
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* This is the implementation of a file that consists of blocks of
|
1999-01-30 14:24:23 +01:00
|
|
|
* a predetermined size.
|
2002-06-01 01:06:46 +02:00
|
|
|
* This class is used in the Compound File implementation of the
|
|
|
|
* IStorage and IStream interfaces. It provides the functionality
|
|
|
|
* to read and write any blocks in the file as well as setting and
|
1999-01-30 14:24:23 +01:00
|
|
|
* obtaining the size of the file.
|
|
|
|
* The blocks are indexed sequentially from the start of the file
|
|
|
|
* starting with -1.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
* TODO:
|
|
|
|
* - Support for a transacted mode
|
|
|
|
*
|
|
|
|
* Copyright 1999 Thuy Nguyen
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-03-17 16:08:25 +01:00
|
|
|
#include <limits.h>
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-02-28 20:14:33 +01:00
|
|
|
#include "winbase.h"
|
1999-01-30 14:24:23 +01:00
|
|
|
#include "winerror.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "wine/obj_base.h"
|
1999-02-02 17:14:23 +01:00
|
|
|
#include "wine/obj_storage.h"
|
1999-05-08 12:05:08 +02:00
|
|
|
#include "ole2.h"
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
#include "storage32.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-05-08 12:05:08 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(storage);
|
1999-05-08 12:05:08 +02:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/***********************************************************
|
|
|
|
* Data structures used internally by the BigBlockFile
|
|
|
|
* class.
|
|
|
|
*/
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
/* We map in PAGE_SIZE-sized chunks. Must be a multiple of 4096. */
|
|
|
|
#define PAGE_SIZE 131072
|
|
|
|
|
|
|
|
#define BLOCKS_PER_PAGE (PAGE_SIZE / BIG_BLOCK_SIZE)
|
|
|
|
|
|
|
|
/* We keep a list of recently-discarded pages. This controls the
|
|
|
|
* size of that list. */
|
|
|
|
#define MAX_VICTIM_PAGES 16
|
|
|
|
|
|
|
|
/* This structure provides one bit for each block in a page.
|
|
|
|
* Use BIGBLOCKFILE_{Test,Set,Clear}Bit to manipulate it. */
|
|
|
|
typedef struct
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
unsigned int bits[BLOCKS_PER_PAGE / (CHAR_BIT * sizeof(unsigned int))];
|
|
|
|
} BlockBits;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/***
|
|
|
|
* This structure identifies the paged that are mapped
|
2002-06-01 01:06:46 +02:00
|
|
|
* from the file and their position in memory. It is
|
1999-01-30 14:24:23 +01:00
|
|
|
* also used to hold a reference count to those pages.
|
2000-03-17 16:08:25 +01:00
|
|
|
*
|
|
|
|
* page_index identifies which PAGE_SIZE chunk from the
|
|
|
|
* file this mapping represents. (The mappings are always
|
|
|
|
* PAGE_SIZE-aligned.)
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
struct MappedPage
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *next;
|
|
|
|
MappedPage *prev;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD page_index;
|
|
|
|
LPVOID lpBytes;
|
|
|
|
LONG refcnt;
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BlockBits readable_blocks;
|
|
|
|
BlockBits writable_blocks;
|
|
|
|
};
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Prototypes for private methods
|
|
|
|
*/
|
|
|
|
static void* BIGBLOCKFILE_GetMappedView(LPBIGBLOCKFILE This,
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD page_index);
|
1999-03-12 18:06:46 +01:00
|
|
|
static void BIGBLOCKFILE_ReleaseMappedPage(LPBIGBLOCKFILE This,
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page);
|
1999-01-30 14:24:23 +01:00
|
|
|
static void BIGBLOCKFILE_FreeAllMappedPages(LPBIGBLOCKFILE This);
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This);
|
|
|
|
static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This);
|
1999-01-30 14:24:23 +01:00
|
|
|
static void* BIGBLOCKFILE_GetBigBlockPointer(LPBIGBLOCKFILE This,
|
1999-03-12 18:06:46 +01:00
|
|
|
ULONG index,
|
|
|
|
DWORD desired_access);
|
2002-06-01 01:06:46 +02:00
|
|
|
static MappedPage* BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This,
|
2000-03-17 16:08:25 +01:00
|
|
|
void* pBlock);
|
|
|
|
static MappedPage* BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This,
|
|
|
|
ULONG page_index);
|
1999-03-12 18:06:46 +01:00
|
|
|
static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags);
|
1999-05-08 12:05:08 +02:00
|
|
|
static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile);
|
|
|
|
static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt);
|
2000-03-17 16:08:25 +01:00
|
|
|
|
|
|
|
/* Note that this evaluates a and b multiple times, so don't
|
|
|
|
* pass expressions with side effects. */
|
|
|
|
#define ROUND_UP(a, b) ((((a) + (b) - 1)/(b))*(b))
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Blockbits functions.
|
|
|
|
*/
|
|
|
|
static inline BOOL BIGBLOCKFILE_TestBit(const BlockBits *bb,
|
|
|
|
unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
|
|
|
|
return bb->bits[array_index] & (1 << bit_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void BIGBLOCKFILE_SetBit(BlockBits *bb, unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
|
|
|
|
bb->bits[array_index] |= (1 << bit_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void BIGBLOCKFILE_ClearBit(BlockBits *bb, unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
|
|
|
|
|
|
|
|
bb->bits[array_index] &= ~(1 << bit_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void BIGBLOCKFILE_Zero(BlockBits *bb)
|
|
|
|
{
|
|
|
|
memset(bb->bits, 0, sizeof(bb->bits));
|
|
|
|
}
|
1999-02-18 16:55:53 +01:00
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_Construct
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Construct a big block file. Create the file mapping object.
|
2000-03-17 16:08:25 +01:00
|
|
|
* Create the read only mapped pages list, the writable mapped page list
|
1999-01-30 14:24:23 +01:00
|
|
|
* and the blocks in use list.
|
|
|
|
*/
|
|
|
|
BigBlockFile * BIGBLOCKFILE_Construct(
|
1999-05-08 12:05:08 +02:00
|
|
|
HANDLE hFile,
|
|
|
|
ILockBytes* pLkByt,
|
1999-03-12 18:06:46 +01:00
|
|
|
DWORD openFlags,
|
1999-05-08 12:05:08 +02:00
|
|
|
ULONG blocksize,
|
|
|
|
BOOL fileBased)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
LPBIGBLOCKFILE This;
|
|
|
|
|
|
|
|
This = (LPBIGBLOCKFILE)HeapAlloc(GetProcessHeap(), 0, sizeof(BigBlockFile));
|
|
|
|
|
|
|
|
if (This == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
This->fileBased = fileBased;
|
|
|
|
|
1999-05-12 12:36:17 +02:00
|
|
|
This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags);
|
|
|
|
|
|
|
|
This->blocksize = blocksize;
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
This->maplist = NULL;
|
|
|
|
This->victimhead = NULL;
|
|
|
|
This->victimtail = NULL;
|
|
|
|
This->num_victim_pages = 0;
|
1999-05-12 12:36:17 +02:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
if (This->fileBased)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
1999-05-08 12:05:08 +02:00
|
|
|
if (!BIGBLOCKFILE_FileInit(This, hFile))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!BIGBLOCKFILE_MemInit(This, pLkByt))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
return This;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_FileInit
|
|
|
|
*
|
|
|
|
* Initialize a big block object supported by a file.
|
|
|
|
*/
|
|
|
|
static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile)
|
|
|
|
{
|
|
|
|
This->pLkbyt = NULL;
|
|
|
|
This->hbytearray = 0;
|
|
|
|
This->pbytearray = NULL;
|
|
|
|
|
|
|
|
This->hfile = hFile;
|
|
|
|
|
|
|
|
if (This->hfile == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
1999-01-30 14:24:23 +01:00
|
|
|
/* create the file mapping object
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
This->hfilemap = CreateFileMappingA(This->hfile,
|
1999-05-08 12:05:08 +02:00
|
|
|
NULL,
|
|
|
|
This->flProtect,
|
|
|
|
0, 0,
|
|
|
|
NULL);
|
|
|
|
|
2000-11-25 02:40:34 +01:00
|
|
|
if (!This->hfilemap)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
CloseHandle(This->hfile);
|
1999-05-08 12:05:08 +02:00
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
This->filesize.s.LowPart = GetFileSize(This->hfile,
|
|
|
|
&This->filesize.s.HighPart);
|
1999-05-08 12:05:08 +02:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
This->maplist = NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
TRACE("file len %lu\n", This->filesize.s.LowPart);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_MemInit
|
|
|
|
*
|
|
|
|
* Initialize a big block object supported by an ILockBytes on HGLOABL.
|
|
|
|
*/
|
|
|
|
static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt)
|
|
|
|
{
|
|
|
|
This->hfile = 0;
|
2000-11-25 02:40:34 +01:00
|
|
|
This->hfilemap = 0;
|
1999-05-08 12:05:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve the handle to the byte array from the LockByte object.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
1999-05-08 12:05:08 +02:00
|
|
|
if (GetHGlobalFromILockBytes(plkbyt, &(This->hbytearray)) != S_OK)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
FIXME("May not be an ILockBytes on HGLOBAL\n");
|
1999-05-08 12:05:08 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
This->pLkbyt = plkbyt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Increment the reference count of the ILockByte object since
|
|
|
|
* we're keeping a reference to it.
|
|
|
|
*/
|
|
|
|
ILockBytes_AddRef(This->pLkbyt);
|
|
|
|
|
1999-09-19 16:20:33 +02:00
|
|
|
This->filesize.s.LowPart = GlobalSize(This->hbytearray);
|
|
|
|
This->filesize.s.HighPart = 0;
|
1999-05-08 12:05:08 +02:00
|
|
|
|
|
|
|
This->pbytearray = GlobalLock(This->hbytearray);
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
TRACE("mem on %p len %lu\n", This->pbytearray, This->filesize.s.LowPart);
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
return TRUE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_Destructor
|
|
|
|
*
|
|
|
|
* Destructor. Clean up, free memory.
|
|
|
|
*/
|
|
|
|
void BIGBLOCKFILE_Destructor(
|
|
|
|
LPBIGBLOCKFILE This)
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_FreeAllMappedPages(This);
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
if (This->fileBased)
|
|
|
|
{
|
|
|
|
CloseHandle(This->hfilemap);
|
|
|
|
CloseHandle(This->hfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GlobalUnlock(This->hbytearray);
|
|
|
|
ILockBytes_Release(This->pLkbyt);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
/* destroy this
|
|
|
|
*/
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_GetROBigBlock
|
|
|
|
*
|
|
|
|
* Returns the specified block in read only mode.
|
|
|
|
* Will return NULL if the block doesn't exists.
|
|
|
|
*/
|
|
|
|
void* BIGBLOCKFILE_GetROBigBlock(
|
|
|
|
LPBIGBLOCKFILE This,
|
|
|
|
ULONG index)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* block index starts at -1
|
|
|
|
* translate to zero based index
|
|
|
|
*/
|
|
|
|
if (index == 0xffffffff)
|
|
|
|
index = 0;
|
|
|
|
else
|
|
|
|
index++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* validate the block index
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2000-03-17 16:08:25 +01:00
|
|
|
if (This->blocksize * (index + 1)
|
|
|
|
> ROUND_UP(This->filesize.s.LowPart, This->blocksize))
|
|
|
|
{
|
|
|
|
TRACE("out of range %lu vs %lu\n", This->blocksize * (index + 1),
|
|
|
|
This->filesize.s.LowPart);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_READ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_GetBigBlock
|
|
|
|
*
|
|
|
|
* Returns the specified block.
|
|
|
|
* Will grow the file if necessary.
|
|
|
|
*/
|
|
|
|
void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* block index starts at -1
|
|
|
|
* translate to zero based index
|
|
|
|
*/
|
|
|
|
if (index == 0xffffffff)
|
|
|
|
index = 0;
|
|
|
|
else
|
|
|
|
index++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure that the block physically exists
|
|
|
|
*/
|
1999-09-19 16:20:33 +02:00
|
|
|
if ((This->blocksize * (index + 1)) > This->filesize.s.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
|
|
|
ULARGE_INTEGER newSize;
|
|
|
|
|
1999-09-19 16:20:33 +02:00
|
|
|
newSize.s.HighPart = 0;
|
|
|
|
newSize.s.LowPart = This->blocksize * (index + 1);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
BIGBLOCKFILE_SetSize(This, newSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_WRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_ReleaseBigBlock
|
|
|
|
*
|
|
|
|
* Releases the specified block.
|
|
|
|
*/
|
|
|
|
void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock)
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (pBlock == NULL)
|
|
|
|
return;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page = BIGBLOCKFILE_GetPageFromPointer(This, pBlock);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (page == NULL)
|
|
|
|
return;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_ReleaseMappedPage(This, page);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_SetSize
|
|
|
|
*
|
|
|
|
* Sets the size of the file.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize)
|
|
|
|
{
|
1999-09-19 16:20:33 +02:00
|
|
|
if (This->filesize.s.LowPart == newSize.s.LowPart)
|
1999-01-30 14:24:23 +01:00
|
|
|
return;
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
TRACE("from %lu to %lu\n", This->filesize.s.LowPart, newSize.s.LowPart);
|
|
|
|
/*
|
|
|
|
* unmap all views, must be done before call to SetEndFile
|
|
|
|
*/
|
|
|
|
BIGBLOCKFILE_UnmapAllMappedPages(This);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
if (This->fileBased)
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
char buf[10];
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/*
|
|
|
|
* close file-mapping object, must be done before call to SetEndFile
|
|
|
|
*/
|
|
|
|
CloseHandle(This->hfilemap);
|
2000-11-25 02:40:34 +01:00
|
|
|
This->hfilemap = 0;
|
2000-03-17 16:08:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BEGIN HACK
|
|
|
|
* This fixes a bug when saving through smbfs.
|
|
|
|
* smbmount a Windows shared directory, save a structured storage file
|
|
|
|
* to that dir: crash.
|
|
|
|
*
|
|
|
|
* The problem is that the SetFilePointer-SetEndOfFile combo below
|
2002-06-01 01:06:46 +02:00
|
|
|
* doesn't always succeed. The file is not grown. It seems like the
|
2000-03-17 16:08:25 +01:00
|
|
|
* operation is cached. By doing the WriteFile, the file is actually
|
|
|
|
* grown on disk.
|
|
|
|
* This hack is only needed when saving to smbfs.
|
|
|
|
*/
|
|
|
|
memset(buf, '0', 10);
|
|
|
|
SetFilePointer(This->hfile, newSize.s.LowPart, NULL, FILE_BEGIN);
|
|
|
|
WriteFile(This->hfile, buf, 10, NULL, NULL);
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* END HACK
|
2000-03-17 16:08:25 +01:00
|
|
|
*/
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/*
|
|
|
|
* set the new end of file
|
|
|
|
*/
|
1999-09-19 16:20:33 +02:00
|
|
|
SetFilePointer(This->hfile, newSize.s.LowPart, NULL, FILE_BEGIN);
|
1999-05-08 12:05:08 +02:00
|
|
|
SetEndOfFile(This->hfile);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/*
|
|
|
|
* re-create the file mapping object
|
|
|
|
*/
|
|
|
|
This->hfilemap = CreateFileMappingA(This->hfile,
|
|
|
|
NULL,
|
|
|
|
This->flProtect,
|
2002-06-01 01:06:46 +02:00
|
|
|
0, 0,
|
1999-05-08 12:05:08 +02:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GlobalUnlock(This->hbytearray);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/*
|
|
|
|
* Resize the byte array object.
|
|
|
|
*/
|
|
|
|
ILockBytes_SetSize(This->pLkbyt, newSize);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/*
|
|
|
|
* Re-acquire the handle, it may have changed.
|
|
|
|
*/
|
|
|
|
GetHGlobalFromILockBytes(This->pLkbyt, &This->hbytearray);
|
|
|
|
This->pbytearray = GlobalLock(This->hbytearray);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
1999-09-19 16:20:33 +02:00
|
|
|
This->filesize.s.LowPart = newSize.s.LowPart;
|
|
|
|
This->filesize.s.HighPart = newSize.s.HighPart;
|
2000-03-17 16:08:25 +01:00
|
|
|
|
|
|
|
BIGBLOCKFILE_RemapAllMappedPages(This);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_GetSize
|
|
|
|
*
|
|
|
|
* Returns the size of the file.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
ULARGE_INTEGER BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This)
|
|
|
|
{
|
|
|
|
return This->filesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-17 16:08:25 +01:00
|
|
|
* BIGBLOCKFILE_AccessCheck [PRIVATE]
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
2000-03-17 16:08:25 +01:00
|
|
|
* block_index is the index within the page.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2000-03-17 16:08:25 +01:00
|
|
|
static BOOL BIGBLOCKFILE_AccessCheck(MappedPage *page, ULONG block_index,
|
|
|
|
DWORD desired_access)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
assert(block_index < BLOCKS_PER_PAGE);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (desired_access == FILE_MAP_READ)
|
|
|
|
{
|
|
|
|
if (BIGBLOCKFILE_TestBit(&page->writable_blocks, block_index))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_SetBit(&page->readable_blocks, block_index);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
else
|
2000-03-17 16:08:25 +01:00
|
|
|
{
|
|
|
|
assert(desired_access == FILE_MAP_WRITE);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (BIGBLOCKFILE_TestBit(&page->readable_blocks, block_index))
|
|
|
|
return FALSE;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_SetBit(&page->writable_blocks, block_index);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return TRUE;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-17 16:08:25 +01:00
|
|
|
* BIGBLOCKFILE_GetBigBlockPointer [PRIVATE]
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
2000-03-17 16:08:25 +01:00
|
|
|
* Returns a pointer to the specified block.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2000-03-17 16:08:25 +01:00
|
|
|
static void* BIGBLOCKFILE_GetBigBlockPointer(
|
2002-06-01 01:06:46 +02:00
|
|
|
LPBIGBLOCKFILE This,
|
|
|
|
ULONG block_index,
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD desired_access)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD page_index = block_index / BLOCKS_PER_PAGE;
|
|
|
|
DWORD block_on_page = block_index % BLOCKS_PER_PAGE;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page = BIGBLOCKFILE_GetMappedView(This, page_index);
|
|
|
|
if (!page || !page->lpBytes) return NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (!BIGBLOCKFILE_AccessCheck(page, block_on_page, desired_access))
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_ReleaseMappedPage(This, page);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return (LPBYTE)page->lpBytes + (block_on_page * This->blocksize);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-17 16:08:25 +01:00
|
|
|
* BIGBLOCKFILE_GetMappedPageFromPointer [PRIVATE]
|
|
|
|
*
|
|
|
|
* pBlock is a pointer to a block on a page.
|
|
|
|
* The page has to be on the in-use list. (As oppsed to the victim list.)
|
1999-01-30 14:24:23 +01:00
|
|
|
*
|
2000-03-17 16:08:25 +01:00
|
|
|
* Does not increment the usage count.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
2000-03-17 16:08:25 +01:00
|
|
|
static MappedPage *BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This,
|
|
|
|
void *pBlock)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
for (page = This->maplist; page != NULL; page = page->next)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
if ((LPBYTE)pBlock >= (LPBYTE)page->lpBytes
|
|
|
|
&& (LPBYTE)pBlock <= (LPBYTE)page->lpBytes + PAGE_SIZE)
|
|
|
|
break;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return page;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-05-08 12:05:08 +02:00
|
|
|
/******************************************************************************
|
2000-03-17 16:08:25 +01:00
|
|
|
* BIGBLOCKFILE_FindPageInList [PRIVATE]
|
1999-05-08 12:05:08 +02:00
|
|
|
*
|
|
|
|
*/
|
2000-03-17 16:08:25 +01:00
|
|
|
static MappedPage *BIGBLOCKFILE_FindPageInList(MappedPage *head,
|
|
|
|
ULONG page_index)
|
1999-05-08 12:05:08 +02:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
for (; head != NULL; head = head->next)
|
|
|
|
{
|
|
|
|
if (head->page_index == page_index)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&head->refcnt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
1999-05-08 12:05:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_UnlinkPage(MappedPage *page)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
if (page->next) page->next->prev = page->prev;
|
|
|
|
if (page->prev) page->prev->next = page->next;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
if (*head) (*head)->prev = page;
|
|
|
|
page->next = *head;
|
|
|
|
page->prev = NULL;
|
|
|
|
*head = page;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_GetMappedView [PRIVATE]
|
|
|
|
*
|
|
|
|
* Gets the page requested if it is already mapped.
|
|
|
|
* If it's not already mapped, this method will map it
|
|
|
|
*/
|
|
|
|
static void * BIGBLOCKFILE_GetMappedView(
|
|
|
|
LPBIGBLOCKFILE This,
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD page_index)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page = BIGBLOCKFILE_FindPageInList(This->maplist, page_index);
|
|
|
|
if (!page)
|
|
|
|
{
|
|
|
|
page = BIGBLOCKFILE_FindPageInList(This->victimhead, page_index);
|
|
|
|
if (page)
|
|
|
|
{
|
|
|
|
This->num_victim_pages--;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_Zero(&page->readable_blocks);
|
|
|
|
BIGBLOCKFILE_Zero(&page->writable_blocks);
|
|
|
|
}
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (page)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
/* If the page is not already at the head of the list, move
|
|
|
|
* it there. (Also moves pages from victim to main list.) */
|
|
|
|
if (This->maplist != page)
|
|
|
|
{
|
|
|
|
if (This->victimhead == page) This->victimhead = page->next;
|
|
|
|
if (This->victimtail == page) This->victimtail = page->prev;
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_UnlinkPage(page);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_LinkHeadPage(&This->maplist, page);
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return page;
|
1999-03-12 18:06:46 +01:00
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page = BIGBLOCKFILE_CreatePage(This, page_index);
|
|
|
|
if (!page) return NULL;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_LinkHeadPage(&This->maplist, page);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL BIGBLOCKFILE_MapPage(LPBIGBLOCKFILE This, MappedPage *page)
|
|
|
|
{
|
|
|
|
DWORD lowoffset = PAGE_SIZE * page->page_index;
|
|
|
|
|
|
|
|
if (This->fileBased)
|
1999-03-12 18:06:46 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
DWORD numBytesToMap;
|
|
|
|
DWORD desired_access;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (lowoffset + PAGE_SIZE > This->filesize.s.LowPart)
|
|
|
|
numBytesToMap = This->filesize.s.LowPart - lowoffset;
|
|
|
|
else
|
|
|
|
numBytesToMap = PAGE_SIZE;
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (This->flProtect == PAGE_READONLY)
|
|
|
|
desired_access = FILE_MAP_READ;
|
|
|
|
else
|
|
|
|
desired_access = FILE_MAP_WRITE;
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0,
|
|
|
|
lowoffset, numBytesToMap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
page->lpBytes = (LPBYTE)This->pbytearray + lowoffset;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
TRACE("mapped page %lu to %p\n", page->page_index, page->lpBytes);
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return page->lpBytes != NULL;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static MappedPage *BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This,
|
|
|
|
ULONG page_index)
|
|
|
|
{
|
|
|
|
MappedPage *page;
|
|
|
|
|
|
|
|
page = HeapAlloc(GetProcessHeap(), 0, sizeof(MappedPage));
|
|
|
|
if (page == NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
return NULL;
|
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page->page_index = page_index;
|
|
|
|
page->refcnt = 1;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
page->next = NULL;
|
|
|
|
page->prev = NULL;
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_MapPage(This, page);
|
1999-02-24 11:52:26 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_Zero(&page->readable_blocks);
|
|
|
|
BIGBLOCKFILE_Zero(&page->writable_blocks);
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
return page;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_UnmapPage(LPBIGBLOCKFILE This, MappedPage *page)
|
|
|
|
{
|
|
|
|
TRACE("%ld at %p\n", page->page_index, page->lpBytes);
|
|
|
|
if (page->refcnt > 0)
|
|
|
|
ERR("unmapping inuse page %p\n", page->lpBytes);
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
if (This->fileBased && page->lpBytes)
|
|
|
|
UnmapViewOfFile(page->lpBytes);
|
|
|
|
|
|
|
|
page->lpBytes = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BIGBLOCKFILE_DeletePage(LPBIGBLOCKFILE This, MappedPage *page)
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_UnmapPage(This, page);
|
1999-03-12 18:06:46 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, page);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_ReleaseMappedPage [PRIVATE]
|
|
|
|
*
|
|
|
|
* Decrements the reference count of the mapped page.
|
|
|
|
*/
|
|
|
|
static void BIGBLOCKFILE_ReleaseMappedPage(
|
|
|
|
LPBIGBLOCKFILE This,
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *page)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
assert(This != NULL);
|
|
|
|
assert(page != NULL);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
/* If the page is no longer refenced, move it to the victim list.
|
|
|
|
* If the victim list is too long, kick somebody off. */
|
|
|
|
if (!InterlockedDecrement(&page->refcnt))
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
if (This->maplist == page) This->maplist = page->next;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_UnlinkPage(page);
|
|
|
|
|
|
|
|
if (MAX_VICTIM_PAGES > 0)
|
|
|
|
{
|
|
|
|
if (This->num_victim_pages >= MAX_VICTIM_PAGES)
|
|
|
|
{
|
|
|
|
MappedPage *victim = This->victimtail;
|
|
|
|
if (victim)
|
|
|
|
{
|
|
|
|
This->victimtail = victim->prev;
|
|
|
|
if (This->victimhead == victim)
|
|
|
|
This->victimhead = victim->next;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_UnlinkPage(victim);
|
|
|
|
BIGBLOCKFILE_DeletePage(This, victim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else This->num_victim_pages++;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_LinkHeadPage(&This->victimhead, page);
|
|
|
|
if (This->victimtail == NULL) This->victimtail = page;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BIGBLOCKFILE_DeletePage(This, page);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
2000-03-17 16:08:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BIGBLOCKFILE_DeleteList(LPBIGBLOCKFILE This, MappedPage *list)
|
|
|
|
{
|
|
|
|
while (list != NULL)
|
1999-01-30 14:24:23 +01:00
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
MappedPage *next = list->next;
|
|
|
|
|
|
|
|
BIGBLOCKFILE_DeletePage(This, list);
|
|
|
|
|
|
|
|
list = next;
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BIGBLOCKFILE_FreeAllMappedPages [PRIVATE]
|
|
|
|
*
|
|
|
|
* Unmap all currently mapped pages.
|
1999-03-12 18:06:46 +01:00
|
|
|
* Empty mapped pages list.
|
1999-01-30 14:24:23 +01:00
|
|
|
*/
|
|
|
|
static void BIGBLOCKFILE_FreeAllMappedPages(
|
|
|
|
LPBIGBLOCKFILE This)
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
BIGBLOCKFILE_DeleteList(This, This->maplist);
|
|
|
|
BIGBLOCKFILE_DeleteList(This, This->victimhead);
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
This->maplist = NULL;
|
|
|
|
This->victimhead = NULL;
|
|
|
|
This->victimtail = NULL;
|
|
|
|
This->num_victim_pages = 0;
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_UnmapList(LPBIGBLOCKFILE This, MappedPage *list)
|
|
|
|
{
|
|
|
|
for (; list != NULL; list = list->next)
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_UnmapPage(This, list);
|
|
|
|
}
|
|
|
|
}
|
1999-01-30 14:24:23 +01:00
|
|
|
|
2000-03-17 16:08:25 +01:00
|
|
|
static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This)
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_UnmapList(This, This->maplist);
|
|
|
|
BIGBLOCKFILE_UnmapList(This, This->victimhead);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BIGBLOCKFILE_RemapList(LPBIGBLOCKFILE This, MappedPage *list)
|
|
|
|
{
|
|
|
|
while (list != NULL)
|
|
|
|
{
|
|
|
|
MappedPage *next = list->next;
|
|
|
|
|
|
|
|
if (list->page_index * PAGE_SIZE > This->filesize.s.LowPart)
|
|
|
|
{
|
|
|
|
TRACE("discarding %lu\n", list->page_index);
|
|
|
|
|
|
|
|
/* page is entirely outside of the file, delete it */
|
|
|
|
BIGBLOCKFILE_UnlinkPage(list);
|
|
|
|
BIGBLOCKFILE_DeletePage(This, list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise, remap it */
|
|
|
|
BIGBLOCKFILE_MapPage(This, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This)
|
|
|
|
{
|
|
|
|
BIGBLOCKFILE_RemapList(This, This->maplist);
|
|
|
|
BIGBLOCKFILE_RemapList(This, This->victimhead);
|
1999-01-30 14:24:23 +01:00
|
|
|
}
|
|
|
|
|
1999-02-18 16:55:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2000-03-17 16:08:25 +01:00
|
|
|
if (openFlags & (STGM_WRITE | STGM_READWRITE))
|
|
|
|
return PAGE_READWRITE;
|
|
|
|
else
|
|
|
|
return PAGE_READONLY;
|
1999-02-18 16:55:53 +01:00
|
|
|
}
|