[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / fstub / disksup.c
index 7c4f651..86a7e0a 100644 (file)
@@ -64,17 +64,20 @@ HalpAssignDrive(IN PUNICODE_STRING PartitionName,
     if ((DriveNumber != AUTO_DRIVE) && (DriveNumber < 26))
     {
         /* Force assignment */
+        KeAcquireGuardedMutex(&ObpDeviceMapLock);
         if ((ObSystemDeviceMap->DriveMap & (1 << DriveNumber)) != 0)
         {
             DbgPrint("Drive letter already used!\n");
+            KeReleaseGuardedMutex(&ObpDeviceMapLock);
             return FALSE;
         }
+        KeReleaseGuardedMutex(&ObpDeviceMapLock);
     }
     else
     {
         /* Automatic assignment */
         DriveNumber = AUTO_DRIVE;
-
+        KeAcquireGuardedMutex(&ObpDeviceMapLock);
         for (i = 2; i < 26; i++)
         {
             if ((ObSystemDeviceMap->DriveMap & (1 << i)) == 0)
@@ -83,6 +86,7 @@ HalpAssignDrive(IN PUNICODE_STRING PartitionName,
                 break;
             }
         }
+        KeReleaseGuardedMutex(&ObpDeviceMapLock);
 
         if (DriveNumber == AUTO_DRIVE)
         {
@@ -91,11 +95,7 @@ HalpAssignDrive(IN PUNICODE_STRING PartitionName,
         }
     }
 
-    DPRINT("DriveNumber %d\n", DriveNumber);
-
-    /* Update the System Device Map */
-    ObSystemDeviceMap->DriveMap |= (1 << DriveNumber);
-    ObSystemDeviceMap->DriveType[DriveNumber] = DriveType;
+    DPRINT("DriveNumber %lu\n", DriveNumber);
 
     /* Build drive name */
     swprintf(DriveNameBuffer,
@@ -159,7 +159,7 @@ xHalpGetRDiskCount(VOID)
     BOOLEAN First = TRUE;
     ULONG Count;
 
-    DirectoryInfo = ExAllocatePool(PagedPool, 2 * PAGE_SIZE);
+    DirectoryInfo = ExAllocatePoolWithTag(PagedPool, 2 * PAGE_SIZE, TAG_FILE_SYSTEM);
     if (DirectoryInfo == NULL)
     {
         return 0;
@@ -178,7 +178,7 @@ xHalpGetRDiskCount(VOID)
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("ZwOpenDirectoryObject for %wZ failed, status=%lx\n", &ArcName, Status);
-        ExFreePool(DirectoryInfo);
+        ExFreePoolWithTag(DirectoryInfo, TAG_FILE_SYSTEM);
         return 0;
     }
 
@@ -223,7 +223,7 @@ xHalpGetRDiskCount(VOID)
             }
         }
     }
-    ExFreePool(DirectoryInfo);
+    ExFreePoolWithTag(DirectoryInfo, TAG_FILE_SYSTEM);
     return RDiskCount;
 }
 
@@ -369,7 +369,7 @@ xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName,
         }
     }
 
-    DPRINT("DiskGeometry.BytesPerSector: %d\n",
+    DPRINT("DiskGeometry.BytesPerSector: %lu\n",
         DiskGeometry.BytesPerSector);
 
     if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA)
@@ -377,8 +377,8 @@ xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName,
         PDRIVE_LAYOUT_INFORMATION Buffer;
 
         /* Allocate a partition list for a single entry. */
