1 /*
2 * PROJECT: ReactOS DiskPart
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/diskpart/setid.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
15 BOOL
setid_main(_In_ INT argc,_In_ PWSTR * argv)16 setid_main(
17 _In_ INT argc,
18 _In_ PWSTR *argv)
19 {
20 UCHAR PartitionType = 0;
21 INT i, length;
22 PWSTR pszSuffix = NULL;
23 NTSTATUS Status;
24
25 DPRINT("SetId()\n");
26
27 if (CurrentDisk == NULL)
28 {
29 ConResPuts(StdOut, IDS_SELECT_NO_DISK);
30 return TRUE;
31 }
32
33 if (CurrentPartition == NULL)
34 {
35 ConResPuts(StdOut, IDS_SELECT_NO_PARTITION);
36 return TRUE;
37 }
38
39 for (i = 1; i < argc; i++)
40 {
41 if (HasPrefix(argv[i], L"id=", &pszSuffix))
42 {
43 /* id=<Byte>|<GUID> */
44 DPRINT("Id : %s\n", pszSuffix);
45
46 length = wcslen(pszSuffix);
47 if (length == 0)
48 {
49 ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
50 return TRUE;
51 }
52
53 if (length > 2)
54 {
55 ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
56 return TRUE;
57 }
58
59 /* Byte */
60 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
61 if (PartitionType == 0)
62 {
63 ConResPuts(StdErr, IDS_SETID_INVALID_FORMAT);
64 return TRUE;
65 }
66 }
67 }
68
69 if (PartitionType == 0x42)
70 {
71 ConResPuts(StdErr, IDS_SETID_INVALID_TYPE);
72 return TRUE;
73 }
74
75 CurrentPartition->PartitionType = PartitionType;
76 CurrentDisk->Dirty = TRUE;
77 UpdateDiskLayout(CurrentDisk);
78 Status = WritePartitions(CurrentDisk);
79 if (!NT_SUCCESS(Status))
80 {
81 ConResPuts(StdOut, IDS_SETID_FAIL);
82 return TRUE;
83 }
84
85 ConResPuts(StdOut, IDS_SETID_SUCCESS);
86
87 return TRUE;
88 }
89