Add support for HCBT_SYSCOMMAND hook, add logging for HCBT_SYSCOMMAND
[wine.git] / dlls / ole32 / stg_bigblockfile.c
blobf7282dd9b3f32f0f4dfb9858410f77d0f1217c41
1 /******************************************************************************
3 * BigBlockFile
5 * This is the implementation of a file that consists of blocks of
6 * a predetermined size.
7 * This class is used in the Compound File implementation of the
8 * IStorage and IStream interfaces. It provides the functionality
9 * to read and write any blocks in the file as well as setting and
10 * obtaining the size of the file.
11 * The blocks are indexed sequentially from the start of the file
12 * starting with -1.
14 * TODO:
15 * - Support for a transacted mode
17 * Copyright 1999 Thuy Nguyen
19 * This library is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU Lesser General Public
21 * License as published by the Free Software Foundation; either
22 * version 2.1 of the License, or (at your option) any later version.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <assert.h>
35 #include <stdlib.h>
36 #include <stdarg.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <limits.h>
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winuser.h"
46 #include "winerror.h"
47 #include "objbase.h"
48 #include "ole2.h"
50 #include "storage32.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(storage);
56 /***********************************************************
57 * Data structures used internally by the BigBlockFile
58 * class.
61 /* We map in PAGE_SIZE-sized chunks. Must be a multiple of 4096. */
62 #define PAGE_SIZE 131072
64 #define BLOCKS_PER_PAGE (PAGE_SIZE / BIG_BLOCK_SIZE)
66 /* We keep a list of recently-discarded pages. This controls the
67 * size of that list. */
68 #define MAX_VICTIM_PAGES 16
70 /* This structure provides one bit for each block in a page.
71 * Use BIGBLOCKFILE_{Test,Set,Clear}Bit to manipulate it. */
72 typedef struct
74 unsigned int bits[BLOCKS_PER_PAGE / (CHAR_BIT * sizeof(unsigned int))];
75 } BlockBits;
77 /***
78 * This structure identifies the paged that are mapped
79 * from the file and their position in memory. It is
80 * also used to hold a reference count to those pages.
82 * page_index identifies which PAGE_SIZE chunk from the
83 * file this mapping represents. (The mappings are always
84 * PAGE_SIZE-aligned.)
86 struct MappedPage
88 MappedPage *next;
89 MappedPage *prev;
91 DWORD page_index;
92 LPVOID lpBytes;
93 LONG refcnt;
95 BlockBits readable_blocks;
96 BlockBits writable_blocks;
99 /***********************************************************
100 * Prototypes for private methods
102 static void* BIGBLOCKFILE_GetMappedView(LPBIGBLOCKFILE This,
103 DWORD page_index);
104 static void BIGBLOCKFILE_ReleaseMappedPage(LPBIGBLOCKFILE This,
105 MappedPage *page);
106 static void BIGBLOCKFILE_FreeAllMappedPages(LPBIGBLOCKFILE This);
107 static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This);
108 static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This);
109 static void* BIGBLOCKFILE_GetBigBlockPointer(LPBIGBLOCKFILE This,
110 ULONG index,
111 DWORD desired_access);
112 static MappedPage* BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This,
113 void* pBlock);
114 static MappedPage* BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This,
115 ULONG page_index);
116 static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags);
117 static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile);
118 static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt);
120 /* Note that this evaluates a and b multiple times, so don't
121 * pass expressions with side effects. */
122 #define ROUND_UP(a, b) ((((a) + (b) - 1)/(b))*(b))
124 /***********************************************************
125 * Blockbits functions.
127 static inline BOOL BIGBLOCKFILE_TestBit(const BlockBits *bb,
128 unsigned int index)
130 unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
131 unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
133 return bb->bits[array_index] & (1 << bit_index);
136 static inline void BIGBLOCKFILE_SetBit(BlockBits *bb, unsigned int index)
138 unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
139 unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
141 bb->bits[array_index] |= (1 << bit_index);
144 static inline void BIGBLOCKFILE_ClearBit(BlockBits *bb, unsigned int index)
146 unsigned int array_index = index / (CHAR_BIT * sizeof(unsigned int));
147 unsigned int bit_index = index % (CHAR_BIT * sizeof(unsigned int));
149 bb->bits[array_index] &= ~(1 << bit_index);
152 static inline void BIGBLOCKFILE_Zero(BlockBits *bb)
154 memset(bb->bits, 0, sizeof(bb->bits));
157 /******************************************************************************
158 * BIGBLOCKFILE_Construct
160 * Construct a big block file. Create the file mapping object.
161 * Create the read only mapped pages list, the writable mapped page list
162 * and the blocks in use list.
164 BigBlockFile * BIGBLOCKFILE_Construct(
165 HANDLE hFile,
166 ILockBytes* pLkByt,
167 DWORD openFlags,
168 ULONG blocksize,
169 BOOL fileBased)
171 LPBIGBLOCKFILE This;
173 This = (LPBIGBLOCKFILE)HeapAlloc(GetProcessHeap(), 0, sizeof(BigBlockFile));
175 if (This == NULL)
176 return NULL;
178 This->fileBased = fileBased;
180 This->flProtect = BIGBLOCKFILE_GetProtectMode(openFlags);
182 This->blocksize = blocksize;
184 This->maplist = NULL;
185 This->victimhead = NULL;
186 This->victimtail = NULL;
187 This->num_victim_pages = 0;
189 if (This->fileBased)
191 if (!BIGBLOCKFILE_FileInit(This, hFile))
193 HeapFree(GetProcessHeap(), 0, This);
194 return NULL;
197 else
199 if (!BIGBLOCKFILE_MemInit(This, pLkByt))
201 HeapFree(GetProcessHeap(), 0, This);
202 return NULL;
206 return This;
209 /******************************************************************************
210 * BIGBLOCKFILE_FileInit
212 * Initialize a big block object supported by a file.
214 static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile)
216 This->pLkbyt = NULL;
217 This->hbytearray = 0;
218 This->pbytearray = NULL;
220 This->hfile = hFile;
222 if (This->hfile == INVALID_HANDLE_VALUE)
223 return FALSE;
225 This->filesize.u.LowPart = GetFileSize(This->hfile,
226 &This->filesize.u.HighPart);
228 if( This->filesize.u.LowPart || This->filesize.u.HighPart )
230 /* create the file mapping object
232 This->hfilemap = CreateFileMappingA(This->hfile,
233 NULL,
234 This->flProtect,
235 0, 0,
236 NULL);
238 if (!This->hfilemap)
240 CloseHandle(This->hfile);
241 return FALSE;
244 else
245 This->hfilemap = NULL;
247 This->maplist = NULL;
249 TRACE("file len %lu\n", This->filesize.u.LowPart);
251 return TRUE;
254 /******************************************************************************
255 * BIGBLOCKFILE_MemInit
257 * Initialize a big block object supported by an ILockBytes on HGLOABL.
259 static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt)
261 This->hfile = 0;
262 This->hfilemap = 0;
265 * Retrieve the handle to the byte array from the LockByte object.
267 if (GetHGlobalFromILockBytes(plkbyt, &(This->hbytearray)) != S_OK)
269 FIXME("May not be an ILockBytes on HGLOBAL\n");
270 return FALSE;
273 This->pLkbyt = plkbyt;
276 * Increment the reference count of the ILockByte object since
277 * we're keeping a reference to it.
279 ILockBytes_AddRef(This->pLkbyt);
281 This->filesize.u.LowPart = GlobalSize(This->hbytearray);
282 This->filesize.u.HighPart = 0;
284 This->pbytearray = GlobalLock(This->hbytearray);
286 TRACE("mem on %p len %lu\n", This->pbytearray, This->filesize.u.LowPart);
288 return TRUE;
291 /******************************************************************************
292 * BIGBLOCKFILE_Destructor
294 * Destructor. Clean up, free memory.
296 void BIGBLOCKFILE_Destructor(
297 LPBIGBLOCKFILE This)
299 BIGBLOCKFILE_FreeAllMappedPages(This);
301 if (This->fileBased)
303 CloseHandle(This->hfilemap);
304 CloseHandle(This->hfile);
306 else
308 GlobalUnlock(This->hbytearray);
309 ILockBytes_Release(This->pLkbyt);
312 /* destroy this
314 HeapFree(GetProcessHeap(), 0, This);
317 /******************************************************************************
318 * BIGBLOCKFILE_GetROBigBlock
320 * Returns the specified block in read only mode.
321 * Will return NULL if the block doesn't exists.
323 void* BIGBLOCKFILE_GetROBigBlock(
324 LPBIGBLOCKFILE This,
325 ULONG index)
328 * block index starts at -1
329 * translate to zero based index
331 if (index == 0xffffffff)
332 index = 0;
333 else
334 index++;
337 * validate the block index
340 if (This->blocksize * (index + 1)
341 > ROUND_UP(This->filesize.u.LowPart, This->blocksize))
343 TRACE("out of range %lu vs %lu\n", This->blocksize * (index + 1),
344 This->filesize.u.LowPart);
345 return NULL;
348 return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_READ);
351 /******************************************************************************
352 * BIGBLOCKFILE_GetBigBlock
354 * Returns the specified block.
355 * Will grow the file if necessary.
357 void* BIGBLOCKFILE_GetBigBlock(LPBIGBLOCKFILE This, ULONG index)
360 * block index starts at -1
361 * translate to zero based index
363 if (index == 0xffffffff)
364 index = 0;
365 else
366 index++;
369 * make sure that the block physically exists
371 if ((This->blocksize * (index + 1)) > This->filesize.u.LowPart)
373 ULARGE_INTEGER newSize;
375 newSize.u.HighPart = 0;
376 newSize.u.LowPart = This->blocksize * (index + 1);
378 BIGBLOCKFILE_SetSize(This, newSize);
381 return BIGBLOCKFILE_GetBigBlockPointer(This, index, FILE_MAP_WRITE);
384 /******************************************************************************
385 * BIGBLOCKFILE_ReleaseBigBlock
387 * Releases the specified block.
389 void BIGBLOCKFILE_ReleaseBigBlock(LPBIGBLOCKFILE This, void *pBlock)
391 MappedPage *page;
393 if (pBlock == NULL)
394 return;
396 page = BIGBLOCKFILE_GetPageFromPointer(This, pBlock);
398 if (page == NULL)
399 return;
401 BIGBLOCKFILE_ReleaseMappedPage(This, page);
404 /******************************************************************************
405 * BIGBLOCKFILE_SetSize
407 * Sets the size of the file.
410 void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize)
412 if (This->filesize.u.LowPart == newSize.u.LowPart)
413 return;
415 TRACE("from %lu to %lu\n", This->filesize.u.LowPart, newSize.u.LowPart);
417 * unmap all views, must be done before call to SetEndFile
419 BIGBLOCKFILE_UnmapAllMappedPages(This);
421 if (This->fileBased)
423 char buf[10];
426 * close file-mapping object, must be done before call to SetEndFile
428 if( This->hfilemap )
429 CloseHandle(This->hfilemap);
430 This->hfilemap = 0;
433 * BEGIN HACK
434 * This fixes a bug when saving through smbfs.
435 * smbmount a Windows shared directory, save a structured storage file
436 * to that dir: crash.
438 * The problem is that the SetFilePointer-SetEndOfFile combo below
439 * doesn't always succeed. The file is not grown. It seems like the
440 * operation is cached. By doing the WriteFile, the file is actually
441 * grown on disk.
442 * This hack is only needed when saving to smbfs.
444 memset(buf, '0', 10);
445 SetFilePointer(This->hfile, newSize.u.LowPart, NULL, FILE_BEGIN);
446 WriteFile(This->hfile, buf, 10, NULL, NULL);
448 * END HACK
452 * set the new end of file
454 SetFilePointer(This->hfile, newSize.u.LowPart, NULL, FILE_BEGIN);
455 SetEndOfFile(This->hfile);
458 * re-create the file mapping object
460 This->hfilemap = CreateFileMappingA(This->hfile,
461 NULL,
462 This->flProtect,
463 0, 0,
464 NULL);
466 else
468 GlobalUnlock(This->hbytearray);
471 * Resize the byte array object.
473 ILockBytes_SetSize(This->pLkbyt, newSize);
476 * Re-acquire the handle, it may have changed.
478 GetHGlobalFromILockBytes(This->pLkbyt, &This->hbytearray);
479 This->pbytearray = GlobalLock(This->hbytearray);
482 This->filesize.u.LowPart = newSize.u.LowPart;
483 This->filesize.u.HighPart = newSize.u.HighPart;
485 BIGBLOCKFILE_RemapAllMappedPages(This);
488 /******************************************************************************
489 * BIGBLOCKFILE_GetSize
491 * Returns the size of the file.
494 ULARGE_INTEGER BIGBLOCKFILE_GetSize(LPBIGBLOCKFILE This)
496 return This->filesize;
499 /******************************************************************************
500 * BIGBLOCKFILE_AccessCheck [PRIVATE]
502 * block_index is the index within the page.
504 static BOOL BIGBLOCKFILE_AccessCheck(MappedPage *page, ULONG block_index,
505 DWORD desired_access)
507 assert(block_index < BLOCKS_PER_PAGE);
509 if (desired_access == FILE_MAP_READ)
511 if (BIGBLOCKFILE_TestBit(&page->writable_blocks, block_index))
512 return FALSE;
514 BIGBLOCKFILE_SetBit(&page->readable_blocks, block_index);
516 else
518 assert(desired_access == FILE_MAP_WRITE);
520 if (BIGBLOCKFILE_TestBit(&page->readable_blocks, block_index))
521 return FALSE;
523 BIGBLOCKFILE_SetBit(&page->writable_blocks, block_index);
526 return TRUE;
529 /******************************************************************************
530 * BIGBLOCKFILE_GetBigBlockPointer [PRIVATE]
532 * Returns a pointer to the specified block.
534 static void* BIGBLOCKFILE_GetBigBlockPointer(
535 LPBIGBLOCKFILE This,
536 ULONG block_index,
537 DWORD desired_access)
539 DWORD page_index = block_index / BLOCKS_PER_PAGE;
540 DWORD block_on_page = block_index % BLOCKS_PER_PAGE;
542 MappedPage *page = BIGBLOCKFILE_GetMappedView(This, page_index);
543 if (!page || !page->lpBytes) return NULL;
545 if (!BIGBLOCKFILE_AccessCheck(page, block_on_page, desired_access))
547 BIGBLOCKFILE_ReleaseMappedPage(This, page);
548 return NULL;
551 return (LPBYTE)page->lpBytes + (block_on_page * This->blocksize);
554 /******************************************************************************
555 * BIGBLOCKFILE_GetMappedPageFromPointer [PRIVATE]
557 * pBlock is a pointer to a block on a page.
558 * The page has to be on the in-use list. (As oppsed to the victim list.)
560 * Does not increment the usage count.
562 static MappedPage *BIGBLOCKFILE_GetPageFromPointer(LPBIGBLOCKFILE This,
563 void *pBlock)
565 MappedPage *page;
567 for (page = This->maplist; page != NULL; page = page->next)
569 if ((LPBYTE)pBlock >= (LPBYTE)page->lpBytes
570 && (LPBYTE)pBlock <= (LPBYTE)page->lpBytes + PAGE_SIZE)
571 break;
575 return page;
578 /******************************************************************************
579 * BIGBLOCKFILE_FindPageInList [PRIVATE]
582 static MappedPage *BIGBLOCKFILE_FindPageInList(MappedPage *head,
583 ULONG page_index)
585 for (; head != NULL; head = head->next)
587 if (head->page_index == page_index)
589 InterlockedIncrement(&head->refcnt);
590 break;
594 return head;
598 static void BIGBLOCKFILE_UnlinkPage(MappedPage *page)
600 if (page->next) page->next->prev = page->prev;
601 if (page->prev) page->prev->next = page->next;
604 static void BIGBLOCKFILE_LinkHeadPage(MappedPage **head, MappedPage *page)
606 if (*head) (*head)->prev = page;
607 page->next = *head;
608 page->prev = NULL;
609 *head = page;
612 /******************************************************************************
613 * BIGBLOCKFILE_GetMappedView [PRIVATE]
615 * Gets the page requested if it is already mapped.
616 * If it's not already mapped, this method will map it
618 static void * BIGBLOCKFILE_GetMappedView(
619 LPBIGBLOCKFILE This,
620 DWORD page_index)
622 MappedPage *page;
624 page = BIGBLOCKFILE_FindPageInList(This->maplist, page_index);
625 if (!page)
627 page = BIGBLOCKFILE_FindPageInList(This->victimhead, page_index);
628 if (page)
630 This->num_victim_pages--;
632 BIGBLOCKFILE_Zero(&page->readable_blocks);
633 BIGBLOCKFILE_Zero(&page->writable_blocks);
637 if (page)
639 /* If the page is not already at the head of the list, move
640 * it there. (Also moves pages from victim to main list.) */
641 if (This->maplist != page)
643 if (This->victimhead == page) This->victimhead = page->next;
644 if (This->victimtail == page) This->victimtail = page->prev;
646 BIGBLOCKFILE_UnlinkPage(page);
648 BIGBLOCKFILE_LinkHeadPage(&This->maplist, page);
651 return page;
654 page = BIGBLOCKFILE_CreatePage(This, page_index);
655 if (!page) return NULL;
657 BIGBLOCKFILE_LinkHeadPage(&This->maplist, page);
659 return page;
662 static BOOL BIGBLOCKFILE_MapPage(LPBIGBLOCKFILE This, MappedPage *page)
664 DWORD lowoffset = PAGE_SIZE * page->page_index;
666 if (This->fileBased)
668 DWORD numBytesToMap;
669 DWORD desired_access;
671 if( !This->hfilemap )
672 return FALSE;
674 if (lowoffset + PAGE_SIZE > This->filesize.u.LowPart)
675 numBytesToMap = This->filesize.u.LowPart - lowoffset;
676 else
677 numBytesToMap = PAGE_SIZE;
679 if (This->flProtect == PAGE_READONLY)
680 desired_access = FILE_MAP_READ;
681 else
682 desired_access = FILE_MAP_WRITE;
684 page->lpBytes = MapViewOfFile(This->hfilemap, desired_access, 0,
685 lowoffset, numBytesToMap);
687 else
689 page->lpBytes = (LPBYTE)This->pbytearray + lowoffset;
692 TRACE("mapped page %lu to %p\n", page->page_index, page->lpBytes);
694 return page->lpBytes != NULL;
697 static MappedPage *BIGBLOCKFILE_CreatePage(LPBIGBLOCKFILE This,
698 ULONG page_index)
700 MappedPage *page;
702 page = HeapAlloc(GetProcessHeap(), 0, sizeof(MappedPage));
703 if (page == NULL)
704 return NULL;
706 page->page_index = page_index;
707 page->refcnt = 1;
709 page->next = NULL;
710 page->prev = NULL;
712 BIGBLOCKFILE_MapPage(This, page);
714 BIGBLOCKFILE_Zero(&page->readable_blocks);
715 BIGBLOCKFILE_Zero(&page->writable_blocks);
717 return page;
720 static void BIGBLOCKFILE_UnmapPage(LPBIGBLOCKFILE This, MappedPage *page)
722 TRACE("%ld at %p\n", page->page_index, page->lpBytes);
723 if (page->refcnt > 0)
724 ERR("unmapping inuse page %p\n", page->lpBytes);
726 if (This->fileBased && page->lpBytes)
727 UnmapViewOfFile(page->lpBytes);
729 page->lpBytes = NULL;
732 static void BIGBLOCKFILE_DeletePage(LPBIGBLOCKFILE This, MappedPage *page)
734 BIGBLOCKFILE_UnmapPage(This, page);
736 HeapFree(GetProcessHeap(), 0, page);
739 /******************************************************************************
740 * BIGBLOCKFILE_ReleaseMappedPage [PRIVATE]
742 * Decrements the reference count of the mapped page.
744 static void BIGBLOCKFILE_ReleaseMappedPage(
745 LPBIGBLOCKFILE This,
746 MappedPage *page)
748 assert(This != NULL);
749 assert(page != NULL);
751 /* If the page is no longer refenced, move it to the victim list.
752 * If the victim list is too long, kick somebody off. */
753 if (!InterlockedDecrement(&page->refcnt))
755 if (This->maplist == page) This->maplist = page->next;
757 BIGBLOCKFILE_UnlinkPage(page);
759 if (MAX_VICTIM_PAGES > 0)
761 if (This->num_victim_pages >= MAX_VICTIM_PAGES)
763 MappedPage *victim = This->victimtail;
764 if (victim)
766 This->victimtail = victim->prev;
767 if (This->victimhead == victim)
768 This->victimhead = victim->next;
770 BIGBLOCKFILE_UnlinkPage(victim);
771 BIGBLOCKFILE_DeletePage(This, victim);
774 else This->num_victim_pages++;
776 BIGBLOCKFILE_LinkHeadPage(&This->victimhead, page);
777 if (This->victimtail == NULL) This->victimtail = page;
779 else
780 BIGBLOCKFILE_DeletePage(This, page);
784 static void BIGBLOCKFILE_DeleteList(LPBIGBLOCKFILE This, MappedPage *list)
786 while (list != NULL)
788 MappedPage *next = list->next;
790 BIGBLOCKFILE_DeletePage(This, list);
792 list = next;
796 /******************************************************************************
797 * BIGBLOCKFILE_FreeAllMappedPages [PRIVATE]
799 * Unmap all currently mapped pages.
800 * Empty mapped pages list.
802 static void BIGBLOCKFILE_FreeAllMappedPages(
803 LPBIGBLOCKFILE This)
805 BIGBLOCKFILE_DeleteList(This, This->maplist);
806 BIGBLOCKFILE_DeleteList(This, This->victimhead);
808 This->maplist = NULL;
809 This->victimhead = NULL;
810 This->victimtail = NULL;
811 This->num_victim_pages = 0;
814 static void BIGBLOCKFILE_UnmapList(LPBIGBLOCKFILE This, MappedPage *list)
816 for (; list != NULL; list = list->next)
818 BIGBLOCKFILE_UnmapPage(This, list);
822 static void BIGBLOCKFILE_UnmapAllMappedPages(LPBIGBLOCKFILE This)
824 BIGBLOCKFILE_UnmapList(This, This->maplist);
825 BIGBLOCKFILE_UnmapList(This, This->victimhead);
828 static void BIGBLOCKFILE_RemapList(LPBIGBLOCKFILE This, MappedPage *list)
830 while (list != NULL)
832 MappedPage *next = list->next;
834 if (list->page_index * PAGE_SIZE > This->filesize.u.LowPart)
836 TRACE("discarding %lu\n", list->page_index);
838 /* page is entirely outside of the file, delete it */
839 BIGBLOCKFILE_UnlinkPage(list);
840 BIGBLOCKFILE_DeletePage(This, list);
842 else
844 /* otherwise, remap it */
845 BIGBLOCKFILE_MapPage(This, list);
848 list = next;
852 static void BIGBLOCKFILE_RemapAllMappedPages(LPBIGBLOCKFILE This)
854 BIGBLOCKFILE_RemapList(This, This->maplist);
855 BIGBLOCKFILE_RemapList(This, This->victimhead);
858 /****************************************************************************
859 * BIGBLOCKFILE_GetProtectMode
861 * This function will return a protection mode flag for a file-mapping object
862 * from the open flags of a file.
864 static DWORD BIGBLOCKFILE_GetProtectMode(DWORD openFlags)
866 if (openFlags & (STGM_WRITE | STGM_READWRITE))
867 return PAGE_READWRITE;
868 else
869 return PAGE_READONLY;