-        Buffer = ExAllocatePool(NonPagedPool,
-            sizeof(DRIVE_LAYOUT_INFORMATION));
+        Buffer = ExAllocatePoolWithTag(NonPagedPool,
+            sizeof(DRIVE_LAYOUT_INFORMATION), TAG_FILE_SYSTEM);
         if (Buffer != NULL)
         {
             RtlZeroMemory(Buffer,
@@ -398,7 +398,7 @@ xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName,
         /* Read the partition table */
         Status = IoReadPartitionTable(DeviceObject,
             DiskGeometry.BytesPerSector,
-            FALSE,
+            TRUE,
             LayoutInfo);
     }
 
@@ -444,40 +444,48 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
 
     RDiskCount = xHalpGetRDiskCount();
 
-    DPRINT("RDiskCount %d\n", RDiskCount);
+    DPRINT("RDiskCount %lu\n", RDiskCount);
 
-    Buffer1 = (PWSTR)ExAllocatePool(PagedPool,
-        64 * sizeof(WCHAR));
-    Buffer2 = (PWSTR)ExAllocatePool(PagedPool,
-        32 * sizeof(WCHAR));
+    Buffer1 = ExAllocatePoolWithTag(PagedPool,
+        64 * sizeof(WCHAR),
+        TAG_FILE_SYSTEM);
+    if (!Buffer1) return;
 
-    PartialInformation = (PKEY_VALUE_PARTIAL_INFORMATION)ExAllocatePool(PagedPool,
-        sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(REG_DISK_MOUNT_INFO));
+    Buffer2 = ExAllocatePoolWithTag(PagedPool,
+        32 * sizeof(WCHAR),
+        TAG_FILE_SYSTEM);
+    if (!Buffer2)
+    {
+        ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
+        return;
+    }
 
-    if (!Buffer1 || !Buffer2 || !PartialInformation) return;
+    PartialInformation = ExAllocatePoolWithTag(PagedPool,
+        sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(REG_DISK_MOUNT_INFO),
+        TAG_FILE_SYSTEM);
+    if (!PartialInformation)
+    {
+        ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM);
+        ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
+        return;
+    }
 
     DiskMountInfo = (PREG_DISK_MOUNT_INFO) PartialInformation->Data;
 
-    /* Open or Create the 'MountedDevices' key */
+    /* Create or open the 'MountedDevices' key */
     RtlInitUnicodeString(&UnicodeString1, L"\\Registry\\Machine\\SYSTEM\\MountedDevices");
     InitializeObjectAttributes(&ObjectAttributes,
         &UnicodeString1,
-        OBJ_CASE_INSENSITIVE,
+        OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
         NULL,
         NULL);
