[DISKPART] GUID partition preparations

- Improve parameter handling in the setid and uniqueid commands.
- Improve error messages.
This commit is contained in:
Eric Kohl
2025-12-07 12:25:25 +01:00
parent 920153534b
commit 5a224e277d
15 changed files with 177 additions and 63 deletions
+4 -10
View File
@@ -37,7 +37,7 @@ CreateExtendedPartition(
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT)
{
ConPuts(StdOut, L"GPT Partitions are not supported yet!\n");
ConResPuts(StdOut, IDS_CREATE_PARTITION_INVALID_STYLE);
return TRUE;
}
else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
@@ -226,9 +226,9 @@ CreateLogicalPartition(
return TRUE;
}
if (CurrentDisk->PartitionStyle != PARTITION_STYLE_MBR)
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT)
{
ConPuts(StdOut, L"Invalid partition style!\n");
ConResPuts(StdOut, IDS_CREATE_PARTITION_INVALID_STYLE);
return TRUE;
}
@@ -262,7 +262,7 @@ CreateLogicalPartition(
}
else if (HasPrefix(argv[i], L"id=", &pszSuffix))
{
/* id=<Byte>|<GUID> */
/* id=<Byte> */
DPRINT("Id : %s\n", pszSuffix);
length = wcslen(pszSuffix);
@@ -276,12 +276,6 @@ CreateLogicalPartition(
return TRUE;
}
}
#if 0
else if ()
{
/* GUID */
}
#endif
else
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
+6
View File
@@ -43,6 +43,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDie angegebene Partition konnte nicht erstellt werden.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDie angegebene Partition wurde erfolgreich erstellt.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -144,6 +145,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nDer Partitionstyp ist ungültig.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -43,6 +43,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart was unable to create the specified partition.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -144,6 +145,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -50,6 +50,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart non è stato in grado di creare la partizione specificata.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart ha creato con successo la partizione selezionata.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -151,6 +152,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nIl tipo di partizione non è valido.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -43,6 +43,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart nie może utworzyć określonej partycji.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart pomyślnie utworzył określoną partycję.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -144,6 +145,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nTyp partycji jest nieprawidłowy.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -45,6 +45,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart was unable to create the specified partition.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -146,6 +147,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -51,6 +51,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart nu a reușit să creeze partiția specificată.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -152,6 +153,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nTipul partiției este nevalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -45,6 +45,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart was unable to create the specified partition.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -146,6 +147,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -47,6 +47,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart was unable to create the specified partition.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -148,6 +149,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -53,6 +53,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart belirtilen bölümü oluşturamadı.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart, belirtilen bölümü oluşturdu.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -154,6 +155,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nBölüm türü geçersiz.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -52,6 +52,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart was unable to create the specified partition.\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart succeeded in creating the specified partition.\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -153,6 +154,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+6
View File
@@ -52,6 +52,7 @@ STRINGTABLE
BEGIN
IDS_CREATE_PARTITION_FAIL "\nDiskPart 無法建立指定的磁碟分割。\n"
IDS_CREATE_PARTITION_SUCCESS "\nDiskPart 成功建立指定的磁碟分割。\n"
IDS_CREATE_PARTITION_INVALID_STYLE "\nLogical or extended partitions can not be created on a GPT disk.\nCreate a primary partition on a GPT disk instead.\n"
END
STRINGTABLE
@@ -153,6 +154,11 @@ BEGIN
IDS_SETID_INVALID_TYPE "\n無效的磁碟類型。\n"
END
STRINGTABLE
BEGIN
IDS_UNIQUID_DISK_INVALID_STYLE "\nThe selected disk is neither a GPT disk nor an MBR disk.\nSelect a GPT disk or an MBR disk.\n"
END
/* Disk Status */
STRINGTABLE
BEGIN
+2
View File
@@ -35,6 +35,7 @@
#define IDS_CREATE_PARTITION_FAIL 1050
#define IDS_CREATE_PARTITION_SUCCESS 1051
#define IDS_CREATE_PARTITION_INVALID_STYLE 1052
#define IDS_DELETE_PARTITION_FAIL 1070
#define IDS_DELETE_PARTITION_SUCCESS 1071
@@ -107,6 +108,7 @@
#define IDS_SETID_INVALID_FORMAT 4452
#define IDS_SETID_INVALID_TYPE 4453
#define IDS_UNIQUID_DISK_INVALID_STYLE 4500
#define IDS_STATUS_YES 31
#define IDS_STATUS_NO 32
+58 -33
View File
@@ -19,7 +19,7 @@ setid_main(
{
UCHAR PartitionType = 0;
INT i, length;
PWSTR pszSuffix = NULL;
PWSTR pszSuffix, pszId = NULL;
NTSTATUS Status;
DPRINT("SetId()\n");
@@ -41,45 +41,70 @@ setid_main(
if (HasPrefix(argv[i], L"id=", &pszSuffix))
{
/* id=<Byte>|<GUID> */
DPRINT("Id : %s\n", pszSuffix);
length = wcslen(pszSuffix);
if (length == 0)
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
if (length > 2)
{
ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
return TRUE;
}
/* Byte */
PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
if (PartitionType == 0)
{
ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
return TRUE;
}
DPRINT("ID : %s\n", pszSuffix);
pszId = pszSuffix;
}
else if (_wcsicmp(argv[i], L"noerr") == 0)
{
/* noerr */
DPRINT("NOERR\n");
ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
}
else if (_wcsicmp(argv[i], L"override") == 0)
{
/* override */
DPRINT("OVERRIDE\n");
ConPuts(StdOut, L"The OVERRIDE option is not supported yet!\n");
}
else
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
}
if (PartitionType == 0x42)
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT)
{
ConResPuts(StdErr, IDS_SETID_INVALID_TYPE);
ConPuts(StdErr, L"The setid command does not support GPT disks yet!\n");
return TRUE;
}
CurrentPartition->PartitionType = PartitionType;
CurrentDisk->Dirty = TRUE;
UpdateDiskLayout(CurrentDisk);
Status = WritePartitions(CurrentDisk);
if (!NT_SUCCESS(Status))
else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_MBR)
{
ConResPuts(StdOut, IDS_SETID_FAIL);
return TRUE;
length = wcslen(pszId);
if (length == 0)
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
if (length > 2)
{
ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
return TRUE;
}
PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
if ((PartitionType == 0) && (errno == ERANGE))
{
ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
return TRUE;
}
if (PartitionType == 0x42)
{
ConResPuts(StdErr, IDS_SETID_INVALID_TYPE);
return TRUE;
}
CurrentPartition->PartitionType = PartitionType;
CurrentDisk->Dirty = TRUE;
UpdateDiskLayout(CurrentDisk);
Status = WritePartitions(CurrentDisk);
if (!NT_SUCCESS(Status))
{
ConResPuts(StdOut, IDS_SETID_FAIL);
return TRUE;
}
}
ConResPuts(StdOut, IDS_SETID_SUCCESS);
+47 -20
View File
@@ -19,7 +19,8 @@ UniqueIdDisk(
_In_ PWSTR *argv)
{
WCHAR szBuffer[40];
PWSTR pszSuffix = NULL;
PWSTR pszSuffix, pszId = NULL;
INT i;
ULONG ulValue;
if (CurrentDisk == NULL)
@@ -48,32 +49,58 @@ UniqueIdDisk(
return TRUE;
}
if (!HasPrefix(argv[2], L"ID=", &pszSuffix))
for (i = 1; i < argc; i++)
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
if (HasPrefix(argv[2], L"id=", &pszSuffix))
{
/* id=<Byte>|<GUID> */
DPRINT("ID : %s\n", pszSuffix);
pszId = pszSuffix;
}
else if (_wcsicmp(argv[i], L"noerr") == 0)
{
/* noerr */
DPRINT("NOERR\n");
ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
}
else
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
}
if ((pszSuffix == NULL) ||
(wcslen(pszSuffix) != 8) ||
(IsHexString(pszSuffix) == FALSE))
if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT)
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
ConPuts(StdErr, L"The uniqueid disk command does not support GPT disks yet!\n");
}
ulValue = wcstoul(pszSuffix, NULL, 16);
if ((ulValue == 0) && (errno == ERANGE))
else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_MBR)
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
if ((pszId == NULL) ||
(wcslen(pszId) != 8) ||
(IsHexString(pszId) == FALSE))
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
DPRINT("New Signature: 0x%08lx\n", ulValue);
CurrentDisk->LayoutBuffer->Mbr.Signature = ulValue;
CurrentDisk->Dirty = TRUE;
UpdateDiskLayout(CurrentDisk);
WritePartitions(CurrentDisk);
ulValue = wcstoul(pszId, NULL, 16);
if ((ulValue == 0) && (errno == ERANGE))
{
ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
return TRUE;
}
DPRINT("New Signature: 0x%08lx\n", ulValue);
CurrentDisk->LayoutBuffer->Mbr.Signature = ulValue;
CurrentDisk->Dirty = TRUE;
UpdateDiskLayout(CurrentDisk);
WritePartitions(CurrentDisk);
}
else
{
ConResPuts(StdOut, IDS_UNIQUID_DISK_INVALID_STYLE);
}
return TRUE;
}