https://git.reactos.org/?p=reactos.git;a=commitdiff;h=eaf7d6ebbe4bc2f3a6e718...
commit eaf7d6ebbe4bc2f3a6e71882d3fa53a3e8b74dee Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sat May 13 16:32:53 2017 +0000 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Sat May 26 19:09:39 2018 +0200
[USETUP] Code improvements for PartList.
- Use explicit ansi string safe functions (where they are used ansi, but not explicitely); - Add (old-school) function parameters annotations; - Use PARTITION_ENTRY_UNUSED where needed (instead of hardcoding its value); - Turn some functions static to this module; - Turn the 2nd parameter of both GetNextUnformattedPartition() and GetNextUncheckedPartition() optional (for next commit); - Improve some comments; - Use NT types.
svn path=/branches/setup_improvements/; revision=74531 --- base/setup/usetup/partlist.c | 181 ++++++++++++++++++++----------------------- base/setup/usetup/partlist.h | 64 +++++++-------- 2 files changed, 118 insertions(+), 127 deletions(-)
diff --git a/base/setup/usetup/partlist.c b/base/setup/usetup/partlist.c index b047a227b5..22867b73a4 100644 --- a/base/setup/usetup/partlist.c +++ b/base/setup/usetup/partlist.c @@ -174,19 +174,19 @@ static PARTITION_TYPE PartitionTypes[] =
VOID GetPartTypeStringFromPartitionType( - UCHAR partitionType, - PCHAR strPartType, - DWORD cchPartType) + IN UCHAR partitionType, + OUT PCHAR strPartType, + IN ULONG cchPartType) { /* Determine partition type */
if (IsContainerPartition(partitionType)) { - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_EXTENDED_PARTITION)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_EXTENDED_PARTITION)); } else if (partitionType == PARTITION_ENTRY_UNUSED) { - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_FORMATUNUSED)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_FORMATUNUSED)); } else { @@ -197,13 +197,13 @@ GetPartTypeStringFromPartitionType( { if (partitionType == PartitionTypes[i].Type) { - StringCchCopy(strPartType, cchPartType, PartitionTypes[i].Description); + RtlStringCchCopyA(strPartType, cchPartType, PartitionTypes[i].Description); return; } }
/* We are here because the partition type is unknown */ - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_FORMATUNKNOWN)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_FORMATUNKNOWN)); } }
@@ -253,7 +253,6 @@ AlignDown( return Temp * Alignment; }
- ULONGLONG AlignUp( IN ULONGLONG Value, @@ -282,7 +281,7 @@ RoundingDivide( static VOID GetDriverName( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { RTL_QUERY_REGISTRY_TABLE QueryTable[2]; WCHAR KeyName[32]; @@ -317,7 +316,7 @@ GetDriverName( static VOID AssignDriveLetters( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -396,7 +395,7 @@ AssignDriveLetters( }
-NTSTATUS +static NTSTATUS NTAPI DiskIdentifierQueryRoutine( PWSTR ValueName, @@ -426,7 +425,7 @@ DiskIdentifierQueryRoutine( }
-NTSTATUS +static NTSTATUS NTAPI DiskConfigurationDataQueryRoutine( PWSTR ValueName, @@ -470,7 +469,7 @@ DiskConfigurationDataQueryRoutine( }
-NTSTATUS +static NTSTATUS NTAPI SystemConfigurationDataQueryRoutine( PWSTR ValueName, @@ -522,7 +521,7 @@ SystemConfigurationDataQueryRoutine(
static VOID EnumerateBiosDiskEntries( - PPARTLIST PartList) + IN PPARTLIST PartList) { RTL_QUERY_REGISTRY_TABLE QueryTable[3]; WCHAR Name[120]; @@ -663,16 +662,16 @@ EnumerateBiosDiskEntries( static VOID AddPartitionToDisk( - ULONG DiskNumber, - PDISKENTRY DiskEntry, - ULONG PartitionIndex, - BOOLEAN LogicalPartition) + IN ULONG DiskNumber, + IN PDISKENTRY DiskEntry, + IN ULONG PartitionIndex, + IN BOOLEAN LogicalPartition) { PPARTITION_INFORMATION PartitionInfo; PPARTENTRY PartEntry;
PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartitionIndex]; - if (PartitionInfo->PartitionType == 0 || + if (PartitionInfo->PartitionType == PARTITION_ENTRY_UNUSED || ((LogicalPartition != FALSE) && IsContainerPartition(PartitionInfo->PartitionType))) return;
@@ -773,7 +772,7 @@ AddPartitionToDisk( static VOID ScanForUnpartitionedDiskSpace( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { ULONGLONG LastStartSector; ULONGLONG LastSectorCount; @@ -788,7 +787,7 @@ ScanForUnpartitionedDiskSpace( { DPRINT1("No primary partition!\n");
- /* Create a partition table that represents the empty disk */ + /* Create a partition entry that represents the empty disk */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -906,7 +905,7 @@ ScanForUnpartitionedDiskSpace( { DPRINT1("No logical partition!\n");
- /* Create a partition table entry that represents the empty extended partition */ + /* Create a partition entry that represents the empty extended partition */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -1080,12 +1079,12 @@ SetDiskSignature( static VOID UpdateDiskSignatures( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry; PDISKENTRY DiskEntry;
- /* Print partition lines*/ + /* Print partition lines */ Entry = List->DiskListHead.Flink; while (Entry != &List->DiskListHead) { @@ -1106,9 +1105,9 @@ UpdateDiskSignatures( static VOID AddDiskToList( - HANDLE FileHandle, - ULONG DiskNumber, - PPARTLIST List) + IN HANDLE FileHandle, + IN ULONG DiskNumber, + IN PPARTLIST List) { DISK_GEOMETRY DiskGeometry; SCSI_ADDRESS ScsiAddress; @@ -1138,9 +1137,7 @@ AddDiskToList( &DiskGeometry, sizeof(DISK_GEOMETRY)); if (!NT_SUCCESS(Status)) - { return; - }
if (DiskGeometry.MediaType != FixedMedia && DiskGeometry.MediaType != RemovableMedia) @@ -1159,17 +1156,13 @@ AddDiskToList( &ScsiAddress, sizeof(SCSI_ADDRESS)); if (!NT_SUCCESS(Status)) - { return; - }
Mbr = (PARTITION_SECTOR*)RtlAllocateHeap(ProcessHeap, 0, DiskGeometry.BytesPerSector); if (Mbr == NULL) - { return; - }
FileOffset.QuadPart = 0; Status = NtReadFile(FileHandle, @@ -1219,7 +1212,7 @@ AddDiskToList( else DiskEntry->NoMbr = FALSE;
- /* Free Mbr sector buffer */ + /* Free the MBR sector buffer */ RtlFreeHeap(ProcessHeap, 0, Mbr);
ListEntry = List->BiosDiskListHead.Flink; @@ -1228,7 +1221,7 @@ AddDiskToList( BiosDiskEntry = CONTAINING_RECORD(ListEntry, BIOSDISKENTRY, ListEntry); /* FIXME: * Compare the size from bios and the reported size from driver. - * If we have more than one disk with a zero or with the same signatur + * If we have more than one disk with a zero or with the same signature * we must create new signatures and reboot. After the reboot, * it is possible to identify the disks. */ @@ -1348,7 +1341,7 @@ AddDiskToList(
if (DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart != 0 && DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionLength.QuadPart != 0 && - DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionType != 0) + DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionType != PARTITION_ENTRY_UNUSED) { if ((DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart / DiskEntry->BytesPerSector) % DiskEntry->SectorsPerTrack == 0) { @@ -1499,7 +1492,7 @@ CreatePartitionList(
if (IsListEmpty(&List->CurrentDisk->PrimaryPartListHead)) { - List->CurrentPartition = 0; + List->CurrentPartition = NULL; } else { @@ -1515,7 +1508,7 @@ CreatePartitionList(
VOID DestroyPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PBIOSDISKENTRY BiosDiskEntry; @@ -1575,10 +1568,10 @@ DestroyPartitionList( static VOID PrintEmptyLine( - PPARTLIST List) + IN PPARTLIST List) { COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height;
@@ -1610,13 +1603,13 @@ PrintEmptyLine( static VOID PrintPartitionData( - PPARTLIST List, - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PPARTLIST List, + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { CHAR LineBuffer[128]; COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height; LARGE_INTEGER PartSize; @@ -1766,14 +1759,14 @@ PrintPartitionData( static VOID PrintDiskData( - PPARTLIST List, - PDISKENTRY DiskEntry) + IN PPARTLIST List, + IN PDISKENTRY DiskEntry) { PPARTENTRY PrimaryPartEntry, LogicalPartEntry; PLIST_ENTRY PrimaryEntry, LogicalEntry; CHAR LineBuffer[128]; COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height; ULARGE_INTEGER DiskSize; @@ -1888,19 +1881,19 @@ PrintDiskData(
VOID DrawPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry, Entry2; PDISKENTRY DiskEntry; PPARTENTRY PartEntry = NULL; COORD coPos; - DWORD Written; + ULONG Written; SHORT i; SHORT CurrentDiskLine; SHORT CurrentPartLine; SHORT LastLine; - BOOL CurrentPartLineFound = FALSE; - BOOL CurrentDiskLineFound = FALSE; + BOOLEAN CurrentPartLineFound = FALSE; + BOOLEAN CurrentDiskLineFound = FALSE;
/* Calculate the line of the current disk and partition */ CurrentDiskLine = 0; @@ -2130,11 +2123,11 @@ DrawPartitionList( }
-DWORD +ULONG SelectPartition( - PPARTLIST List, - ULONG DiskNumber, - ULONG PartitionNumber) + IN PPARTLIST List, + IN ULONG DiskNumber, + IN ULONG PartitionNumber) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2181,7 +2174,7 @@ SelectPartition(
BOOL ScrollDownPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY DiskListEntry; PLIST_ENTRY PartListEntry; @@ -2277,7 +2270,7 @@ ScrollDownPartitionList(
BOOL ScrollUpPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY DiskListEntry; PLIST_ENTRY PartListEntry; @@ -2374,7 +2367,7 @@ ScrollUpPartitionList( static BOOLEAN IsEmptyLayoutEntry( - PPARTITION_INFORMATION PartitionInfo) + IN PPARTITION_INFORMATION PartitionInfo) { if (PartitionInfo->StartingOffset.QuadPart == 0 && PartitionInfo->PartitionLength.QuadPart == 0) @@ -2427,7 +2420,7 @@ GetPrimaryPartitionCount( static ULONG GetLogicalPartitionCount( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PLIST_ENTRY ListEntry; PPARTENTRY PartEntry; @@ -2448,9 +2441,9 @@ GetLogicalPartitionCount(
static -BOOL +BOOLEAN ReAllocateLayoutBuffer( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PDRIVE_LAYOUT_INFORMATION NewLayoutBuffer; ULONG NewPartitionCount; @@ -2486,8 +2479,8 @@ ReAllocateLayoutBuffer( /* If the layout buffer grows, make sure the new (empty) entries are written to the disk */ if (NewPartitionCount > CurrentPartitionCount) { - for (i = CurrentPartitionCount; i < NewPartitionCount; i++) - NewLayoutBuffer->PartitionEntry[i].RewritePartition = TRUE; + for (i = CurrentPartitionCount; i < NewPartitionCount; i++) + NewLayoutBuffer->PartitionEntry[i].RewritePartition = TRUE; }
DiskEntry->LayoutBuffer = NewLayoutBuffer; @@ -2556,7 +2549,7 @@ UpdateDiskLayout( ListEntry = ListEntry->Flink; }
- /* Update the logical partition tables */ + /* Update the logical partition table */ Index = 4; ListEntry = DiskEntry->LogicalPartListHead.Flink; while (ListEntry != &DiskEntry->LogicalPartListHead) @@ -2581,7 +2574,7 @@ UpdateDiskLayout( PartEntry->PartitionNumber = PartitionNumber; PartEntry->PartitionIndex = Index;
- /* Fill the link entry of the previous partition table */ + /* Fill the link entry of the previous partition entry */ if (LinkInfo != NULL) { LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector; @@ -2595,7 +2588,7 @@ UpdateDiskLayout( LinkInfo->RewritePartition = TRUE; }
- /* Save a pointer to the link entry of the current partition table */ + /* Save a pointer to the link entry of the current partition entry */ LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
PartitionNumber++; @@ -2605,7 +2598,7 @@ UpdateDiskLayout( ListEntry = ListEntry->Flink; }
- /* Wipe unused primary partition table entries */ + /* Wipe unused primary partition entries */ for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++) { DPRINT1("Primary partition entry %lu\n", Index); @@ -2627,7 +2620,7 @@ UpdateDiskLayout( } }
- /* Wipe unused logical partition table entries */ + /* Wipe unused logical partition entries */ for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++) { if (Index % 4 >= 2) @@ -2661,8 +2654,8 @@ UpdateDiskLayout( static PPARTENTRY GetPrevUnpartitionedEntry( - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { PPARTENTRY PrevPartEntry; PLIST_ENTRY ListHead; @@ -2688,8 +2681,8 @@ GetPrevUnpartitionedEntry( static PPARTENTRY GetNextUnpartitionedEntry( - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { PPARTENTRY NextPartEntry; PLIST_ENTRY ListHead; @@ -2714,9 +2707,9 @@ GetNextUnpartitionedEntry(
VOID CreatePrimaryPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate) + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2800,13 +2793,13 @@ CreatePrimaryPartition( static VOID AddLogicalDiskSpace( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PPARTENTRY NewPartEntry;
DPRINT1("AddLogicalDiskSpace()\n");
- /* Create a partition table entry that represents the empty space in the container partition */ + /* Create a partition entry that represents the empty space in the container partition */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -2833,8 +2826,8 @@ AddLogicalDiskSpace(
VOID CreateExtendedPartition( - PPARTLIST List, - ULONGLONG SectorCount) + IN PPARTLIST List, + IN ULONGLONG SectorCount) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2845,7 +2838,7 @@ CreateExtendedPartition( if (List == NULL || List->CurrentDisk == NULL || List->CurrentPartition == NULL || - (List->CurrentPartition->IsPartitioned != FALSE)) + List->CurrentPartition->IsPartitioned != FALSE) { return; } @@ -2942,9 +2935,9 @@ CreateExtendedPartition(
VOID CreateLogicalPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate) + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -3029,7 +3022,7 @@ CreateLogicalPartition(
VOID DeleteCurrentPartition( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -3046,7 +3039,7 @@ DeleteCurrentPartition( return; }
- /* Clear the system disk and partition pointers if the system partition will be deleted */ + /* Clear the system disk and partition pointers if the system partition is being deleted */ if (List->SystemPartition == List->CurrentPartition) { List->SystemDisk = NULL; @@ -3462,7 +3455,7 @@ WritePartitions(
BOOLEAN WritePartitionsToDisk( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry; PDISKENTRY DiskEntry; @@ -3488,9 +3481,9 @@ WritePartitionsToDisk( }
-BOOL +BOOLEAN SetMountedDeviceValues( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry1, Entry2; PDISKENTRY DiskEntry; @@ -3498,9 +3491,7 @@ SetMountedDeviceValues( LARGE_INTEGER StartingOffset;
if (List == NULL) - { return FALSE; - }
Entry1 = List->DiskListHead.Flink; while (Entry1 != &List->DiskListHead) @@ -3515,6 +3506,7 @@ SetMountedDeviceValues( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->IsPartitioned) { + /* Assign a "\DosDevices#:" mount point to this partition */ if (PartEntry->DriveLetter) { StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector; @@ -3603,10 +3595,10 @@ LogicalPartitionCreationChecks( }
-BOOL +BOOLEAN GetNextUnformattedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry) { PLIST_ENTRY Entry1, Entry2; @@ -3657,11 +3649,10 @@ GetNextUnformattedPartition( return FALSE; }
- -BOOL +BOOLEAN GetNextUncheckedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry) { PLIST_ENTRY Entry1, Entry2; diff --git a/base/setup/usetup/partlist.h b/base/setup/usetup/partlist.h index c42335a70a..9787f94ae3 100644 --- a/base/setup/usetup/partlist.h +++ b/base/setup/usetup/partlist.h @@ -209,6 +209,12 @@ typedef struct ULONG Signature; } BIOS_DISK, *PBIOS_DISK;
+VOID +GetPartTypeStringFromPartitionType( + IN UCHAR partitionType, + OUT PCHAR strPartType, + IN ULONG cchPartType); + PPARTLIST CreatePartitionList( SHORT Left, @@ -218,50 +224,46 @@ CreatePartitionList(
VOID DestroyPartitionList( - PPARTLIST List); + IN PPARTLIST List);
VOID DrawPartitionList( - PPARTLIST List); + IN PPARTLIST List);
-DWORD +ULONG SelectPartition( - PPARTLIST List, - ULONG DiskNumber, - ULONG PartitionNumber); - -BOOL -SetMountedDeviceValues( - PPARTLIST List); + IN PPARTLIST List, + IN ULONG DiskNumber, + IN ULONG PartitionNumber);
BOOL ScrollDownPartitionList( - PPARTLIST List); + IN PPARTLIST List);
BOOL ScrollUpPartitionList( - PPARTLIST List); + IN PPARTLIST List);
VOID CreatePrimaryPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate); + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate);
VOID CreateExtendedPartition( - PPARTLIST List, - ULONGLONG SectorCount); + IN PPARTLIST List, + IN ULONGLONG SectorCount);
VOID CreateLogicalPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate); + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate);
VOID DeleteCurrentPartition( - PPARTLIST List); + IN PPARTLIST List);
VOID CheckActiveSystemPartition( @@ -270,7 +272,11 @@ CheckActiveSystemPartition(
BOOLEAN WritePartitionsToDisk( - PPARTLIST List); + IN PPARTLIST List); + +BOOLEAN +SetMountedDeviceValues( + IN PPARTLIST List);
ULONG PrimaryPartitionCreationChecks( @@ -284,22 +290,16 @@ ULONG LogicalPartitionCreationChecks( IN PPARTLIST List);
-BOOL +BOOLEAN GetNextUnformattedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry);
-BOOL +BOOLEAN GetNextUncheckedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry);
-VOID -GetPartTypeStringFromPartitionType( - UCHAR partitionType, - PCHAR strPartType, - DWORD cchPartType); - /* EOF */