3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * PROJECT: ReactOS kernel
21 * FILE: ntoskrnl/mm/pagefile.c
22 * PURPOSE: Paging file functions
23 * PROGRAMMER: David Welch (welch@mcmail.com)
28 /* INCLUDES *****************************************************************/
34 #if defined (ALLOC_PRAGMA)
35 #pragma alloc_text(INIT, MmInitPagingFile)
40 MiFindExportedRoutineByName(IN PVOID DllBase
,
41 IN PANSI_STRING ExportName
);
43 /* TYPES *********************************************************************/
45 typedef struct _PAGINGFILE
47 LIST_ENTRY PagingFileListEntry
;
48 PFILE_OBJECT FileObject
;
49 LARGE_INTEGER MaximumSize
;
50 LARGE_INTEGER CurrentSize
;
54 KSPIN_LOCK AllocMapLock
;
56 PRETRIEVAL_POINTERS_BUFFER RetrievalPointers
;
58 PAGINGFILE
, *PPAGINGFILE
;
60 typedef struct _RETRIEVEL_DESCRIPTOR_LIST
62 struct _RETRIEVEL_DESCRIPTOR_LIST
* Next
;
63 RETRIEVAL_POINTERS_BUFFER RetrievalPointers
;
65 RETRIEVEL_DESCRIPTOR_LIST
, *PRETRIEVEL_DESCRIPTOR_LIST
;
67 /* GLOBALS *******************************************************************/
69 #define PAIRS_PER_RUN (1024)
71 #define MAX_PAGING_FILES (32)
73 /* List of paging files, both used and free */
74 static PPAGINGFILE PagingFileList
[MAX_PAGING_FILES
];
76 /* Lock for examining the list of paging files */
77 static KSPIN_LOCK PagingFileListLock
;
79 /* Number of paging files */
80 static ULONG MiPagingFileCount
;
81 ULONG MmNumberOfPagingFiles
;
83 /* Number of pages that are available for swapping */
84 PFN_NUMBER MiFreeSwapPages
;
86 /* Number of pages that have been allocated for swapping */
87 PFN_NUMBER MiUsedSwapPages
;
89 BOOLEAN MmZeroPageFile
;
92 * Number of pages that have been reserved for swapping but not yet allocated
94 static PFN_NUMBER MiReservedSwapPages
;
97 * Ratio between reserved and available swap pages, e.g. setting this to five
98 * forces one swap page to be available for every five swap pages that are
99 * reserved. Setting this to zero turns off commit checking altogether.
101 #define MM_PAGEFILE_COMMIT_RATIO (1)
104 * Number of pages that can be used for potentially swapable memory without
105 * pagefile space being reserved. The intention is that this allows smss
106 * to start up and create page files while ordinarily having a commit
109 #define MM_PAGEFILE_COMMIT_GRACE (256)
112 * Translate between a swap entry and a file and offset pair.
114 #define FILE_FROM_ENTRY(i) ((i) & 0x0f)
115 #define OFFSET_FROM_ENTRY(i) ((i) >> 11)
116 #define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | (j) << 11 | 0x400)
118 static BOOLEAN MmSwapSpaceMessage
= FALSE
;
120 /* FUNCTIONS *****************************************************************/
124 MmBuildMdlFromPages(PMDL Mdl
, PPFN_NUMBER Pages
)
126 memcpy(Mdl
+ 1, Pages
, sizeof(PFN_NUMBER
) * (PAGE_ROUND_UP(Mdl
->ByteOffset
+Mdl
->ByteCount
)/PAGE_SIZE
));
128 /* FIXME: this flag should be set by the caller perhaps? */
129 Mdl
->MdlFlags
|= MDL_IO_PAGE_READ
;
135 MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject
)
139 /* Loop through all the paging files */
140 for (i
= 0; i
< MiPagingFileCount
; i
++)
142 /* Check if this is one of them */
143 if (PagingFileList
[i
]->FileObject
== FileObject
) return TRUE
;
152 MmShowOutOfSpaceMessagePagingFile(VOID
)
154 if (!MmSwapSpaceMessage
)
156 DPRINT1("MM: Out of swap space.\n");
157 MmSwapSpaceMessage
= TRUE
;
162 MmGetOffsetPageFile(PRETRIEVAL_POINTERS_BUFFER RetrievalPointers
, LARGE_INTEGER Offset
)
164 /* Simple binary search */
165 ULONG first
, last
, mid
;
167 last
= RetrievalPointers
->ExtentCount
- 1;
168 while (first
<= last
)
170 mid
= (last
- first
) / 2 + first
;
171 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
)
175 Offset
.QuadPart
+= RetrievalPointers
->Extents
[0].Lcn
.QuadPart
- RetrievalPointers
->StartingVcn
.QuadPart
;
180 if (Offset
.QuadPart
>= RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
)
182 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
;
190 if (mid
== RetrievalPointers
->ExtentCount
- 1)
194 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
+1].NextVcn
.QuadPart
)
196 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
+1].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
;
202 KeBugCheck(MEMORY_MANAGEMENT
);
203 #if defined(__GNUC__)
205 return (LARGE_INTEGER
)0LL;
209 const LARGE_INTEGER dummy
=
220 MmWriteToSwapPage(SWAPENTRY SwapEntry
, PFN_NUMBER Page
)
223 LARGE_INTEGER file_offset
;
224 IO_STATUS_BLOCK Iosb
;
227 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
228 PMDL Mdl
= (PMDL
)MdlBase
;
230 DPRINT("MmWriteToSwapPage\n");
234 KeBugCheck(MEMORY_MANAGEMENT
);
235 return(STATUS_UNSUCCESSFUL
);
238 i
= FILE_FROM_ENTRY(SwapEntry
);
239 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
241 if (i
>= MAX_PAGING_FILES
)
243 DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry
);
244 KeBugCheck(MEMORY_MANAGEMENT
);
246 if (PagingFileList
[i
]->FileObject
== NULL
||
247 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
249 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
250 KeBugCheck(MEMORY_MANAGEMENT
);
253 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
254 MmBuildMdlFromPages(Mdl
, &Page
);
255 MmReferencePage(Page
);
256 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
258 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
259 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
261 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
262 Status
= IoSynchronousPageWrite(PagingFileList
[i
]->FileObject
,
267 if (Status
== STATUS_PENDING
)
269 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
270 Status
= Iosb
.Status
;
273 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
275 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
282 MmReadFromSwapPage(SWAPENTRY SwapEntry
, PFN_NUMBER Page
)
285 LARGE_INTEGER file_offset
;
286 IO_STATUS_BLOCK Iosb
;
289 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
290 PMDL Mdl
= (PMDL
)MdlBase
;
292 DPRINT("MmReadFromSwapPage\n");
296 KeBugCheck(MEMORY_MANAGEMENT
);
297 return(STATUS_UNSUCCESSFUL
);
300 i
= FILE_FROM_ENTRY(SwapEntry
);
301 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
303 if (i
>= MAX_PAGING_FILES
)
305 DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry
);
306 KeBugCheck(MEMORY_MANAGEMENT
);
308 if (PagingFileList
[i
]->FileObject
== NULL
||
309 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
311 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
312 KeBugCheck(MEMORY_MANAGEMENT
);
315 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
316 MmBuildMdlFromPages(Mdl
, &Page
);
317 MmReferencePage(Page
);
318 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
320 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
321 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
323 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
324 Status
= IoPageRead(PagingFileList
[i
]->FileObject
,
329 if (Status
== STATUS_PENDING
)
331 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
332 Status
= Iosb
.Status
;
334 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
336 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
344 MmInitPagingFile(VOID
)
348 KeInitializeSpinLock(&PagingFileListLock
);
352 MiReservedSwapPages
= 0;
354 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
356 PagingFileList
[i
] = NULL
;
358 MiPagingFileCount
= 0;
363 MmReserveSwapPages(ULONG Nr
)
366 ULONG MiAvailSwapPages
;
368 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
370 (MiFreeSwapPages
* MM_PAGEFILE_COMMIT_RATIO
) + MM_PAGEFILE_COMMIT_GRACE
;
371 MiReservedSwapPages
= MiReservedSwapPages
+ Nr
;
372 if ((MM_PAGEFILE_COMMIT_RATIO
!= 0) && (MiAvailSwapPages
< MiReservedSwapPages
))
374 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
377 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
383 MmDereserveSwapPages(ULONG Nr
)
387 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
388 MiReservedSwapPages
= MiReservedSwapPages
- Nr
;
389 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
393 MiAllocPageFromPagingFile(PPAGINGFILE PagingFile
)
398 KeAcquireSpinLock(&PagingFile
->AllocMapLock
, &oldIrql
);
400 for (i
= 0; i
< PagingFile
->AllocMapSize
; i
++)
402 for (j
= 0; j
< 32; j
++)
404 if (!(PagingFile
->AllocMap
[i
] & (1 << j
)))
406 PagingFile
->AllocMap
[i
] |= (1 << j
);
407 PagingFile
->UsedPages
++;
408 PagingFile
->FreePages
--;
409 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
410 return((i
* 32) + j
);
415 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
421 MmFreeSwapPage(SWAPENTRY Entry
)
427 i
= FILE_FROM_ENTRY(Entry
);
428 off
= OFFSET_FROM_ENTRY(Entry
);
430 if (i
>= MAX_PAGING_FILES
)
432 DPRINT1("Bad swap entry 0x%.8X\n", Entry
);
433 KeBugCheck(MEMORY_MANAGEMENT
);
436 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
437 if (PagingFileList
[i
] == NULL
)
439 KeBugCheck(MEMORY_MANAGEMENT
);
441 KeAcquireSpinLockAtDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
443 PagingFileList
[i
]->AllocMap
[off
>> 5] &= (~(1 << (off
% 32)));
445 PagingFileList
[i
]->FreePages
++;
446 PagingFileList
[i
]->UsedPages
--;
451 KeReleaseSpinLockFromDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
452 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
457 MmIsAvailableSwapPage(VOID
)
459 return(MiFreeSwapPages
> 0);
464 MmAllocSwapPage(VOID
)
471 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
473 if (MiFreeSwapPages
== 0)
475 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
479 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
481 if (PagingFileList
[i
] != NULL
&&
482 PagingFileList
[i
]->FreePages
>= 1)
484 off
= MiAllocPageFromPagingFile(PagingFileList
[i
]);
485 if (off
== 0xFFFFFFFF)
487 KeBugCheck(MEMORY_MANAGEMENT
);
488 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
489 return(STATUS_UNSUCCESSFUL
);
493 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
495 entry
= ENTRY_FROM_FILE_OFFSET(i
, off
);
500 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
501 KeBugCheck(MEMORY_MANAGEMENT
);
505 static PRETRIEVEL_DESCRIPTOR_LIST FASTCALL
506 MmAllocRetrievelDescriptorList(ULONG Pairs
)
509 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
511 Size
= sizeof(RETRIEVEL_DESCRIPTOR_LIST
) + Pairs
* 2 * sizeof(LARGE_INTEGER
);
512 RetDescList
= ExAllocatePool(NonPagedPool
, Size
);
515 RtlZeroMemory(RetDescList
, Size
);
522 NtCreatePagingFile(IN PUNICODE_STRING FileName
,
523 IN PLARGE_INTEGER InitialSize
,
524 IN PLARGE_INTEGER MaximumSize
,
528 OBJECT_ATTRIBUTES ObjectAttributes
;
530 IO_STATUS_BLOCK IoStatus
;
531 PFILE_OBJECT FileObject
;
532 PPAGINGFILE PagingFile
;
535 FILE_FS_SIZE_INFORMATION FsSizeInformation
;
536 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
537 PRETRIEVEL_DESCRIPTOR_LIST CurrentRetDescList
;
539 ULONG BytesPerAllocationUnit
;
542 LARGE_INTEGER MaxVcn
;
545 KPROCESSOR_MODE PreviousMode
;
546 UNICODE_STRING CapturedFileName
;
547 LARGE_INTEGER SafeInitialSize
, SafeMaximumSize
;
549 DPRINT("NtCreatePagingFile(FileName %wZ, InitialSize %I64d)\n",
550 FileName
, InitialSize
->QuadPart
);
552 if (MiPagingFileCount
>= MAX_PAGING_FILES
)
554 return(STATUS_TOO_MANY_PAGING_FILES
);
557 PreviousMode
= ExGetPreviousMode();
559 if (PreviousMode
!= KernelMode
)
563 SafeInitialSize
= ProbeForReadLargeInteger(InitialSize
);
564 SafeMaximumSize
= ProbeForReadLargeInteger(MaximumSize
);
566 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
568 /* Return the exception code */
569 _SEH2_YIELD(return _SEH2_GetExceptionCode());
575 SafeInitialSize
= *InitialSize
;
576 SafeMaximumSize
= *MaximumSize
;
579 /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
580 smaller than the maximum */
581 if (0 != SafeInitialSize
.u
.HighPart
)
583 return STATUS_INVALID_PARAMETER_2
;
585 if (0 != SafeMaximumSize
.u
.HighPart
)
587 return STATUS_INVALID_PARAMETER_3
;
589 if (SafeMaximumSize
.u
.LowPart
< SafeInitialSize
.u
.LowPart
)
591 return STATUS_INVALID_PARAMETER_MIX
;
594 Status
= ProbeAndCaptureUnicodeString(&CapturedFileName
,
597 if (!NT_SUCCESS(Status
))
602 InitializeObjectAttributes(&ObjectAttributes
,
608 Status
= IoCreateFile(&FileHandle
,
616 FILE_SYNCHRONOUS_IO_NONALERT
,
621 SL_OPEN_PAGING_FILE
| IO_NO_PARAMETER_CHECKING
);
623 ReleaseCapturedUnicodeString(&CapturedFileName
,
625 if (!NT_SUCCESS(Status
))
630 Status
= ZwQueryVolumeInformationFile(FileHandle
,
633 sizeof(FILE_FS_SIZE_INFORMATION
),
634 FileFsSizeInformation
);
635 if (!NT_SUCCESS(Status
))
641 BytesPerAllocationUnit
= FsSizeInformation
.SectorsPerAllocationUnit
*
642 FsSizeInformation
.BytesPerSector
;
643 /* FIXME: If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
644 * a problem if the paging file is fragmented. Suppose the first cluster
645 * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
646 * paging file but of another file. We can't write a complete page (4096
647 * bytes) to the physical location of cluster 3042 then. */
648 if (BytesPerAllocationUnit
% PAGE_SIZE
)
650 DPRINT1("BytesPerAllocationUnit %d is not a multiple of PAGE_SIZE %d\n",
651 BytesPerAllocationUnit
, PAGE_SIZE
);
653 return STATUS_UNSUCCESSFUL
;
656 Status
= ZwSetInformationFile(FileHandle
,
659 sizeof(LARGE_INTEGER
),
660 FileAllocationInformation
);
661 if (!NT_SUCCESS(Status
))
667 Status
= ObReferenceObjectByHandle(FileHandle
,
673 if (!NT_SUCCESS(Status
))
679 CurrentRetDescList
= RetDescList
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
681 if (CurrentRetDescList
== NULL
)
683 ObDereferenceObject(FileObject
);
685 return(STATUS_NO_MEMORY
);
688 #if defined(__GNUC__)
696 MaxVcn
.QuadPart
= (SafeInitialSize
.QuadPart
+ BytesPerAllocationUnit
- 1) / BytesPerAllocationUnit
;
699 Status
= ZwFsControlFile(FileHandle
,
704 FSCTL_GET_RETRIEVAL_POINTERS
,
706 sizeof(LARGE_INTEGER
),
707 &CurrentRetDescList
->RetrievalPointers
,
708 sizeof(RETRIEVAL_POINTERS_BUFFER
) + PAIRS_PER_RUN
* 2 * sizeof(LARGE_INTEGER
));
709 if (!NT_SUCCESS(Status
))
713 CurrentRetDescList
= RetDescList
;
714 RetDescList
= RetDescList
->Next
;
715 ExFreePool(CurrentRetDescList
);
717 ObDereferenceObject(FileObject
);
721 ExtentCount
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
722 if (CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
.QuadPart
< MaxVcn
.QuadPart
)
724 CurrentRetDescList
->Next
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
725 if (CurrentRetDescList
->Next
== NULL
)
729 CurrentRetDescList
= RetDescList
;
730 RetDescList
= RetDescList
->Next
;
731 ExFreePool(CurrentRetDescList
);
733 ObDereferenceObject(FileObject
);
735 return(STATUS_NO_MEMORY
);
737 Vcn
= CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
;
738 CurrentRetDescList
= CurrentRetDescList
->Next
;
746 PagingFile
= ExAllocatePool(NonPagedPool
, sizeof(*PagingFile
));
747 if (PagingFile
== NULL
)
751 CurrentRetDescList
= RetDescList
;
752 RetDescList
= RetDescList
->Next
;
753 ExFreePool(CurrentRetDescList
);
755 ObDereferenceObject(FileObject
);
757 return(STATUS_NO_MEMORY
);
760 RtlZeroMemory(PagingFile
, sizeof(*PagingFile
));
762 PagingFile
->FileObject
= FileObject
;
763 PagingFile
->MaximumSize
.QuadPart
= SafeMaximumSize
.QuadPart
;
764 PagingFile
->CurrentSize
.QuadPart
= SafeInitialSize
.QuadPart
;
765 PagingFile
->FreePages
= (ULONG
)(SafeInitialSize
.QuadPart
/ PAGE_SIZE
);
766 PagingFile
->UsedPages
= 0;
767 KeInitializeSpinLock(&PagingFile
->AllocMapLock
);
769 AllocMapSize
= (PagingFile
->FreePages
/ 32) + 1;
770 PagingFile
->AllocMap
= ExAllocatePool(NonPagedPool
,
771 AllocMapSize
* sizeof(ULONG
));
772 PagingFile
->AllocMapSize
= AllocMapSize
;
774 if (PagingFile
->AllocMap
== NULL
)
778 CurrentRetDescList
= RetDescList
;
779 RetDescList
= RetDescList
->Next
;
780 ExFreePool(CurrentRetDescList
);
782 ExFreePool(PagingFile
);
783 ObDereferenceObject(FileObject
);
785 return(STATUS_NO_MEMORY
);
787 DPRINT("ExtentCount: %d\n", ExtentCount
);
788 Size
= sizeof(RETRIEVAL_POINTERS_BUFFER
) + ExtentCount
* 2 * sizeof(LARGE_INTEGER
);
789 PagingFile
->RetrievalPointers
= ExAllocatePool(NonPagedPool
, Size
);
790 if (PagingFile
->RetrievalPointers
== NULL
)
794 CurrentRetDescList
= RetDescList
;
795 RetDescList
= RetDescList
->Next
;
796 ExFreePool(CurrentRetDescList
);
798 ExFreePool(PagingFile
->AllocMap
);
799 ExFreePool(PagingFile
);
800 ObDereferenceObject(FileObject
);
802 return(STATUS_NO_MEMORY
);
805 RtlZeroMemory(PagingFile
->AllocMap
, AllocMapSize
* sizeof(ULONG
));
806 RtlZeroMemory(PagingFile
->RetrievalPointers
, Size
);
809 PagingFile
->RetrievalPointers
->ExtentCount
= ExtentCount
;
810 PagingFile
->RetrievalPointers
->StartingVcn
= RetDescList
->RetrievalPointers
.StartingVcn
;
811 CurrentRetDescList
= RetDescList
;
812 while (CurrentRetDescList
)
814 memcpy(&PagingFile
->RetrievalPointers
->Extents
[Count
],
815 CurrentRetDescList
->RetrievalPointers
.Extents
,
816 CurrentRetDescList
->RetrievalPointers
.ExtentCount
* 2 * sizeof(LARGE_INTEGER
));
817 Count
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
818 RetDescList
= CurrentRetDescList
;
819 CurrentRetDescList
= CurrentRetDescList
->Next
;
820 ExFreePool(RetDescList
);
823 if (PagingFile
->RetrievalPointers
->ExtentCount
!= ExtentCount
||
824 PagingFile
->RetrievalPointers
->Extents
[ExtentCount
- 1].NextVcn
.QuadPart
!= MaxVcn
.QuadPart
)
826 ExFreePool(PagingFile
->RetrievalPointers
);
827 ExFreePool(PagingFile
->AllocMap
);
828 ExFreePool(PagingFile
);
829 ObDereferenceObject(FileObject
);
831 return(STATUS_UNSUCCESSFUL
);
835 * Change the entries from lcn's to volume offset's.
837 PagingFile
->RetrievalPointers
->StartingVcn
.QuadPart
*= BytesPerAllocationUnit
;
838 for (i
= 0; i
< ExtentCount
; i
++)
840 PagingFile
->RetrievalPointers
->Extents
[i
].Lcn
.QuadPart
*= BytesPerAllocationUnit
;
841 PagingFile
->RetrievalPointers
->Extents
[i
].NextVcn
.QuadPart
*= BytesPerAllocationUnit
;
844 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
845 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
847 if (PagingFileList
[i
] == NULL
)
849 PagingFileList
[i
] = PagingFile
;
853 MiFreeSwapPages
= MiFreeSwapPages
+ PagingFile
->FreePages
;
855 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
859 MmSwapSpaceMessage
= FALSE
;
861 return(STATUS_SUCCESS
);