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