ReactOS  0.4.13-dev-241-g63286c6
partlist.h File Reference
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for partlist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _PARTITION_TYPE
 
struct  _PARTENTRY
 
struct  _DISKENTRY
 
struct  _BIOSDISKENTRY
 
struct  _PARTLIST
 
struct  _PARTITION
 
struct  _PARTITION_SECTOR
 
struct  BIOS_DISK
 

Macros

#define NUM_PARTITION_TYPE_ENTRIES   143
 
#define PARTITION_TBL_SIZE   4
 
#define PARTITION_MAGIC   0xAA55
 
#define EFI_PMBR_OSTYPE_EFI   0xEE
 

Typedefs

typedef struct _PARTITION_TYPE PARTITION_TYPE
 
typedef struct _PARTITION_TYPEPPARTITION_TYPE
 
typedef enum _FORMATSTATE FORMATSTATE
 
typedef enum _FORMATSTATEPFORMATSTATE
 
typedef struct _PARTENTRY PARTENTRY
 
typedef struct _PARTENTRYPPARTENTRY
 
typedef struct _DISKENTRY DISKENTRY
 
typedef struct _DISKENTRYPDISKENTRY
 
typedef struct _BIOSDISKENTRY BIOSDISKENTRY
 
typedef struct _BIOSDISKENTRYPBIOSDISKENTRY
 
typedef struct _PARTLIST PARTLIST
 
typedef struct _PARTLISTPPARTLIST
 
typedef struct _PARTITION PARTITION
 
typedef struct _PARTITIONPPARTITION
 
typedef struct _PARTITION_SECTOR PARTITION_SECTOR
 
typedef struct _PARTITION_SECTORPPARTITION_SECTOR
 
typedef struct BIOS_DISKPBIOS_DISK
 

Enumerations

enum  _FORMATSTATE {
  Unformatted, UnformattedOrDamaged, UnknownFormat, Preformatted,
  Formatted, Unformatted, UnformattedOrDamaged, UnknownFormat,
  Preformatted, Formatted
}
 

Functions

ULONGLONG AlignDown (IN ULONGLONG Value, IN ULONG Alignment)
 
ULONGLONG AlignUp (IN ULONGLONG Value, IN ULONG Alignment)
 
ULONGLONG RoundingDivide (IN ULONGLONG Dividend, IN ULONGLONG Divisor)
 
BOOLEAN IsSuperFloppy (IN PDISKENTRY DiskEntry)
 
PPARTLIST CreatePartitionList (VOID)
 
VOID DestroyPartitionList (IN PPARTLIST List)
 
PDISKENTRY GetDiskByBiosNumber (IN PPARTLIST List, IN ULONG HwDiskNumber)
 
PDISKENTRY GetDiskByNumber (IN PPARTLIST List, IN ULONG DiskNumber)
 
