https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5a63f3e85a6e1e8ee6733…
commit 5a63f3e85a6e1e8ee6733d2ad3124fb190699c52
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Mar 27 17:54:38 2022 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Mar 27 17:54:38 2022 +0200
[DISKPART] Implement the uniqueid command
TODO: Set disk signatures.
---
base/system/diskpart/diskpart.h | 2 +
base/system/diskpart/uniqueid.c | 115 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+)
diff --git a/base/system/diskpart/diskpart.h b/base/system/diskpart/diskpart.h
index 751c3ff6aaf..c7a453ed241 100644
--- a/base/system/diskpart/diskpart.h
+++ b/base/system/diskpart/diskpart.h
@@ -20,6 +20,8 @@
#include <winreg.h>
#include <wincon.h>
+#include <errno.h>
+
#include <conutils.h>
/*
diff --git a/base/system/diskpart/uniqueid.c b/base/system/diskpart/uniqueid.c
index 9096c7a2425..af2c5e4fc64 100644
--- a/base/system/diskpart/uniqueid.c
+++ b/base/system/diskpart/uniqueid.c
@@ -8,7 +8,122 @@
#include "diskpart.h"
+#define NDEBUG
+#include <debug.h>
+
+/* FUNCTIONS ******************************************************************/
+
+static
+BOOL
+isHexString(
+ _In_ PWSTR pszHexString)
+{
+ PWSTR ptr;
+
+ ptr = pszHexString;
+ while (*ptr != UNICODE_NULL)
+ {
+ if (!iswxdigit(*ptr))
+ return FALSE;
+
+ ptr++;
+ }
+
+ return TRUE;
+}
+
+
+static
+BOOL
+hasPrefix(
+ _In_ PWSTR pszString,
+ _In_ PWSTR pszPrefix)
+{
+ return (_wcsnicmp(pszString, pszPrefix, wcslen(pszPrefix)) == 0);
+}
+
+
+static
+VOID
+UniqueIdDisk(
+ _In_ INT argc,
+ _In_ LPWSTR *argv)
+{
+ ULONG ulLength;
+ ULONG ulValue;
+ PWSTR startptr = NULL, endptr = NULL;
+
+ if (CurrentDisk == NULL)
+ {
+ ConResPuts(StdOut, IDS_SELECT_NO_DISK);
+ return;
+ }
+
+ if (argc == 2)
+ {
+ ConPuts(StdOut, L"\n");
+ ConPrintf(StdOut, L"Disk ID: %08lx\n",
CurrentDisk->LayoutBuffer->Signature);
+ ConPuts(StdOut, L"\n");
+ return;
+ }
+
+ if (argc != 3)
+ {
+ ConResPuts(StdOut, IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ ulLength = wcslen(argv[2]);
+ if ((ulLength <= 3) || (ulLength > 11))
+ {
+ ConResPuts(StdOut, IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ if (!hasPrefix(argv[2], L"ID="))
+ {
+ ConResPuts(StdOut, IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ startptr = &argv[2][3];
+ if (isHexString(startptr) == FALSE)
+ {
+ ConResPuts(StdOut, IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ ulValue = wcstoul(startptr, &endptr, 16);
+ if ((ulValue == 0) && (errno == ERANGE))
+ {
+ ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
+ return;
+ }
+
+ ConPrintf(StdOut, L"Setting the disk signature is not implemented
yet!\n");
+#if 0
+ DPRINT1("New Signature: %lx\n", ulValue);
+ CurrentDisk->LayoutBuffer->Signature = ulValue;
+// SetDiskLayout(CurrentDisk);
+#endif
+
+}
+
+
BOOL uniqueid_main(INT argc, LPWSTR *argv)
{
+ /* gets the first word from the string */
+ if (argc == 1)
+ {
+ ConResPuts(StdOut, IDS_HELP_CMD_UNIQUEID);
+ return TRUE;
+ }
+
+ /* determines which details to print (disk, partition, etc.) */
+ if (!wcsicmp(argv[1], L"disk"))
+ UniqueIdDisk(argc, argv);
+ else
+ ConResPuts(StdOut, IDS_HELP_CMD_UNIQUEID);
+
return TRUE;
}