Make SystemConfigurationDataQueryRoutine() store information about as many drives...
[reactos.git] / reactos / base / setup / usetup / partlist.c
index 8a14cb9..477a20e 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$
- * COPYRIGHT:       See COPYING in the top level directory
+/* COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS text-mode setup
  * FILE:            subsys/system/usetup/partlist.c
  * PURPOSE:         Partition list functions
@@ -214,8 +213,8 @@ AddPartitionToList (ULONG DiskNumber,
     {
       for (j = 0; j < 4; j++)
        {
-         if (LayoutBuffer->PartitionEntry[j].PartitionType != PARTITION_ENTRY_UNUSED ||
-             LayoutBuffer->PartitionEntry[j].PartitionLength.QuadPart != 0ULL)
+         if (LayoutBuffer->PartitionEntry[i+j].PartitionType != PARTITION_ENTRY_UNUSED ||
+             LayoutBuffer->PartitionEntry[i+j].PartitionLength.QuadPart != 0ULL)
            {
              break;
            }
@@ -457,31 +456,33 @@ DiskConfigurationDataQueryRoutine(PWSTR ValueName,
                                   PVOID Context,
                                   PVOID EntryContext)
 {
-  PBIOSDISKENTRY BiosDiskEntry = (PBIOSDISKENTRY)Context;
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
-  PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
+       PBIOSDISKENTRY BiosDiskEntry = (PBIOSDISKENTRY)Context;
+       PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+       PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
+       ULONG i;
+
+       if (ValueType != REG_FULL_RESOURCE_DESCRIPTOR ||
+               ValueLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR))
+               return STATUS_UNSUCCESSFUL;
+
+       FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
+       /* Hm. Version and Revision are not set on Microsoft Windows XP... */
+       /*if (FullResourceDescriptor->PartialResourceList.Version != 1 ||
+               FullResourceDescriptor->PartialResourceList.Revision != 1)
+               return STATUS_UNSUCCESSFUL;*/
+
+       for (i = 0; i < FullResourceDescriptor->PartialResourceList.Count; i++)
+       {
+               if (FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].Type != CmResourceTypeDeviceSpecific ||
+                       FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize != sizeof(CM_DISK_GEOMETRY_DEVICE_DATA))
+                       continue;
 
-  if (ValueType == REG_FULL_RESOURCE_DESCRIPTOR &&
-      ValueLength == sizeof(CM_FULL_RESOURCE_DESCRIPTOR) + sizeof(CM_DISK_GEOMETRY_DEVICE_DATA))
-    {
-      FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
-      /* FIXME:
-       *   Is this 'paranoia' check correct ?
-       */
-      if (FullResourceDescriptor->InterfaceType != InterfaceTypeUndefined ||
-          FullResourceDescriptor->BusNumber != 0 ||
-          FullResourceDescriptor->PartialResourceList.Count != 1 ||
-          FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type != CmResourceTypeDeviceSpecific ||
-          FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.DeviceSpecificData.DataSize != sizeof(CM_DISK_GEOMETRY_DEVICE_DATA))
-        {
-          return STATUS_UNSUCCESSFUL;
-        }
-      DiskGeometry = (PCM_DISK_GEOMETRY_DEVICE_DATA)(FullResourceDescriptor + 1);
-      BiosDiskEntry->DiskGeometry = *DiskGeometry;
+               DiskGeometry = (PCM_DISK_GEOMETRY_DEVICE_DATA)&FullResourceDescriptor->PartialResourceList.PartialDescriptors[i + 1];
+               BiosDiskEntry->DiskGeometry = *DiskGeometry;
 
-      return STATUS_SUCCESS;
-    }
-  return STATUS_UNSUCCESSFUL;
+               return STATUS_SUCCESS;
+       }
+       return STATUS_UNSUCCESSFUL;
 }
 
 NTSTATUS
@@ -493,31 +494,36 @@ SystemConfigurationDataQueryRoutine(PWSTR ValueName,
                                     PVOID Context,
                                     PVOID EntryContext)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
-  PCM_INT13_DRIVE_PARAMETER* Int13Drives = (PCM_INT13_DRIVE_PARAMETER*)Context;
-
-  if (ValueType == REG_FULL_RESOURCE_DESCRIPTOR &&
-      ValueLength >= sizeof (CM_FULL_RESOURCE_DESCRIPTOR) &&
-      (ValueLength - sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) % sizeof(CM_INT13_DRIVE_PARAMETER) == 0)
-    {
-      FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
-      if (FullResourceDescriptor->InterfaceType != InterfaceTypeUndefined ||
-          FullResourceDescriptor->BusNumber != -1 ||
-          FullResourceDescriptor->PartialResourceList.Count != 1 ||
-          FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type != CmResourceTypeDeviceSpecific)
-        {
-          return STATUS_UNSUCCESSFUL;
-        }
-      *Int13Drives = RtlAllocateHeap(ProcessHeap, 0, ValueLength - sizeof (CM_FULL_RESOURCE_DESCRIPTOR));
-      if (*Int13Drives == NULL)
-        {
-          return STATUS_NO_MEMORY;
-        }
-      memcpy(*Int13Drives, FullResourceDescriptor + 1, ValueLength - sizeof (CM_FULL_RESOURCE_DESCRIPTOR));
-      return STATUS_SUCCESS;
-    }
-  return STATUS_UNSUCCESSFUL;
+       PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+       PCM_INT13_DRIVE_PARAMETER* Int13Drives = (PCM_INT13_DRIVE_PARAMETER*)Context;
+       ULONG i;
 
