Author: jmorlan
Date: Wed Mar 18 21:11:19 2009
New Revision: 40094
URL:
http://svn.reactos.org/svn/reactos?rev=40094&view=rev
Log:
- Make MEMORY command use GlobalMemoryStatusEx if available, so it can show values >=
4GB.
- Fix overflow bug in FREE command that caused values >= 4GB to wrap around.
- A little simplification of ConvertULargeInteger function
Modified:
trunk/reactos/base/shell/cmd/cmd.c
trunk/reactos/base/shell/cmd/cmd.h
trunk/reactos/base/shell/cmd/dir.c
trunk/reactos/base/shell/cmd/free.c
trunk/reactos/base/shell/cmd/memory.c
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Wed Mar 18 21:11:19 2009
@@ -179,36 +179,29 @@
* insert commas into a number
*/
INT
-ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator)
+ConvertULargeInteger(ULONGLONG num, LPTSTR des, INT len, BOOL bPutSeperator)
{
TCHAR temp[32];
UINT n, iTarget;
if (len <= 1)
return 0;
-
- if (num.QuadPart == 0)
- {
- des[0] = _T('0');
- des[1] = _T('\0');
- return 1;
- }
n = 0;
iTarget = nNumberGroups;
if (!nNumberGroups)
bPutSeperator = FALSE;
- while (num.QuadPart > 0)
+ do
{
if (iTarget == n && bPutSeperator)
{
iTarget += nNumberGroups + 1;
temp[31 - n++] = cThousandSeparator;
}
- temp[31 - n++] = (TCHAR)(num.QuadPart % 10) + _T('0');
- num.QuadPart /= 10;
- }
+ temp[31 - n++] = (TCHAR)(num % 10) + _T('0');
+ num /= 10;
+ } while (num > 0);
if (n > len-1)
n = len-1;
Modified: trunk/reactos/base/shell/cmd/cmd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Wed Mar 18 21:11:19 2009
@@ -99,7 +99,7 @@
/* Prototypes for CMD.C */
-INT ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator);
+INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, INT len, BOOL bPutSeperator);
VOID ParseCommandLine (LPTSTR);
struct _PARSED_COMMAND;
BOOL ExecuteCommand(struct _PARSED_COMMAND *Cmd);
Modified: trunk/reactos/base/shell/cmd/dir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=4…
==============================================================================
--- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Wed Mar 18 21:11:19 2009
@@ -211,7 +211,7 @@
* probabaly later pass them to functions. Rob Lake */
static ULONG recurse_dir_cnt;
static ULONG recurse_file_cnt;
-static ULARGE_INTEGER recurse_bytes;
+static ULONGLONG recurse_bytes;
/*
@@ -772,7 +772,7 @@
PrintSummary(LPTSTR szPath,
ULONG ulFiles,
ULONG ulDirs,
- ULARGE_INTEGER u64Bytes,
+ ULONGLONG u64Bytes,
LPDIRSWITCHFLAGS lpFlags,
BOOL TotalSummary)
{
@@ -817,7 +817,7 @@
if (!lpFlags->bRecursive || TotalSummary)
{
GetUserDiskFreeSpace(szPath, &uliFree);
- ConvertULargeInteger(uliFree, szBuffer, sizeof(szBuffer), lpFlags->bTSeperator);
+ ConvertULargeInteger(uliFree.QuadPart, szBuffer, sizeof(szBuffer),
lpFlags->bTSeperator);
LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, (LPTSTR) szMsg, RC_STRING_MAX_SIZE);
DirPrintf(lpFlags, szMsg, ulDirs, szBuffer);
}
@@ -910,7 +910,7 @@
iSizeFormat = 14;
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
- ConvertULargeInteger(u64FileSize, szSize, 20, lpFlags->bTSeperator);
+ ConvertULargeInteger(u64FileSize.QuadPart, szSize, 20, lpFlags->bTSeperator);
}
/* Calculate short name */
@@ -1065,7 +1065,7 @@
iSizeFormat = 17;
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
- ConvertULargeInteger(u64FileSize, szSize, 20, lpFlags->bTSeperator);
+ ConvertULargeInteger(u64FileSize.QuadPart, szSize, 20, lpFlags->bTSeperator);
}
/* Format date and time */
@@ -1345,7 +1345,7 @@
DWORD dwCount; /* A counter of files found in directory */
DWORD dwCountFiles; /* Counter for files */
DWORD dwCountDirs; /* Counter for directories */
- ULARGE_INTEGER u64CountBytes; /* Counter for bytes */
+ ULONGLONG u64CountBytes; /* Counter for bytes */
ULARGE_INTEGER u64Temp; /* A temporary counter */
/* Initialize Variables */
@@ -1354,7 +1354,7 @@
dwCount = 0;
dwCountFiles = 0;
dwCountDirs = 0;
- u64CountBytes.QuadPart = 0;
+ u64CountBytes = 0;
fPoint= FALSE;
/* Create szFullPath */
@@ -1448,7 +1448,7 @@
dwCountFiles++;
u64Temp.HighPart = wfdFileInfo.nFileSizeHigh;
u64Temp.LowPart = wfdFileInfo.nFileSizeLow;
- u64CountBytes.QuadPart += u64Temp.QuadPart;
+ u64CountBytes += u64Temp.QuadPart;
}
}
}
@@ -1524,7 +1524,7 @@
/* Add statistics to recursive statistics*/
recurse_dir_cnt += dwCountDirs;
recurse_file_cnt += dwCountFiles;
- recurse_bytes.QuadPart += u64CountBytes.QuadPart;
+ recurse_bytes += u64CountBytes;
/* Do the recursive job if requested
the recursive is be done on ALL(indepent of their attribs)
@@ -1648,7 +1648,7 @@
recurse_dir_cnt = 0L;
recurse_file_cnt = 0L;
- recurse_bytes.QuadPart = 0;
+ recurse_bytes = 0;
/* <Debug :>
Uncomment this to show the final state of switch flags*/
Modified: trunk/reactos/base/shell/cmd/free.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/free.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/free.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/free.c [iso-8859-1] Wed Mar 18 21:11:19 2009
@@ -27,7 +27,7 @@
TCHAR szUsed[40];
TCHAR szFree[40];
DWORD dwSerial;
- ULARGE_INTEGER uliSize;
+ ULONGLONG uliSize;
DWORD dwSecPerCl;
DWORD dwBytPerSec;
DWORD dwFreeCl;
@@ -70,14 +70,14 @@
return;
}
- uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
- ConvertULargeInteger (uliSize, szTotal, 40, TRUE);
+ uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwTotCl;
+ ConvertULargeInteger(uliSize, szTotal, 40, TRUE);
- uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
- ConvertULargeInteger (uliSize, szUsed, 40, TRUE);
+ uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)(dwTotCl - dwFreeCl);
+ ConvertULargeInteger(uliSize, szUsed, 40, TRUE);
- uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
- ConvertULargeInteger (uliSize, szFree, 40, TRUE);
+ uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwFreeCl;
+ ConvertULargeInteger(uliSize, szFree, 40, TRUE);
ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed,
szFree);
Modified: trunk/reactos/base/shell/cmd/memory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/memory.c?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/memory.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/memory.c [iso-8859-1] Wed Mar 18 21:11:19 2009
@@ -15,33 +15,16 @@
#ifdef INCLUDE_CMD_MEMORY
-
-/*
- * convert
- *
- * insert commas into a number
- */
-static INT
-ConvertDWord (DWORD num, LPTSTR des, INT len, BOOL bSeparator)
-{
- ULARGE_INTEGER ui;
-
- ui.u.LowPart = num;
- ui.u.HighPart = 0;
- return ConvertULargeInteger(ui, des, len, bSeparator);
-}
-
-
INT CommandMemory (LPTSTR param)
{
- MEMORYSTATUS ms;
+ MEMORYSTATUSEX msex;
TCHAR szMemoryLoad[20];
- TCHAR szTotalPhys[20];
- TCHAR szAvailPhys[20];
- TCHAR szTotalPageFile[20];
- TCHAR szAvailPageFile[20];
- TCHAR szTotalVirtual[20];
- TCHAR szAvailVirtual[20];
+ TCHAR szTotalPhys[40];
+ TCHAR szAvailPhys[40];
+ TCHAR szTotalPageFile[40];
+ TCHAR szAvailPageFile[40];
+ TCHAR szTotalVirtual[40];
+ TCHAR szAvailVirtual[40];
if (!_tcsncmp (param, _T("/?"), 2))
{
@@ -49,17 +32,34 @@
return 0;
}
- ms.dwLength = sizeof(MEMORYSTATUS);
+ BOOL (WINAPI *GlobalMemoryStatusEx)(LPMEMORYSTATUSEX)
+ = GetProcAddress(GetModuleHandle(_T("KERNEL32")),
"GlobalMemoryStatusEx");
+ if (GlobalMemoryStatusEx)
+ {
+ msex.dwLength = sizeof(MEMORYSTATUSEX);
+ GlobalMemoryStatusEx(&msex);
+ }
+ else
+ {
+ MEMORYSTATUS ms;
+ ms.dwLength = sizeof(MEMORYSTATUS);
+ GlobalMemoryStatus(&ms);
+ msex.dwMemoryLoad = ms.dwMemoryLoad;
+ msex.ullTotalPhys = ms.dwTotalPhys;
+ msex.ullAvailPhys = ms.dwAvailPhys;
+ msex.ullTotalPageFile = ms.dwTotalPageFile;
+ msex.ullAvailPageFile = ms.dwAvailPageFile;
+ msex.ullTotalVirtual = ms.dwTotalVirtual;
+ msex.ullAvailVirtual = ms.dwAvailVirtual;
+ }
- GlobalMemoryStatus (&ms);
-
- ConvertDWord (ms.dwMemoryLoad, szMemoryLoad, 20, FALSE);
- ConvertDWord (ms.dwTotalPhys, szTotalPhys, 20, TRUE);
- ConvertDWord (ms.dwAvailPhys, szAvailPhys, 20, TRUE);
- ConvertDWord (ms.dwTotalPageFile, szTotalPageFile, 20, TRUE);
- ConvertDWord (ms.dwAvailPageFile, szAvailPageFile, 20, TRUE);
- ConvertDWord (ms.dwTotalVirtual, szTotalVirtual, 20, TRUE);
- ConvertDWord (ms.dwAvailVirtual, szAvailVirtual, 20, TRUE);
+ ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
+ ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
+ ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
+ ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
+ ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
+ ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
+ ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
ConOutResPrintf(STRING_MEMMORY_HELP2,
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,