[DISKPART] Implement the uniqueid command

TODO: Set disk signatures.
This commit is contained in:
Eric Kohl 2022-03-27 17:54:38 +02:00
parent 2ba6b09754
commit 5a63f3e85a
2 changed files with 118 additions and 1 deletions

View file

@ -20,6 +20,8 @@
#include <winreg.h>
#include <wincon.h>
#include <errno.h>
#include <conutils.h>
/*

View file

@ -8,7 +8,122 @@
#include "diskpart.h"
BOOL uniqueid_main(INT argc, LPWSTR *argv)
#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;
}