ReactOS  0.4.14-dev-50-g13bb5e2
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 static
17 VOID
19  INT argc,
20  LPWSTR *argv)
21 {
23  PDISKENTRY DiskEntry;
24  LONG lValue;
25  LPWSTR endptr = NULL;
26 
27  DPRINT("Select Disk()\n");
28 
29  if (argc > 3)
30  {
32  return;
33  }
34 
35  if (argc == 2)
36  {
37  if (CurrentDisk == NULL)
39  else
41  return;
42  }
43 
44  lValue = wcstol(argv[2], &endptr, 10);
45  if (((lValue == 0) && (endptr == argv[2])) ||
46  (lValue < 0))
47  {
49  return;
50  }
51 
52  CurrentDisk = NULL;
53 
55  while (Entry != &DiskListHead)
56  {
57  DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
58 
59  if (DiskEntry->DiskNumber == (ULONG)lValue)
60  {
61  CurrentDisk = DiskEntry;
64  return;
65  }
66 
67  Entry = Entry->Flink;
68  }
69 
71 }
72 
73 
74 static
75 VOID
77  INT argc,
78  LPWSTR *argv)
79 {
81  PPARTENTRY PartEntry;
82  LONG lValue;
83  LPWSTR endptr = NULL;
84  ULONG PartNumber = 1;
85 
86  DPRINT("Select Partition()\n");
87 
88  if (argc > 3)
89  {
91  return;
92  }
93 
94  if (CurrentDisk == NULL)
95  {
97  return;
98  }
99 
100  if (argc == 2)
101  {
102  if (CurrentPartition == NULL)
104  else
106  return;
107  }
108 
109  lValue = wcstol(argv[2], &endptr, 10);
110  if (((lValue == 0) && (endptr == argv[2])) ||
111  (lValue < 0))
112  {
114  return;
115  }
116 
119  {
120  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
121 
122  if (PartEntry->PartitionType != 0)
123  {
124  if (PartNumber == (ULONG)lValue)
125  {
126  CurrentPartition = PartEntry;
128  return;
129  }
130 
131  PartNumber++;
132  }
133 
134  Entry = Entry->Flink;
135  }
136 
139  {
140  PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
141 
142  if (PartEntry->PartitionType != 0)
143  {
144  if (PartNumber == (ULONG)lValue)
145  {
146  CurrentPartition = PartEntry;
148  return;
149  }
150 
151  PartNumber++;
152  }
153  Entry = Entry->Flink;
154  }
155 
157 }
158 
159 
160 BOOL
162  INT argc,
163  LPWSTR *argv)
164 {
165  /* gets the first word from the string */
166  if (argc == 1)
167  {
169  return TRUE;
170  }
171 
172  /* determines which to list (disk, partition, etc.) */
173  if (!wcsicmp(argv[1], L"disk"))
174  SelectDisk(argc, argv);
175  else if (!wcsicmp(argv[1], L"partition"))
177  else
179 
180  return TRUE;
181 }
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:53
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:124
static VOID SelectPartition(INT argc, LPWSTR *argv)
Definition: select.c:76
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:50
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
#define IDS_SELECT_DISK_INVALID
Definition: resource.h:49
ULONG DiskNumber
Definition: partlist.h:104
static PPARTENTRY CurrentPartition
Definition: usetup.c:76
PDISKENTRY CurrentDisk
Definition: partlist.c:73
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
BOOL select_main(INT argc, LPWSTR *argv)
Definition: select.c:161
static VOID SelectDisk(INT argc, LPWSTR *argv)
Definition: select.c:18
#define IDS_SELECT_PARTITION
Definition: resource.h:51
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:147
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY DiskListHead
Definition: partlist.c:70
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
UCHAR PartitionType
Definition: partlist.h:46
#define IDS_SELECT_NO_DISK
Definition: resource.h:47
#define StdErr
Definition: stream.h:77
#define IDS_HELP_CMD_SELECT
Definition: resource.h:142
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:52
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:117
#define wcsicmp
Definition: string.h:1152
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:125
#define IDS_SELECT_DISK
Definition: resource.h:48
#define StdOut
Definition: stream.h:76
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
base of all file and directory entries
Definition: entries.h:82