+       if (ValueType != REG_FULL_RESOURCE_DESCRIPTOR ||
+               ValueLength < sizeof (CM_FULL_RESOURCE_DESCRIPTOR))
+               return STATUS_UNSUCCESSFUL;
+
+       FullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR)ValueData;
+       /* Hm. Version and Revision are not set on Microsoft Windows XP... */
+       /*if (FullResourceDescriptor->PartialResourceList.Version != 1 ||
+               FullResourceDescriptor->PartialResourceList.Revision != 1)
+               return STATUS_UNSUCCESSFUL;*/
+
+       for (i = 0; i < FullResourceDescriptor->PartialResourceList.Count; i++)
+       {
+               if (FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].Type != CmResourceTypeDeviceSpecific ||
+                       FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize % sizeof(CM_INT13_DRIVE_PARAMETER) != 0)
+                       continue;
+
+               *Int13Drives = RtlAllocateHeap(ProcessHeap, 0, FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize);
+               if (*Int13Drives == NULL)
+                       return STATUS_NO_MEMORY;
+               memcpy(
+                       *Int13Drives,
+                       &FullResourceDescriptor->PartialResourceList.PartialDescriptors[i + 1],
+                       FullResourceDescriptor->PartialResourceList.PartialDescriptors[i].u.DeviceSpecificData.DataSize);
+               return STATUS_SUCCESS;
+       }
+       return STATUS_UNSUCCESSFUL;
 }
 #define ROOT_NAME   L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"
 
@@ -948,7 +954,7 @@ CreatePartitionList (SHORT Left,
                           &Iosb,
                           FILE_SHARE_READ,
                           FILE_SYNCHRONOUS_IO_NONALERT);
-      if (NT_SUCCESS(Status))
+         if (NT_SUCCESS(Status))
        {
          AddDiskToList (FileHandle,
                         DiskNumber,
@@ -1083,7 +1089,7 @@ PrintPartitionData (PPARTLIST List,
   USHORT Width;
   USHORT Height;
 
-  ULONGLONG PartSize;
+  LARGE_INTEGER PartSize;
   PCHAR Unit;
   UCHAR Attribute;
   PCHAR PartType;
@@ -1100,25 +1106,25 @@ PrintPartitionData (PPARTLIST List,
 #if 0
       if (PartEntry->UnpartitionledLength >= 0x280000000ULL) /* 10 GB */
        {
-         PartSize = (PartEntry->UnpartitionedLength + (1 << 29)) >> 30;
+         PartSize.QuadPart = (PartEntry->UnpartitionedLength + (1 << 29)) >> 30;
          Unit = "GB";
        }
       else
 #endif
       if (PartEntry->UnpartitionedLength >= 0xA00000ULL) /* 10 MB */
        {
-         PartSize = (PartEntry->UnpartitionedLength + (1 << 19)) >> 20;
+         PartSize.QuadPart = (PartEntry->UnpartitionedLength + (1 << 19)) >> 20;
          Unit = "MB";
        }
       else
        {
-         PartSize = (PartEntry->UnpartitionedLength + (1 << 9)) >> 10;
+         PartSize.QuadPart = (PartEntry->UnpartitionedLength + (1 << 9)) >> 10;
          Unit = "KB";
        }
 
       sprintf (LineBuffer,
-              "    Unpartitioned space              %6I64u %s",
-              PartSize,
+              "    Unpartitioned space              %6lu %s",
+              PartSize.u.LowPart,
               Unit);
     }
   else
@@ -1152,40 +1158,40 @@ PrintPartitionData (PPARTLIST List,
 #if 0
       if (PartEntry->PartInfo[0].PartitionLength.QuadPart >= 0x280000000LL) /* 10 GB */
        {
-         PartSize = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 29)) >> 30;
+         PartSize.QuadPart = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 29)) >> 30;
          Unit = "GB";
        }
       else
 #endif
       if (PartEntry->PartInfo[0].PartitionLength.QuadPart >= 0xA00000LL) /* 10 MB */
        {
-         PartSize = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 19)) >> 20;
+         PartSize.QuadPart = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 19)) >> 20;
          Unit = "MB";
        }
       else
        {
-         PartSize = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 9)) >> 10;
+         PartSize.QuadPart = (PartEntry->PartInfo[0].PartitionLength.QuadPart + (1 << 9)) >> 10;
          Unit = "KB";
        }
 
       if (PartType == NULL)
        {
          sprintf (LineBuffer,
-                  "%c%c  Type %-3u                         %6I64u %s",
+                  "%c%c  Type %-3u                         %6lu %s",
                   (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
                   (PartEntry->DriveLetter == 0) ? '-' : ':',
                   PartEntry->PartInfo[0].PartitionType,
-                  PartSize,
+                  PartSize.u.LowPart,
                   Unit);
        }
       else
        {
          sprintf (LineBuffer,
-                  "%c%c  %-24s         %6I64u %s",
+                  "%c%c  %-24s         %6lu %s",
                   (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
                   (PartEntry->DriveLetter == 0) ? '-' : ':',
                   PartType,
-                  PartSize,
+                  PartSize.u.LowPart,
                   Unit);
        }
     }