mirror of
https://github.com/reactos/reactos.git
synced 2025-05-29 22:18:13 +00:00
- 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 svn path=/trunk/; revision=40094
This commit is contained in:
parent
de32a44cb9
commit
a98a143a48
5 changed files with 57 additions and 64 deletions
|
@ -179,7 +179,7 @@ WORD wDefColor; /* default color */
|
||||||
* insert commas into a number
|
* insert commas into a number
|
||||||
*/
|
*/
|
||||||
INT
|
INT
|
||||||
ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator)
|
ConvertULargeInteger(ULONGLONG num, LPTSTR des, INT len, BOOL bPutSeperator)
|
||||||
{
|
{
|
||||||
TCHAR temp[32];
|
TCHAR temp[32];
|
||||||
UINT n, iTarget;
|
UINT n, iTarget;
|
||||||
|
@ -187,28 +187,21 @@ ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperato
|
||||||
if (len <= 1)
|
if (len <= 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (num.QuadPart == 0)
|
|
||||||
{
|
|
||||||
des[0] = _T('0');
|
|
||||||
des[1] = _T('\0');
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
iTarget = nNumberGroups;
|
iTarget = nNumberGroups;
|
||||||
if (!nNumberGroups)
|
if (!nNumberGroups)
|
||||||
bPutSeperator = FALSE;
|
bPutSeperator = FALSE;
|
||||||
|
|
||||||
while (num.QuadPart > 0)
|
do
|
||||||
{
|
{
|
||||||
if (iTarget == n && bPutSeperator)
|
if (iTarget == n && bPutSeperator)
|
||||||
{
|
{
|
||||||
iTarget += nNumberGroups + 1;
|
iTarget += nNumberGroups + 1;
|
||||||
temp[31 - n++] = cThousandSeparator;
|
temp[31 - n++] = cThousandSeparator;
|
||||||
}
|
}
|
||||||
temp[31 - n++] = (TCHAR)(num.QuadPart % 10) + _T('0');
|
temp[31 - n++] = (TCHAR)(num % 10) + _T('0');
|
||||||
num.QuadPart /= 10;
|
num /= 10;
|
||||||
}
|
} while (num > 0);
|
||||||
if (n > len-1)
|
if (n > len-1)
|
||||||
n = len-1;
|
n = len-1;
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ INT cmd_cls (LPTSTR);
|
||||||
|
|
||||||
|
|
||||||
/* Prototypes for CMD.C */
|
/* 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);
|
VOID ParseCommandLine (LPTSTR);
|
||||||
struct _PARSED_COMMAND;
|
struct _PARSED_COMMAND;
|
||||||
BOOL ExecuteCommand(struct _PARSED_COMMAND *Cmd);
|
BOOL ExecuteCommand(struct _PARSED_COMMAND *Cmd);
|
||||||
|
|
|
@ -211,7 +211,7 @@ typedef BOOL
|
||||||
* probabaly later pass them to functions. Rob Lake */
|
* probabaly later pass them to functions. Rob Lake */
|
||||||
static ULONG recurse_dir_cnt;
|
static ULONG recurse_dir_cnt;
|
||||||
static ULONG recurse_file_cnt;
|
static ULONG recurse_file_cnt;
|
||||||
static ULARGE_INTEGER recurse_bytes;
|
static ULONGLONG recurse_bytes;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -772,7 +772,7 @@ static INT
|
||||||
PrintSummary(LPTSTR szPath,
|
PrintSummary(LPTSTR szPath,
|
||||||
ULONG ulFiles,
|
ULONG ulFiles,
|
||||||
ULONG ulDirs,
|
ULONG ulDirs,
|
||||||
ULARGE_INTEGER u64Bytes,
|
ULONGLONG u64Bytes,
|
||||||
LPDIRSWITCHFLAGS lpFlags,
|
LPDIRSWITCHFLAGS lpFlags,
|
||||||
BOOL TotalSummary)
|
BOOL TotalSummary)
|
||||||
{
|
{
|
||||||
|
@ -817,7 +817,7 @@ PrintSummary(LPTSTR szPath,
|
||||||
if (!lpFlags->bRecursive || TotalSummary)
|
if (!lpFlags->bRecursive || TotalSummary)
|
||||||
{
|
{
|
||||||
GetUserDiskFreeSpace(szPath, &uliFree);
|
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);
|
LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, (LPTSTR) szMsg, RC_STRING_MAX_SIZE);
|
||||||
DirPrintf(lpFlags, szMsg, ulDirs, szBuffer);
|
DirPrintf(lpFlags, szMsg, ulDirs, szBuffer);
|
||||||
}
|
}
|
||||||
|
@ -910,7 +910,7 @@ DirPrintNewList(LPWIN32_FIND_DATA ptrFiles[], /* [IN]Files' Info */
|
||||||
iSizeFormat = 14;
|
iSizeFormat = 14;
|
||||||
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
|
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
|
||||||
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
|
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
|
||||||
ConvertULargeInteger(u64FileSize, szSize, 20, lpFlags->bTSeperator);
|
ConvertULargeInteger(u64FileSize.QuadPart, szSize, 20, lpFlags->bTSeperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate short name */
|
/* Calculate short name */
|
||||||
|
@ -1065,7 +1065,7 @@ ULARGE_INTEGER u64FileSize; /* The file size */
|
||||||
iSizeFormat = 17;
|
iSizeFormat = 17;
|
||||||
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
|
u64FileSize.HighPart = ptrFiles[i]->nFileSizeHigh;
|
||||||
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
|
u64FileSize.LowPart = ptrFiles[i]->nFileSizeLow;
|
||||||
ConvertULargeInteger(u64FileSize, szSize, 20, lpFlags->bTSeperator);
|
ConvertULargeInteger(u64FileSize.QuadPart, szSize, 20, lpFlags->bTSeperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Format date and time */
|
/* Format date and time */
|
||||||
|
@ -1345,7 +1345,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
DWORD dwCount; /* A counter of files found in directory */
|
DWORD dwCount; /* A counter of files found in directory */
|
||||||
DWORD dwCountFiles; /* Counter for files */
|
DWORD dwCountFiles; /* Counter for files */
|
||||||
DWORD dwCountDirs; /* Counter for directories */
|
DWORD dwCountDirs; /* Counter for directories */
|
||||||
ULARGE_INTEGER u64CountBytes; /* Counter for bytes */
|
ULONGLONG u64CountBytes; /* Counter for bytes */
|
||||||
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||||
|
|
||||||
/* Initialize Variables */
|
/* Initialize Variables */
|
||||||
|
@ -1354,7 +1354,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
dwCount = 0;
|
dwCount = 0;
|
||||||
dwCountFiles = 0;
|
dwCountFiles = 0;
|
||||||
dwCountDirs = 0;
|
dwCountDirs = 0;
|
||||||
u64CountBytes.QuadPart = 0;
|
u64CountBytes = 0;
|
||||||
fPoint= FALSE;
|
fPoint= FALSE;
|
||||||
|
|
||||||
/* Create szFullPath */
|
/* Create szFullPath */
|
||||||
|
@ -1448,7 +1448,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
dwCountFiles++;
|
dwCountFiles++;
|
||||||
u64Temp.HighPart = wfdFileInfo.nFileSizeHigh;
|
u64Temp.HighPart = wfdFileInfo.nFileSizeHigh;
|
||||||
u64Temp.LowPart = wfdFileInfo.nFileSizeLow;
|
u64Temp.LowPart = wfdFileInfo.nFileSizeLow;
|
||||||
u64CountBytes.QuadPart += u64Temp.QuadPart;
|
u64CountBytes += u64Temp.QuadPart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1524,7 +1524,7 @@ DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
/* Add statistics to recursive statistics*/
|
/* Add statistics to recursive statistics*/
|
||||||
recurse_dir_cnt += dwCountDirs;
|
recurse_dir_cnt += dwCountDirs;
|
||||||
recurse_file_cnt += dwCountFiles;
|
recurse_file_cnt += dwCountFiles;
|
||||||
recurse_bytes.QuadPart += u64CountBytes.QuadPart;
|
recurse_bytes += u64CountBytes;
|
||||||
|
|
||||||
/* Do the recursive job if requested
|
/* Do the recursive job if requested
|
||||||
the recursive is be done on ALL(indepent of their attribs)
|
the recursive is be done on ALL(indepent of their attribs)
|
||||||
|
@ -1648,7 +1648,7 @@ CommandDir(LPTSTR rest)
|
||||||
|
|
||||||
recurse_dir_cnt = 0L;
|
recurse_dir_cnt = 0L;
|
||||||
recurse_file_cnt = 0L;
|
recurse_file_cnt = 0L;
|
||||||
recurse_bytes.QuadPart = 0;
|
recurse_bytes = 0;
|
||||||
|
|
||||||
/* <Debug :>
|
/* <Debug :>
|
||||||
Uncomment this to show the final state of switch flags*/
|
Uncomment this to show the final state of switch flags*/
|
||||||
|
|
|
@ -27,7 +27,7 @@ PrintDiskInfo (LPTSTR szDisk)
|
||||||
TCHAR szUsed[40];
|
TCHAR szUsed[40];
|
||||||
TCHAR szFree[40];
|
TCHAR szFree[40];
|
||||||
DWORD dwSerial;
|
DWORD dwSerial;
|
||||||
ULARGE_INTEGER uliSize;
|
ULONGLONG uliSize;
|
||||||
DWORD dwSecPerCl;
|
DWORD dwSecPerCl;
|
||||||
DWORD dwBytPerSec;
|
DWORD dwBytPerSec;
|
||||||
DWORD dwFreeCl;
|
DWORD dwFreeCl;
|
||||||
|
@ -70,14 +70,14 @@ PrintDiskInfo (LPTSTR szDisk)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwTotCl;
|
||||||
ConvertULargeInteger (uliSize, szTotal, 40, TRUE);
|
ConvertULargeInteger(uliSize, szTotal, 40, TRUE);
|
||||||
|
|
||||||
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)(dwTotCl - dwFreeCl);
|
||||||
ConvertULargeInteger (uliSize, szUsed, 40, TRUE);
|
ConvertULargeInteger(uliSize, szUsed, 40, TRUE);
|
||||||
|
|
||||||
uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwFreeCl;
|
||||||
ConvertULargeInteger (uliSize, szFree, 40, TRUE);
|
ConvertULargeInteger(uliSize, szFree, 40, TRUE);
|
||||||
|
|
||||||
|
|
||||||
ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
|
ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
|
||||||
|
|
|
@ -15,33 +15,16 @@
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MEMORY
|
#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)
|
INT CommandMemory (LPTSTR param)
|
||||||
{
|
{
|
||||||
MEMORYSTATUS ms;
|
MEMORYSTATUSEX msex;
|
||||||
TCHAR szMemoryLoad[20];
|
TCHAR szMemoryLoad[20];
|
||||||
TCHAR szTotalPhys[20];
|
TCHAR szTotalPhys[40];
|
||||||
TCHAR szAvailPhys[20];
|
TCHAR szAvailPhys[40];
|
||||||
TCHAR szTotalPageFile[20];
|
TCHAR szTotalPageFile[40];
|
||||||
TCHAR szAvailPageFile[20];
|
TCHAR szAvailPageFile[40];
|
||||||
TCHAR szTotalVirtual[20];
|
TCHAR szTotalVirtual[40];
|
||||||
TCHAR szAvailVirtual[20];
|
TCHAR szAvailVirtual[40];
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
|
@ -49,17 +32,34 @@ INT CommandMemory (LPTSTR param)
|
||||||
return 0;
|
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);
|
ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
|
||||||
|
ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
|
||||||
ConvertDWord (ms.dwMemoryLoad, szMemoryLoad, 20, FALSE);
|
ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
|
||||||
ConvertDWord (ms.dwTotalPhys, szTotalPhys, 20, TRUE);
|
ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
|
||||||
ConvertDWord (ms.dwAvailPhys, szAvailPhys, 20, TRUE);
|
ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
|
||||||
ConvertDWord (ms.dwTotalPageFile, szTotalPageFile, 20, TRUE);
|
ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
|
||||||
ConvertDWord (ms.dwAvailPageFile, szAvailPageFile, 20, TRUE);
|
ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
|
||||||
ConvertDWord (ms.dwTotalVirtual, szTotalVirtual, 20, TRUE);
|
|
||||||
ConvertDWord (ms.dwAvailVirtual, szAvailVirtual, 20, TRUE);
|
|
||||||
|
|
||||||
ConOutResPrintf(STRING_MEMMORY_HELP2,
|
ConOutResPrintf(STRING_MEMMORY_HELP2,
|
||||||
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
|
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
|
||||||
|
|
Loading…
Reference in a new issue