[SETUPLIB][USETUP] Some cleanup for partition code.

- Make the Create*Partition helpers take a size in bytes, not in sectors.

  This allows them to be easier to use by the caller, alleviating the
  need for making the size conversion into sectors. Instead it is done
  internally by the helpers.

- Introduce helper macros to easily retrieve the size of a partition
  entry or a disk in bytes, from their internal representation in number
  of sectors.

- The 'AutoCreate' variable being USETUP-specific, remove it from the
  PARTENTRY structure and use instead a flag set into the 'New' member.

- Rename IsDiskSizeValid to IsPartitionLargeEnough, to better describe
  what the function is for.
This commit is contained in:
Hermès Bélusca-Maïto 2023-12-07 23:29:28 +01:00
parent b2ec78673d
commit b7ad4a2298
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 143 additions and 131 deletions

View file

@ -70,9 +70,6 @@ typedef struct _PARTENTRY
/* Partition is new, table does not exist on disk yet */
BOOLEAN New;
/* Partition was created automatically */
BOOLEAN AutoCreate;
/* Partition must be checked */
BOOLEAN NeedsCheck;
@ -227,6 +224,16 @@ RoundingDivide(
IN ULONGLONG Divisor);
#define GetPartEntryOffsetInBytes(PartEntry) \
((PartEntry)->StartSector.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
#define GetPartEntrySizeInBytes(PartEntry) \
((PartEntry)->SectorCount.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
#define GetDiskSizeInBytes(DiskEntry) \
((DiskEntry)->SectorCount.QuadPart * (DiskEntry)->BytesPerSector)
BOOLEAN
IsSuperFloppy(
IN PDISKENTRY DiskEntry);
@ -306,14 +313,13 @@ BOOLEAN
CreatePartition(
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount,
_In_ BOOLEAN AutoCreate);
_In_opt_ ULONGLONG SizeBytes);
BOOLEAN
CreateExtendedPartition(
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount);
_In_opt_ ULONGLONG SizeBytes);
NTSTATUS
DismountVolume(