PDISKENTRY GetDiskBySCSI (IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
 
PDISKENTRY GetDiskBySignature (IN PPARTLIST List, IN ULONG Signature)
 
PPARTENTRY GetPartition (IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
 
BOOLEAN GetDiskOrPartition (IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
 
PPARTENTRY SelectPartition (IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
 
PPARTENTRY GetNextPartition (IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
 
PPARTENTRY GetPrevPartition (IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
 
BOOLEAN CreatePrimaryPartition (IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
 
BOOLEAN CreateExtendedPartition (IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount)
 
BOOLEAN CreateLogicalPartition (IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
 
BOOLEAN DeletePartition (IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
 
VOID CheckActiveSystemPartition (IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternateDisk OPTIONAL, IN PPARTENTRY AlternatePart OPTIONAL)
 
NTSTATUS WritePartitions (IN PDISKENTRY DiskEntry)
 
BOOLEAN WritePartitionsToDisk (IN PPARTLIST List)
 
BOOLEAN SetMountedDeviceValue (IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
 
BOOLEAN SetMountedDeviceValues (IN PPARTLIST List)
 
VOID SetPartitionType (IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
 
ERROR_NUMBER PrimaryPartitionCreationChecks (IN PPARTENTRY PartEntry)
 
ERROR_NUMBER ExtendedPartitionCreationChecks (IN PPARTENTRY PartEntry)
 
ERROR_NUMBER LogicalPartitionCreationChecks (IN PPARTENTRY PartEntry)
 
BOOLEAN GetNextUnformattedPartition (IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
 
BOOLEAN GetNextUncheckedPartition (IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
 

Variables

PARTITION_TYPE PartitionTypes [NUM_PARTITION_TYPE_ENTRIES]
 

Macro Definition Documentation

◆ EFI_PMBR_OSTYPE_EFI

#define EFI_PMBR_OSTYPE_EFI   0xEE

Definition at line 175 of file partlist.h.

◆ NUM_PARTITION_TYPE_ENTRIES

#define NUM_PARTITION_TYPE_ENTRIES   143

Definition at line 19 of file partlist.h.

◆ PARTITION_MAGIC

#define PARTITION_MAGIC   0xAA55

Definition at line 172 of file partlist.h.

◆ PARTITION_TBL_SIZE

#define PARTITION_TBL_SIZE   4

Definition at line 170 of file partlist.h.

Typedef Documentation

◆ BIOSDISKENTRY

◆ DISKENTRY

◆ FORMATSTATE

◆ PARTENTRY

◆ PARTITION

◆ PARTITION_SECTOR

◆ PARTITION_TYPE

◆ PARTLIST

◆ PBIOS_DISK

◆ PBIOSDISKENTRY

◆ PDISKENTRY

◆ PFORMATSTATE

◆ PPARTENTRY

◆ PPARTITION

◆ PPARTITION_SECTOR

◆ PPARTITION_TYPE

◆ PPARTLIST

Enumeration Type Documentation

◆ _FORMATSTATE

Enumerator
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Preformatted 
Formatted 
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Preformatted 
Formatted 

Definition at line 25 of file partlist.h.

26 {
31  Formatted
enum _FORMATSTATE FORMATSTATE
enum _FORMATSTATE * PFORMATSTATE

Function Documentation

◆ AlignDown()

ULONGLONG AlignDown ( IN ULONGLONG  Value,
IN ULONG  Alignment 
)

Definition at line 245 of file partlist.c.

248 {
249  ULONGLONG Temp;
250 
251  Temp = Value / Alignment;
252 
253  return Temp * Alignment;
254 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
union Alignment_ Alignment
uint64_t ULONGLONG
Definition: typedefs.h:65

Referenced by InitializePartitionEntry(), and ScanForUnpartitionedDiskSpace().

◆ AlignUp()

ULONGLONG AlignUp ( IN ULONGLONG  Value,
IN ULONG  Alignment 
)

Definition at line 257 of file partlist.c.

260 {
261  ULONGLONG Temp, Result;
262 
263  Temp = Value / Alignment;
264 
265  Result = Temp * Alignment;
266  if (Value % Alignment)
267  Result += Alignment;
268 
269  return Result;
270 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
union Alignment_ Alignment
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
uint64_t ULONGLONG
Definition: typedefs.h:65

Referenced by PeFmtCreateSection().

◆ CheckActiveSystemPartition()

VOID CheckActiveSystemPartition ( IN PPARTLIST  List,
IN BOOLEAN  ForceSelect,
IN PDISKENTRY AlternateDisk  OPTIONAL,
IN PPARTENTRY AlternatePart  OPTIONAL 
)

Definition at line 3324 of file partlist.c.

3329 {
3330  PLIST_ENTRY ListEntry;
3331  PDISKENTRY DiskEntry;
3332  PPARTENTRY PartEntry;
3333  PPARTENTRY ActivePartition;
3334  PPARTENTRY CandidatePartition = NULL;
3335 
3336  /* Check for empty disk list */
3337  if (IsListEmpty(&List->DiskListHead))
3338  {
3339  /* No system partition! */
3340  List->SystemPartition = NULL;
3341  List->OriginalSystemPartition = NULL;
3342  goto NoSystemPartition;
3343  }
3344 
3345  if (List->SystemPartition != NULL)
3346  {
3347  /* We already have an active system partition */
3348  DPRINT1("Use the current system partition %lu in disk %lu, drive letter %C\n",
3349  List->SystemPartition->PartitionNumber,
3350  List->SystemPartition->DiskEntry->DiskNumber,
3351  (List->SystemPartition->DriveLetter == 0) ? L'-' : List->SystemPartition->DriveLetter);
3352  return;
3353  }
3354 
3355  /* Start fresh */
3356  List->SystemPartition = NULL;
3357  List->OriginalSystemPartition = NULL;
3358 
3359  /* Adjust the optional alternate disk if needed */
3360  if (!AlternateDisk && AlternatePart)
3361  AlternateDisk = AlternatePart->DiskEntry;
3362 
3363  /* Ensure that the alternate partition is on the alternate disk */
3364  if (AlternatePart)
3365  ASSERT(AlternateDisk && (AlternatePart->DiskEntry == AlternateDisk));
3366 
3367  /* Ensure that the alternate disk is in the list */
3368  if (AlternateDisk)
3369  ASSERT(AlternateDisk->PartList == List);
3370 
3371 //
3372 // Pass == 1 : Check the first (system) disk.
3373 //
3374 
3375  /*
3376  * First, check whether the first disk (the one that will be booted
3377  * by default by the hardware) contains an active partition. If so
3378  * this should be our system partition.
3379  */
3380  DiskEntry = CONTAINING_RECORD(List->DiskListHead.Flink,
3381  DISKENTRY, ListEntry);
3382 
3383  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
3384  {
3385  DPRINT1("First (system) disk -- GPT-partitioned disk detected, not currently supported by SETUP!\n");
3386  goto UseAlternateDisk;
3387  }
3388 
3389  ActivePartition = GetActiveDiskPartition(DiskEntry);
3390  if (ActivePartition)
3391  {
3392  /* Save the actual system partition */
3393  List->OriginalSystemPartition = ActivePartition;
3394 
3395  /* If we get a candidate active partition in the first disk, validate it */
3396  if (IsSupportedActivePartition(ActivePartition))
3397  {
3398  CandidatePartition = ActivePartition;
3399  goto SystemPartitionFound;
3400  }
3401  }
3402 
3403  /* If this first disk is not the optional alternate disk, perform the minimal checks */
3404  if (DiskEntry != AlternateDisk)
3405  {
3406  /*
3407  * No active partition has been recognized. Enumerate all the (primary)
3408  * partitions in the first disk, excluding the possible current active
3409  * partition, to find a new candidate.
3410  */
3411  for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
3412  ListEntry != &DiskEntry->PrimaryPartListHead;
3413  ListEntry = ListEntry->Flink)
3414  {
3415  /* Retrieve the partition */
3416  PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
3417 
3418  /* Skip the current active partition */
3419  if (/* ActivePartition != NULL && */ PartEntry == ActivePartition)
3420  continue;
3421 
3422  /* Check if the partition is partitioned and used */
3423  if (PartEntry->IsPartitioned &&
3424  !IsContainerPartition(PartEntry->PartitionType))
3425  {
3427 
3428  /* If we get a candidate active partition in the first disk, validate it */
3429  if (IsSupportedActivePartition(PartEntry))
3430  {
3431  CandidatePartition = PartEntry;
3432  goto FindAndUseAlternativeSystemPartition;
3433  }
3434  }
3435 
3436 #if 0
3437  /* Check if the partition is partitioned and used */
3438  if (!PartEntry->IsPartitioned)
3439  {
3441 
3442  // TODO: Check for minimal size!!
3443  CandidatePartition = PartEntry;
3444  goto FindAndUseAlternativeSystemPartition;
3445  }
3446 #endif
3447  }
3448 
3449  /*
3450  * Still nothing, look whether there is some free space that we can use
3451  * for the new system partition. We must be sure that the total number
3452  * of partition is less than the maximum allowed, and that the minimal
3453  * size is fine.
3454  */
3455 //
3456 // TODO: Fix the handling of system partition being created in unpartitioned space!!
3457 // --> When to partition it? etc...
3458 //
3459  if (GetPrimaryPartitionCount(DiskEntry) < 4)
3460  {
3461  for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
3462  ListEntry != &DiskEntry->PrimaryPartListHead;
3463  ListEntry = ListEntry->Flink)
3464  {
3465  /* Retrieve the partition */
3466  PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
3467 
3468  /* Skip the current active partition */
3469  if (/* ActivePartition != NULL && */ PartEntry == ActivePartition)
3470  continue;
3471 
3472  /* Check for unpartitioned space */
3473  if (!PartEntry->IsPartitioned)
3474  {
3476 
3477  // TODO: Check for minimal size!!
3478  CandidatePartition = PartEntry;
3479  goto FindAndUseAlternativeSystemPartition;
3480  }
3481  }
3482  }
3483  }
3484 
3485 
3486 //
3487 // Pass == 2 : No active partition found: Check the alternate disk if specified.
3488 //
3489 
3490 UseAlternateDisk:
3491  if (!AlternateDisk || (!ForceSelect && (DiskEntry != AlternateDisk)))
3492  goto NoSystemPartition;
3493 
3494  if (AlternateDisk->DiskStyle == PARTITION_STYLE_GPT)
3495  {
3496  DPRINT1("Alternate disk -- GPT-partitioned disk detected, not currently supported by SETUP!\n");
3497  goto NoSystemPartition;
3498  }
3499 
3500  if (DiskEntry != AlternateDisk)
3501  {
3502  /* Choose the alternate disk */
3503  DiskEntry = AlternateDisk;
3504 
3505  ActivePartition = GetActiveDiskPartition(DiskEntry);
3506  if (ActivePartition)
3507  {
3508  /* If we get a candidate active partition, validate it */
3509  if (IsSupportedActivePartition(ActivePartition))
3510  {
3511  CandidatePartition = ActivePartition;
3512  goto FindAndUseAlternativeSystemPartition;
3513  }
3514  }
3515  }
3516 
3517  /* We now may have an unsupported active partition, or none */
3518 
3519 /***
3520  *** TODO: Improve the selection:
3521  *** - If we want a really separate system partition from the partition where
3522  *** we install, do something similar to what's done below in the code.
3523  *** - Otherwise if we allow for the system partition to be also the partition
3524  *** where we install, just directly fall down to using AlternatePart.
3525  ***/
3526 
3527  /* Retrieve the first partition of the disk */
3528  PartEntry = CONTAINING_RECORD(DiskEntry->PrimaryPartListHead.Flink,
3529  PARTENTRY, ListEntry);
3530  ASSERT(DiskEntry == PartEntry->DiskEntry);
3531 
3532  CandidatePartition = PartEntry;
3533 
3534  //
3535  // See: https://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/partlist.c?r1=63355&r2=63354&pathrev=63355#l2318
3536  //
3537 
3538  /* Check if the disk is new and if so, use its first partition as the active system partition */
3539  if (DiskEntry->NewDisk)
3540  {
3541  // !IsContainerPartition(PartEntry->PartitionType);
3542  if (!CandidatePartition->IsPartitioned || !CandidatePartition->BootIndicator) /* CandidatePartition != ActivePartition */
3543  {
3544  ASSERT(DiskEntry == CandidatePartition->DiskEntry);
3545 
3546  List->SystemPartition = CandidatePartition;
3547  List->OriginalSystemPartition = List->SystemPartition;
3548 
3549  DPRINT1("Use new first active system partition %lu in disk %lu, drive letter %C\n",
3550  List->SystemPartition->PartitionNumber,
3551  List->SystemPartition->DiskEntry->DiskNumber,
3552  (List->SystemPartition->DriveLetter == 0) ? L'-' : List->SystemPartition->DriveLetter);
3553 
3554  goto SetSystemPartition;
3555  }
3556 
3557  // FIXME: What to do??
3558  DPRINT1("NewDisk TRUE but first partition is used?\n");
3559  }
3560 
3561  /*
3562  * The disk is not new, check if any partition is initialized;
3563  * if not, the first one becomes the system partition.
3564  */
3565  for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
3566  ListEntry != &DiskEntry->PrimaryPartListHead;
3567  ListEntry = ListEntry->Flink)
3568  {
3569  /* Retrieve the partition */
3570  PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
3571 
3572  /* Check if the partition is partitioned and is used */
3573  // !IsContainerPartition(PartEntry->PartitionType);
3574  if (/* PartEntry->IsPartitioned && */
3575  PartEntry->PartitionType != PARTITION_ENTRY_UNUSED || PartEntry->BootIndicator)
3576  {
3577  break;
3578  }
3579  }
3580  if (ListEntry == &DiskEntry->PrimaryPartListHead)
3581  {
3582  /*
3583  * OK we haven't encountered any used and active partition,
3584  * so use the first one as the system partition.
3585  */
3586  ASSERT(DiskEntry == CandidatePartition->DiskEntry);
3587  List->SystemPartition = CandidatePartition; // The first PartEntry
3588  List->OriginalSystemPartition = List->SystemPartition;
3589 
3590  DPRINT1("Use first active system partition %lu in disk %lu, drive letter %C\n",
3591  List->SystemPartition->PartitionNumber,
3592  List->SystemPartition->DiskEntry->DiskNumber,
3593  (List->SystemPartition->DriveLetter == 0) ? L'-' : List->SystemPartition->DriveLetter);
3594 
3595  goto SetSystemPartition;
3596  }
3597 
3598  /*
3599  * The disk is not new, we did not find any actual active partition,
3600  * or the one we found was not supported, or any possible other canditate
3601  * is not supported. We then use the alternate partition if specified.
3602  */
3603  if (AlternatePart)
3604  {
3605  DPRINT1("No system partition found, use the alternative partition!\n");
3606  CandidatePartition = AlternatePart;
3607  goto UseAlternativeSystemPartition;
3608  }
3609  else
3610  {
3611 NoSystemPartition:
3612  DPRINT1("No valid or supported system partition has been found on this system!\n");
3613  return;
3614  }
3615 
3616 
3617 SystemPartitionFound:
3618  ASSERT(CandidatePartition);
3619  List->SystemPartition = CandidatePartition;
3620 
3621  DPRINT1("Use existing active system partition %lu in disk %lu, drive letter %C\n",
3622  List->SystemPartition->PartitionNumber,
3623  List->SystemPartition->DiskEntry->DiskNumber,
3624  (List->SystemPartition->DriveLetter == 0) ? L'-' : List->SystemPartition->DriveLetter);
3625 
3626  return;
3627 
3628 FindAndUseAlternativeSystemPartition:
3629  /*
3630  * We are here because we have not found any (active) candidate
3631  * system partition that we know how to support. What we are going
3632  * to do is to change the existing system partition and use the
3633  * partition on which we install ReactOS as the new system partition,
3634  * and then we will need to add in FreeLdr's entry a boot entry to boot
3635  * from the original system partition.
3636  */
3637 
3638  /* Unset the old system partition */
3639  if (List->OriginalSystemPartition)
3640  {
3641  List->OriginalSystemPartition->BootIndicator = FALSE;
3642  List->OriginalSystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->OriginalSystemPartition->PartitionIndex].BootIndicator = FALSE;
3643  List->OriginalSystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->OriginalSystemPartition->PartitionIndex].RewritePartition = TRUE;
3644  List->OriginalSystemPartition->DiskEntry->Dirty = TRUE;
3645  }
3646 
3647 UseAlternativeSystemPartition:
3648  ASSERT(CandidatePartition);
3649  List->SystemPartition = CandidatePartition;
3650 
3651  DPRINT1("Use alternative active system partition %lu in disk %lu, drive letter %C\n",
3652  List->SystemPartition->PartitionNumber,
3653  List->SystemPartition->DiskEntry->DiskNumber,
3654  (List->SystemPartition->DriveLetter == 0) ? L'-' : List->SystemPartition->DriveLetter);
3655 
3656 SetSystemPartition:
3657  /* Set the new active system partition */
3658  List->SystemPartition->BootIndicator = TRUE;
3659  List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator = TRUE;
3660  List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition = TRUE;
3661  List->SystemPartition->DiskEntry->Dirty = TRUE;
3662 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
#define TRUE
Definition: types.h:120
static PPARTENTRY GetActiveDiskPartition(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3184
static BOOLEAN IsSupportedActivePartition(IN PPARTENTRY PartEntry)
Definition: partlist.c:3247
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:245
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
UCHAR PartitionType
Definition: partlist.h:46
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static ULONG GetPrimaryPartitionCount(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2414
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
#define DPRINT1
Definition: precomp.h:8
BOOLEAN BootIndicator
Definition: partlist.h:45
BOOLEAN NewDisk
Definition: partlist.h:114
BOOLEAN IsPartitioned
Definition: partlist.h:60

Referenced by SelectFileSystemPage().

◆ CreateExtendedPartition()

BOOLEAN CreateExtendedPartition ( IN PPARTLIST  List,
IN PPARTENTRY  SelectedEntry,
IN ULONGLONG  SectorCount 
)

Definition at line 2837 of file partlist.c.

2841 {
2843  PPARTENTRY PartEntry;
2844 
2845  DPRINT1("CreateExtendedPartition(%I64u)\n", SectorCount);
2846 
2847  if (List == NULL ||
2848  SelectedEntry == NULL ||
2849  SelectedEntry->DiskEntry == NULL ||
2850  SelectedEntry->IsPartitioned)
2851  {
2852  return FALSE;
2853  }
2854 
2855  Error = ExtendedPartitionCreationChecks(SelectedEntry);
2856  if (Error != NOT_AN_ERROR)
2857  {
2858  DPRINT1("ExtendedPartitionCreationChecks() failed with error %lu\n", Error);
2859  return FALSE;
2860  }
2861 
2862  /* Convert the current entry, or insert and initialize a new partition entry */
2863  PartEntry = InitializePartitionEntry(SelectedEntry->DiskEntry, SelectedEntry, SectorCount, FALSE);
2864  if (PartEntry == NULL)
2865  return FALSE;
2866 
2867  if (PartEntry->StartSector.QuadPart < 1450560)
2868  {
2869  /* Partition starts below the 8.4GB boundary ==> CHS partition */
2870  PartEntry->PartitionType = PARTITION_EXTENDED;
2871  }
2872  else
2873  {
2874  /* Partition starts above the 8.4GB boundary ==> LBA partition */
2876  }
2877 
2878  // FIXME? Possibly to make GetNextUnformattedPartition work (i.e. skip the extended partition container)
2879  PartEntry->New = FALSE;
2880  PartEntry->FormatState = Formatted;
2881 
2882  PartEntry->DiskEntry->ExtendedPartition = PartEntry;
2883 
2884  AddLogicalDiskSpace(PartEntry->DiskEntry);
2885 
2886  UpdateDiskLayout(PartEntry->DiskEntry);
2887 
2889 
2890  return TRUE;
2891 }
ULARGE_INTEGER StartSector
Definition: partlist.h:42
ERROR_NUMBER ExtendedPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4023
#define TRUE
Definition: types.h:120
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
FORMATSTATE FormatState
Definition: partlist.h:55
smooth NULL
Definition: ftsmooth.c:416
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2520
#define PARTITION_EXTENDED
Definition: disk.h:91
UCHAR PartitionType
Definition: partlist.h:46
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
BOOL Error
Definition: chkdsk.c:66
enum _ERROR_NUMBER ERROR_NUMBER
ULONG SectorCount
Definition: part_xbox.c:32
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:98
BOOLEAN New
Definition: partlist.h:65
#define DPRINT1
Definition: precomp.h:8
static PPARTENTRY InitializePartitionEntry(IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:855
static VOID AddLogicalDiskSpace(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2809
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:316

Referenced by CreateExtendedPartitionPage().

◆ CreateLogicalPartition()

BOOLEAN CreateLogicalPartition ( IN PPARTLIST  List,
IN PPARTENTRY  SelectedEntry,
IN ULONGLONG  SectorCount,
IN BOOLEAN  AutoCreate 
)

Definition at line 2894 of file partlist.c.

2899 {
2901  PPARTENTRY PartEntry;
2902 
2903  DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount);
2904 
2905  if (List == NULL ||
2906  SelectedEntry == NULL ||
2907  SelectedEntry->DiskEntry == NULL ||
2908  SelectedEntry->IsPartitioned)
2909  {
2910  return FALSE;
2911  }
2912 
2913  Error = LogicalPartitionCreationChecks(SelectedEntry);
2914  if (Error != NOT_AN_ERROR)
2915  {
2916  DPRINT1("LogicalPartitionCreationChecks() failed with error %lu\n", Error);
2917  return FALSE;
2918  }
2919 
2920  /* Convert the current entry, or insert and initialize a new partition entry */
2921  PartEntry = InitializePartitionEntry(SelectedEntry->DiskEntry, SelectedEntry, SectorCount, AutoCreate);
2922  if (PartEntry == NULL)
2923  return FALSE;
2924 
2925  PartEntry->LogicalPartition = TRUE;
2926 
2927  UpdateDiskLayout(PartEntry->DiskEntry);
2928 
2930 
2931  return TRUE;
2932 }
#define TRUE
Definition: types.h:120
ERROR_NUMBER LogicalPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4054
BOOLEAN LogicalPartition
Definition: partlist.h:57
smooth NULL
Definition: ftsmooth.c:416
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2520
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
BOOL Error
Definition: chkdsk.c:66
enum _ERROR_NUMBER ERROR_NUMBER
ULONG SectorCount
Definition: part_xbox.c:32
#define DPRINT1
Definition: precomp.h:8
static PPARTENTRY InitializePartitionEntry(IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:855
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:316

Referenced by CreateLogicalPartitionPage(), and SelectPartitionPage().

◆ CreatePartitionList()

PPARTLIST CreatePartitionList ( VOID  )

Definition at line 1840 of file partlist.c.

1841 {
1842  PPARTLIST List;
1846  ULONG ReturnSize;
1847  NTSTATUS Status;
1848  ULONG DiskNumber;
1852 
1854  0,
1855  sizeof(PARTLIST));
1856  if (List == NULL)
1857  return NULL;
1858 
1859  List->SystemPartition = NULL;
1860  List->OriginalSystemPartition = NULL;
1861 
1862  InitializeListHead(&List->DiskListHead);
1863  InitializeListHead(&List->BiosDiskListHead);
1864 
1865  /*
1866  * Enumerate the disks seen by the BIOS; this will be used later
1867  * to map drives seen by NTOS with their corresponding BIOS names.
1868  */
1870 
1871  /* Enumerate disks seen by NTOS */
1873  &Sdi,
1874  sizeof(Sdi),
1875  &ReturnSize);
1876  if (!NT_SUCCESS(Status))
1877  {
1878  DPRINT1("NtQuerySystemInformation() failed, Status 0x%08lx", Status);
1880  return NULL;
1881  }
1882 
1883  for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
1884  {
1886  L"\\Device\\Harddisk%lu\\Partition0",
1887  DiskNumber);
1889 
1891  &Name,
1893  NULL,
1894  NULL);
1895 
1899  &Iosb,
1902  if (NT_SUCCESS(Status))
1903  {
1904  AddDiskToList(FileHandle, DiskNumber, List);
1906  }
1907  }
1908 
1912 
1913  return List;
1914 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
struct _PARTLIST * PPARTLIST
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
static VOID UpdateDiskSignatures(IN PPARTLIST List)
Definition: partlist.c:1344
#define FILE_SHARE_READ
Definition: compat.h:125
HANDLE FileHandle
Definition: stats.c:38
#define FILE_READ_DATA
Definition: nt_native.h:628
struct NameRec_ * Name
Definition: cdprocs.h:464
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static __inline NTSTATUS RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1064
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
LIST_ENTRY List
Definition: psmgr.c:57
__wchar_t WCHAR
Definition: xmlstorage.h:180
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static VOID UpdateHwDiskNumbers(IN PPARTLIST List)
Definition: partlist.c:1374
#define MAX_PATH
Definition: compat.h:26
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
static const WCHAR L[]
Definition: oid.c:1250
#define SYNCHRONIZE
Definition: nt_native.h:61
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
static VOID EnumerateBiosDiskEntries(IN PPARTLIST PartList)
Definition: partlist.c:515
static VOID AddDiskToList(IN HANDLE FileHandle, IN ULONG DiskNumber, IN PPARTLIST List)
Definition: partlist.c:1435
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:316

◆ CreatePrimaryPartition()

BOOLEAN CreatePrimaryPartition ( IN PPARTLIST  List,
IN PPARTENTRY  SelectedEntry,
IN ULONGLONG  SectorCount,
IN BOOLEAN  AutoCreate 
)

Definition at line 2769 of file partlist.c.

2774 {
2776  PPARTENTRY PartEntry;
2777 
2778  DPRINT1("CreatePrimaryPartition(%I64u)\n", SectorCount);
2779 
2780  if (List == NULL ||
2781  SelectedEntry == NULL ||
2782  SelectedEntry->DiskEntry == NULL ||
2783  SelectedEntry->IsPartitioned)
2784  {
2785  return FALSE;
2786  }
2787 
2788  Error = PrimaryPartitionCreationChecks(SelectedEntry);
2789  if (Error != NOT_AN_ERROR)
2790  {
2791  DPRINT1("PrimaryPartitionCreationChecks() failed with error %lu\n", Error);
2792  return FALSE;
2793  }
2794 
2795  /* Convert the current entry, or insert and initialize a new partition entry */
2796  PartEntry = InitializePartitionEntry(SelectedEntry->DiskEntry, SelectedEntry, SectorCount, AutoCreate);
2797  if (PartEntry == NULL)
2798  return FALSE;
2799 
2800  UpdateDiskLayout(PartEntry->DiskEntry);
2801 
2803 
2804  return TRUE;
2805 }
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2520
ERROR_NUMBER PrimaryPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:3996
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
BOOL Error
Definition: chkdsk.c:66
enum _ERROR_NUMBER ERROR_NUMBER
ULONG SectorCount
Definition: part_xbox.c:32
#define DPRINT1
Definition: precomp.h:8
static PPARTENTRY InitializePartitionEntry(IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:855
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:316

Referenced by CreatePrimaryPartitionPage(), SelectFileSystemPage(), and SelectPartitionPage().

◆ DeletePartition()

BOOLEAN DeletePartition ( IN PPARTLIST  List,
IN PPARTENTRY  PartEntry,
OUT PPARTENTRY *FreeRegion  OPTIONAL 
)

Definition at line 3041 of file partlist.c.

3045 {
3046  PDISKENTRY DiskEntry;
3047  PPARTENTRY PrevPartEntry;
3048  PPARTENTRY NextPartEntry;
3049  PPARTENTRY LogicalPartEntry;
3051 
3052  if (List == NULL ||
3053  PartEntry == NULL ||
3054  PartEntry->DiskEntry == NULL ||
3055  PartEntry->IsPartitioned == FALSE)
3056  {
3057  return FALSE;
3058  }
3059 
3060  ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED);
3061 
3062  /* Clear the system partition pointers if it is being deleted */
3063  if (List->SystemPartition == PartEntry)
3064  {
3065  ASSERT(List->SystemPartition);
3066  ASSERT(List->SystemPartition->DiskEntry->MediaType != RemovableMedia);
3067 
3068  if (List->SystemPartition == List->OriginalSystemPartition)
3069  List->OriginalSystemPartition = NULL;
3070  List->SystemPartition = NULL;
3071  }
3072 
3073  DiskEntry = PartEntry->DiskEntry;
3074 
3075  /* Check which type of partition (primary/logical or extended) is being deleted */
3076  if (DiskEntry->ExtendedPartition == PartEntry)
3077  {
3078  /* An extended partition is being deleted: delete all logical partition entries */
3079  while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
3080  {
3081  Entry = RemoveHeadList(&DiskEntry->LogicalPartListHead);
3082  LogicalPartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
3083 
3084  /* Dismount the logical partition */
3085  DismountVolume(LogicalPartEntry);
3086 
3087  /* Delete it */
3088  RtlFreeHeap(ProcessHeap, 0, LogicalPartEntry);
3089  }
3090 
3091  DiskEntry->ExtendedPartition = NULL;
3092  }
3093  else
3094  {
3095  /* A primary partition is being deleted: dismount it */
3096  DismountVolume(PartEntry);
3097  }
3098 
3099  /* Adjust the unpartitioned disk space entries */
3100 
3101  /* Get pointer to previous and next unpartitioned entries */
3102  PrevPartEntry = GetPrevUnpartitionedEntry(PartEntry);
3103  NextPartEntry = GetNextUnpartitionedEntry(PartEntry);
3104 
3105  if (PrevPartEntry != NULL && NextPartEntry != NULL)
3106  {
3107  /* Merge the previous, current and next unpartitioned entries */
3108 
3109  /* Adjust the previous entry length */
3110  PrevPartEntry->SectorCount.QuadPart += (PartEntry->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
3111 
3112  /* Remove the current and next entries */
3113  RemoveEntryList(&PartEntry->ListEntry);
3114  RtlFreeHeap(ProcessHeap, 0, PartEntry);
3115  RemoveEntryList(&NextPartEntry->ListEntry);
3116  RtlFreeHeap(ProcessHeap, 0, NextPartEntry);
3117 
3118  /* Optionally return the freed region */
3119  if (FreeRegion)
3120  *FreeRegion = PrevPartEntry;
3121  }
3122  else if (PrevPartEntry != NULL && NextPartEntry == NULL)
3123  {
3124  /* Merge the current and the previous unpartitioned entries */
3125 
3126  /* Adjust the previous entry length */
3127  PrevPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart;
3128 
3129  /* Remove the current entry */
3130  RemoveEntryList(&PartEntry->ListEntry);
3131  RtlFreeHeap(ProcessHeap, 0, PartEntry);
3132 
3133  /* Optionally return the freed region */
3134  if (FreeRegion)
3135  *FreeRegion = PrevPartEntry;
3136  }
3137  else if (PrevPartEntry == NULL && NextPartEntry != NULL)
3138  {
3139  /* Merge the current and the next unpartitioned entries */
3140 
3141  /* Adjust the next entry offset and length */
3142  NextPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
3143  NextPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart;
3144 
3145  /* Remove the current entry */
3146  RemoveEntryList(&PartEntry->ListEntry);
3147  RtlFreeHeap(ProcessHeap, 0, PartEntry);
3148 
3149  /* Optionally return the freed region */
3150  if (FreeRegion)
3151  *FreeRegion = NextPartEntry;
3152  }
3153  else
3154  {
3155  /* Nothing to merge but change the current entry */
3156  PartEntry->IsPartitioned = FALSE;
3157  PartEntry->PartitionType = PARTITION_ENTRY_UNUSED;
3158  PartEntry->FormatState = Unformatted;
3159  PartEntry->FileSystem[0] = L'\0';
3160  PartEntry->DriveLetter = 0;
3161  PartEntry->OnDiskPartitionNumber = 0;
3162  PartEntry->PartitionNumber = 0;
3163  // PartEntry->PartitionIndex = 0;
3164 
3165  /* Optionally return the freed region */
3166  if (FreeRegion)
3167  *FreeRegion = PartEntry;
3168  }
3169 
3170  UpdateDiskLayout(DiskEntry);
3171 
3173 
3174  return TRUE;
3175 }
ULARGE_INTEGER StartSector
Definition: partlist.h:42
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
ULARGE_INTEGER SectorCount
Definition: partlist.h:43
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PPARTENTRY ExtendedPartition
Definition: partlist.h:129
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
LIST_ENTRY ListEntry
Definition: partlist.h:36
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2520
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
static NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2936
HANDLE ProcessHeap
Definition: servman.c:15
static PPARTENTRY GetPrevUnpartitionedEntry(IN PPARTENTRY PartEntry)
Definition: partlist.c:2700
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
static PPARTENTRY GetNextUnpartitionedEntry(IN PPARTENTRY PartEntry)
Definition: partlist.c:2735
base of all file and directory entries
Definition: entries.h:82
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:316
BOOLEAN IsPartitioned
Definition: partlist.h:60

Referenced by DeletePartitionPage().

◆ DestroyPartitionList()

VOID DestroyPartitionList ( IN PPARTLIST  List)

Definition at line 1917 of file partlist.c.

1919 {
1920  PDISKENTRY DiskEntry;
1921  PBIOSDISKENTRY BiosDiskEntry;
1922  PPARTENTRY PartEntry;
1924 
1925  /* Release disk and partition info */
1926  while (!IsListEmpty(&List->DiskListHead))
1927  {
1928  Entry = RemoveHeadList(&List->DiskListHead);
1929  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1930 
1931  /* Release driver name */
1932  RtlFreeUnicodeString(&DiskEntry->DriverName);
1933 
1934  /* Release primary partition list */
1935  while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1936  {
1937  Entry = RemoveHeadList(&DiskEntry->PrimaryPartListHead);
1938  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1939 
1940  RtlFreeHeap(ProcessHeap, 0, PartEntry);
1941  }
1942 
1943  /* Release logical partition list */
1944  while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1945  {
1946  Entry = RemoveHeadList(&DiskEntry->LogicalPartListHead);
1947  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1948 
1949  RtlFreeHeap(ProcessHeap, 0, PartEntry);
1950  }
1951 
1952  /* Release layout buffer */
1953  if (DiskEntry->LayoutBuffer != NULL)
1954  RtlFreeHeap(ProcessHeap, 0, DiskEntry->LayoutBuffer);
1955 
1956  /* Release disk entry */
1957  RtlFreeHeap(ProcessHeap, 0, DiskEntry);
1958  }
1959 
1960  /* Release the bios disk info */
1961  while (!IsListEmpty(&List->BiosDiskListHead))
1962  {
1963  Entry = RemoveHeadList(&List->BiosDiskListHead);
1964  BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1965 
1966  RtlFreeHeap(ProcessHeap, 0, BiosDiskEntry);
1967  }
1968 
1969  /* Release list head */
1971 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
struct _Entry Entry
Definition: kefuncs.h:640
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY List
Definition: psmgr.c:57
UNICODE_STRING DriverName
Definition: partlist.h:117
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Definition: typedefs.h:117
HANDLE ProcessHeap
Definition: servman.c:15
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:119
base of all file and directory entries
Definition: entries.h:82

Referenced by QuitPage(), rescan_main(), SelectPartitionPage(), and wmain().

◆ ExtendedPartitionCreationChecks()

ERROR_NUMBER ExtendedPartitionCreationChecks ( IN PPARTENTRY  PartEntry)

Definition at line 4023 of file partlist.c.

4025 {
4026  PDISKENTRY DiskEntry = PartEntry->DiskEntry;
4027 
4028  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
4029  {
4030  DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
4031  return ERROR_WARN_PARTITION;
4032  }
4033 
4034  /* Fail if the partition is already in use */
4035  if (PartEntry->IsPartitioned)
4036  return ERROR_NEW_PARTITION;
4037 
4038  /* Only one primary partition is allowed on super-floppy */
4039  if (IsSuperFloppy(DiskEntry))
4041 
4042  /* Fail if there are already 4 primary partitions in the list */
4043  if (GetPrimaryPartitionCount(DiskEntry) >= 4)
4045 
4046  /* Fail if there is another extended partition in the list */
4047  if (DiskEntry->ExtendedPartition != NULL)
4048  return ERROR_ONLY_ONE_EXTENDED;
4049 
4050  return ERROR_SUCCESS;
4051 }
#define ERROR_SUCCESS
Definition: deptool.c:10
PPARTENTRY ExtendedPartition
Definition: partlist.h:129
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
static ULONG GetPrimaryPartitionCount(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2414
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:679
#define DPRINT1
Definition: precomp.h:8

Referenced by CreateExtendedPartition(), and SelectPartitionPage().

◆ GetDiskByBiosNumber()

PDISKENTRY GetDiskByBiosNumber ( IN PPARTLIST  List,
IN ULONG  HwDiskNumber 
)

Definition at line 1974 of file partlist.c.

1977 {
1978  PDISKENTRY DiskEntry;
1980 
1981  /* Loop over the disks and find the correct one */
1982  for (Entry = List->DiskListHead.Flink;
1983  Entry != &List->DiskListHead;
1984  Entry = Entry->Flink)
1985  {
1986  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1987 
1988  if (DiskEntry->HwDiskNumber == HwDiskNumber)
1989  {
1990  /* Disk found */
1991  return DiskEntry;
1992  }
1993  }
1994 
1995  /* Disk not found, stop there */
1996  return NULL;
1997 }
struct _Entry Entry
Definition: kefuncs.h:640
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
ULONG HwDiskNumber
Definition: partlist.h:99
Definition: typedefs.h:117
base of all file and directory entries
Definition: entries.h:82

◆ GetDiskByNumber()

PDISKENTRY GetDiskByNumber ( IN PPARTLIST  List,
IN ULONG  DiskNumber 
)

Definition at line 2000 of file partlist.c.

2003 {
2004  PDISKENTRY DiskEntry;
2006 
2007  /* Loop over the disks and find the correct one */
2008  for (Entry = List->DiskListHead.Flink;
2009  Entry != &List->DiskListHead;
2010  Entry = Entry->Flink)
2011  {
2012  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
2013 
2014  if (DiskEntry->DiskNumber == DiskNumber)
2015  {
2016  /* Disk found */
2017  return DiskEntry;
2018  }
2019  }
2020 
2021  /* Disk not found, stop there */
2022  return NULL;
2023 }
struct _Entry Entry
Definition: kefuncs.h:640
ULONG DiskNumber
Definition: partlist.h:105
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
Definition: typedefs.h:117
base of all file and directory entries
Definition: entries.h:82

Referenced by GetDiskOrPartition(), and SelectPartition().

◆ GetDiskBySCSI()

PDISKENTRY GetDiskBySCSI ( IN PPARTLIST  List,
IN USHORT  Port,
IN USHORT  Bus,
IN USHORT  Id 
)

Definition at line 2026 of file partlist.c.

2031 {
2032  PDISKENTRY DiskEntry;
2034 
2035  /* Loop over the disks and find the correct one */
2036  for (Entry = List->DiskListHead.Flink;
2037  Entry != &List->DiskListHead;
2038  Entry = Entry->Flink)
2039  {
2040  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
2041 
2042  if (DiskEntry->Port == Port &&
2043  DiskEntry->Bus == Bus &&
2044  DiskEntry->Id == Id)
2045  {
2046  /* Disk found */
2047  return DiskEntry;
2048  }
2049  }
2050 
2051  /* Disk not found, stop there */
2052  return NULL;
2053 }
CPPORT Port[4]
Definition: headless.c:34
USHORT Id
Definition: partlist.h:109
struct _Entry Entry
Definition: kefuncs.h:640
USHORT Bus
Definition: partlist.h:108
DWORD Id
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
Definition: typedefs.h:117
USHORT Port
Definition: partlist.h:107
base of all file and directory entries
Definition: entries.h:82

Referenced by ResolveArcNameManually().

◆ GetDiskBySignature()

PDISKENTRY GetDiskBySignature ( IN PPARTLIST  List,
IN ULONG  Signature 
)

Definition at line 2056 of file partlist.c.

2059 {
2060  PDISKENTRY DiskEntry;
2062 
2063  /* Loop over the disks and find the correct one */
2064  for (Entry = List->DiskListHead.Flink;
2065  Entry != &List->DiskListHead;
2066  Entry = Entry->Flink)
2067  {
2068  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
2069 
2070  if (DiskEntry->LayoutBuffer->Signature == Signature)
2071  {
2072  /* Disk found */
2073  return DiskEntry;
2074  }
2075  }
2076 
2077  /* Disk not found, stop there */
2078  return NULL;
2079 }
struct _Entry Entry
Definition: kefuncs.h:640
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
Definition: typedefs.h:117
static const WCHAR Signature[]
Definition: parser.c:141
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:119
base of all file and directory entries
Definition: entries.h:82

Referenced by ResolveArcNameManually().

◆ GetDiskOrPartition()

BOOLEAN GetDiskOrPartition ( IN PPARTLIST  List,
IN ULONG  DiskNumber,
IN ULONG PartitionNumber  OPTIONAL,
OUT PDISKENTRY pDiskEntry,
OUT PPARTENTRY *pPartEntry  OPTIONAL 
)

Definition at line 2129 of file partlist.c.

2135 {
2136  PDISKENTRY DiskEntry;
2137  PPARTENTRY PartEntry = NULL;
2138 
2139  /* Find the disk */
2140  DiskEntry = GetDiskByNumber(List, DiskNumber);
2141  if (!DiskEntry)
2142  return FALSE;
2143 
2144  /* If we have a partition (PartitionNumber != 0), find it */
2145  if (PartitionNumber != 0)
2146  {
2147  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2148  {
2149  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2150  return FALSE;
2151  }
2152 
2153  PartEntry = GetPartition(/*List,*/ DiskEntry, PartitionNumber);
2154  if (!PartEntry)
2155  return FALSE;
2156  ASSERT(PartEntry->DiskEntry == DiskEntry);
2157  }
2158 
2159  /* Return the disk (and optionally the partition) */
2160  *pDiskEntry = DiskEntry;
2161  if (pPartEntry) *pPartEntry = PartEntry;
2162  return TRUE;
2163 }
#define TRUE
Definition: types.h:120
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2082
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2000
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by EnumerateInstallations().

◆ GetNextPartition()

PPARTENTRY GetNextPartition ( IN PPARTLIST  List,
IN PPARTENTRY CurrentPart  OPTIONAL 
)

Definition at line 2193 of file partlist.c.

2196 {
2197  PLIST_ENTRY DiskListEntry;
2198  PLIST_ENTRY PartListEntry;
2200 
2201  /* Fail if no disks are available */
2202  if (IsListEmpty(&List->DiskListHead))
2203  return NULL;
2204 
2205  /* Check for the next usable entry on the current partition's disk */
2206  if (CurrentPart != NULL)
2207  {
2208  CurrentDisk = CurrentPart->DiskEntry;
2209 
2210  if (CurrentPart->LogicalPartition)
2211  {
2212  /* Logical partition */
2213 
2214  PartListEntry = CurrentPart->ListEntry.Flink;
2215  if (PartListEntry != &CurrentDisk->LogicalPartListHead)
2216  {
2217  /* Next logical partition */
2218  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2219  return CurrentPart;
2220  }
2221  else
2222  {
2223  PartListEntry = CurrentDisk->ExtendedPartition->ListEntry.Flink;
2224  if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
2225  {
2226  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2227  return CurrentPart;
2228  }
2229  }
2230  }
2231  else
2232  {
2233  /* Primary or extended partition */
2234 
2235  if (CurrentPart->IsPartitioned &&
2236  IsContainerPartition(CurrentPart->PartitionType))
2237  {
2238  /* First logical partition */
2239  PartListEntry = CurrentDisk->LogicalPartListHead.Flink;
2240  if (PartListEntry != &CurrentDisk->LogicalPartListHead)
2241  {
2242  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2243  return CurrentPart;
2244  }
2245  }
2246  else
2247  {
2248  /* Next primary partition */
2249  PartListEntry = CurrentPart->ListEntry.Flink;
2250  if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
2251  {
2252  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2253  return CurrentPart;
2254  }
2255  }
2256  }
2257  }
2258 
2259  /* Search for the first partition entry on the next disk */
2260  for (DiskListEntry = (CurrentPart ? CurrentDisk->ListEntry.Flink
2261  : List->DiskListHead.Flink);
2262  DiskListEntry != &List->DiskListHead;
2263  DiskListEntry = DiskListEntry->Flink)
2264  {
2265  CurrentDisk = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
2266 
2268  {
2269  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2270  continue;
2271  }
2272 
2273  PartListEntry = CurrentDisk->PrimaryPartListHead.Flink;
2274  if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
2275  {
2276  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2277  return CurrentPart;
2278  }
2279  }
2280 
2281  return NULL;
2282 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
PDISKENTRY CurrentDisk
Definition: partlist.c:73
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:245
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PPARTENTRY ExtendedPartition
Definition: partlist.h:129
LIST_ENTRY ListEntry
Definition: partlist.h:36
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
LIST_ENTRY ListEntry
Definition: partlist.h:77
Definition: typedefs.h:117
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126

Referenced by ScrollDownPartitionList().

◆ GetNextUncheckedPartition()

BOOLEAN GetNextUncheckedPartition ( IN PPARTLIST  List,
OUT PDISKENTRY *pDiskEntry  OPTIONAL,
OUT PPARTENTRY pPartEntry 
)

Definition at line 4136 of file partlist.c.

4140 {
4141  PLIST_ENTRY Entry1, Entry2;
4142  PDISKENTRY DiskEntry;
4143  PPARTENTRY PartEntry;
4144 
4145  for (Entry1 = List->DiskListHead.Flink;
4146  Entry1 != &List->DiskListHead;
4147  Entry1 = Entry1->Flink)
4148  {
4149  DiskEntry = CONTAINING_RECORD(Entry1,
4150  DISKENTRY,
4151  ListEntry);
4152 
4153  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
4154  {
4155  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
4156  continue;
4157  }
4158 
4159  for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
4160  Entry2 != &DiskEntry->PrimaryPartListHead;
4161  Entry2 = Entry2->Flink)
4162  {
4163  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
4164  if (PartEntry->IsPartitioned && PartEntry->NeedsCheck)
4165  {
4166  ASSERT(DiskEntry == PartEntry->DiskEntry);
4167  if (pDiskEntry) *pDiskEntry = DiskEntry;
4168  *pPartEntry = PartEntry;
4169  return TRUE;
4170  }
4171  }
4172 
4173  for (Entry2 = DiskEntry->LogicalPartListHead.Flink;
4174  Entry2 != &DiskEntry->LogicalPartListHead;
4175  Entry2 = Entry2->Flink)
4176  {
4177  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
4178  if (PartEntry->IsPartitioned && PartEntry->NeedsCheck)
4179  {
4180  ASSERT(DiskEntry == PartEntry->DiskEntry);
4181  if (pDiskEntry) *pDiskEntry = DiskEntry;
4182  *pPartEntry = PartEntry;
4183  return TRUE;
4184  }
4185  }
4186  }
4187 
4188  if (pDiskEntry) *pDiskEntry = NULL;
4189  *pPartEntry = NULL;
4190 
4191  return FALSE;
4192 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
#define TRUE
Definition: types.h:120
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
BOOLEAN NeedsCheck
Definition: partlist.h:71
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
BOOLEAN IsPartitioned
Definition: partlist.h:60

Referenced by CheckFileSystemPage().

◆ GetNextUnformattedPartition()

BOOLEAN GetNextUnformattedPartition ( IN PPARTLIST  List,
OUT PDISKENTRY *pDiskEntry  OPTIONAL,
OUT PPARTENTRY pPartEntry 
)

Definition at line 4077 of file partlist.c.

4081 {
4082  PLIST_ENTRY Entry1, Entry2;
4083  PDISKENTRY DiskEntry;
4084  PPARTENTRY PartEntry;
4085 
4086  for (Entry1 = List->DiskListHead.Flink;
4087  Entry1 != &List->DiskListHead;
4088  Entry1 = Entry1->Flink)
4089  {
4090  DiskEntry = CONTAINING_RECORD(Entry1,
4091  DISKENTRY,
4092  ListEntry);
4093 
4094  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
4095  {
4096  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
4097  continue;
4098  }
4099 
4100  for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
4101  Entry2 != &DiskEntry->PrimaryPartListHead;
4102  Entry2 = Entry2->Flink)
4103  {
4104  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
4105  if (PartEntry->IsPartitioned && PartEntry->New)
4106  {
4107  ASSERT(DiskEntry == PartEntry->DiskEntry);
4108  if (pDiskEntry) *pDiskEntry = DiskEntry;
4109  *pPartEntry = PartEntry;
4110  return TRUE;
4111  }
4112  }
4113 
4114  for (Entry2 = DiskEntry->LogicalPartListHead.Flink;
4115  Entry2 != &DiskEntry->LogicalPartListHead;
4116  Entry2 = Entry2->Flink)
4117  {
4118  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
4119  if (PartEntry->IsPartitioned && PartEntry->New)
4120  {
4121  ASSERT(DiskEntry == PartEntry->DiskEntry);
4122  if (pDiskEntry) *pDiskEntry = DiskEntry;
4123  *pPartEntry = PartEntry;
4124  return TRUE;
4125  }
4126  }
4127  }
4128 
4129  if (pDiskEntry) *pDiskEntry = NULL;
4130  *pPartEntry = NULL;
4131 
4132  return FALSE;
4133 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
#define TRUE
Definition: types.h:120
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
BOOLEAN New
Definition: partlist.h:65
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
BOOLEAN IsPartitioned
Definition: partlist.h:60

Referenced by SelectFileSystemPage().

◆ GetPartition()

PPARTENTRY GetPartition ( IN PDISKENTRY  DiskEntry,
IN ULONG  PartitionNumber 
)

Definition at line 2082 of file partlist.c.

2086 {
2087  PPARTENTRY PartEntry;
2089 
2090  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2091  {
2092  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2093  return NULL;
2094  }
2095 
2096  /* Disk found, loop over the primary partitions first... */
2097  for (Entry = DiskEntry->PrimaryPartListHead.Flink;
2098  Entry != &DiskEntry->PrimaryPartListHead;
2099  Entry = Entry->Flink)
2100  {
2101  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
2102 
2103  if (PartEntry->PartitionNumber == PartitionNumber)
2104  {
2105  /* Partition found */
2106  return PartEntry;
2107  }
2108  }
2109 
2110  /* ... then over the logical partitions if needed */
2111  for (Entry = DiskEntry->LogicalPartListHead.Flink;
2112  Entry != &DiskEntry->LogicalPartListHead;
2113  Entry = Entry->Flink)
2114  {
2115  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
2116 
2117  if (PartEntry->PartitionNumber == PartitionNumber)
2118  {
2119  /* Partition found */
2120  return PartEntry;
2121  }
2122  }
2123 
2124  /* The partition was not found on the disk, stop there */
2125  return NULL;
2126 }
ULONG PartitionNumber
Definition: partlist.h:49
struct _Entry Entry
Definition: kefuncs.h:640
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:117
base of all file and directory entries
Definition: entries.h:82

Referenced by GetDiskOrPartition(), ResolveArcNameManually(), and SelectPartition().

◆ GetPrevPartition()

PPARTENTRY GetPrevPartition ( IN PPARTLIST  List,
IN PPARTENTRY CurrentPart  OPTIONAL 
)

Definition at line 2285 of file partlist.c.

2288 {
2289  PLIST_ENTRY DiskListEntry;
2290  PLIST_ENTRY PartListEntry;
2292 
2293  /* Fail if no disks are available */
2294  if (IsListEmpty(&List->DiskListHead))
2295  return NULL;
2296 
2297  /* Check for the previous usable entry on the current partition's disk */
2298  if (CurrentPart != NULL)
2299  {
2300  CurrentDisk = CurrentPart->DiskEntry;
2301 
2302  if (CurrentPart->LogicalPartition)
2303  {
2304  /* Logical partition */
2305 
2306  PartListEntry = CurrentPart->ListEntry.Blink;
2307  if (PartListEntry != &CurrentDisk->LogicalPartListHead)
2308  {
2309  /* Previous logical partition */
2310  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2311  }
2312  else
2313  {
2314  /* Extended partition */
2315  CurrentPart = CurrentDisk->ExtendedPartition;
2316  }
2317  return CurrentPart;
2318  }
2319  else
2320  {
2321  /* Primary or extended partition */
2322 
2323  PartListEntry = CurrentPart->ListEntry.Blink;
2324  if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
2325  {
2326  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2327 
2328  if (CurrentPart->IsPartitioned &&
2329  IsContainerPartition(CurrentPart->PartitionType))
2330  {
2331  PartListEntry = CurrentDisk->LogicalPartListHead.Blink;
2332  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2333  }
2334 
2335  return CurrentPart;
2336  }
2337  }
2338  }
2339 
2340  /* Search for the last partition entry on the previous disk */
2341  for (DiskListEntry = (CurrentPart ? CurrentDisk->ListEntry.Blink
2342  : List->DiskListHead.Blink);
2343  DiskListEntry != &List->DiskListHead;
2344  DiskListEntry = DiskListEntry->Blink)
2345  {
2346  CurrentDisk = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
2347 
2349  {
2350  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2351  continue;
2352  }
2353 
2354  PartListEntry = CurrentDisk->PrimaryPartListHead.Blink;
2355  if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
2356  {
2357  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2358 
2359  if (CurrentPart->IsPartitioned &&
2360  IsContainerPartition(CurrentPart->PartitionType))
2361  {
2362  PartListEntry = CurrentDisk->LogicalPartListHead.Blink;
2363  if (PartListEntry != &CurrentDisk->LogicalPartListHead)
2364  {
2365  CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
2366  return CurrentPart;
2367  }
2368  }
2369  else
2370  {
2371  return CurrentPart;
2372  }
2373  }
2374  }
2375 
2376  return NULL;
2377 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
PDISKENTRY CurrentDisk
Definition: partlist.c:73
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:245
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PPARTENTRY ExtendedPartition
Definition: partlist.h:129
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY List
Definition: psmgr.c:57
LIST_ENTRY ListEntry
Definition: partlist.h:77
Definition: typedefs.h:117
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126

Referenced by ScrollUpPartitionList().

◆ IsSuperFloppy()

BOOLEAN IsSuperFloppy ( IN PDISKENTRY  DiskEntry)

Definition at line 679 of file partlist.c.

681 {
683  ULONGLONG PartitionLengthEstimate;
684 
685  /* No layout buffer: we cannot say anything yet */
686  if (DiskEntry->LayoutBuffer == NULL)
687  return FALSE;
688 
689  /* We must have only one partition */
690  if (DiskEntry->LayoutBuffer->PartitionCount != 1)
691  return FALSE;
692 
693  /* Get the single partition entry */
694  PartitionInfo = DiskEntry->LayoutBuffer->PartitionEntry;
695 
696  /* The single partition must start at the beginning of the disk */
697  if (!(PartitionInfo->StartingOffset.QuadPart == 0 &&
698  PartitionInfo->HiddenSectors == 0))
699  {
700  return FALSE;
701  }
702 
703  /* The disk signature is usually set to one; warn in case it's not */
704  if (DiskEntry->LayoutBuffer->Signature != 1)
705  {
706  DPRINT1("Super-Floppy disk %lu signature %08x != 1!\n",
707  DiskEntry->DiskNumber, DiskEntry->LayoutBuffer->Signature);
708  }
709 
710  /*
711  * The partition number must be zero or one, be recognized,
712  * have FAT16 type and report as non-bootable.
713  */
714  if ((PartitionInfo->PartitionNumber != 0 &&
715  PartitionInfo->PartitionNumber != 1) ||
716  PartitionInfo->RecognizedPartition != TRUE ||
717  PartitionInfo->PartitionType != PARTITION_FAT_16 ||
718  PartitionInfo->BootIndicator != FALSE)
719  {
720  DPRINT1("Super-Floppy disk %lu does not return default settings!\n"
721  " PartitionNumber = %lu, expected 0\n"
722  " RecognizedPartition = %s, expected TRUE\n"
723  " PartitionType = 0x%02x, expected 0x04 (PARTITION_FAT_16)\n"
724  " BootIndicator = %s, expected FALSE\n",
725  DiskEntry->DiskNumber,
726  PartitionInfo->PartitionNumber,
727  PartitionInfo->RecognizedPartition ? "TRUE" : "FALSE",
728  PartitionInfo->PartitionType,
729  PartitionInfo->BootIndicator ? "TRUE" : "FALSE");
730  }
731 
732  /* The partition lengths should agree */
733  PartitionLengthEstimate = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
734  if (PartitionInfo->PartitionLength.QuadPart != PartitionLengthEstimate)
735  {
736  DPRINT1("PartitionLength = %I64u is different from PartitionLengthEstimate = %I64u\n",
737  PartitionInfo->PartitionLength.QuadPart, PartitionLengthEstimate);
738  }
739 
740  return TRUE;
741 }
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
uint64_t ULONGLONG
Definition: typedefs.h:65
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
#define PARTITION_FAT_16
Definition: disk.h:90
#define DPRINT1
Definition: precomp.h:8

Referenced by AddDiskToList(), BootLoaderHarddiskMbrPage(), ExtendedPartitionCreationChecks(), LogicalPartitionCreationChecks(), PrimaryPartitionCreationChecks(), and xHalIoWritePartitionTable().

◆ LogicalPartitionCreationChecks()

ERROR_NUMBER LogicalPartitionCreationChecks ( IN PPARTENTRY  PartEntry)

Definition at line 4054 of file partlist.c.

4056 {
4057  PDISKENTRY DiskEntry = PartEntry->DiskEntry;
4058 
4059  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
4060  {
4061  DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
4062  return ERROR_WARN_PARTITION;
4063  }
4064 
4065  /* Fail if the partition is already in use */
4066  if (PartEntry->IsPartitioned)
4067  return ERROR_NEW_PARTITION;
4068 
4069  /* Only one primary partition is allowed on super-floppy */
4070  if (IsSuperFloppy(DiskEntry))
4072 
4073  return ERROR_SUCCESS;
4074 }
#define ERROR_SUCCESS
Definition: deptool.c:10
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:679
#define DPRINT1
Definition: precomp.h:8

Referenced by CreateLogicalPartition(), and SelectPartitionPage().

◆ PrimaryPartitionCreationChecks()

ERROR_NUMBER PrimaryPartitionCreationChecks ( IN PPARTENTRY  PartEntry)

Definition at line 3996 of file partlist.c.

3998 {
3999  PDISKENTRY DiskEntry = PartEntry->DiskEntry;
4000 
4001  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
4002  {
4003  DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
4004  return ERROR_WARN_PARTITION;
4005  }
4006 
4007  /* Fail if the partition is already in use */
4008  if (PartEntry->IsPartitioned)
4009  return ERROR_NEW_PARTITION;
4010 
4011  /* Only one primary partition is allowed on super-floppy */
4012  if (IsSuperFloppy(DiskEntry))
4014 
4015  /* Fail if there are already 4 primary partitions in the list */
4016  if (GetPrimaryPartitionCount(DiskEntry) >= 4)
4018 
4019  return ERROR_SUCCESS;
4020 }
#define ERROR_SUCCESS
Definition: deptool.c:10
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
static ULONG GetPrimaryPartitionCount(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2414
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:679
#define DPRINT1
Definition: precomp.h:8

Referenced by CreatePrimaryPartition(), and SelectPartitionPage().

◆ RoundingDivide()

ULONGLONG RoundingDivide ( IN ULONGLONG  Dividend,
IN ULONGLONG  Divisor 
)

Definition at line 273 of file partlist.c.

276 {
277  return (Dividend + Divisor / 2) / Divisor;
278 }
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3046

Referenced by PrintDiskData(), and PrintPartitionData().

◆ SelectPartition()

PPARTENTRY SelectPartition ( IN PPARTLIST  List,
IN ULONG  DiskNumber,
IN ULONG  PartitionNumber 
)

Definition at line 2169 of file partlist.c.

2173 {
2174  PDISKENTRY DiskEntry;
2175  PPARTENTRY PartEntry;
2176 
2177  DiskEntry = GetDiskByNumber(List, DiskNumber);
2178  if (!DiskEntry)
2179  return NULL;
2180 
2181  PartEntry = GetPartition(/*List,*/ DiskEntry, PartitionNumber);
2182  if (!PartEntry)
2183  return NULL;
2184 
2185  ASSERT(PartEntry->DiskEntry == DiskEntry);
2186  ASSERT(DiskEntry->DiskNumber == DiskNumber);
2187  ASSERT(PartEntry->PartitionNumber == PartitionNumber);
2188 
2189  return PartEntry;
2190 }
ULONG PartitionNumber
Definition: partlist.h:49
ULONG DiskNumber
Definition: partlist.h:105
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2082
smooth NULL
Definition: ftsmooth.c:416
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2000
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by SelectPartitionPage().

◆ SetMountedDeviceValue()

BOOLEAN SetMountedDeviceValue ( IN WCHAR  Letter,
IN ULONG  Signature,
IN LARGE_INTEGER  StartingOffset 
)

Definition at line 3843 of file partlist.c.

3847 {
3849  WCHAR ValueNameBuffer[16];
3850  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\MountedDevices");
3852  REG_DISK_MOUNT_INFO MountInfo;
3853  NTSTATUS Status;
3854  HANDLE KeyHandle;
3855 
3856  RtlStringCchPrintfW(ValueNameBuffer, ARRAYSIZE(ValueNameBuffer),
3857  L"\\DosDevices\\%c:", Letter);
3858  RtlInitUnicodeString(&ValueName, ValueNameBuffer);
3859 
3861  &KeyName,
3863  NULL,
3864  NULL);
3865 
3868  &ObjectAttributes);
3869  if (!NT_SUCCESS(Status))
3870  {
3874  0,
3875  NULL,
3877  NULL);
3878  }
3879 
3880  if (!NT_SUCCESS(Status))
3881  {
3882  DPRINT1("NtCreateKey() failed (Status %lx)\n", Status);
3883  return FALSE;
3884  }
3885 
3886  MountInfo.Signature = Signature;
3887  MountInfo.StartingOffset = StartingOffset;
3889  &ValueName,
3890  0,
3891  REG_BINARY,
3892  (PVOID)&MountInfo,
3893  sizeof(MountInfo));
3894  NtClose(KeyHandle);
3895  if (!NT_SUCCESS(Status))
3896  {
3897  DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
3898  return FALSE;
3899  }
3900 
3901  return TRUE;
3902 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define TRUE
Definition: types.h:120
LARGE_INTEGER StartingOffset
Definition: partlist.c:25
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define REG_BINARY
Definition: nt_native.h:1496
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
static __inline NTSTATUS RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1064
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
WCHAR Letter
Status
Definition: gdiplustypes.h:24
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static const WCHAR Signature[]
Definition: parser.c:141
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by SetMountedDeviceValues().

◆ SetMountedDeviceValues()

BOOLEAN SetMountedDeviceValues ( IN PPARTLIST  List)

Definition at line 3905 of file partlist.c.

3907 {
3908  PLIST_ENTRY Entry1, Entry2;
3909  PDISKENTRY DiskEntry;
3910  PPARTENTRY PartEntry;
3912 
3913  if (List == NULL)
3914  return FALSE;
3915 
3916  for (Entry1 = List->DiskListHead.Flink;
3917  Entry1 != &List->DiskListHead;
3918  Entry1 = Entry1->Flink)
3919  {
3920  DiskEntry = CONTAINING_RECORD(Entry1,
3921  DISKENTRY,
3922  ListEntry);
3923 
3924  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
3925  {
3926  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
3927  continue;
3928  }
3929 
3930  for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
3931  Entry2 != &DiskEntry->PrimaryPartListHead;
3932  Entry2 = Entry2->Flink)
3933  {
3934  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
3935  if (PartEntry->IsPartitioned) // && !IsContainerPartition(PartEntry->PartitionType)
3936  {
3938 
3939  /* Assign a "\DosDevices\#:" mount point to this partition */
3940  if (PartEntry->DriveLetter)
3941  {
3942  StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
3943  if (!SetMountedDeviceValue(PartEntry->DriveLetter,
3944  DiskEntry->LayoutBuffer->Signature,
3945  StartingOffset))
3946  {
3947  return FALSE;
3948  }
3949  }
3950  }
3951  }
3952 
3953  for (Entry2 = DiskEntry->LogicalPartListHead.Flink;
3954  Entry2 != &DiskEntry->LogicalPartListHead;
3955  Entry2 = Entry2->Flink)
3956  {
3957  PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
3958  if (PartEntry->IsPartitioned) // && !IsContainerPartition(PartEntry->PartitionType)
3959  {
3961 
3962  /* Assign a "\DosDevices\#:" mount point to this partition */
3963  if (PartEntry->DriveLetter)
3964  {
3965  StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
3966  if (!SetMountedDeviceValue(PartEntry->DriveLetter,
3967  DiskEntry->LayoutBuffer->Signature,
3968  StartingOffset))
3969  {
3970  return FALSE;
3971  }
3972  }
3973  }
3974  }
3975  }
3976 
3977  return TRUE;
3978 }
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
WCHAR DriveLetter
Definition: partlist.h:52
ULARGE_INTEGER StartSector
Definition: partlist.h:42
#define TRUE
Definition: types.h:120
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3843
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
UCHAR PartitionType
Definition: partlist.h:46
ULONG BytesPerSector
Definition: partlist.h:89
LIST_ENTRY List
Definition: psmgr.c:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:119
BOOLEAN IsPartitioned
Definition: partlist.h:60

Referenced by UpdateRegistry().

◆ SetPartitionType()

VOID SetPartitionType ( IN PPARTENTRY  PartEntry,
IN UCHAR  PartitionType 
)

Definition at line 3981 of file partlist.c.

3984 {
3985  PDISKENTRY DiskEntry = PartEntry->DiskEntry;
3986 
3987  PartEntry->PartitionType = PartitionType;
3988 
3989  DiskEntry->Dirty = TRUE;
3990  DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartitionType;
3991  DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RecognizedPartition = IsRecognizedPartition(PartitionType);
3992  DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE;
3993 }
#define TRUE
Definition: types.h:120
BOOLEAN Dirty
Definition: partlist.h:112
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:467
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:271
BOOLEAN RewritePartition
Definition: ntdddisk.h:400
CHAR PartitionType
Definition: part_xbox.c:33
BOOLEAN RecognizedPartition
Definition: ntdddisk.h:399
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:119

Referenced by PreparePartitionForFormatting().

◆ WritePartitions()

NTSTATUS WritePartitions ( IN PDISKENTRY  DiskEntry)

Definition at line 3665 of file partlist.c.

3667 {
3668  NTSTATUS Status;
3673  ULONG BufferSize;
3675  ULONG PartitionCount;
3676  PLIST_ENTRY ListEntry;
3677  PPARTENTRY PartEntry;
3678  WCHAR DstPath[MAX_PATH];
3679 
3680  DPRINT("WritePartitions() Disk: %lu\n", DiskEntry->DiskNumber);
3681 
3682  /* If the disk is not dirty, there is nothing to do */
3683  if (!DiskEntry->Dirty)
3684  return STATUS_SUCCESS;
3685 
3686  RtlStringCchPrintfW(DstPath, ARRAYSIZE(DstPath),
3687  L"\\Device\\Harddisk%lu\\Partition0",
3688  DiskEntry->DiskNumber);
3689  RtlInitUnicodeString(&Name, DstPath);
3690 
3692  &Name,
3694  NULL,
3695  NULL);
3696 
3700  &Iosb,
3701  0,
3703  if (!NT_SUCCESS(Status))
3704  {
3705  DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
3706  return Status;
3707  }
3708 
3709 #ifdef DUMP_PARTITION_TABLE
3710  DumpPartitionTable(DiskEntry);
3711 #endif
3712 
3713  //
3714  // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
3715  // the disk in MBR or GPT format in case the disk was not initialized!!
3716  // For this we must ask the user which format to use.
3717  //
3718 
3719  /* Save the original partition count to be restored later (see comment below) */
3720  PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
3721 
3722  /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
3724  ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION));
3726  NULL,
3727  NULL,
3728  NULL,
3729  &Iosb,
3731  DiskEntry->LayoutBuffer,
3732  BufferSize,
3733  DiskEntry->LayoutBuffer,
3734  BufferSize);
3736 
3737  /*
3738  * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
3739  * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
3740  * where such a table is expected to enumerate up to 4 partitions:
3741  * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
3742  * Due to this we need to restore the original PartitionCount number.
3743  */
3744  DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
3745 
3746  /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
3747  if (!NT_SUCCESS(Status))
3748  {
3749  DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
3750  return Status;
3751  }
3752 
3753 #ifdef DUMP_PARTITION_TABLE
3754  DumpPartitionTable(DiskEntry);
3755 #endif
3756 
3757  /* Update the partition numbers */
3758 
3759  /* Update the primary partition table */
3760  for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
3761  ListEntry != &DiskEntry->PrimaryPartListHead;
3762  ListEntry = ListEntry->Flink)
3763  {
3764  PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
3765 
3766  if (PartEntry->IsPartitioned)
3767  {
3769  PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
3770  PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
3771  }
3772  }
3773 
3774  /* Update the logical partition table */
3775  for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
3776  ListEntry != &DiskEntry->LogicalPartListHead;
3777  ListEntry = ListEntry->Flink)
3778  {
3779  PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
3780 
3781  if (PartEntry->IsPartitioned)
3782  {
3784  PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
3785  PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
3786  }
3787  }
3788 
3789  //
3790  // NOTE: Originally (see r40437), we used to install here also a new MBR
3791  // for this disk (by calling InstallMbrBootCodeToDisk), only if:
3792  // DiskEntry->NewDisk == TRUE and DiskEntry->HwDiskNumber == 0.
3793  // Then after that, both DiskEntry->NewDisk and DiskEntry->NoMbr were set
3794  // to FALSE. In the other place (in usetup.c) where InstallMbrBootCodeToDisk
3795  // was called too, the installation test was modified by checking whether
3796  // DiskEntry->NoMbr was TRUE (instead of NewDisk).
3797  //
3798 
3799  /* The layout has been successfully updated, the disk is not dirty anymore */
3800  DiskEntry->Dirty = FALSE;
3801 
3802  return Status;
3803 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
ULONG PartitionNumber
Definition: partlist.h:49
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
struct _PARTITION_INFORMATION PARTITION_INFORMATION
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
HANDLE FileHandle
Definition: stats.c:38
#define GENERIC_WRITE
Definition: nt_native.h:90
struct _DRIVE_LAYOUT_INFORMATION DRIVE_LAYOUT_INFORMATION
struct NameRec_ * Name
Definition: cdprocs.h:464
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static __inline NTSTATUS RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1064
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
UCHAR PartitionType
Definition: partlist.h:46
__wchar_t WCHAR
Definition: xmlstorage.h:180
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
#define BufferSize
Definition: classpnp.h:419
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
Definition: typedefs.h:117
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define IOCTL_DISK_SET_DRIVE_LAYOUT
Definition: ntdddisk.h:170
return STATUS_SUCCESS
Definition: btrfs.c:2745
BOOLEAN IsPartitioned
Definition: partlist.h:60
ULONG PartitionIndex
Definition: partlist.h:50

Referenced by FormatPartitionPage(), and WritePartitionsToDisk().

◆ WritePartitionsToDisk()

BOOLEAN WritePartitionsToDisk ( IN PPARTLIST  List)

Definition at line 3806 of file partlist.c.

3808 {
3809  NTSTATUS Status;
3811  PDISKENTRY DiskEntry;
3812 
3813  if (List == NULL)
3814  return TRUE;
3815 
3816  for (Entry = List->DiskListHead.Flink;
3817  Entry != &List->DiskListHead;
3818  Entry = Entry->Flink)
3819  {
3820  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
3821 
3822  if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
3823  {
3824  DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
3825  continue;
3826  }
3827 
3828  if (DiskEntry->Dirty != FALSE)
3829  {
3830  Status = WritePartitions(DiskEntry);
3831  if (!NT_SUCCESS(Status))
3832  {
3833  DPRINT1("WritePartitionsToDisk() failed to update disk %lu, Status 0x%08lx\n",
3834  DiskEntry->DiskNumber, Status);
3835  }
3836  }
3837  }
3838 
3839  return TRUE;
3840 }
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
LONG NTSTATUS
Definition: precomp.h:26
ULONG DiskNumber
Definition: partlist.h:105
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
BOOLEAN Dirty
Definition: partlist.h:112
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3665
base of all file and directory entries
Definition: entries.h:82

Referenced by SelectFileSystemPage().

Variable Documentation

◆ PartitionTypes

Definition at line 62 of file partlist.c.

Referenced by GetPartTypeStringFromPartitionType().