[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

@ -1,9 +1,9 @@
/*
* PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Partition list functions
* COPYRIGHT: Copyright 2003-2019 Casper S. Hornstrup (chorns@users.sourceforge.net)
* Copyright 2018-2019 Hermes Belusca-Maito
* Copyright 2018-2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/
#pragma once
@ -34,10 +34,30 @@ typedef enum _FORMATSTATE
Unformatted,
UnformattedOrDamaged,
UnknownFormat,
Preformatted,
Formatted
} FORMATSTATE, *PFORMATSTATE;
#include "volutil.h"
typedef struct _PARTENTRY PARTENTRY, *PPARTENTRY;
typedef struct _VOLENTRY
{
LIST_ENTRY ListEntry; ///< Entry in VolumesList
VOLINFO Info;
FORMATSTATE FormatState;
/* Volume must be checked */
BOOLEAN NeedsCheck;
/* Volume is new and has not yet been actually formatted and mounted */
BOOLEAN New;
// union {
// PVOLUME_DISK_EXTENTS pExtents;
PPARTENTRY PartEntry;
// };
} VOLENTRY, *PVOLENTRY;
typedef struct _PARTENTRY
{
LIST_ENTRY ListEntry;
@ -54,24 +74,25 @@ typedef struct _PARTENTRY
ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
WCHAR DriveLetter;
WCHAR VolumeLabel[20];
WCHAR FileSystem[MAX_PATH+1];
FORMATSTATE FormatState;
WCHAR DeviceName[MAX_PATH]; ///< NT device name: "\Device\HarddiskM\PartitionN"
BOOLEAN LogicalPartition;
/* Partition is partitioned disk space */
BOOLEAN IsPartitioned;
/** The following three properties may be replaced by flags **/
/* Partition is new, table does not exist on disk yet */
BOOLEAN New;
/* Partition must be checked */
BOOLEAN NeedsCheck;
/*
* Volume-related properties:
* NULL: No volume is associated to this partition (either because it is
* an empty disk region, or the partition type is unrecognized).
* 0x1 : TBD.
* Valid pointer: A basic volume associated to this partition is (or will)
* be mounted by the PARTMGR and enumerated by the MOUNTMGR.
*/
PVOLENTRY Volume;
} PARTENTRY, *PPARTENTRY;
@ -162,9 +183,12 @@ typedef struct _PARTLIST
LIST_ENTRY DiskListHead;
LIST_ENTRY BiosDiskListHead;
/* (Basic) Volumes management */
LIST_ENTRY VolumesList;
} PARTLIST, *PPARTLIST;
#define PARTITION_TBL_SIZE 4
#define PARTITION_TBL_SIZE 4
#define PARTITION_MAGIC 0xAA55
@ -307,10 +331,6 @@ CreatePartition(
_In_opt_ ULONGLONG SizeBytes,
_In_opt_ ULONG_PTR PartitionInfo);
NTSTATUS
DismountVolume(
IN PPARTENTRY PartEntry);
BOOLEAN
DeletePartition(
_In_ PPARTLIST List,
@ -338,15 +358,9 @@ BOOLEAN
WritePartitionsToDisk(
IN PPARTLIST List);
BOOLEAN
SetMountedDeviceValue(
IN WCHAR Letter,
IN ULONG Signature,
IN LARGE_INTEGER StartingOffset);
BOOLEAN
SetMountedDeviceValues(
IN PPARTLIST List);
_In_ PPARTLIST List);
VOID
SetMBRPartitionType(