[SETUPLIB][REACTOS][USETUP] Split FS-volume-specific functionality from partitions (#7258)

CORE-13525

This greatly helps in reducing code complexity in some areas: code that
previously iterated over all partitions of a given disk, just to find
which ones were partitioned and contained a valid file system, now just
have to iterate over mounted volumes.
See in particular, `lib/utils/osdetect.c` and `lib/fsutil.c` .

- Remove FORMATSTATE "Preformatted" enum value;
- Cleanup osdetect code after introducing Volume support;
- Some simplifications for FormatState.

- Differentiate between 'new' partition and 'new' volume:

  * "New" partition: it has been created and added in the cached list,
    but not yet actually written into the disk.

  * "New" volume: newly-created volume (may be backed by a partition or
    not), not yet formatted. May exist on either new, or not new partition,
    or elsewhere.

- Cache partition and volume NT device names.

  These do not change across repartitioning operations, as long as the
  partition or the filesystem volume hasn't been deleted/recreated.
  This avoids doing \Device\Harddisk%u\Partition%u sprintf's everytime
  we need to retrieve the given partition or volume device name.

  When a partition/fileysystem volume is "virtually" created (i.e. in
  the partition list, but not yet committed to disk and exposed to the
  OS), no device partition number and device name are available yet.
  In particular, validate that no manipulation of \Device\HarddiskM\Partition0
  (i.e. the whole disk) is being made.
This commit is contained in:
Hermès Bélusca-Maïto 2024-05-18 23:09:16 +02:00
parent 0f8dc6b2df
commit 6f15802af7
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
15 changed files with 1017 additions and 871 deletions

View file

@ -695,7 +695,8 @@ InitSystemPartition(
* In all cases, whether or not we are going to perform a formatting,
* we must perform a filesystem check of the system partition.
*/
SystemPartition->NeedsCheck = TRUE;
if (SystemPartition->Volume)
SystemPartition->Volume->NeedsCheck = TRUE;
return TRUE;
}
@ -794,23 +795,21 @@ IsValidInstallDirectory(
NTSTATUS
InitDestinationPaths(
IN OUT PUSETUP_DATA pSetupData,
IN PCWSTR InstallationDir,
IN PPARTENTRY PartEntry) // FIXME: HACK!
_Inout_ PUSETUP_DATA pSetupData,
_In_ PCWSTR InstallationDir,
_In_ PVOLENTRY Volume)
{
NTSTATUS Status;
PPARTENTRY PartEntry = Volume->PartEntry;
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
WCHAR PathBuffer[MAX_PATH];
WCHAR PathBuffer[RTL_NUMBER_OF_FIELD(VOLINFO, DeviceName) + 1];
ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
/* Create 'pSetupData->DestinationRootPath' string */
RtlFreeUnicodeString(&pSetupData->DestinationRootPath);
Status = RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"\\Device\\Harddisk%lu\\Partition%lu\\",
DiskEntry->DiskNumber,
PartEntry->PartitionNumber);
Status = RtlStringCchPrintfW(PathBuffer, _countof(PathBuffer),
L"%s\\", Volume->Info.DeviceName);
if (!NT_SUCCESS(Status))
{
DPRINT1("RtlStringCchPrintfW() failed with status 0x%08lx\n", Status);