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 MmIsFileAPagingFile(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 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
257 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
258 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
260 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
261 Status
= IoSynchronousPageWrite(PagingFileList
[i
]->FileObject
,
266 if (Status
== STATUS_PENDING
)
268 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
269 Status
= Iosb
.Status
;
272 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
274 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
281 MmReadFromSwapPage(SWAPENTRY SwapEntry
, PFN_NUMBER Page
)
284 LARGE_INTEGER file_offset
;
285 IO_STATUS_BLOCK Iosb
;
288 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
289 PMDL Mdl
= (PMDL
)MdlBase
;
291 DPRINT("MmReadFromSwapPage\n");
295 KeBugCheck(MEMORY_MANAGEMENT
);
296 return(STATUS_UNSUCCESSFUL
);
299 i
= FILE_FROM_ENTRY(SwapEntry
);
300 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
302 if (i
>= MAX_PAGING_FILES
)
304 DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry
);
305 KeBugCheck(MEMORY_MANAGEMENT
);
307 if (PagingFileList
[i
]->FileObject
== NULL
||
308 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
310 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
311 KeBugCheck(MEMORY_MANAGEMENT
);
314 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
315 MmBuildMdlFromPages(Mdl
, &Page
);
316 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
318 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
319 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
321 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
322 Status
= IoPageRead(PagingFileList
[i
]->FileObject
,
327 if (Status
== STATUS_PENDING
)
329 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
330 Status
= Iosb
.Status
;
332 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
334 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
342 MmInitPagingFile(VOID
)
346 KeInitializeSpinLock(&PagingFileListLock
);
350 MiReservedSwapPages
= 0;
352 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
354 PagingFileList
[i
] = NULL
;
356 MiPagingFileCount
= 0;
361 MmReserveSwapPages(ULONG Nr
)
364 ULONG MiAvailSwapPages
;
366 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
368 (MiFreeSwapPages
* MM_PAGEFILE_COMMIT_RATIO
) + MM_PAGEFILE_COMMIT_GRACE
;
369 MiReservedSwapPages
= MiReservedSwapPages
+ Nr
;
370 if ((MM_PAGEFILE_COMMIT_RATIO
!= 0) && (MiAvailSwapPages
< MiReservedSwapPages
))
372 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
375 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
381 MmDereserveSwapPages(ULONG Nr
)
385 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
386 MiReservedSwapPages
= MiReservedSwapPages
- Nr
;
387 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
391 MiAllocPageFromPagingFile(PPAGINGFILE PagingFile
)
396 KeAcquireSpinLock(&PagingFile
->AllocMapLock
, &oldIrql
);
398 for (i
= 0; i
< PagingFile
->AllocMapSize
; i
++)
400 for (j
= 0; j
< 32; j
++)
402 if (!(PagingFile
->AllocMap
[i
] & (1 << j
)))
404 PagingFile
->AllocMap
[i
] |= (1 << j
);
405 PagingFile
->UsedPages
++;
406 PagingFile
->FreePages
--;
407 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
408 return((i
* 32) + j
);
413 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
419 MmFreeSwapPage(SWAPENTRY Entry
)
425 i
= FILE_FROM_ENTRY(Entry
);
426 off
= OFFSET_FROM_ENTRY(Entry
);
428 if (i
>= MAX_PAGING_FILES
)
430 DPRINT1("Bad swap entry 0x%.8X\n", Entry
);
431 KeBugCheck(MEMORY_MANAGEMENT
);
434 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
435 if (PagingFileList
[i
] == NULL
)
437 KeBugCheck(MEMORY_MANAGEMENT
);
439 KeAcquireSpinLockAtDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
441 PagingFileList
[i
]->AllocMap
[off
>> 5] &= (~(1 << (off
% 32)));
443 PagingFileList
[i
]->FreePages
++;
444 PagingFileList
[i
]->UsedPages
--;
449 KeReleaseSpinLockFromDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
450 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
455 MmIsAvailableSwapPage(VOID
)
457 return(MiFreeSwapPages
> 0);
462 MmAllocSwapPage(VOID
)
469 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
471 if (MiFreeSwapPages
== 0)
473 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
477 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
479 if (PagingFileList
[i
] != NULL
&&
480 PagingFileList
[i
]->FreePages
>= 1)
482 off
= MiAllocPageFromPagingFile(PagingFileList
[i
]);
483 if (off
== 0xFFFFFFFF)
485 KeBugCheck(MEMORY_MANAGEMENT
);
486 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
487 return(STATUS_UNSUCCESSFUL
);
491 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
493 entry
= ENTRY_FROM_FILE_OFFSET(i
, off
);
498 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
499 KeBugCheck(MEMORY_MANAGEMENT
);
503 static PRETRIEVEL_DESCRIPTOR_LIST FASTCALL
504 MmAllocRetrievelDescriptorList(ULONG Pairs
)
507 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
509 Size
= sizeof(RETRIEVEL_DESCRIPTOR_LIST
) + Pairs
* 2 * sizeof(LARGE_INTEGER
);
510 RetDescList
= ExAllocatePool(NonPagedPool
, Size
);
513 RtlZeroMemory(RetDescList
, Size
);
520 NtCreatePagingFile(IN PUNICODE_STRING FileName
,
521 IN PLARGE_INTEGER InitialSize
,
522 IN PLARGE_INTEGER MaximumSize
,
526 OBJECT_ATTRIBUTES ObjectAttributes
;
528 IO_STATUS_BLOCK IoStatus
;
529 PFILE_OBJECT FileObject
;
530 PPAGINGFILE PagingFile
;
533 FILE_FS_SIZE_INFORMATION FsSizeInformation
;
534 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
535 PRETRIEVEL_DESCRIPTOR_LIST CurrentRetDescList
;
537 ULONG BytesPerAllocationUnit
;
540 LARGE_INTEGER MaxVcn
;
543 KPROCESSOR_MODE PreviousMode
;
544 UNICODE_STRING CapturedFileName
;
545 LARGE_INTEGER SafeInitialSize
, SafeMaximumSize
;
547 DPRINT("NtCreatePagingFile(FileName %wZ, InitialSize %I64d)\n",
548 FileName
, InitialSize
->QuadPart
);
550 if (MiPagingFileCount
>= MAX_PAGING_FILES
)
552 return(STATUS_TOO_MANY_PAGING_FILES
);
555 PreviousMode
= ExGetPreviousMode();
557 if (PreviousMode
!= KernelMode
)
561 SafeInitialSize
= ProbeForReadLargeInteger(InitialSize
);
562 SafeMaximumSize
= ProbeForReadLargeInteger(MaximumSize
);
564 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
566 /* Return the exception code */
567 _SEH2_YIELD(return _SEH2_GetExceptionCode());
573 SafeInitialSize
= *InitialSize
;
574 SafeMaximumSize
= *MaximumSize
;
577 /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
578 smaller than the maximum */
579 if (0 != SafeInitialSize
.u
.HighPart
)
581 return STATUS_INVALID_PARAMETER_2
;
583 if (0 != SafeMaximumSize
.u
.HighPart
)
585 return STATUS_INVALID_PARAMETER_3
;
587 if (SafeMaximumSize
.u
.LowPart
< SafeInitialSize
.u
.LowPart
)
589 return STATUS_INVALID_PARAMETER_MIX
;
592 Status
= ProbeAndCaptureUnicodeString(&CapturedFileName
,
595 if (!NT_SUCCESS(Status
))
600 InitializeObjectAttributes(&ObjectAttributes
,
606 Status
= IoCreateFile(&FileHandle
,
614 FILE_SYNCHRONOUS_IO_NONALERT
,
619 SL_OPEN_PAGING_FILE
| IO_NO_PARAMETER_CHECKING
);
621 ReleaseCapturedUnicodeString(&CapturedFileName
,
623 if (!NT_SUCCESS(Status
))
628 Status
= ZwQueryVolumeInformationFile(FileHandle
,
631 sizeof(FILE_FS_SIZE_INFORMATION
),
632 FileFsSizeInformation
);
633 if (!NT_SUCCESS(Status
))
639 BytesPerAllocationUnit
= FsSizeInformation
.SectorsPerAllocationUnit
*
640 FsSizeInformation
.BytesPerSector
;
641 /* FIXME: If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
642 * a problem if the paging file is fragmented. Suppose the first cluster
643 * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
644 * paging file but of another file. We can't write a complete page (4096
645 * bytes) to the physical location of cluster 3042 then. */
646 if (BytesPerAllocationUnit
% PAGE_SIZE
)
648 DPRINT1("BytesPerAllocationUnit %d is not a multiple of PAGE_SIZE %d\n",
649 BytesPerAllocationUnit
, PAGE_SIZE
);
651 return STATUS_UNSUCCESSFUL
;
654 Status
= ZwSetInformationFile(FileHandle
,
657 sizeof(LARGE_INTEGER
),
658 FileAllocationInformation
);
659 if (!NT_SUCCESS(Status
))
665 Status
= ObReferenceObjectByHandle(FileHandle
,
671 if (!NT_SUCCESS(Status
))
677 CurrentRetDescList
= RetDescList
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
679 if (CurrentRetDescList
== NULL
)
681 ObDereferenceObject(FileObject
);
683 return(STATUS_NO_MEMORY
);
686 #if defined(__GNUC__)
694 MaxVcn
.QuadPart
= (SafeInitialSize
.QuadPart
+ BytesPerAllocationUnit
- 1) / BytesPerAllocationUnit
;
697 Status
= ZwFsControlFile(FileHandle
,
702 FSCTL_GET_RETRIEVAL_POINTERS
,
704 sizeof(LARGE_INTEGER
),
705 &CurrentRetDescList
->RetrievalPointers
,
706 sizeof(RETRIEVAL_POINTERS_BUFFER
) + PAIRS_PER_RUN
* 2 * sizeof(LARGE_INTEGER
));
707 if (!NT_SUCCESS(Status
))
711 CurrentRetDescList
= RetDescList
;
712 RetDescList
= RetDescList
->Next
;
713 ExFreePool(CurrentRetDescList
);
715 ObDereferenceObject(FileObject
);
719 ExtentCount
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
720 if (CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
.QuadPart
< MaxVcn
.QuadPart
)
722 CurrentRetDescList
->Next
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
723 if (CurrentRetDescList
->Next
== NULL
)
727 CurrentRetDescList
= RetDescList
;
728 RetDescList
= RetDescList
->Next
;
729 ExFreePool(CurrentRetDescList
);
731 ObDereferenceObject(FileObject
);
733 return(STATUS_NO_MEMORY
);
735 Vcn
= CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
;
736 CurrentRetDescList
= CurrentRetDescList
->Next
;
744 PagingFile
= ExAllocatePool(NonPagedPool
, sizeof(*PagingFile
));
745 if (PagingFile
== NULL
)
749 CurrentRetDescList
= RetDescList
;
750 RetDescList
= RetDescList
->Next
;
751 ExFreePool(CurrentRetDescList
);
753 ObDereferenceObject(FileObject
);
755 return(STATUS_NO_MEMORY
);
758 RtlZeroMemory(PagingFile
, sizeof(*PagingFile
));
760 PagingFile
->FileObject
= FileObject
;
761 PagingFile
->MaximumSize
.QuadPart
= SafeMaximumSize
.QuadPart
;
762 PagingFile
->CurrentSize
.QuadPart
= SafeInitialSize
.QuadPart
;
763 PagingFile
->FreePages
= (ULONG
)(SafeInitialSize
.QuadPart
/ PAGE_SIZE
);
764 PagingFile
->UsedPages
= 0;
765 KeInitializeSpinLock(&PagingFile
->AllocMapLock
);
767 AllocMapSize
= (PagingFile
->FreePages
/ 32) + 1;
768 PagingFile
->AllocMap
= ExAllocatePool(NonPagedPool
,
769 AllocMapSize
* sizeof(ULONG
));
770 PagingFile
->AllocMapSize
= AllocMapSize
;
772 if (PagingFile
->AllocMap
== NULL
)
776 CurrentRetDescList
= RetDescList
;
777 RetDescList
= RetDescList
->Next
;
778 ExFreePool(CurrentRetDescList
);
780 ExFreePool(PagingFile
);
781 ObDereferenceObject(FileObject
);
783 return(STATUS_NO_MEMORY
);
785 DPRINT("ExtentCount: %d\n", ExtentCount
);
786 Size
= sizeof(RETRIEVAL_POINTERS_BUFFER
) + ExtentCount
* 2 * sizeof(LARGE_INTEGER
);
787 PagingFile
->RetrievalPointers
= ExAllocatePool(NonPagedPool
, Size
);
788 if (PagingFile
->RetrievalPointers
== NULL
)
792 CurrentRetDescList
= RetDescList
;
793 RetDescList
= RetDescList
->Next
;
794 ExFreePool(CurrentRetDescList
);
796 ExFreePool(PagingFile
->AllocMap
);
797 ExFreePool(PagingFile
);
798 ObDereferenceObject(FileObject
);
800 return(STATUS_NO_MEMORY
);
803 RtlZeroMemory(PagingFile
->AllocMap
, AllocMapSize
* sizeof(ULONG
));
804 RtlZeroMemory(PagingFile
->RetrievalPointers
, Size
);
807 PagingFile
->RetrievalPointers
->ExtentCount
= ExtentCount
;
808 PagingFile
->RetrievalPointers
->StartingVcn
= RetDescList
->RetrievalPointers
.StartingVcn
;
809 CurrentRetDescList
= RetDescList
;
810 while (CurrentRetDescList
)
812 memcpy(&PagingFile
->RetrievalPointers
->Extents
[Count
],
813 CurrentRetDescList
->RetrievalPointers
.Extents
,
814 CurrentRetDescList
->RetrievalPointers
.ExtentCount
* 2 * sizeof(LARGE_INTEGER
));
815 Count
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
816 RetDescList
= CurrentRetDescList
;
817 CurrentRetDescList
= CurrentRetDescList
->Next
;
818 ExFreePool(RetDescList
);
821 if (PagingFile
->RetrievalPointers
->ExtentCount
!= ExtentCount
||
822 PagingFile
->RetrievalPointers
->Extents
[ExtentCount
- 1].NextVcn
.QuadPart
!= MaxVcn
.QuadPart
)
824 ExFreePool(PagingFile
->RetrievalPointers
);
825 ExFreePool(PagingFile
->AllocMap
);
826 ExFreePool(PagingFile
);
827 ObDereferenceObject(FileObject
);
829 return(STATUS_UNSUCCESSFUL
);
833 * Change the entries from lcn's to volume offset's.
835 PagingFile
->RetrievalPointers
->StartingVcn
.QuadPart
*= BytesPerAllocationUnit
;
836 for (i
= 0; i
< ExtentCount
; i
++)
838 PagingFile
->RetrievalPointers
->Extents
[i
].Lcn
.QuadPart
*= BytesPerAllocationUnit
;
839 PagingFile
->RetrievalPointers
->Extents
[i
].NextVcn
.QuadPart
*= BytesPerAllocationUnit
;
842 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
843 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
845 if (PagingFileList
[i
] == NULL
)
847 PagingFileList
[i
] = PagingFile
;
851 MiFreeSwapPages
= MiFreeSwapPages
+ PagingFile
->FreePages
;
853 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
857 MmSwapSpaceMessage
= FALSE
;
859 return(STATUS_SUCCESS
);