-    Status = ZwOpenKey(&hKey,
+    Status = ZwCreateKey(&hKey,
         KEY_ALL_ACCESS,
-        &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-    {
-        Status = ZwCreateKey(&hKey,
-            KEY_ALL_ACCESS,
-            &ObjectAttributes,
-            0,
-            NULL,
-            REG_OPTION_NON_VOLATILE,
-            NULL);
-    }
+        &ObjectAttributes,
+        0,
+        NULL,
+        REG_OPTION_NON_VOLATILE,
+        NULL);
     if (!NT_SUCCESS(Status))
     {
         hKey = NULL;
@@ -485,14 +493,11 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
     }
 
     /* Create PhysicalDrive links */
-    DPRINT("Physical disk drives: %d\n", ConfigInfo->DiskCount);
+    DPRINT("Physical disk drives: %lu\n", ConfigInfo->DiskCount);
     for (i = 0; i < ConfigInfo->DiskCount; i++)
     {
-        swprintf(Buffer1,
-            L"\\Device\\Harddisk%d\\Partition0",
-            i);
-        RtlInitUnicodeString(&UnicodeString1,
-            Buffer1);
+        swprintf(Buffer1, L"\\Device\\Harddisk%lu\\Partition0", i);
+        RtlInitUnicodeString(&UnicodeString1, Buffer1);
 
         InitializeObjectAttributes(&ObjectAttributes,
             &UnicodeString1,
@@ -510,11 +515,8 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
         {
             ZwClose(FileHandle);
 
-            swprintf(Buffer2,
-                L"\\??\\PhysicalDrive%d",
-                i);
-            RtlInitUnicodeString(&UnicodeString2,
-                Buffer2);
+            swprintf(Buffer2, L"\\??\\PhysicalDrive%lu", i);
+            RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
             DPRINT("Creating link: %S ==> %S\n",
                 Buffer2,
@@ -528,28 +530,25 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
     /* Initialize layout array */
     if (ConfigInfo->DiskCount == 0)
         goto end_assign_disks;
-    LayoutArray = ExAllocatePool(NonPagedPool,
-        ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION));
+    LayoutArray = ExAllocatePoolWithTag(NonPagedPool,
+        ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION), TAG_FILE_SYSTEM);
     if (!LayoutArray)
     {
-        ExFreePool(PartialInformation);
-        ExFreePool(Buffer2);
-        ExFreePool(Buffer1);
-        if (hKey) ZwClose(hKey);
+        ExFreePoolWithTag(PartialInformation, TAG_FILE_SYSTEM);
+        ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM);
+        ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
+        if (hKey) ObCloseHandle(hKey, KernelMode);
+        return;
     }
 
     RtlZeroMemory(LayoutArray,
         ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION));
     for (i = 0; i < ConfigInfo->DiskCount; i++)
     {
-        swprintf(Buffer1,
-            L"\\Device\\Harddisk%d\\Partition0",
-            i);
-        RtlInitUnicodeString(&UnicodeString1,
-            Buffer1);
+        swprintf(Buffer1, L"\\Device\\Harddisk%lu\\Partition0", i);
+        RtlInitUnicodeString(&UnicodeString1, Buffer1);
 
-        Status = xHalQueryDriveLayout(&UnicodeString1,
-            &LayoutArray[i]);
+        Status = xHalQueryDriveLayout(&UnicodeString1, &LayoutArray[i]);
         if (!NT_SUCCESS(Status))
         {
             DbgPrint("xHalQueryDriveLayout() failed (Status = 0x%lx)\n",
@@ -628,11 +627,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                                         LayoutArray[i]->PartitionEntry[j].RewritePartition == FALSE)
                                     {
                                         swprintf(Buffer2,
-                                            L"\\Device\\Harddisk%d\\Partition%d",
-                                            i,
-                                            LayoutArray[i]->PartitionEntry[j].PartitionNumber);
-                                        RtlInitUnicodeString(&UnicodeString2,
-                                            Buffer2);
+                                                 L"\\Device\\Harddisk%lu\\Partition%lu",
+                                                 i,
+                                                 LayoutArray[i]->PartitionEntry[j].PartitionNumber);
+                                        RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                                         /* Assign drive */
                                         DPRINT("  %wZ\n", &UnicodeString2);
@@ -680,11 +678,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                     if (LayoutArray[DiskNumber]->PartitionEntry[j].RewritePartition == FALSE)
                     {
                         swprintf(Buffer2,
-                            L"\\Device\\Harddisk%lu\\Partition%d",
-                            DiskNumber,
-                            LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
-                        RtlInitUnicodeString(&UnicodeString2,
-                            Buffer2);
+                                 L"\\Device\\Harddisk%lu\\Partition%lu",
+                                 DiskNumber,
+                                 LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
+                        RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                         /* Assign drive */
                         DPRINT("  %wZ\n", &UnicodeString2);
@@ -721,11 +718,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                     IsRecognizedPartition(LayoutArray[DiskNumber]->PartitionEntry[j].PartitionType))
                 {
                     swprintf(Buffer2,
-                        L"\\Device\\Harddisk%d\\Partition%d",
-                        DiskNumber,
-                        LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
-                    RtlInitUnicodeString(&UnicodeString2,
-                        Buffer2);
+                             L"\\Device\\Harddisk%lu\\Partition%lu",
+                             DiskNumber,
+                             LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
+                    RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                     /* Assign drive */
                     DPRINT("  %wZ\n",
@@ -762,11 +758,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                     LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber != 0)
                 {
                     swprintf(Buffer2,
-                        L"\\Device\\Harddisk%d\\Partition%d",
-                        DiskNumber,
-                        LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
-                    RtlInitUnicodeString(&UnicodeString2,
-                        Buffer2);
+                             L"\\Device\\Harddisk%lu\\Partition%lu",
+                             DiskNumber,
+                             LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
+                    RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                     /* Assign drive */
                     DPRINT("  %wZ\n",
@@ -799,11 +794,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                     IsRecognizedPartition(LayoutArray[DiskNumber]->PartitionEntry[j].PartitionType))
                 {
                     swprintf(Buffer2,
-                        L"\\Device\\Harddisk%d\\Partition%d",
-                        DiskNumber,
-                        LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
-                    RtlInitUnicodeString(&UnicodeString2,
-                        Buffer2);
+                             L"\\Device\\Harddisk%lu\\Partition%lu",
+                             DiskNumber,
+                             LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
+                    RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                     /* Assign drive */
                     DPRINT("  %wZ\n",
@@ -837,11 +831,10 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
                     LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber != 0)
                 {
                     swprintf(Buffer2,
-                        L"\\Device\\Harddisk%d\\Partition%d",
-                        DiskNumber,
-                        LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
-                    RtlInitUnicodeString(&UnicodeString2,
-                        Buffer2);
+                             L"\\Device\\Harddisk%lu\\Partition%lu",
+                             DiskNumber,
+                             LayoutArray[DiskNumber]->PartitionEntry[j].PartitionNumber);
+                    RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                     /* Assign drive */
                     DPRINT("  %wZ\n",
@@ -871,11 +864,8 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
             if (LayoutArray[i]->PartitionCount == 1 &&
                 LayoutArray[i]->PartitionEntry[0].PartitionType == 0)
             {
-                swprintf(Buffer2,
-                    L"\\Device\\Harddisk%d\\Partition1",
-                    i);
-                RtlInitUnicodeString(&UnicodeString2,
-                    Buffer2);
+                swprintf(Buffer2, L"\\Device\\Harddisk%lu\\Partition1", i);
+                RtlInitUnicodeString(&UnicodeString2, Buffer2);
 
                 /* Assign drive */
                 DPRINT("  %wZ\n",
@@ -896,20 +886,17 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
     for (i = 0; i < ConfigInfo->DiskCount; i++)
     {
         if (LayoutArray[i] != NULL)
-            ExFreePool(LayoutArray[i]);
+            ExFreePoolWithTag(LayoutArray[i], TAG_FILE_SYSTEM);
     }
-    ExFreePool(LayoutArray);
+    ExFreePoolWithTag(LayoutArray, TAG_FILE_SYSTEM);
 end_assign_disks:
 
     /* Assign floppy drives */
-    DPRINT("Floppy drives: %d\n", ConfigInfo->FloppyCount);
+    DPRINT("Floppy drives: %lu\n", ConfigInfo->FloppyCount);
     for (i = 0; i < ConfigInfo->FloppyCount; i++)
     {
-        swprintf(Buffer1,
-            L"\\Device\\Floppy%d",
-            i);
-        RtlInitUnicodeString(&UnicodeString1,
-            Buffer1);
+        swprintf(Buffer1, L"\\Device\\Floppy%lu", i);
+        RtlInitUnicodeString(&UnicodeString1, Buffer1);
 
         /* Assign drive letters A: or B: or first free drive letter */
         DPRINT("  %wZ\n",
@@ -925,14 +912,11 @@ end_assign_disks:
     }
 
     /* Assign cdrom drives */
-    DPRINT("CD-Rom drives: %d\n", ConfigInfo->CdRomCount);
+    DPRINT("CD-Rom drives: %lu\n", ConfigInfo->CdRomCount);
     for (i = 0; i < ConfigInfo->CdRomCount; i++)
     {
-        swprintf(Buffer1,
-            L"\\Device\\CdRom%d",
-            i);
-        RtlInitUnicodeString(&UnicodeString1,
-            Buffer1);
+        swprintf(Buffer1, L"\\Device\\CdRom%lu", i);
+        RtlInitUnicodeString(&UnicodeString1, Buffer1);
 
         /* Assign first free drive letter */
         DPRINT("  %wZ\n", &UnicodeString1);
@@ -948,13 +932,10 @@ end_assign_disks:
 
     /* Anything else to do? */
 
-    ExFreePool(PartialInformation);
-    ExFreePool(Buffer2);
-    ExFreePool(Buffer1);
-    if (hKey)
-    {
-        ZwClose(hKey);
-    }
+    ExFreePoolWithTag(PartialInformation, TAG_FILE_SYSTEM);
+    ExFreePoolWithTag(Buffer2, TAG_FILE_SYSTEM);
+    ExFreePoolWithTag(Buffer1, TAG_FILE_SYSTEM);
+    if (hKey) ObCloseHandle(hKey, KernelMode);
 }
 
 #endif
@@ -1249,8 +1230,8 @@ xHalGetPartialGeometry(IN PDEVICE_OBJECT DeviceObject,
 Cleanup:
     /* Free all the pointers */
     if (Event) ExFreePoolWithTag(Event, TAG_FILE_SYSTEM);
-    if (IoStatusBlock) ExFreePool(IoStatusBlock);
-    if (DiskGeometry) ExFreePool(DiskGeometry);
+    if (IoStatusBlock) ExFreePoolWithTag(IoStatusBlock, TAG_FILE_SYSTEM);
+    if (DiskGeometry) ExFreePoolWithTag(DiskGeometry, TAG_FILE_SYSTEM);
     return;
 }
 
@@ -1365,16 +1346,17 @@ NTAPI
 FstubFixupEfiPartition(IN PPARTITION_DESCRIPTOR PartitionDescriptor,
                        IN ULONGLONG MaxOffset)
 {
-    ULONG PartitionLength;
+    ULONG PartitionMaxOffset, PartitionLength;
     PAGED_CODE();
 
     /* Compute partition length (according to MBR entry) */
-    PartitionLength = PartitionDescriptor->StartingSectorLsb0 + PartitionDescriptor->PartitionLengthLsb0;
+    PartitionMaxOffset = GET_STARTING_SECTOR(PartitionDescriptor) + GET_PARTITION_LENGTH(PartitionDescriptor);
     /* In case the partition length goes beyond disk size... */
-    if (PartitionLength > MaxOffset)
+    if (PartitionMaxOffset > MaxOffset)
     {
         /* Resize partition to its maximum real length */
-        PartitionDescriptor->PartitionLengthLsb0 = MaxOffset - PartitionDescriptor->StartingSectorLsb0;
+        PartitionLength = (ULONG)(PartitionMaxOffset - GET_STARTING_SECTOR(PartitionDescriptor));
+        SET_PARTITION_LENGTH(PartitionDescriptor, PartitionLength);
     }
 }
 
@@ -1425,7 +1407,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
     {
         /* EZ Drive found, bias the offset */
         IsEzDrive = TRUE;
-        ExFreePool(MbrBuffer);
+        ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
         Offset.QuadPart = 512;
     }
 
@@ -1673,7 +1655,8 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
                     UInt32x32To64(GET_PARTITION_LENGTH(PartitionDescriptor),
                                   SectorSize);
 
-                /* FIXME: REACTOS HACK */
+                // BUGBUGBUG: The correct partition numbers seem to cause boot failures!!!
+//                PartitionInfo->PartitionNumber = (!IsContainerPartition(PartitionType)) ? i : 0;
                 PartitionInfo->PartitionNumber = i + 1;
             }
             else
@@ -1685,7 +1668,6 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
                 PartitionInfo->PartitionLength.QuadPart = 0;
                 PartitionInfo->HiddenSectors = 0;
 
-                /* FIXME: REACTOS HACK */
                 PartitionInfo->PartitionNumber = 0;
             }
         }
@@ -1724,7 +1706,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
 
                 /* Also update the maximum sector */
                 MaxSector = GET_PARTITION_LENGTH(PartitionDescriptor);
-                DPRINT1("FSTUB: MaxSector now = %#08lx\n", MaxSector);
+                DPRINT1("FSTUB: MaxSector now = %I64d\n", MaxSector);
                 break;
             }
         }
@@ -1761,7 +1743,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
             DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a "
                     "super-floppy\n",
                     DeviceObject);
-            DPRINT1("FSTUB: Drive has %#08lx sectors and is %#016I64x "
+            DPRINT1("FSTUB: Drive has %I64d sectors and is %#016I64x "
                     "bytes large\n",
                     EndSector, EndSector * DiskGeometry.BytesPerSector);
 
@@ -1843,7 +1825,7 @@ xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
     {
         /* EZ Drive found, bias the offset */
         IsEzDrive = TRUE;
-        ExFreePool(MbrBuffer);
+        ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
         Offset.QuadPart = 512;
     }
 
@@ -1995,7 +1977,7 @@ xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
     } while (i < PartitionNumber);
 
     /* Everything done, cleanup */
-    if (Buffer) ExFreePool(Buffer);
+    if (Buffer) ExFreePoolWithTag(Buffer, TAG_FILE_SYSTEM);
     return Status;
 }
 
@@ -2043,7 +2025,7 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
     {
         /* EZ Drive found, bias the offset */
         IsEzDrive = TRUE;
-        ExFreePool(MbrBuffer);
+        ExFreePoolWithTag(MbrBuffer, TAG_FILE_SYSTEM);
         Offset.QuadPart = 512;
     }