mirror of
https://github.com/reactos/reactos.git
synced 2025-06-20 07:36:05 +00:00
Don't alloc an extra console upon startup.
Added correct calculation of free disk size for drives larger than 2GB. svn path=/trunk/; revision=3309
This commit is contained in:
parent
4201812a7e
commit
cfa1943b4f
2 changed files with 165 additions and 82 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: cmd.c,v 1.30 2002/05/07 23:05:33 hbirr Exp $
|
/* $Id: cmd.c,v 1.31 2002/08/01 10:29:17 ekohl Exp $
|
||||||
*
|
*
|
||||||
* CMD.C - command-line interface.
|
* CMD.C - command-line interface.
|
||||||
*
|
*
|
||||||
|
@ -1146,27 +1146,29 @@ static VOID Cleanup (int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
INT nExitCode;
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO Info;
|
CONSOLE_SCREEN_BUFFER_INFO Info;
|
||||||
|
INT nExitCode;
|
||||||
|
|
||||||
AllocConsole ();
|
SetFileApisToOEM();
|
||||||
SetFileApisToOEM ();
|
|
||||||
|
|
||||||
if( GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &Info ) == FALSE )
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info) == FALSE)
|
||||||
fprintf(stderr, "GetConsoleScreenBufferInfo: Error: %ld\n", GetLastError() );
|
{
|
||||||
|
fprintf(stderr, "GetConsoleScreenBufferInfo: Error: %ld\n", GetLastError());
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
wColor = Info.wAttributes;
|
wColor = Info.wAttributes;
|
||||||
wDefColor = wColor;
|
wDefColor = wColor;
|
||||||
|
|
||||||
/* check switches on command-line */
|
/* check switches on command-line */
|
||||||
Initialize (argc, argv);
|
Initialize(argc, argv);
|
||||||
|
|
||||||
/* call prompt routine */
|
/* call prompt routine */
|
||||||
nExitCode = ProcessInput (FALSE);
|
nExitCode = ProcessInput(FALSE);
|
||||||
|
|
||||||
/* do the cleanup */
|
/* do the cleanup */
|
||||||
Cleanup (argc, argv);
|
Cleanup(argc, argv);
|
||||||
FreeConsole ();
|
|
||||||
|
|
||||||
return nExitCode;
|
return(nExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: dir.c,v 1.12 2002/07/15 22:29:32 sedwards Exp $
|
/* $Id: dir.c,v 1.13 2002/08/01 10:29:18 ekohl Exp $
|
||||||
*
|
*
|
||||||
* DIR.C - dir internal command.
|
* DIR.C - dir internal command.
|
||||||
*
|
*
|
||||||
|
@ -128,6 +128,9 @@
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef BOOL STDCALL
|
||||||
|
(*PGETFREEDISKSPACEEX)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
||||||
|
|
||||||
|
|
||||||
/* flag definitions */
|
/* flag definitions */
|
||||||
enum
|
enum
|
||||||
|
@ -159,7 +162,7 @@ static ULARGE_INTEGER recurse_bytes;
|
||||||
*/
|
*/
|
||||||
static VOID Help (VOID)
|
static VOID Help (VOID)
|
||||||
{
|
{
|
||||||
ConOutPuts (_T("Displays a list of files and subdirectories in a directory.\n"
|
ConOutPuts(_T("Displays a list of files and subdirectories in a directory.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"DIR [drive:][path][filename] [/A] [/B] [/L] [/N] [/S] [/P] [/W] [/4]\n"
|
"DIR [drive:][path][filename] [/A] [/B] [/L] [/N] [/S] [/P] [/W] [/4]\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -497,41 +500,79 @@ IncLine (LPINT pLine, DWORD dwFlags)
|
||||||
static BOOL
|
static BOOL
|
||||||
PrintDirectoryHeader (LPTSTR szPath, LPINT pLine, DWORD dwFlags)
|
PrintDirectoryHeader (LPTSTR szPath, LPINT pLine, DWORD dwFlags)
|
||||||
{
|
{
|
||||||
TCHAR szRootName[] = _T("A:\\");
|
TCHAR szRootName[MAX_PATH];
|
||||||
TCHAR szVolName[80];
|
TCHAR szVolName[80];
|
||||||
DWORD dwSerialNr;
|
DWORD dwSerialNr;
|
||||||
|
LPTSTR p;
|
||||||
|
|
||||||
if (dwFlags & DIR_BARE)
|
if (dwFlags & DIR_BARE)
|
||||||
return TRUE;
|
return(TRUE);
|
||||||
|
|
||||||
|
/* build usable root path */
|
||||||
|
if (szPath[1] == _T(':') && szPath[2] == _T('\\'))
|
||||||
|
{
|
||||||
|
/* normal path */
|
||||||
|
szRootName[0] = szPath[0];
|
||||||
|
szRootName[1] = _T(':');
|
||||||
|
szRootName[2] = _T('\\');
|
||||||
|
szRootName[3] = 0;
|
||||||
|
}
|
||||||
|
else if (szPath[0] == _T('\\') && szPath[1] == _T('\\'))
|
||||||
|
{
|
||||||
|
/* UNC path */
|
||||||
|
p = _tcschr(&szPath[2], _T('\\'));
|
||||||
|
if (p == NULL)
|
||||||
|
{
|
||||||
|
error_invalid_drive();
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
p = _tcschr(p+1, _T('\\'));
|
||||||
|
if (p == NULL)
|
||||||
|
{
|
||||||
|
_tcscpy(szRootName, szPath);
|
||||||
|
_tcscat(szRootName, _T("\\"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*p = 0;
|
||||||
|
_tcscpy(szRootName, szPath);
|
||||||
|
_tcscat(szRootName, _T("\\"));
|
||||||
|
*p = _T('\\');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_invalid_drive();
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
/* get the media ID of the drive */
|
/* get the media ID of the drive */
|
||||||
szRootName[0] = szPath[0];
|
if (!GetVolumeInformation(szRootName, szVolName, 80, &dwSerialNr,
|
||||||
if (!GetVolumeInformation (szRootName, szVolName, 80, &dwSerialNr,
|
|
||||||
NULL, NULL, NULL, 0))
|
NULL, NULL, NULL, 0))
|
||||||
{
|
{
|
||||||
error_invalid_drive();
|
error_invalid_drive();
|
||||||
return FALSE;
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print drive info */
|
/* print drive info */
|
||||||
ConOutPrintf (_T(" Volume in drive %c"), szRootName[0]);
|
ConOutPrintf(_T(" Volume in drive %c"), szRootName[0]);
|
||||||
|
|
||||||
if (szVolName[0] != _T('\0'))
|
if (szVolName[0] != _T('\0'))
|
||||||
ConOutPrintf (_T(" is %s\n"), szVolName);
|
ConOutPrintf(_T(" is %s\n"), szVolName);
|
||||||
else
|
else
|
||||||
ConOutPrintf (_T(" has no label\n"));
|
ConOutPrintf(_T(" has no label\n"));
|
||||||
|
|
||||||
if (IncLine (pLine, dwFlags))
|
if (IncLine(pLine, dwFlags))
|
||||||
return FALSE;
|
return(FALSE);
|
||||||
|
|
||||||
/* print the volume serial number if the return was successful */
|
/* print the volume serial number if the return was successful */
|
||||||
ConOutPrintf (_T(" Volume Serial Number is %04X-%04X\n"),
|
ConOutPrintf(_T(" Volume Serial Number is %04X-%04X\n"),
|
||||||
HIWORD(dwSerialNr),
|
HIWORD(dwSerialNr),
|
||||||
LOWORD(dwSerialNr));
|
LOWORD(dwSerialNr));
|
||||||
if (IncLine (pLine, dwFlags))
|
if (IncLine(pLine, dwFlags))
|
||||||
return FALSE;
|
return(FALSE);
|
||||||
|
|
||||||
return TRUE;
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -646,6 +687,47 @@ PrintFileDateTime (LPSYSTEMTIME dt, DWORD dwFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
GetUserDiskFreeSpace(LPCTSTR lpRoot,
|
||||||
|
PULARGE_INTEGER lpFreeSpace)
|
||||||
|
{
|
||||||
|
PGETFREEDISKSPACEEX pGetFreeDiskSpaceEx;
|
||||||
|
HINSTANCE hInstance;
|
||||||
|
DWORD dwSecPerCl;
|
||||||
|
DWORD dwBytPerSec;
|
||||||
|
DWORD dwFreeCl;
|
||||||
|
DWORD dwTotCl;
|
||||||
|
|
||||||
|
lpFreeSpace->QuadPart = 0;
|
||||||
|
|
||||||
|
hInstance = LoadLibrary(_T("KERNEL32"));
|
||||||
|
if (hInstance != NULL)
|
||||||
|
{
|
||||||
|
#ifndef UNICODE
|
||||||
|
pGetFreeDiskSpaceEx = GetProcAddress(hInstance,
|
||||||
|
"GetDiskFreeSpaceExA");
|
||||||
|
#else
|
||||||
|
pGetFreeDiskSpaceEx = GetProcAddress(hInstance,
|
||||||
|
"GetDiskFreeSpaceExW");
|
||||||
|
#endif
|
||||||
|
if (pGetFreeDiskSpaceEx != NULL)
|
||||||
|
{
|
||||||
|
if (pGetFreeDiskSpaceEx(lpRoot, lpFreeSpace, NULL, NULL) == TRUE)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FreeLibrary(hInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
GetDiskFreeSpace(lpRoot,
|
||||||
|
&dwSecPerCl,
|
||||||
|
&dwBytPerSec,
|
||||||
|
&dwFreeCl,
|
||||||
|
&dwTotCl);
|
||||||
|
|
||||||
|
lpFreeSpace->QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print_summary: prints dir summary
|
* print_summary: prints dir summary
|
||||||
* Added by Rob Lake 06/17/98 to compact code
|
* Added by Rob Lake 06/17/98 to compact code
|
||||||
|
@ -653,15 +735,21 @@ PrintFileDateTime (LPSYSTEMTIME dt, DWORD dwFlags)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static INT
|
static INT
|
||||||
PrintSummary (LPTSTR szPath, ULONG ulFiles, ULONG ulDirs, ULARGE_INTEGER bytes,
|
PrintSummary(LPTSTR szPath,
|
||||||
LPINT pLine, DWORD dwFlags)
|
ULONG ulFiles,
|
||||||
|
ULONG ulDirs,
|
||||||
|
ULARGE_INTEGER bytes,
|
||||||
|
LPINT pLine,
|
||||||
|
DWORD dwFlags)
|
||||||
{
|
{
|
||||||
TCHAR buffer[64];
|
TCHAR buffer[64];
|
||||||
|
ULARGE_INTEGER uliFree;
|
||||||
|
TCHAR szRoot[] = _T("A:\\");
|
||||||
|
|
||||||
if (dwFlags & DIR_BARE)
|
if (dwFlags & DIR_BARE)
|
||||||
return 0;
|
return(0);
|
||||||
|
|
||||||
/* print number of files and bytes */
|
/* Print number of files and bytes */
|
||||||
ConvertULong (ulFiles, buffer, sizeof(buffer));
|
ConvertULong (ulFiles, buffer, sizeof(buffer));
|
||||||
ConOutPrintf (_T(" %6s File%c"),
|
ConOutPrintf (_T(" %6s File%c"),
|
||||||
buffer, ulFiles == 1 ? _T(' ') : _T('s'));
|
buffer, ulFiles == 1 ? _T(' ') : _T('s'));
|
||||||
|
@ -669,28 +757,21 @@ PrintSummary (LPTSTR szPath, ULONG ulFiles, ULONG ulDirs, ULARGE_INTEGER bytes,
|
||||||
ConvertULargeInteger (bytes, buffer, sizeof(buffer));
|
ConvertULargeInteger (bytes, buffer, sizeof(buffer));
|
||||||
ConOutPrintf (_T(" %15s byte%c\n"),
|
ConOutPrintf (_T(" %15s byte%c\n"),
|
||||||
buffer, bytes.QuadPart == 1 ? _T(' ') : _T('s'));
|
buffer, bytes.QuadPart == 1 ? _T(' ') : _T('s'));
|
||||||
|
ConOutPrintf (_T(" %I64u byte%c\n"),
|
||||||
|
bytes.QuadPart, bytes.QuadPart == 1 ? _T(' ') : _T('s'));
|
||||||
|
|
||||||
if (IncLine (pLine, dwFlags))
|
if (IncLine (pLine, dwFlags))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* print number of dirs and bytes free */
|
/* Print number of dirs and bytes free */
|
||||||
ConvertULong (ulDirs, buffer, sizeof(buffer));
|
ConvertULong (ulDirs, buffer, sizeof(buffer));
|
||||||
ConOutPrintf (_T(" %6s Dir%c"),
|
ConOutPrintf (_T(" %6s Dir%c"),
|
||||||
buffer, ulDirs == 1 ? _T(' ') : _T('s'));
|
buffer, ulDirs == 1 ? _T(' ') : _T('s'));
|
||||||
|
|
||||||
|
|
||||||
if (!(dwFlags & DIR_RECURSE))
|
if (!(dwFlags & DIR_RECURSE))
|
||||||
{
|
{
|
||||||
ULARGE_INTEGER uliFree;
|
|
||||||
TCHAR szRoot[] = _T("A:\\");
|
|
||||||
DWORD dwSecPerCl;
|
|
||||||
DWORD dwBytPerSec;
|
|
||||||
DWORD dwFreeCl;
|
|
||||||
DWORD dwTotCl;
|
|
||||||
|
|
||||||
szRoot[0] = szPath[0];
|
szRoot[0] = szPath[0];
|
||||||
GetDiskFreeSpace (szRoot, &dwSecPerCl, &dwBytPerSec, &dwFreeCl, &dwTotCl);
|
GetUserDiskFreeSpace(szRoot, &uliFree);
|
||||||
uliFree.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
|
|
||||||
ConvertULargeInteger (uliFree, buffer, sizeof(buffer));
|
ConvertULargeInteger (uliFree, buffer, sizeof(buffer));
|
||||||
ConOutPrintf (_T(" %15s bytes free\n"), buffer);
|
ConOutPrintf (_T(" %15s bytes free\n"), buffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue