ReactOS 0.4.15-dev-8138-g1e75ea8
list.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/list.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
16VOID
18 _In_ PDISKENTRY DiskEntry)
19{
20 ULONGLONG DiskSize;
21 ULONGLONG FreeSize;
22 LPWSTR lpSizeUnit;
23 LPWSTR lpFreeUnit;
24
25 DiskSize = DiskEntry->SectorCount.QuadPart *
26 (ULONGLONG)DiskEntry->BytesPerSector;
27
28 if (DiskSize >= 10737418240) /* 10 GB */
29 {
30 DiskSize = RoundingDivide(DiskSize, 1073741824);
31 lpSizeUnit = L"GB";
32 }
33 else
34 {
35 DiskSize = RoundingDivide(DiskSize, 1048576);
36 if (DiskSize == 0)
37 DiskSize = 1;
38 lpSizeUnit = L"MB";
39 }
40
41 /* FIXME */
42 FreeSize = 0;
43 lpFreeUnit = L"B";
44
46 (CurrentDisk == DiskEntry) ? L'*' : L' ',
47 DiskEntry->DiskNumber,
48 L"Online",
49 DiskSize,
50 lpSizeUnit,
51 FreeSize,
52 lpFreeUnit,
53 L" ",
54 L" ");
55}
56
57
58BOOL
60 INT argc,
61 PWSTR *argv)
62{
64 PDISKENTRY DiskEntry;
65
66 /* Header labels */
67 ConPuts(StdOut, L"\n");
70
72 while (Entry != &DiskListHead)
73 {
74 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
75
76 PrintDisk(DiskEntry);
77
78 Entry = Entry->Flink;
79 }
80
81 ConPuts(StdOut, L"\n\n");
82
83 return TRUE;
84}
85
86
87BOOL
89 INT argc,
90 PWSTR *argv)
91{
93 PPARTENTRY PartEntry;
94 ULONGLONG PartSize;
95 ULONGLONG PartOffset;
96 LPWSTR lpSizeUnit;
97 LPWSTR lpOffsetUnit;
98 ULONG PartNumber = 1;
99
100 if (CurrentDisk == NULL)
101 {
103 return TRUE;
104 }
105
106 /* Header labels */
107 ConPuts(StdOut, L"\n");
110
113 {
114 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
115
116 if (PartEntry->PartitionType != 0)
117 {
118 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
119
120 if (PartSize >= 10737418240) /* 10 GB */
121 {
122 PartSize = RoundingDivide(PartSize, 1073741824);
123 lpSizeUnit = L"GB";
124 }
125 else if (PartSize >= 10485760) /* 10 MB */
126 {
127 PartSize = RoundingDivide(PartSize, 1048576);
128 lpSizeUnit = L"MB";
129 }
130 else
131 {
132 PartSize = RoundingDivide(PartSize, 1024);
133 lpSizeUnit = L"KB";
134 }
135
136 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
137
138 if (PartOffset >= 10737418240) /* 10 GB */
139 {
140 PartOffset = RoundingDivide(PartOffset, 1073741824);
141 lpOffsetUnit = L"GB";
142 }
143 else if (PartOffset >= 10485760) /* 10 MB */
144 {
145 PartOffset = RoundingDivide(PartOffset, 1048576);
146 lpOffsetUnit = L"MB";
147 }
148 else
149 {
150 PartOffset = RoundingDivide(PartOffset, 1024);
151 lpOffsetUnit = L"KB";
152 }
153
155 (CurrentPartition == PartEntry) ? L'*' : L' ',
156 PartNumber++,
157 IsContainerPartition(PartEntry->PartitionType) ? L"Extended" : L"Primary",
158 PartSize,
159 lpSizeUnit,
160 PartOffset,
161 lpOffsetUnit);
162 }
163
164 Entry = Entry->Flink;
165 }
166
169 {
170 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
171
172 if (PartEntry->PartitionType != 0)
173 {
174 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
175
176 if (PartSize >= 10737418240) /* 10 GB */
177 {
178 PartSize = RoundingDivide(PartSize, 1073741824);
179 lpSizeUnit = L"GB";
180 }
181 else if (PartSize >= 10485760) /* 10 MB */
182 {
183 PartSize = RoundingDivide(PartSize, 1048576);
184 lpSizeUnit = L"MB";
185 }
186 else
187 {
188 PartSize = RoundingDivide(PartSize, 1024);
189 lpSizeUnit = L"KB";
190 }
191
192 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
193
194 if (PartOffset >= 10737418240) /* 10 GB */
195 {
196 PartOffset = RoundingDivide(PartOffset, 1073741824);
197 lpOffsetUnit = L"GB";
198 }
199 else if (PartOffset >= 10485760) /* 10 MB */
200 {
201 PartOffset = RoundingDivide(PartOffset, 1048576);
202 lpOffsetUnit = L"MB";
203 }
204 else
205 {
206 PartOffset = RoundingDivide(PartOffset, 1024);
207 lpOffsetUnit = L"KB";
208 }
209
211 (CurrentPartition == PartEntry) ? L'*' : L' ',
212 PartNumber++,
213 L"Logical",
214 PartSize,
215 lpSizeUnit,
216 PartOffset,
217 lpOffsetUnit);
218 }
219
220 Entry = Entry->Flink;
221 }
222
223 ConPuts(StdOut, L"\n");
224
225 return TRUE;
226}
227
228
229VOID
231 _In_ PVOLENTRY VolumeEntry)
232{
233 ULONGLONG VolumeSize;
234 PWSTR pszSizeUnit;
235 PWSTR pszVolumeType;
236
237 VolumeSize = VolumeEntry->Size.QuadPart;
238 if (VolumeSize >= 10737418240) /* 10 GB */
239 {
240 VolumeSize = RoundingDivide(VolumeSize, 1073741824);
241 pszSizeUnit = L"GB";
242 }
243 else if (VolumeSize >= 10485760) /* 10 MB */
244 {
245 VolumeSize = RoundingDivide(VolumeSize, 1048576);
246 pszSizeUnit = L"MB";
247 }
248 else
249 {
250 VolumeSize = RoundingDivide(VolumeSize, 1024);
251 pszSizeUnit = L"KB";
252 }
253 switch (VolumeEntry->VolumeType)
254 {
256 pszVolumeType = L"DVD";
257 break;
259 pszVolumeType = L"Partition";
260 break;
262 pszVolumeType = L"Removable";
263 break;
265 default:
266 pszVolumeType = L"Unknown";
267 break;
268 }
269
271 (CurrentVolume == VolumeEntry) ? L'*' : L' ',
272 VolumeEntry->VolumeNumber,
273 VolumeEntry->DriveLetter,
274 (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"",
275 (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"",
276 pszVolumeType,
277 VolumeSize, pszSizeUnit);
278}
279
280
281BOOL
283 INT argc,
284 PWSTR *argv)
285{
287 PVOLENTRY VolumeEntry;
288
289 ConPuts(StdOut, L"\n");
292
294 while (Entry != &VolumeListHead)
295 {
296 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
297
298 PrintVolume(VolumeEntry);
299
300 Entry = Entry->Flink;
301 }
302
303 ConPuts(StdOut, L"\n");
304
305 return TRUE;
306}
307
308
309BOOL
311 INT argc,
312 PWSTR *argv)
313{
314 ConPuts(StdOut, L"ListVirtualDisk()!\n");
315 return TRUE;
316}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL ListPartition(INT argc, PWSTR *argv)
Definition: list.c:88
BOOL ListVolume(INT argc, PWSTR *argv)
Definition: list.c:282
BOOL ListVirtualDisk(INT argc, PWSTR *argv)
Definition: list.c:310
VOID PrintDisk(_In_ PDISKENTRY DiskEntry)
Definition: list.c:17
BOOL ListDisk(INT argc, PWSTR *argv)
Definition: list.c:59
VOID PrintVolume(_In_ PVOLENTRY VolumeEntry)
Definition: list.c:230
#define IDS_LIST_DISK_LINE
Definition: resource.h:72
#define IDS_LIST_PARTITION_NO_DISK
Definition: resource.h:77
#define IDS_LIST_DISK_HEAD
Definition: resource.h:71
#define IDS_LIST_VOLUME_LINE
Definition: resource.h:79
#define IDS_LIST_VOLUME_HEAD
Definition: resource.h:78
#define IDS_LIST_DISK_FORMAT
Definition: resource.h:73
#define IDS_LIST_PARTITION_HEAD
Definition: resource.h:74
#define IDS_LIST_PARTITION_LINE
Definition: resource.h:75
#define IDS_LIST_VOLUME_FORMAT
Definition: resource.h:80
#define IDS_LIST_PARTITION_FORMAT
Definition: resource.h:76
LIST_ENTRY VolumeListHead
Definition: partlist.c:72
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:93
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:92
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:90
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:91
PDISKENTRY CurrentDisk
Definition: partlist.c:74
LIST_ENTRY DiskListHead
Definition: partlist.c:70
PVOLENTRY CurrentVolume
Definition: partlist.c:76
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
if(dx< 0)
Definition: linetemp.h:194
#define argv
Definition: mplay32.c:18
#define _In_
Definition: ms_sal.h:308
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:316
#define L(x)
Definition: ntvdm.h:50
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:92
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
ULARGE_INTEGER SectorCount
Definition: partlist.h:50
ULARGE_INTEGER StartSector
Definition: partlist.h:49
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
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
uint64_t ULONGLONG
Definition: typedefs.h:67
static PPARTENTRY CurrentPartition
Definition: usetup.c:76
WCHAR * LPWSTR
Definition: xmlstorage.h:184