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 ULONG MiFreeSwapPages
;
86 /* Number of pages that have been allocated for swapping */
87 ULONG MiUsedSwapPages
;
90 * Number of pages that have been reserved for swapping but not yet allocated
92 static ULONG MiReservedSwapPages
;
95 * Ratio between reserved and available swap pages, e.g. setting this to five
96 * forces one swap page to be available for every five swap pages that are
97 * reserved. Setting this to zero turns off commit checking altogether.
99 #define MM_PAGEFILE_COMMIT_RATIO (1)
102 * Number of pages that can be used for potentially swapable memory without
103 * pagefile space being reserved. The intention is that this allows smss
104 * to start up and create page files while ordinarily having a commit
107 #define MM_PAGEFILE_COMMIT_GRACE (256)
110 * Translate between a swap entry and a file and offset pair.
112 #define FILE_FROM_ENTRY(i) ((i) & 0x0f)
113 #define OFFSET_FROM_ENTRY(i) ((i) >> 11)
114 #define ENTRY_FROM_FILE_OFFSET(i, j) ((i) | (j) << 11 | 0x400)
116 static BOOLEAN MmSwapSpaceMessage
= FALSE
;
118 /* FUNCTIONS *****************************************************************/
122 MmBuildMdlFromPages(PMDL Mdl
, PPFN_TYPE Pages
)
124 memcpy(Mdl
+ 1, Pages
, sizeof(PFN_TYPE
) * (PAGE_ROUND_UP(Mdl
->ByteOffset
+Mdl
->ByteCount
)/PAGE_SIZE
));
126 /* FIXME: this flag should be set by the caller perhaps? */
127 Mdl
->MdlFlags
|= MDL_IO_PAGE_READ
;
133 MmIsFileAPagingFile(PFILE_OBJECT FileObject
)
137 /* Loop through all the paging files */
138 for (i
= 0; i
< MiPagingFileCount
; i
++)
140 /* Check if this is one of them */
141 if (PagingFileList
[i
]->FileObject
== FileObject
) return TRUE
;
150 MmShowOutOfSpaceMessagePagingFile(VOID
)
152 if (!MmSwapSpaceMessage
)
154 DPRINT1("MM: Out of swap space.\n");
155 MmSwapSpaceMessage
= TRUE
;
160 MmGetOffsetPageFile(PRETRIEVAL_POINTERS_BUFFER RetrievalPointers
, LARGE_INTEGER Offset
)
162 /* Simple binary search */
163 ULONG first
, last
, mid
;
165 last
= RetrievalPointers
->ExtentCount
- 1;
166 while (first
<= last
)
168 mid
= (last
- first
) / 2 + first
;
169 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
)
173 Offset
.QuadPart
+= RetrievalPointers
->Extents
[0].Lcn
.QuadPart
- RetrievalPointers
->StartingVcn
.QuadPart
;
178 if (Offset
.QuadPart
>= RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
)
180 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
-1].NextVcn
.QuadPart
;
188 if (mid
== RetrievalPointers
->ExtentCount
- 1)
192 if (Offset
.QuadPart
< RetrievalPointers
->Extents
[mid
+1].NextVcn
.QuadPart
)
194 Offset
.QuadPart
+= RetrievalPointers
->Extents
[mid
+1].Lcn
.QuadPart
- RetrievalPointers
->Extents
[mid
].NextVcn
.QuadPart
;
200 KeBugCheck(MEMORY_MANAGEMENT
);
201 #if defined(__GNUC__)
203 return (LARGE_INTEGER
)0LL;
207 const LARGE_INTEGER dummy
=
218 MmWriteToSwapPage(SWAPENTRY SwapEntry
, PFN_TYPE Page
)
221 LARGE_INTEGER file_offset
;
222 IO_STATUS_BLOCK Iosb
;
225 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
226 PMDL Mdl
= (PMDL
)MdlBase
;
228 DPRINT("MmWriteToSwapPage\n");
232 KeBugCheck(MEMORY_MANAGEMENT
);
233 return(STATUS_UNSUCCESSFUL
);
236 i
= FILE_FROM_ENTRY(SwapEntry
);
237 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
239 if (i
>= MAX_PAGING_FILES
)
241 DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry
);
242 KeBugCheck(MEMORY_MANAGEMENT
);
244 if (PagingFileList
[i
]->FileObject
== NULL
||
245 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
247 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
248 KeBugCheck(MEMORY_MANAGEMENT
);
251 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
252 MmBuildMdlFromPages(Mdl
, &Page
);
253 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
255 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
256 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
258 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
259 Status
= IoSynchronousPageWrite(PagingFileList
[i
]->FileObject
,
264 if (Status
== STATUS_PENDING
)
266 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
267 Status
= Iosb
.Status
;
270 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
272 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
279 MmReadFromSwapPage(SWAPENTRY SwapEntry
, PFN_TYPE Page
)
282 LARGE_INTEGER file_offset
;
283 IO_STATUS_BLOCK Iosb
;
286 UCHAR MdlBase
[sizeof(MDL
) + sizeof(ULONG
)];
287 PMDL Mdl
= (PMDL
)MdlBase
;
289 DPRINT("MmReadFromSwapPage\n");
293 KeBugCheck(MEMORY_MANAGEMENT
);
294 return(STATUS_UNSUCCESSFUL
);
297 i
= FILE_FROM_ENTRY(SwapEntry
);
298 offset
= OFFSET_FROM_ENTRY(SwapEntry
);
300 if (i
>= MAX_PAGING_FILES
)
302 DPRINT1("Bad swap entry 0x%.8X\n", SwapEntry
);
303 KeBugCheck(MEMORY_MANAGEMENT
);
305 if (PagingFileList
[i
]->FileObject
== NULL
||
306 PagingFileList
[i
]->FileObject
->DeviceObject
== NULL
)
308 DPRINT1("Bad paging file 0x%.8X\n", SwapEntry
);
309 KeBugCheck(MEMORY_MANAGEMENT
);
312 MmInitializeMdl(Mdl
, NULL
, PAGE_SIZE
);
313 MmBuildMdlFromPages(Mdl
, &Page
);
314 Mdl
->MdlFlags
|= MDL_PAGES_LOCKED
;
316 file_offset
.QuadPart
= offset
* PAGE_SIZE
;
317 file_offset
= MmGetOffsetPageFile(PagingFileList
[i
]->RetrievalPointers
, file_offset
);
319 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
320 Status
= IoPageRead(PagingFileList
[i
]->FileObject
,
325 if (Status
== STATUS_PENDING
)
327 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
328 Status
= Iosb
.Status
;
330 if (Mdl
->MdlFlags
& MDL_MAPPED_TO_SYSTEM_VA
)
332 MmUnmapLockedPages (Mdl
->MappedSystemVa
, Mdl
);
340 MmInitPagingFile(VOID
)
344 KeInitializeSpinLock(&PagingFileListLock
);
348 MiReservedSwapPages
= 0;
350 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
352 PagingFileList
[i
] = NULL
;
354 MiPagingFileCount
= 0;
359 MmReserveSwapPages(ULONG Nr
)
362 ULONG MiAvailSwapPages
;
364 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
366 (MiFreeSwapPages
* MM_PAGEFILE_COMMIT_RATIO
) + MM_PAGEFILE_COMMIT_GRACE
;
367 MiReservedSwapPages
= MiReservedSwapPages
+ Nr
;
368 if ((MM_PAGEFILE_COMMIT_RATIO
!= 0) && (MiAvailSwapPages
< MiReservedSwapPages
))
370 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
373 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
379 MmDereserveSwapPages(ULONG Nr
)
383 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
384 MiReservedSwapPages
= MiReservedSwapPages
- Nr
;
385 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
389 MiAllocPageFromPagingFile(PPAGINGFILE PagingFile
)
394 KeAcquireSpinLock(&PagingFile
->AllocMapLock
, &oldIrql
);
396 for (i
= 0; i
< PagingFile
->AllocMapSize
; i
++)
398 for (j
= 0; j
< 32; j
++)
400 if (!(PagingFile
->AllocMap
[i
] & (1 << j
)))
402 PagingFile
->AllocMap
[i
] |= (1 << j
);
403 PagingFile
->UsedPages
++;
404 PagingFile
->FreePages
--;
405 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
406 return((i
* 32) + j
);
411 KeReleaseSpinLock(&PagingFile
->AllocMapLock
, oldIrql
);
417 MmFreeSwapPage(SWAPENTRY Entry
)
423 i
= FILE_FROM_ENTRY(Entry
);
424 off
= OFFSET_FROM_ENTRY(Entry
);
426 if (i
>= MAX_PAGING_FILES
)
428 DPRINT1("Bad swap entry 0x%.8X\n", Entry
);
429 KeBugCheck(MEMORY_MANAGEMENT
);
432 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
433 if (PagingFileList
[i
] == NULL
)
435 KeBugCheck(MEMORY_MANAGEMENT
);
437 KeAcquireSpinLockAtDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
439 PagingFileList
[i
]->AllocMap
[off
>> 5] &= (~(1 << (off
% 32)));
441 PagingFileList
[i
]->FreePages
++;
442 PagingFileList
[i
]->UsedPages
--;
447 KeReleaseSpinLockFromDpcLevel(&PagingFileList
[i
]->AllocMapLock
);
448 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
453 MmIsAvailableSwapPage(VOID
)
455 return(MiFreeSwapPages
> 0);
460 MmAllocSwapPage(VOID
)
467 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
469 if (MiFreeSwapPages
== 0)
471 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
475 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
477 if (PagingFileList
[i
] != NULL
&&
478 PagingFileList
[i
]->FreePages
>= 1)
480 off
= MiAllocPageFromPagingFile(PagingFileList
[i
]);
481 if (off
== 0xFFFFFFFF)
483 KeBugCheck(MEMORY_MANAGEMENT
);
484 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
485 return(STATUS_UNSUCCESSFUL
);
489 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
491 entry
= ENTRY_FROM_FILE_OFFSET(i
, off
);
496 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
497 KeBugCheck(MEMORY_MANAGEMENT
);
501 static PRETRIEVEL_DESCRIPTOR_LIST FASTCALL
502 MmAllocRetrievelDescriptorList(ULONG Pairs
)
505 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
507 Size
= sizeof(RETRIEVEL_DESCRIPTOR_LIST
) + Pairs
* 2 * sizeof(LARGE_INTEGER
);
508 RetDescList
= ExAllocatePool(NonPagedPool
, Size
);
511 RtlZeroMemory(RetDescList
, Size
);
518 NtCreatePagingFile(IN PUNICODE_STRING FileName
,
519 IN PLARGE_INTEGER InitialSize
,
520 IN PLARGE_INTEGER MaximumSize
,
524 OBJECT_ATTRIBUTES ObjectAttributes
;
526 IO_STATUS_BLOCK IoStatus
;
527 PFILE_OBJECT FileObject
;
528 PPAGINGFILE PagingFile
;
531 FILE_FS_SIZE_INFORMATION FsSizeInformation
;
532 PRETRIEVEL_DESCRIPTOR_LIST RetDescList
;
533 PRETRIEVEL_DESCRIPTOR_LIST CurrentRetDescList
;
535 ULONG BytesPerAllocationUnit
;
538 LARGE_INTEGER MaxVcn
;
541 KPROCESSOR_MODE PreviousMode
;
542 UNICODE_STRING CapturedFileName
;
543 LARGE_INTEGER SafeInitialSize
, SafeMaximumSize
;
545 DPRINT("NtCreatePagingFile(FileName %wZ, InitialSize %I64d)\n",
546 FileName
, InitialSize
->QuadPart
);
548 if (MiPagingFileCount
>= MAX_PAGING_FILES
)
550 return(STATUS_TOO_MANY_PAGING_FILES
);
553 PreviousMode
= ExGetPreviousMode();
555 if (PreviousMode
!= KernelMode
)
559 SafeInitialSize
= ProbeForReadLargeInteger(InitialSize
);
560 SafeMaximumSize
= ProbeForReadLargeInteger(MaximumSize
);
562 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
564 /* Return the exception code */
565 _SEH2_YIELD(return _SEH2_GetExceptionCode());
571 SafeInitialSize
= *InitialSize
;
572 SafeMaximumSize
= *MaximumSize
;
575 /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
576 smaller than the maximum */
577 if (0 != SafeInitialSize
.u
.HighPart
)
579 return STATUS_INVALID_PARAMETER_2
;
581 if (0 != SafeMaximumSize
.u
.HighPart
)
583 return STATUS_INVALID_PARAMETER_3
;
585 if (SafeMaximumSize
.u
.LowPart
< SafeInitialSize
.u
.LowPart
)
587 return STATUS_INVALID_PARAMETER_MIX
;
590 Status
= ProbeAndCaptureUnicodeString(&CapturedFileName
,
593 if (!NT_SUCCESS(Status
))
598 InitializeObjectAttributes(&ObjectAttributes
,
604 Status
= IoCreateFile(&FileHandle
,
612 FILE_SYNCHRONOUS_IO_NONALERT
,
617 SL_OPEN_PAGING_FILE
| IO_NO_PARAMETER_CHECKING
);
619 ReleaseCapturedUnicodeString(&CapturedFileName
,
621 if (!NT_SUCCESS(Status
))
626 Status
= ZwQueryVolumeInformationFile(FileHandle
,
629 sizeof(FILE_FS_SIZE_INFORMATION
),
630 FileFsSizeInformation
);
631 if (!NT_SUCCESS(Status
))
637 BytesPerAllocationUnit
= FsSizeInformation
.SectorsPerAllocationUnit
*
638 FsSizeInformation
.BytesPerSector
;
639 /* FIXME: If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
640 * a problem if the paging file is fragmented. Suppose the first cluster
641 * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
642 * paging file but of another file. We can't write a complete page (4096
643 * bytes) to the physical location of cluster 3042 then. */
644 if (BytesPerAllocationUnit
% PAGE_SIZE
)
646 DPRINT1("BytesPerAllocationUnit %d is not a multiple of PAGE_SIZE %d\n",
647 BytesPerAllocationUnit
, PAGE_SIZE
);
649 return STATUS_UNSUCCESSFUL
;
652 Status
= ZwSetInformationFile(FileHandle
,
655 sizeof(LARGE_INTEGER
),
656 FileAllocationInformation
);
657 if (!NT_SUCCESS(Status
))
663 Status
= ObReferenceObjectByHandle(FileHandle
,
669 if (!NT_SUCCESS(Status
))
675 CurrentRetDescList
= RetDescList
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
677 if (CurrentRetDescList
== NULL
)
679 ObDereferenceObject(FileObject
);
681 return(STATUS_NO_MEMORY
);
684 #if defined(__GNUC__)
692 MaxVcn
.QuadPart
= (SafeInitialSize
.QuadPart
+ BytesPerAllocationUnit
- 1) / BytesPerAllocationUnit
;
695 Status
= ZwFsControlFile(FileHandle
,
700 FSCTL_GET_RETRIEVAL_POINTERS
,
702 sizeof(LARGE_INTEGER
),
703 &CurrentRetDescList
->RetrievalPointers
,
704 sizeof(RETRIEVAL_POINTERS_BUFFER
) + PAIRS_PER_RUN
* 2 * sizeof(LARGE_INTEGER
));
705 if (!NT_SUCCESS(Status
))
709 CurrentRetDescList
= RetDescList
;
710 RetDescList
= RetDescList
->Next
;
711 ExFreePool(CurrentRetDescList
);
713 ObDereferenceObject(FileObject
);
717 ExtentCount
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
718 if (CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
.QuadPart
< MaxVcn
.QuadPart
)
720 CurrentRetDescList
->Next
= MmAllocRetrievelDescriptorList(PAIRS_PER_RUN
);
721 if (CurrentRetDescList
->Next
== NULL
)
725 CurrentRetDescList
= RetDescList
;
726 RetDescList
= RetDescList
->Next
;
727 ExFreePool(CurrentRetDescList
);
729 ObDereferenceObject(FileObject
);
731 return(STATUS_NO_MEMORY
);
733 Vcn
= CurrentRetDescList
->RetrievalPointers
.Extents
[CurrentRetDescList
->RetrievalPointers
.ExtentCount
-1].NextVcn
;
734 CurrentRetDescList
= CurrentRetDescList
->Next
;
742 PagingFile
= ExAllocatePool(NonPagedPool
, sizeof(*PagingFile
));
743 if (PagingFile
== NULL
)
747 CurrentRetDescList
= RetDescList
;
748 RetDescList
= RetDescList
->Next
;
749 ExFreePool(CurrentRetDescList
);
751 ObDereferenceObject(FileObject
);
753 return(STATUS_NO_MEMORY
);
756 RtlZeroMemory(PagingFile
, sizeof(*PagingFile
));
758 PagingFile
->FileObject
= FileObject
;
759 PagingFile
->MaximumSize
.QuadPart
= SafeMaximumSize
.QuadPart
;
760 PagingFile
->CurrentSize
.QuadPart
= SafeInitialSize
.QuadPart
;
761 PagingFile
->FreePages
= (ULONG
)(SafeInitialSize
.QuadPart
/ PAGE_SIZE
);
762 PagingFile
->UsedPages
= 0;
763 KeInitializeSpinLock(&PagingFile
->AllocMapLock
);
765 AllocMapSize
= (PagingFile
->FreePages
/ 32) + 1;
766 PagingFile
->AllocMap
= ExAllocatePool(NonPagedPool
,
767 AllocMapSize
* sizeof(ULONG
));
768 PagingFile
->AllocMapSize
= AllocMapSize
;
770 if (PagingFile
->AllocMap
== NULL
)
774 CurrentRetDescList
= RetDescList
;
775 RetDescList
= RetDescList
->Next
;
776 ExFreePool(CurrentRetDescList
);
778 ExFreePool(PagingFile
);
779 ObDereferenceObject(FileObject
);
781 return(STATUS_NO_MEMORY
);
783 DPRINT("ExtentCount: %d\n", ExtentCount
);
784 Size
= sizeof(RETRIEVAL_POINTERS_BUFFER
) + ExtentCount
* 2 * sizeof(LARGE_INTEGER
);
785 PagingFile
->RetrievalPointers
= ExAllocatePool(NonPagedPool
, Size
);
786 if (PagingFile
->RetrievalPointers
== NULL
)
790 CurrentRetDescList
= RetDescList
;
791 RetDescList
= RetDescList
->Next
;
792 ExFreePool(CurrentRetDescList
);
794 ExFreePool(PagingFile
->AllocMap
);
795 ExFreePool(PagingFile
);
796 ObDereferenceObject(FileObject
);
798 return(STATUS_NO_MEMORY
);
801 RtlZeroMemory(PagingFile
->AllocMap
, AllocMapSize
* sizeof(ULONG
));
802 RtlZeroMemory(PagingFile
->RetrievalPointers
, Size
);
805 PagingFile
->RetrievalPointers
->ExtentCount
= ExtentCount
;
806 PagingFile
->RetrievalPointers
->StartingVcn
= RetDescList
->RetrievalPointers
.StartingVcn
;
807 CurrentRetDescList
= RetDescList
;
808 while (CurrentRetDescList
)
810 memcpy(&PagingFile
->RetrievalPointers
->Extents
[Count
],
811 CurrentRetDescList
->RetrievalPointers
.Extents
,
812 CurrentRetDescList
->RetrievalPointers
.ExtentCount
* 2 * sizeof(LARGE_INTEGER
));
813 Count
+= CurrentRetDescList
->RetrievalPointers
.ExtentCount
;
814 RetDescList
= CurrentRetDescList
;
815 CurrentRetDescList
= CurrentRetDescList
->Next
;
816 ExFreePool(RetDescList
);
819 if (PagingFile
->RetrievalPointers
->ExtentCount
!= ExtentCount
||
820 PagingFile
->RetrievalPointers
->Extents
[ExtentCount
- 1].NextVcn
.QuadPart
!= MaxVcn
.QuadPart
)
822 ExFreePool(PagingFile
->RetrievalPointers
);
823 ExFreePool(PagingFile
->AllocMap
);
824 ExFreePool(PagingFile
);
825 ObDereferenceObject(FileObject
);
827 return(STATUS_UNSUCCESSFUL
);
831 * Change the entries from lcn's to volume offset's.
833 PagingFile
->RetrievalPointers
->StartingVcn
.QuadPart
*= BytesPerAllocationUnit
;
834 for (i
= 0; i
< ExtentCount
; i
++)
836 PagingFile
->RetrievalPointers
->Extents
[i
].Lcn
.QuadPart
*= BytesPerAllocationUnit
;
837 PagingFile
->RetrievalPointers
->Extents
[i
].NextVcn
.QuadPart
*= BytesPerAllocationUnit
;
840 KeAcquireSpinLock(&PagingFileListLock
, &oldIrql
);
841 for (i
= 0; i
< MAX_PAGING_FILES
; i
++)
843 if (PagingFileList
[i
] == NULL
)
845 PagingFileList
[i
] = PagingFile
;
849 MiFreeSwapPages
= MiFreeSwapPages
+ PagingFile
->FreePages
;
851 KeReleaseSpinLock(&PagingFileListLock
, oldIrql
);
855 MmSwapSpaceMessage
= FALSE
;
857 return(STATUS_SUCCESS
);