ReactOS 0.4.16-dev-340-g0540c21
select.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS DiskPart
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/diskpart/select.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
16BOOL
18 INT argc,
19 PWSTR *argv)
20{
22 PDISKENTRY DiskEntry;
23 ULONG ulValue;
24
25 DPRINT("Select Disk()\n");
26
27 if (argc > 3)
28 {
30 return TRUE;
31 }
32
33 if (argc == 2)
34 {
35 if (CurrentDisk == NULL)
37 else
39 return TRUE;
40 }
41
42 if (!_wcsicmp(argv[2], L"system"))
43 {
45
47 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
48
49 CurrentDisk = DiskEntry;
52 return TRUE;
53 }
54 else if (!_wcsicmp(argv[2], L"next"))
55 {
56 if (CurrentDisk == NULL)
57 {
60 return TRUE;
61 }
62
64 {
68 return TRUE;
69 }
70
72
73 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
74
75 CurrentDisk = DiskEntry;
78 return TRUE;
79 }
80 else if (IsDecString(argv[2]))
81 {
82 ulValue = wcstoul(argv[2], NULL, 10);
83 if ((ulValue == 0) && (errno == ERANGE))
84 {
86 return TRUE;
87 }
88
90
92 while (Entry != &DiskListHead)
93 {
94 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
95
96 if (DiskEntry->DiskNumber == ulValue)
97 {
98 CurrentDisk = DiskEntry;
101 return TRUE;
102 }
103
104 Entry = Entry->Flink;
105 }
106 }
107 else
108 {
110 return TRUE;
111 }
112
114 return TRUE;
115}
116
117
118BOOL
120 INT argc,
121 PWSTR *argv)
122{
124 PPARTENTRY PartEntry;
125 ULONG ulValue;
126 ULONG PartNumber = 1;
127
128 DPRINT("Select Partition()\n");
129
130 if (argc > 3)
131 {
133 return TRUE;
134 }
135
136 if (CurrentDisk == NULL)
137 {
139 return TRUE;
140 }
141
142 if (argc == 2)
143 {
144 if (CurrentPartition == NULL)
146 else
148 return TRUE;
149 }
150
151 if (!IsDecString(argv[2]))
152 {
154 return TRUE;
155 }
156
157 ulValue = wcstoul(argv[2], NULL, 10);
158 if ((ulValue == 0) && (errno == ERANGE))
159 {
161 return TRUE;
162 }
163
166 {
167 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
168
169 if (PartEntry->PartitionType != 0)
170 {
171 if (PartNumber == ulValue)
172 {
173 CurrentPartition = PartEntry;
175 return TRUE;
176 }
177
178 PartNumber++;
179 }
180
181 Entry = Entry->Flink;
182 }
183
186 {
187 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
188
189 if (PartEntry->PartitionType != 0)
190 {
191 if (PartNumber == ulValue)
192 {
193 CurrentPartition = PartEntry;
195 return TRUE;
196 }
197
198 PartNumber++;
199 }
200 Entry = Entry->Flink;
201 }
202
204 return TRUE;
205}
206
207
208BOOL
210 INT argc,
211 PWSTR *argv)
212{
214 PVOLENTRY VolumeEntry;
215 ULONG ulValue;
216
217 DPRINT("SelectVolume()\n");
218
219 if (argc > 3)
220 {
222 return TRUE;
223 }
224
225 if (argc == 2)
226 {
227 if (CurrentDisk == NULL)
229 else
231 return TRUE;
232 }
233
234 if (!IsDecString(argv[2]))
235 {
237 return TRUE;
238 }
239
240 ulValue = wcstoul(argv[2], NULL, 10);
241 if ((ulValue == 0) && (errno == ERANGE))
242 {
244 return TRUE;
245 }
246
248
250 while (Entry != &VolumeListHead)
251 {
252 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
253
254 if (VolumeEntry->VolumeNumber == ulValue)
255 {
256 CurrentVolume = VolumeEntry;
258 return TRUE;
259 }
260
261 Entry = Entry->Flink;
262 }
263
265 return TRUE;
266}
static int argc
Definition: ServiceArgs.c:12
#define ERANGE
Definition: acclib.h:92
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define IDS_SELECT_DISK_INVALID
Definition: resource.h:87
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:94
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:90
#define IDS_SELECT_DISK_ENUM_NO_START
Definition: resource.h:88
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:189
#define IDS_SELECT_DISK
Definition: resource.h:86
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:92
#define IDS_SELECT_VOLUME
Definition: resource.h:95
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:93
#define IDS_SELECT_DISK_ENUM_FINISHED
Definition: resource.h:89
#define IDS_SELECT_PARTITION
Definition: resource.h:91
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:96
BOOL SelectDisk(INT argc, PWSTR *argv)
Definition: select.c:17
BOOL SelectPartition(INT argc, PWSTR *argv)
Definition: select.c:119
BOOL SelectVolume(INT argc, PWSTR *argv)
Definition: select.c:209
LIST_ENTRY VolumeListHead
Definition: partlist.c:74
PDISKENTRY CurrentDisk
Definition: partlist.c:76
LIST_ENTRY DiskListHead
Definition: partlist.c:72
PVOLENTRY CurrentVolume
Definition: partlist.c:78
BOOL IsDecString(_In_ PWSTR pszDecString)
Definition: misc.c:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
ULONG DiskNumber
Definition: partlist.h:129
LIST_ENTRY ListEntry
Definition: partlist.h:101
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UCHAR PartitionType
Definition: partlist.h:73
ULONG VolumeNumber
Definition: diskpart.h:193
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static PPARTENTRY CurrentPartition
Definition: usetup.c:77