https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7dec75ff670286f47d8243...
commit 7dec75ff670286f47d82431838330b1ee20a0f66 Author: Eric Kohl eric.kohl@reactos.org AuthorDate: Sat Jun 11 14:31:55 2022 +0200 Commit: Eric Kohl eric.kohl@reactos.org CommitDate: Sat Jun 11 14:31:55 2022 +0200
[DISKPART] Implement the SETID command --- base/system/diskpart/lang/de-DE.rc | 8 ++++ base/system/diskpart/lang/en-US.rc | 8 ++++ base/system/diskpart/lang/pl-PL.rc | 8 ++++ base/system/diskpart/lang/pt-PT.rc | 8 ++++ base/system/diskpart/lang/ro-RO.rc | 8 ++++ base/system/diskpart/lang/ru-RU.rc | 8 ++++ base/system/diskpart/lang/sq-AL.rc | 8 ++++ base/system/diskpart/lang/tr-TR.rc | 8 ++++ base/system/diskpart/lang/zh-CN.rc | 8 ++++ base/system/diskpart/lang/zh-TW.rc | 8 ++++ base/system/diskpart/resource.h | 6 +++ base/system/diskpart/setid.c | 76 +++++++++++++++++++++++++++++++++++++- 12 files changed, 161 insertions(+), 1 deletion(-)
diff --git a/base/system/diskpart/lang/de-DE.rc b/base/system/diskpart/lang/de-DE.rc index 97378fd99fe..6de5a7687ba 100644 --- a/base/system/diskpart/lang/de-DE.rc +++ b/base/system/diskpart/lang/de-DE.rc @@ -117,6 +117,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart konnte den Partitionstyp nicht ändern.\n" + IDS_SETID_SUCCESS "\nDer Partitionstyp wurde erfolgreich geändert.\n" + IDS_SETID_INVALID_FORMAT "\nDas Format des Partitionstyps ist ungültig.\n" + IDS_SETID_INVALID_TYPE "\nDer Partitionstyp ist ungültig.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/en-US.rc b/base/system/diskpart/lang/en-US.rc index 8b3222d2de7..e0e23003df4 100644 --- a/base/system/diskpart/lang/en-US.rc +++ b/base/system/diskpart/lang/en-US.rc @@ -117,6 +117,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/pl-PL.rc b/base/system/diskpart/lang/pl-PL.rc index 10c96c15d8e..d15721a8809 100644 --- a/base/system/diskpart/lang/pl-PL.rc +++ b/base/system/diskpart/lang/pl-PL.rc @@ -117,6 +117,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nNieprawidłowy wolumin.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/pt-PT.rc b/base/system/diskpart/lang/pt-PT.rc index b3ea79004d2..1187c52bad2 100644 --- a/base/system/diskpart/lang/pt-PT.rc +++ b/base/system/diskpart/lang/pt-PT.rc @@ -119,6 +119,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/ro-RO.rc b/base/system/diskpart/lang/ro-RO.rc index de6dcf2e770..8ff6e4805f0 100644 --- a/base/system/diskpart/lang/ro-RO.rc +++ b/base/system/diskpart/lang/ro-RO.rc @@ -119,6 +119,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/ru-RU.rc b/base/system/diskpart/lang/ru-RU.rc index acc78d19517..52a5058d27b 100644 --- a/base/system/diskpart/lang/ru-RU.rc +++ b/base/system/diskpart/lang/ru-RU.rc @@ -119,6 +119,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/sq-AL.rc b/base/system/diskpart/lang/sq-AL.rc index 495b4b13913..04943b671bf 100644 --- a/base/system/diskpart/lang/sq-AL.rc +++ b/base/system/diskpart/lang/sq-AL.rc @@ -121,6 +121,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/tr-TR.rc b/base/system/diskpart/lang/tr-TR.rc index 94579802b28..683a4bd5617 100644 --- a/base/system/diskpart/lang/tr-TR.rc +++ b/base/system/diskpart/lang/tr-TR.rc @@ -119,6 +119,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/zh-CN.rc b/base/system/diskpart/lang/zh-CN.rc index e35519e0d37..ec002a4ac88 100644 --- a/base/system/diskpart/lang/zh-CN.rc +++ b/base/system/diskpart/lang/zh-CN.rc @@ -126,6 +126,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/lang/zh-TW.rc b/base/system/diskpart/lang/zh-TW.rc index 9ff8b00064c..cb5751ed667 100644 --- a/base/system/diskpart/lang/zh-TW.rc +++ b/base/system/diskpart/lang/zh-TW.rc @@ -120,6 +120,14 @@ BEGIN IDS_SELECT_VOLUME_INVALID "\nInvalid volume.\n\n" END
+STRINGTABLE +BEGIN + IDS_SETID_FAIL "\nDiskPart was unable to change the partition type.\n" + IDS_SETID_SUCCESS "\nThe partition type was changed successfully.\n" + IDS_SETID_INVALID_FORMAT "\nThe format of the partition type is invalid.\n" + IDS_SETID_INVALID_TYPE "\nThe partition type is invalid.\n" +END + /* Disk Status */ STRINGTABLE BEGIN diff --git a/base/system/diskpart/resource.h b/base/system/diskpart/resource.h index fd5899887c8..5afab820c6f 100644 --- a/base/system/diskpart/resource.h +++ b/base/system/diskpart/resource.h @@ -89,6 +89,12 @@ #define IDS_SELECT_VOLUME 4408 #define IDS_SELECT_VOLUME_INVALID 4409
+#define IDS_SETID_FAIL 4450 +#define IDS_SETID_SUCCESS 4451 +#define IDS_SETID_INVALID_FORMAT 4452 +#define IDS_SETID_INVALID_TYPE 4453 + + #define IDS_STATUS_YES 31 #define IDS_STATUS_NO 32 #define IDS_STATUS_DISK_HEALTHY 33 diff --git a/base/system/diskpart/setid.c b/base/system/diskpart/setid.c index 6cec3925fc3..7ab488de374 100644 --- a/base/system/diskpart/setid.c +++ b/base/system/diskpart/setid.c @@ -8,7 +8,81 @@
#include "diskpart.h"
-BOOL setid_main(INT argc, LPWSTR *argv) +#define NDEBUG +#include <debug.h> + + +BOOL +setid_main( + _In_ INT argc, + _In_ PWSTR *argv) { + UCHAR PartitionType = 0; + INT i, length; + PWSTR pszSuffix = NULL; + NTSTATUS Status; + + DPRINT("SetId()\n"); + + if (CurrentDisk == NULL) + { + ConResPuts(StdOut, IDS_SELECT_NO_DISK); + return TRUE; + } + + if (CurrentPartition == NULL) + { + ConResPuts(StdOut, IDS_SELECT_NO_PARTITION); + return TRUE; + } + + for (i = 1; i < argc; i++) + { + 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; + } + } + } + + 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); + return TRUE; }