Revert part of r20493. Created bug 1229 to keep track of the issue.
[reactos.git] / reactos / ntoskrnl / mm / pagefile.c
index 7af435b..5cccff8 100644 (file)
@@ -16,8 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id$
- *
+/*
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/mm/pagefile.c
  * PURPOSE:         Paging file functions
 #define NDEBUG
 #include <internal/debug.h>
 
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, MmInitPagingFile)
+#endif
+
+
 /* TYPES *********************************************************************/
 
 typedef struct _PAGINGFILE
@@ -544,7 +548,7 @@ MmDumpToPagingFile(ULONG BugCode,
    Headers->Type = MmCoreDumpType;
    if (TrapFrame != NULL)
    {
-      if (!(TrapFrame->Eflags & (1 << 17)))
+      if (!(TrapFrame->EFlags & (1 << 17)))
       {
          memcpy(&Headers->TrapFrame, TrapFrame,
                 sizeof(KTRAP_FRAME) - (4 * sizeof(DWORD)));
@@ -804,13 +808,6 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
 
    PreviousMode = ExGetPreviousMode();
 
-   Status = ProbeAndCaptureUnicodeString(&CapturedFileName,
-                                         PreviousMode,
-                                         FileName);
-   if (!NT_SUCCESS(Status))
-   {
-      return(Status);
-   }
    if (PreviousMode != KernelMode)
    {
       _SEH_TRY
@@ -826,8 +823,6 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
 
       if (!NT_SUCCESS(Status))
       {
-         ReleaseCapturedUnicodeString(&CapturedFileName,
-                                      PreviousMode);
          return Status;
       }
    }
@@ -837,6 +832,29 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       SafeMaximumSize = *MaximumSize;
    }
 
+   /* Pagefiles can't be larger than 4GB and ofcourse the minimum should be
+      smaller than the maximum */
+   if (0 != SafeInitialSize.u.HighPart)
+   {
+      return STATUS_INVALID_PARAMETER_2;
+   }
+   if (0 != SafeMaximumSize.u.HighPart)
+   {
+      return STATUS_INVALID_PARAMETER_3;
+   }
+   if (SafeMaximumSize.u.LowPart < SafeInitialSize.u.LowPart)
+   {
+      return STATUS_INVALID_PARAMETER_MIX;
+   }
+
+   Status = ProbeAndCaptureUnicodeString(&CapturedFileName,
+                                         PreviousMode,
+                                         FileName);
+   if (!NT_SUCCESS(Status))
+   {
+      return(Status);
+   }
+
    InitializeObjectAttributes(&ObjectAttributes,
                               &CapturedFileName,
                               0,
@@ -876,9 +894,17 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
       return Status;
    }
 
-   BytesPerAllocationUnit = FsSizeInformation.SectorsPerAllocationUnit * FsSizeInformation.BytesPerSector;
+   BytesPerAllocationUnit = FsSizeInformation.SectorsPerAllocationUnit *
+                            FsSizeInformation.BytesPerSector;
+   /* FIXME: If we have 2048 BytesPerAllocationUnit (FAT16 < 128MB) there is
+    * a problem if the paging file is fragmented. Suppose the first cluster
+    * of the paging file is cluster 3042 but cluster 3043 is NOT part of the
+    * paging file but of another file. We can't write a complete page (4096
+    * bytes) to the physical location of cluster 3042 then. */
    if (BytesPerAllocationUnit % PAGE_SIZE)
    {
+      DPRINT1("BytesPerAllocationUnit %d is not a multiple of PAGE_SIZE %d\n",
+              BytesPerAllocationUnit, PAGE_SIZE);
       ZwClose(FileHandle);
       return STATUS_UNSUCCESSFUL;
    }