Reactos
at master 122 lines 3.3 kB view raw
1/* 2 * PROJECT: ReactOS DiskPart 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: base/system/diskpart/uniqueid.c 5 * PURPOSE: Manages all the partitions of the OS in an interactive way. 6 * PROGRAMMERS: Lee Schroeder 7 */ 8 9#include "diskpart.h" 10 11#define NDEBUG 12#include <debug.h> 13 14/* FUNCTIONS ******************************************************************/ 15 16EXIT_CODE 17UniqueIdDisk( 18 _In_ INT argc, 19 _In_ PWSTR *argv) 20{ 21 WCHAR szBuffer[40]; 22 PWSTR pszSuffix, pszId = NULL; 23 INT i; 24 ULONG ulValue; 25 26 if (CurrentDisk == NULL) 27 { 28 ConResPuts(StdOut, IDS_SELECT_NO_DISK); 29 return EXIT_SUCCESS; 30 } 31 32 if (argc == 2) 33 { 34 ConPuts(StdOut, L"\n"); 35 if (CurrentDisk->LayoutBuffer->PartitionStyle == PARTITION_STYLE_GPT) 36 PrintGUID(szBuffer, &CurrentDisk->LayoutBuffer->Gpt.DiskId); 37 else if (CurrentDisk->LayoutBuffer->PartitionStyle == PARTITION_STYLE_MBR) 38 swprintf(szBuffer, L"%08lx", CurrentDisk->LayoutBuffer->Mbr.Signature); 39 else 40 wcscpy(szBuffer, L"00000000"); 41 ConPrintf(StdOut, L"Disk ID: %s\n", szBuffer); 42 ConPuts(StdOut, L"\n"); 43 return EXIT_SUCCESS; 44 } 45 46 if (argc != 3) 47 { 48 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 49 return EXIT_SUCCESS; 50 } 51 52 for (i = 1; i < argc; i++) 53 { 54 if (_wcsicmp(argv[i], L"noerr") == 0) 55 { 56 /* noerr */ 57 DPRINT("NOERR\n"); 58 ConPuts(StdOut, L"The NOERR option is not supported yet!\n"); 59 } 60 } 61 62 for (i = 1; i < argc; i++) 63 { 64 if (HasPrefix(argv[2], L"id=", &pszSuffix)) 65 { 66 /* id=<Byte>|<GUID> */ 67 DPRINT("ID : %s\n", pszSuffix); 68 pszId = pszSuffix; 69 } 70 else if (_wcsicmp(argv[i], L"noerr") == 0) 71 { 72 /* noerr - Already handled above */ 73 } 74 else 75 { 76 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 77 return EXIT_SUCCESS; 78 } 79 } 80 81 if (CurrentDisk->PartitionStyle == PARTITION_STYLE_GPT) 82 { 83 if (!StringToGUID(&CurrentDisk->LayoutBuffer->Gpt.DiskId, pszId)) 84 { 85 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 86 return EXIT_SUCCESS; 87 } 88 89 CurrentDisk->Dirty = TRUE; 90 UpdateGptDiskLayout(CurrentDisk, FALSE); 91 WriteGptPartitions(CurrentDisk); 92 } 93 else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_MBR) 94 { 95 if ((pszId == NULL) || 96 (wcslen(pszId) != 8) || 97 (IsHexString(pszId) == FALSE)) 98 { 99 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 100 return EXIT_SUCCESS; 101 } 102 103 ulValue = wcstoul(pszId, NULL, 16); 104 if ((ulValue == 0) && (errno == ERANGE)) 105 { 106 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS); 107 return EXIT_SUCCESS; 108 } 109 110 DPRINT("New Signature: 0x%08lx\n", ulValue); 111 CurrentDisk->LayoutBuffer->Mbr.Signature = ulValue; 112 CurrentDisk->Dirty = TRUE; 113 UpdateMbrDiskLayout(CurrentDisk); 114 WriteMbrPartitions(CurrentDisk); 115 } 116 else 117 { 118 ConResPuts(StdOut, IDS_UNIQUID_DISK_INVALID_STYLE); 119 } 120 121 return EXIT_SUCCESS; 122}