ReactOS 0.4.15-dev-7934-g1dc8d80
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 (!IsDecString(argv[2]))
43 {
45 return TRUE;
46 }
47
48 ulValue = wcstoul(argv[2], NULL, 10);
49 if ((ulValue == 0) && (errno == ERANGE))
50 {
52 return TRUE;
53 }
54
56
58 while (Entry != &DiskListHead)
59 {
60 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
61
62 if (DiskEntry->DiskNumber == ulValue)
63 {
64 CurrentDisk = DiskEntry;
67 return TRUE;
68 }
69
70 Entry = Entry->Flink;
71 }
72
74 return TRUE;
75}
76
77
78BOOL
80 INT argc,
81 PWSTR *argv)
82{
84 PPARTENTRY PartEntry;
85 ULONG ulValue;
86 ULONG PartNumber = 1;
87
88 DPRINT("Select Partition()\n");
89
90 if (argc > 3)
91 {
93 return TRUE;
94 }
95
96 if (CurrentDisk == NULL)
97 {
99 return TRUE;
100 }
101
102 if (argc == 2)
103 {
104 if (CurrentPartition == NULL)
106 else
108 return TRUE;
109 }
110
111 if (!IsDecString(argv[2]))
112 {
114 return TRUE;
115 }
116
117 ulValue = wcstoul(argv[2], NULL, 10);
118 if ((ulValue == 0) && (errno == ERANGE))
119 {
121 return TRUE;
122 }
123
126 {
127 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
128
129 if (PartEntry->PartitionType != 0)
130 {
131 if (PartNumber == ulValue)
132 {
133 CurrentPartition = PartEntry;
135 return TRUE;
136 }
137
138 PartNumber++;
139 }
140
141 Entry = Entry->Flink;
142 }
143
146 {
147 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
148
149 if (PartEntry->PartitionType != 0)
150 {
151 if (PartNumber == ulValue)
152 {
153 CurrentPartition = PartEntry;
155 return TRUE;
156 }
157
158 PartNumber++;
159 }
160 Entry = Entry->Flink;
161 }
162
164 return TRUE;
165}
166
167
168BOOL
170 INT argc,
171 PWSTR *argv)
172{
174 PVOLENTRY VolumeEntry;
175 ULONG ulValue;
176
177 DPRINT("SelectVolume()\n");
178
179 if (argc > 3)
180 {
182 return TRUE;
183 }
184
185 if (argc == 2)
186 {
187 if (CurrentDisk == NULL)
189 else
191 return TRUE;
192 }
193
194 if (!IsDecString(argv[2]))
195 {
197 return TRUE;
198 }
199
200 ulValue = wcstoul(argv[2], NULL, 10);
201 if ((ulValue == 0) && (errno == ERANGE))
202 {
204 return TRUE;
205 }
206
208
210 while (Entry != &VolumeListHead)
211 {
212 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
213
214 if (VolumeEntry->VolumeNumber == ulValue)
215 {
216 CurrentVolume = VolumeEntry;
218 return TRUE;
219 }
220
221 Entry = Entry->Flink;
222 }
223
225 return TRUE;
226}
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:92
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:88
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:187
#define IDS_SELECT_DISK
Definition: resource.h:86
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:90
#define IDS_SELECT_VOLUME
Definition: resource.h:93
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:91
#define IDS_SELECT_PARTITION
Definition: resource.h:89
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:94
BOOL SelectDisk(INT argc, PWSTR *argv)
Definition: select.c:17
BOOL SelectPartition(INT argc, PWSTR *argv)
Definition: select.c:79
BOOL SelectVolume(INT argc, PWSTR *argv)
Definition: select.c:169
LIST_ENTRY VolumeListHead
Definition: partlist.c:72
PDISKENTRY CurrentDisk
Definition: partlist.c:74
LIST_ENTRY DiskListHead
Definition: partlist.c:70
PVOLENTRY CurrentVolume
Definition: partlist.c:76
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 errno
Definition: errno.h:18
#define DPRINT
Definition: sndvol32.h:71
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:129
ULONG DiskNumber
Definition: partlist.h:108
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:128
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UCHAR PartitionType
Definition: partlist.h:53
ULONG VolumeNumber
Definition: diskpart.h:191
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:76