Skip to content

Commit 74999e6

Browse files
committed
[DISKPART] Replace some magic values and enter the Terabyte era
1 parent 48fbf27 commit 74999e6

File tree

2 files changed

+99
-44
lines changed

2 files changed

+99
-44
lines changed

base/system/diskpart/diskpart.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ typedef struct _VOLENTRY
231231

232232
} VOLENTRY, *PVOLENTRY;
233233

234+
#define SIZE_1KB (1024ULL)
235+
#define SIZE_10KB (10ULL * 1024ULL)
236+
#define SIZE_1MB (1024ULL * 1024ULL)
237+
#define SIZE_10MB (10ULL * 1024ULL * 1024ULL)
238+
#define SIZE_1GB (1024ULL * 1024ULL * 1024ULL)
239+
#define SIZE_10GB (10ULL * 1024ULL * 1024ULL * 1024ULL)
240+
#define SIZE_1TB (1024ULL * 1024ULL * 1024ULL * 1024ULL)
241+
#define SIZE_10TB (10ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL)
242+
234243

235244
/* GLOBAL VARIABLES ***********************************************************/
236245

base/system/diskpart/list.c

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,43 @@ PrintDisk(
9191
DiskSize = DiskEntry->SectorCount.QuadPart *
9292
(ULONGLONG)DiskEntry->BytesPerSector;
9393

94-
if (DiskSize >= 10737418240) /* 10 GB */
94+
if (DiskSize >= SIZE_10TB) /* 10 TB */
9595
{
96-
DiskSize = RoundingDivide(DiskSize, 1073741824);
96+
DiskSize = RoundingDivide(DiskSize, SIZE_1TB);
97+
lpSizeUnit = L"TB";
98+
}
99+
else if (DiskSize >= SIZE_10GB) /* 10 GB */
100+
{
101+
DiskSize = RoundingDivide(DiskSize, SIZE_1GB);
97102
lpSizeUnit = L"GB";
98103
}
99104
else
100105
{
101-
DiskSize = RoundingDivide(DiskSize, 1048576);
106+
DiskSize = RoundingDivide(DiskSize, SIZE_1MB);
102107
if (DiskSize == 0)
103108
DiskSize = 1;
104109
lpSizeUnit = L"MB";
105110
}
106111

107112
FreeSize = GetFreeDiskSize(DiskEntry);
108-
if (FreeSize >= 10737418240) /* 10 GB */
113+
if (FreeSize >= SIZE_10TB) /* 10 TB */
109114
{
110-
FreeSize = RoundingDivide(FreeSize, 1073741824);
115+
FreeSize = RoundingDivide(FreeSize, SIZE_1TB);
116+
lpFreeUnit = L"TB";
117+
}
118+
else if (FreeSize >= SIZE_10GB) /* 10 GB */
119+
{
120+
FreeSize = RoundingDivide(FreeSize, SIZE_1GB);
111121
lpFreeUnit = L"GB";
112122
}
113-
else if (FreeSize >= 10485760) /* 10 MB */
123+
else if (FreeSize >= SIZE_10MB) /* 10 MB */
114124
{
115-
FreeSize = RoundingDivide(FreeSize, 1048576);
125+
FreeSize = RoundingDivide(FreeSize, SIZE_1MB);
116126
lpFreeUnit = L"MB";
117127
}
118-
else if (FreeSize >= 10240) /* 10 KB */
128+
else if (FreeSize >= SIZE_10KB) /* 10 KB */
119129
{
120-
FreeSize = RoundingDivide(FreeSize, 1024);
130+
FreeSize = RoundingDivide(FreeSize, SIZE_1KB);
121131
lpFreeUnit = L"KB";
122132
}
123133
else
@@ -202,37 +212,47 @@ ListPartition(
202212
{
203213
PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
204214

205-
if (PartSize >= 10737418240) /* 10 GB */
215+
if (PartSize >= SIZE_10TB) /* 10 TB */
216+
{
217+
PartSize = RoundingDivide(PartSize, SIZE_1TB);
218+
lpSizeUnit = L"TB";
219+
}
220+
else if (PartSize >= SIZE_10GB) /* 10 GB */
206221
{
207-
PartSize = RoundingDivide(PartSize, 1073741824);
222+
PartSize = RoundingDivide(PartSize, SIZE_1GB);
208223
lpSizeUnit = L"GB";
209224
}
210-
else if (PartSize >= 10485760) /* 10 MB */
225+
else if (PartSize >= SIZE_10MB) /* 10 MB */
211226
{
212-
PartSize = RoundingDivide(PartSize, 1048576);
227+
PartSize = RoundingDivide(PartSize, SIZE_1MB);
213228
lpSizeUnit = L"MB";
214229
}
215230
else
216231
{
217-
PartSize = RoundingDivide(PartSize, 1024);
232+
PartSize = RoundingDivide(PartSize, SIZE_1KB);
218233
lpSizeUnit = L"KB";
219234
}
220235

221236
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
222237

223-
if (PartOffset >= 10737418240) /* 10 GB */
238+
if (PartOffset >= SIZE_10TB) /* 10 TB */
239+
{
240+
PartOffset = RoundingDivide(PartOffset, SIZE_1TB);
241+
lpOffsetUnit = L"TB";
242+
}
243+
else if (PartOffset >= SIZE_10GB) /* 10 GB */
224244
{
225-
PartOffset = RoundingDivide(PartOffset, 1073741824);
245+
PartOffset = RoundingDivide(PartOffset, SIZE_1GB);
226246
lpOffsetUnit = L"GB";
227247
}
228-
else if (PartOffset >= 10485760) /* 10 MB */
248+
else if (PartOffset >= SIZE_10MB) /* 10 MB */
229249
{
230-
PartOffset = RoundingDivide(PartOffset, 1048576);
250+
PartOffset = RoundingDivide(PartOffset, SIZE_1MB);
231251
lpOffsetUnit = L"MB";
232252
}
233253
else
234254
{
235-
PartOffset = RoundingDivide(PartOffset, 1024);
255+
PartOffset = RoundingDivide(PartOffset, SIZE_1KB);
236256
lpOffsetUnit = L"KB";
237257
}
238258

@@ -258,37 +278,47 @@ ListPartition(
258278
{
259279
PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
260280

261-
if (PartSize >= 10737418240) /* 10 GB */
281+
if (PartSize >= SIZE_10TB) /* 10 TB */
282+
{
283+
PartSize = RoundingDivide(PartSize, SIZE_1TB);
284+
lpSizeUnit = L"TB";
285+
}
286+
else if (PartSize >= SIZE_10GB) /* 10 GB */
262287
{
263-
PartSize = RoundingDivide(PartSize, 1073741824);
288+
PartSize = RoundingDivide(PartSize, SIZE_1GB);
264289
lpSizeUnit = L"GB";
265290
}
266-
else if (PartSize >= 10485760) /* 10 MB */
291+
else if (PartSize >= SIZE_10MB) /* 10 MB */
267292
{
268-
PartSize = RoundingDivide(PartSize, 1048576);
293+
PartSize = RoundingDivide(PartSize, SIZE_1MB);
269294
lpSizeUnit = L"MB";
270295
}
271296
else
272297
{
273-
PartSize = RoundingDivide(PartSize, 1024);
298+
PartSize = RoundingDivide(PartSize, SIZE_1KB);
274299
lpSizeUnit = L"KB";
275300
}
276301

277302
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
278303

279-
if (PartOffset >= 10737418240) /* 10 GB */
304+
if (PartOffset >= SIZE_10TB) /* 10 TB */
280305
{
281-
PartOffset = RoundingDivide(PartOffset, 1073741824);
306+
PartOffset = RoundingDivide(PartOffset, SIZE_1TB);
307+
lpOffsetUnit = L"TB";
308+
}
309+
else if (PartOffset >= SIZE_10GB) /* 10 GB */
310+
{
311+
PartOffset = RoundingDivide(PartOffset, SIZE_1GB);
282312
lpOffsetUnit = L"GB";
283313
}
284-
else if (PartOffset >= 10485760) /* 10 MB */
314+
else if (PartOffset >= SIZE_10MB) /* 10 MB */
285315
{
286-
PartOffset = RoundingDivide(PartOffset, 1048576);
316+
PartOffset = RoundingDivide(PartOffset, SIZE_1MB);
287317
lpOffsetUnit = L"MB";
288318
}
289319
else
290320
{
291-
PartOffset = RoundingDivide(PartOffset, 1024);
321+
PartOffset = RoundingDivide(PartOffset, SIZE_1KB);
292322
lpOffsetUnit = L"KB";
293323
}
294324

@@ -318,37 +348,47 @@ ListPartition(
318348
{
319349
PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
320350

321-
if (PartSize >= 10737418240) /* 10 GB */
351+
if (PartSize >= SIZE_10TB) /* 10 TB */
322352
{
323-
PartSize = RoundingDivide(PartSize, 1073741824);
353+
PartSize = RoundingDivide(PartSize, SIZE_1TB);
354+
lpSizeUnit = L"TB";
355+
}
356+
else if (PartSize >= SIZE_10GB) /* 10 GB */
357+
{
358+
PartSize = RoundingDivide(PartSize, SIZE_1GB);
324359
lpSizeUnit = L"GB";
325360
}
326-
else if (PartSize >= 10485760) /* 10 MB */
361+
else if (PartSize >= SIZE_10MB) /* 10 MB */
327362
{
328-
PartSize = RoundingDivide(PartSize, 1048576);
363+
PartSize = RoundingDivide(PartSize, SIZE_1MB);
329364
lpSizeUnit = L"MB";
330365
}
331366
else
332367
{
333-
PartSize = RoundingDivide(PartSize, 1024);
368+
PartSize = RoundingDivide(PartSize, SIZE_1KB);
334369
lpSizeUnit = L"KB";
335370
}
336371

337372
PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
338373

339-
if (PartOffset >= 10737418240) /* 10 GB */
374+
if (PartOffset >= SIZE_10TB) /* 10 TB */
340375
{
341-
PartOffset = RoundingDivide(PartOffset, 1073741824);
376+
PartOffset = RoundingDivide(PartOffset, SIZE_1TB);
377+
lpOffsetUnit = L"TB";
378+
}
379+
else if (PartOffset >= SIZE_10GB) /* 10 GB */
380+
{
381+
PartOffset = RoundingDivide(PartOffset, SIZE_1GB);
342382
lpOffsetUnit = L"GB";
343383
}
344-
else if (PartOffset >= 10485760) /* 10 MB */
384+
else if (PartOffset >= SIZE_10MB) /* 10 MB */
345385
{
346-
PartOffset = RoundingDivide(PartOffset, 1048576);
386+
PartOffset = RoundingDivide(PartOffset, SIZE_1MB);
347387
lpOffsetUnit = L"MB";
348388
}
349389
else
350390
{
351-
PartOffset = RoundingDivide(PartOffset, 1024);
391+
PartOffset = RoundingDivide(PartOffset, SIZE_1KB);
352392
lpOffsetUnit = L"KB";
353393
}
354394

@@ -402,21 +442,27 @@ PrintVolume(
402442
PWSTR pszVolumeType;
403443

404444
VolumeSize = VolumeEntry->Size.QuadPart;
405-
if (VolumeSize >= 10737418240) /* 10 GB */
445+
if (VolumeSize >= SIZE_10TB) /* 10 TB */
446+
{
447+
VolumeSize = RoundingDivide(VolumeSize, SIZE_1TB);
448+
pszSizeUnit = L"TB";
449+
}
450+
else if (VolumeSize >= SIZE_10GB) /* 10 GB */
406451
{
407-
VolumeSize = RoundingDivide(VolumeSize, 1073741824);
452+
VolumeSize = RoundingDivide(VolumeSize, SIZE_1GB);
408453
pszSizeUnit = L"GB";
409454
}
410-
else if (VolumeSize >= 10485760) /* 10 MB */
455+
else if (VolumeSize >= SIZE_10MB) /* 10 MB */
411456
{
412-
VolumeSize = RoundingDivide(VolumeSize, 1048576);
457+
VolumeSize = RoundingDivide(VolumeSize, SIZE_1MB);
413458
pszSizeUnit = L"MB";
414459
}
415460
else
416461
{
417-
VolumeSize = RoundingDivide(VolumeSize, 1024);
462+
VolumeSize = RoundingDivide(VolumeSize, SIZE_1KB);
418463
pszSizeUnit = L"KB";
419464
}
465+
420466
switch (VolumeEntry->VolumeType)
421467
{
422468
case VOLUME_TYPE_CDROM:

0 commit comments

Comments
 (0)