From 5a63f3e85a6e1e8ee6733d2ad3124fb190699c52 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 27 Mar 2022 17:54:38 +0200 Subject: [PATCH] [DISKPART] Implement the uniqueid command TODO: Set disk signatures. --- base/system/diskpart/diskpart.h | 2 + base/system/diskpart/uniqueid.c | 117 +++++++++++++++++++++++++++++++- 2 files changed, 118 insertions(+), 1 deletion(-) 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 #include +#include + #include /* 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" -BOOL uniqueid_main(INT argc, LPWSTR *argv) +#define NDEBUG +#include + +/* 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; }