2 * FREE.C - internal command.
7 * 01-Sep-1999 (Eric Kohl)
13 #ifdef INCLUDE_CMD_FREE
27 * insert commas into a number
31 ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len)
37 if (num.QuadPart == 0)
46 while (num.QuadPart > 0)
48 if (((c + 1) % (nNumberGroups + 1)) == 0)
49 temp[30 - c++] = cThousandSeparator;
50 temp[30 - c++] = (TCHAR)(num.QuadPart % 10) + _T('0');
54 for (n = 0; n <= c; n++)
55 des[n] = temp[31 - c + n];
63 PrintDiskInfo (LPTSTR szDisk)
65 TCHAR szRootPath[4] = _T("A:\\");
66 TCHAR szDrive[2] = _T("A");
73 ULARGE_INTEGER uliSize;
79 if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
81 ConErrPrintf (_T("Invalid drive %s\n"), szDisk);
85 szRootPath[0] = szDisk[0];
86 szDrive[0] = _totupper (szRootPath[0]);
88 if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
91 ConErrPrintf (_T("Invalid drive %s:\n"), szDrive);
95 if (szVolume[0] == _T('\0'))
96 _tcscpy (szVolume, _T("unlabeled"));
103 if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
104 &dwBytPerSec, &dwFreeCl, &dwTotCl))
106 ConErrPrintf (_T("Invalid drive %s:\n"), szDrive);
110 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
111 ConvertULargeInteger (uliSize, szTotal, 40);
113 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
114 ConvertULargeInteger (uliSize, szUsed, 40);
116 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
117 ConvertULargeInteger (uliSize, szFree, 40);
119 ConOutPrintf (_T("\n"
120 " Volume in drive %s is %-11s Serial number is %s\n"
121 " %16s bytes total disk space\n"
123 " %16s bytes free\n"),
124 szDrive, szVolume, szSerial,
125 szTotal, szUsed, szFree);
129 INT CommandFree (LPTSTR cmd, LPTSTR param)
132 TCHAR szDefPath[MAX_PATH];
136 if (!_tcsncmp (param, _T("/?"), 2))
138 ConOutPuts (_T("Displays drive information.\n"
140 "FREE [drive: ...]"));
144 if (!param || *param == _T('\0'))
146 GetCurrentDirectory (MAX_PATH, szDefPath);
147 szDefPath[2] = _T('\0');
153 arg = split (szParam, &argc, FALSE);
155 for (i = 0; i < argc; i++)
156 PrintDiskInfo (arg[i]);
163 #endif /* INCLUDE_CMD_FREE */