move network tools
[reactos.git] / reactos / subsys / system / cmd / free.c
1 /*
2 * FREE.C - internal command.
3 *
4 *
5 * History:
6 *
7 * 01-Sep-1999 (Eric Kohl)
8 * Started.
9 *
10 * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
11 * Remove all hardcode string to En.rc
12 */
13
14 #include <precomp.h>
15 #include "resource.h"
16
17 #ifdef INCLUDE_CMD_FREE
18
19 static VOID
20 PrintDiskInfo (LPTSTR szDisk)
21 {
22 TCHAR szMsg[RC_STRING_MAX_SIZE];
23 TCHAR szRootPath[4] = _T("A:\\");
24 TCHAR szDrive[2] = _T("A");
25 TCHAR szVolume[64];
26 TCHAR szSerial[10];
27 TCHAR szTotal[40];
28 TCHAR szUsed[40];
29 TCHAR szFree[40];
30 DWORD dwSerial;
31 ULARGE_INTEGER uliSize;
32 DWORD dwSecPerCl;
33 DWORD dwBytPerSec;
34 DWORD dwFreeCl;
35 DWORD dwTotCl;
36
37 if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
38 {
39 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
40 ConErrPrintf(szMsg);
41 return;
42 }
43
44 szRootPath[0] = szDisk[0];
45 szDrive[0] = _totupper (szRootPath[0]);
46
47 if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
48 NULL, NULL, NULL, 0))
49 {
50 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
51 ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
52 return;
53 }
54
55 if (szVolume[0] == _T('\0'))
56 {
57
58 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
59 _tcscpy (szVolume, szMsg);
60 }
61
62 _stprintf (szSerial,
63 _T("%04X-%04X"),
64 HIWORD(dwSerial),
65 LOWORD(dwSerial));
66
67 if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
68 &dwBytPerSec, &dwFreeCl, &dwTotCl))
69 {
70 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
71 ConErrPrintf (_T("%s %s:\n"), szMsg, szDrive);
72 return;
73 }
74
75 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
76 ConvertULargeInteger (uliSize, szTotal, 40, TRUE);
77
78 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
79 ConvertULargeInteger (uliSize, szUsed, 40, TRUE);
80
81 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
82 ConvertULargeInteger (uliSize, szFree, 40, TRUE);
83
84
85 LoadString(CMD_ModuleHandle, STRING_FREE_HELP1, szMsg, RC_STRING_MAX_SIZE);
86 ConOutPrintf(szMsg, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
87 }
88
89
90 INT CommandFree (LPTSTR cmd, LPTSTR param)
91 {
92 LPTSTR szParam;
93 TCHAR szDefPath[MAX_PATH];
94 INT argc, i;
95 LPTSTR *arg;
96
97 if (!_tcsncmp (param, _T("/?"), 2))
98 {
99 ConOutResPaging(TRUE,STRING_FREE_HELP2);
100 return 0;
101 }
102
103 if (!param || *param == _T('\0'))
104 {
105 GetCurrentDirectory (MAX_PATH, szDefPath);
106 szDefPath[2] = _T('\0');
107 szParam = szDefPath;
108 }
109 else
110 szParam = param;
111
112 arg = split (szParam, &argc, FALSE);
113
114 for (i = 0; i < argc; i++)
115 PrintDiskInfo (arg[i]);
116
117 freep (arg);
118
119 return 0;
120 }
121
122 #endif /* INCLUDE_CMD_FREE */
123
124 /* EOF */