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_COUNT MiFreeSwapPages
;
86 /* Number of pages that have been allocated for swapping */
87 PFN_COUNT MiUsedSwapPages
;
89 BOOLEAN MmZeroPageFile
;
92 * Number of pages that have been reserved for swapping but not yet allocated
94 static PFN_COUNT 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 /* Make sure there can be only 16 paging files */
119 C_ASSERT(FILE_FROM_ENTRY(0xffffffff) < MAX_PAGING_FILES
);
121 static BOOLEAN MmSwapSpaceMessage
= FALSE
;
123 /* FUNCTIONS *****************************************************************/
127 MmBuildMdlFromPages(PMDL Mdl
, PPFN_NUMBER Pages
)
129 memcpy(Mdl
+ 1, Pages
, sizeof(PFN_NUMBER
) * (PAGE_ROUND_UP(Mdl
->ByteOffset
+Mdl
->ByteCount
)/PAGE_SIZE
));
131 /* FIXME: this flag should be set by the caller perhaps? */
132 Mdl
->MdlFlags
|= MDL_IO_PAGE_READ
;
138 MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject
)
142 /* Loop through all the paging files */
143 for (i
= 0; i
< MiPagingFileCount
; i
++)
145 /* Check if this is one of them */
146 if (PagingFileList
[i
]->FileObject
== FileObject
) return TRUE
;
155 MmShowOutOfSpaceMessagePagingFile(VOID
)
157 if (!MmSwapSpaceMessage
)
159 DPRINT1("MM: Out of swap space.\n");
160 MmSwapSpaceMessage
= TRUE
;
165 MmGetOffsetPageFile(PRETRIEVAL_POINTERS_BUFFER RetrievalPointers
, LARGE_INTEGER Offset
)
167 /* Simple binary search */
168 ULONG first
, last
, mid
;
170 last
= RetrievalPointers
->ExtentCount
- 1;
171 while (first
<= last
)
173 mid
= (last
- first
) / 2 + first
;
174 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
)
178 Offset
.QuadPart
+= RetrievalPointers
->Extents
[0].Lcn
.QuadPart
- RetrievalPointers
->StartingVcn
.QuadPart
;
183 if (Offset
.QuadPart
>= RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
)
185 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
;
193 if (mid
== RetrievalPointers
->ExtentCount
- 1)
197 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
+1].NextVcn
.QuadPart
)
199 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
+1].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
;
205 KeBugCheck(MEMORY_MANAGEMENT
);
206 #if defined(__GNUC__)
208 return (LARGE_INTEGER
)0LL;
212 const LARGE_INTEGER dummy
=
223 MmWriteToSwapPage(SWAPENTRY SwapEntry
, PFN_NUMBER Page
)
227 LARGE_INTEGER file_offset
;
228 IO_STATUS_BLOCK Iosb
;
231 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
232 PMDL Mdl
= (PMDL
)MdlBase
;
234 DPRINT("MmWriteToSwapPage\n");
238 KeBugCheck(MEMORY_MANAGEMENT
);
239 return(STATUS_UNSUCCESSFUL
);
242 i
= FILE_FROM_ENTRY(SwapEntry
);
243 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
245 if (PagingFileList
[i
]->FileObject
== NULL
||
246 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
248 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
249 KeBugCheck(MEMORY_MANAGEMENT
);
252 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
253 MmBuildMdlFromPages(Mdl
, &Page
);
254 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
256 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
257 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
259 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
260 Status
= IoSynchronousPageWrite(PagingFileList
[i
]->FileObject
,
265 if (Status
== STATUS_PENDING
)
267 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
268 Status
= Iosb
.Status
;
271 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
273 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
280 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 (PagingFileList
[i
]->FileObject
== NULL
||
303 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
305 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
306 KeBugCheck(MEMORY_MANAGEMENT
);
309 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
310 MmBuildMdlFromPages(Mdl
, &Page
);
311 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
313 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
314 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
316 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
317 Status
= IoPageRead(PagingFileList
[i
]->FileObject
,
322 if (Status
== STATUS_PENDING
)
324 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
325 Status
= Iosb
.Status
;
327 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
329 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
337 MmInitPagingFile(VOID
)
341 KeInitializeSpinLock(&PagingFileListLock
);
345 MiReservedSwapPages
= 0;
347 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
349 PagingFileList
[i
] = NULL
;
351 MiPagingFileCount
= 0;
356 MmReserveSwapPages(ULONG Nr
)
359 ULONG MiAvailSwapPages
;
361 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
363 (MiFreeSwapPages
* MM_PAGEFILE_COMMIT_RATIO
) + MM_PAGEFILE_COMMIT_GRACE
;
364 MiReservedSwapPages
= MiReservedSwapPages
+ Nr
;
365 if ((MM_PAGEFILE_COMMIT_RATIO
!= 0) && (MiAvailSwapPages
< MiReservedSwapPages
))
367 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
370 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
376 MmDereserveSwapPages(ULONG Nr
)
380 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
381 MiReservedSwapPages
= MiReservedSwapPages
- Nr
;
382 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
386 MiAllocPageFromPagingFile(PPAGINGFILE PagingFile
)
391 KeAcquireSpinLock(&PagingFile
->AllocMapLock
, &oldIrql
);
393 for (i
= 0; i
< PagingFile
->AllocMapSize
; i
++)
395 for (j
= 0; j
< 32; j
++)
397 if (!(PagingFile
->AllocMap
[i
] & (1 << j
)))
399 PagingFile
->AllocMap
[i
] |= (1 << j
);
400 PagingFile
->UsedPages
++;
401 PagingFile
->FreePages
--;
402 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
403 return((i
* 32) + j
);
408 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
414 MmFreeSwapPage(SWAPENTRY Entry
)
420 i
= FILE_FROM_ENTRY(Entry
);
421 off
= OFFSET_FROM_ENTRY(Entry
);
423 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
424 if (PagingFileList
[i
] == NULL
)
426 KeBugCheck(MEMORY_MANAGEMENT
);
428 KeAcquireSpinLockAtDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
430 PagingFileList
[i
]->AllocMap
[off
>> 5] &= (~(1 << (off
% 32)));
432 PagingFileList
[i
]->FreePages
++;
433 PagingFileList
[i
]->UsedPages
--;
438 KeReleaseSpinLockFromDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
439 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
444 MmIsAvailableSwapPage(VOID
)
446 return(MiFreeSwapPages
> 0);
451 MmAllocSwapPage(VOID
)
458 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
460 if (MiFreeSwapPages
== 0)
462 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
466 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
468 if (PagingFileList
[i
] != NULL
&&
469 PagingFileList
[i
]->FreePages
>= 1)
471 off
= MiAllocPageFromPagingFile(PagingFileList
[i
]);
472 if (off
== 0xFFFFFFFF)
474 KeBugCheck(MEMORY_MANAGEMENT
);
475 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
476 return(STATUS_UNSUCCESSFUL
);
480 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
482 entry
= ENTRY_FROM_FILE_OFFSET(i
, off
);
487 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
488 KeBugCheck(MEMORY_MANAGEMENT
);
492 static PRETRIEVEL_DESCRIPTOR_LIST FASTCALL
493 MmAllocRetrievelDescriptorList(ULONG Pairs
)
496 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
498 Size
= sizeof(RETRIEVEL_DESCRIPTOR_LIST
) + Pairs
* 2 * sizeof(LARGE_INTEGER
);
499 RetDescList
= ExAllocatePool(NonPagedPool
, Size
);
502 RtlZeroMemory(RetDescList
, Size
);
509 NtCreatePagingFile(IN PUNICODE_STRING FileName
,
510 IN PLARGE_INTEGER InitialSize
,
511 IN PLARGE_INTEGER MaximumSize
,
515 OBJECT_ATTRIBUTES ObjectAttributes
;
517 IO_STATUS_BLOCK IoStatus
;
518 PFILE_OBJECT FileObject
;
519 PPAGINGFILE PagingFile
;
522 FILE_FS_SIZE_INFORMATION FsSizeInformation
;
523 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
524 PRETRIEVEL_DESCRIPTOR_LIST CurrentRetDescList
;
526 ULONG BytesPerAllocationUnit
;
529 LARGE_INTEGER MaxVcn
;
532 KPROCESSOR_MODE PreviousMode
;
533 UNICODE_STRING CapturedFileName
;
534 LARGE_INTEGER SafeInitialSize
, SafeMaximumSize
;
536 DPRINT("NtCreatePagingFile(FileName %wZ, InitialSize %I64d)\n",
537 FileName
, InitialSize
->QuadPart
);
539 if (MiPagingFileCount
>= MAX_PAGING_FILES
)
541 return(STATUS_TOO_MANY_PAGING_FILES
);
544 PreviousMode
= ExGetPreviousMode();
546 if (PreviousMode
!= KernelMode
)
550 SafeInitialSize
= ProbeForReadLargeInteger(InitialSize
);
551 SafeMaximumSize
= ProbeForReadLargeInteger(MaximumSize
);
553 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
555 /* Return the exception code */
556 _SEH2_YIELD(return _SEH2_GetExceptionCode());
562 SafeInitialSize
= *InitialSize
;
563 SafeMaximumSize
= *MaximumSize
;
566 /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
567 smaller than the maximum */
568 if (0 != SafeInitialSize
.u
.HighPart
)
570 return STATUS_INVALID_PARAMETER_2
;
572 if (0 != SafeMaximumSize
.u
.HighPart
)
574 return STATUS_INVALID_PARAMETER_3
;
576 if (SafeMaximumSize
.u
.LowPart
< SafeInitialSize
.u
.LowPart
)
578 return STATUS_INVALID_PARAMETER_MIX
;
581 Status
= ProbeAndCaptureUnicodeString(&CapturedFileName
,
584 if (!NT_SUCCESS(Status
))
589 InitializeObjectAttributes(&ObjectAttributes
,
595 Status
= IoCreateFile(&FileHandle
,
603 FILE_SYNCHRONOUS_IO_NONALERT
,
608 SL_OPEN_PAGING_FILE
| IO_NO_PARAMETER_CHECKING
);
610 ReleaseCapturedUnicodeString(&CapturedFileName
,
612 if (!NT_SUCCESS(Status
))
617 Status
= ZwQueryVolumeInformationFile(FileHandle
,
620 sizeof(FILE_FS_SIZE_INFORMATION
),
621 FileFsSizeInformation
);
622 if (!NT_SUCCESS(Status
))
628 BytesPerAllocationUnit
= FsSizeInformation
.SectorsPerAllocationUnit
*
629 FsSizeInformation
.BytesPerSector
;
630 /* FIXME: If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
631 * a problem if the paging file is fragmented. Suppose the first cluster
632 * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
633 * paging file but of another file. We can't write a complete page (4096
634 * bytes) to the physical location of cluster 3042 then. */
635 if (BytesPerAllocationUnit
% PAGE_SIZE
)
637 DPRINT1("BytesPerAllocationUnit %lu is not a multiple of PAGE_SIZE %d\n",
638 BytesPerAllocationUnit
, PAGE_SIZE
);
640 return STATUS_UNSUCCESSFUL
;
643 Status
= ZwSetInformationFile(FileHandle
,
646 sizeof(LARGE_INTEGER
),
647 FileAllocationInformation
);
648 if (!NT_SUCCESS(Status
))
654 Status
= ObReferenceObjectByHandle(FileHandle
,
660 if (!NT_SUCCESS(Status
))
666 CurrentRetDescList
= RetDescList
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
668 if (CurrentRetDescList
== NULL
)
670 ObDereferenceObject(FileObject
);
672 return(STATUS_NO_MEMORY
);
675 #if defined(__GNUC__)
683 MaxVcn
.QuadPart
= (SafeInitialSize
.QuadPart
+ BytesPerAllocationUnit
- 1) / BytesPerAllocationUnit
;
686 Status
= ZwFsControlFile(FileHandle
,
691 FSCTL_GET_RETRIEVAL_POINTERS
,
693 sizeof(LARGE_INTEGER
),
694 &CurrentRetDescList
->RetrievalPointers
,
695 sizeof(RETRIEVAL_POINTERS_BUFFER
) + PAIRS_PER_RUN
* 2 * sizeof(LARGE_INTEGER
));
696 if (!NT_SUCCESS(Status
))
700 CurrentRetDescList
= RetDescList
;
701 RetDescList
= RetDescList
->Next
;
702 ExFreePool(CurrentRetDescList
);
704 ObDereferenceObject(FileObject
);
708 ExtentCount
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
709 if (CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
.QuadPart
< MaxVcn
.QuadPart
)
711 CurrentRetDescList
->Next
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
712 if (CurrentRetDescList
->Next
== NULL
)
716 CurrentRetDescList
= RetDescList
;
717 RetDescList
= RetDescList
->Next
;
718 ExFreePool(CurrentRetDescList
);
720 ObDereferenceObject(FileObject
);
722 return(STATUS_NO_MEMORY
);
724 Vcn
= CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
;
725 CurrentRetDescList
= CurrentRetDescList
->Next
;
733 PagingFile
= ExAllocatePool(NonPagedPool
, sizeof(*PagingFile
));
734 if (PagingFile
== NULL
)
738 CurrentRetDescList
= RetDescList
;
739 RetDescList
= RetDescList
->Next
;
740 ExFreePool(CurrentRetDescList
);
742 ObDereferenceObject(FileObject
);
744 return(STATUS_NO_MEMORY
);
747 RtlZeroMemory(PagingFile
, sizeof(*PagingFile
));
749 PagingFile
->FileObject
= FileObject
;
750 PagingFile
->MaximumSize
.QuadPart
= SafeMaximumSize
.QuadPart
;
751 PagingFile
->CurrentSize
.QuadPart
= SafeInitialSize
.QuadPart
;
752 PagingFile
->FreePages
= (ULONG
)(SafeInitialSize
.QuadPart
/ PAGE_SIZE
);
753 PagingFile
->UsedPages
= 0;
754 KeInitializeSpinLock(&PagingFile
->AllocMapLock
);
756 AllocMapSize
= (PagingFile
->FreePages
/ 32) + 1;
757 PagingFile
->AllocMap
= ExAllocatePool(NonPagedPool
,
758 AllocMapSize
* sizeof(ULONG
));
759 PagingFile
->AllocMapSize
= AllocMapSize
;
761 if (PagingFile
->AllocMap
== NULL
)
765 CurrentRetDescList
= RetDescList
;
766 RetDescList
= RetDescList
->Next
;
767 ExFreePool(CurrentRetDescList
);
769 ExFreePool(PagingFile
);
770 ObDereferenceObject(FileObject
);
772 return(STATUS_NO_MEMORY
);
774 DPRINT("ExtentCount: %lu\n", ExtentCount
);
775 Size
= sizeof(RETRIEVAL_POINTERS_BUFFER
) + ExtentCount
* 2 * sizeof(LARGE_INTEGER
);
776 PagingFile
->RetrievalPointers
= ExAllocatePool(NonPagedPool
, Size
);
777 if (PagingFile
->RetrievalPointers
== NULL
)
781 CurrentRetDescList
= RetDescList
;
782 RetDescList
= RetDescList
->Next
;
783 ExFreePool(CurrentRetDescList
);
785 ExFreePool(PagingFile
->AllocMap
);
786 ExFreePool(PagingFile
);
787 ObDereferenceObject(FileObject
);
789 return(STATUS_NO_MEMORY
);
792 RtlZeroMemory(PagingFile
->AllocMap
, AllocMapSize
* sizeof(ULONG
));
793 RtlZeroMemory(PagingFile
->RetrievalPointers
, Size
);
796 PagingFile
->RetrievalPointers
->ExtentCount
= ExtentCount
;
797 PagingFile
->RetrievalPointers
->StartingVcn
= RetDescList
->RetrievalPointers
.StartingVcn
;
798 CurrentRetDescList
= RetDescList
;
799 while (CurrentRetDescList
)
801 memcpy(&PagingFile
->RetrievalPointers
->Extents
[Count
],
802 CurrentRetDescList
->RetrievalPointers
.Extents
,
803 CurrentRetDescList
->RetrievalPointers
.ExtentCount
* 2 * sizeof(LARGE_INTEGER
));
804 Count
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
805 RetDescList
= CurrentRetDescList
;
806 CurrentRetDescList
= CurrentRetDescList
->Next
;
807 ExFreePool(RetDescList
);
810 if (PagingFile
->RetrievalPointers
->ExtentCount
!= ExtentCount
||
811 PagingFile
->RetrievalPointers
->Extents
[ExtentCount
- 1].NextVcn
.QuadPart
!= MaxVcn
.QuadPart
)
813 ExFreePool(PagingFile
->RetrievalPointers
);
814 ExFreePool(PagingFile
->AllocMap
);
815 ExFreePool(PagingFile
);
816 ObDereferenceObject(FileObject
);
818 return(STATUS_UNSUCCESSFUL
);
822 * Change the entries from lcn's to volume offset's.
824 PagingFile
->RetrievalPointers
->StartingVcn
.QuadPart
*= BytesPerAllocationUnit
;
825 for (i
= 0; i
< ExtentCount
; i
++)
827 PagingFile
->RetrievalPointers
->Extents
[i
].Lcn
.QuadPart
*= BytesPerAllocationUnit
;
828 PagingFile
->RetrievalPointers
->Extents
[i
].NextVcn
.QuadPart
*= BytesPerAllocationUnit
;
831 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
832 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
834 if (PagingFileList
[i
] == NULL
)
836 PagingFileList
[i
] = PagingFile
;
840 MiFreeSwapPages
= MiFreeSwapPages
+ PagingFile
->FreePages
;
842 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
846 MmSwapSpaceMessage
= FALSE
;
848 return(STATUS_SUCCESS
);