2 * FREE.C - internal command.
7 * 01-Sep-1999 (Eric Kohl)
13 #ifdef INCLUDE_CMD_FREE
19 * insert commas into a number
23 ConvertULargeInteger (ULARGE_INTEGER num
, LPTSTR des
, INT len
)
29 if (num
.QuadPart
== 0)
38 while (num
.QuadPart
> 0)
40 if (((c
+ 1) % (nNumberGroups
+ 1)) == 0)
41 temp
[30 - c
++] = cThousandSeparator
;
42 temp
[30 - c
++] = (TCHAR
)(num
.QuadPart
% 10) + _T('0');
46 for (n
= 0; n
<= c
; n
++)
47 des
[n
] = temp
[31 - c
+ n
];
55 PrintDiskInfo (LPTSTR szDisk
)
57 TCHAR szRootPath
[4] = _T("A:\\");
58 TCHAR szDrive
[2] = _T("A");
65 ULARGE_INTEGER uliSize
;
71 if (_tcslen (szDisk
) < 2 || szDisk
[1] != _T(':'))
73 ConErrPrintf (_T("Invalid drive %s\n"), szDisk
);
77 szRootPath
[0] = szDisk
[0];
78 szDrive
[0] = _totupper (szRootPath
[0]);
80 if (!GetVolumeInformation (szRootPath
, szVolume
, 64, &dwSerial
,
83 ConErrPrintf (_T("Invalid drive %s:\n"), szDrive
);
87 if (szVolume
[0] == _T('\0'))
88 _tcscpy (szVolume
, _T("unlabeled"));
95 if (!GetDiskFreeSpace (szRootPath
, &dwSecPerCl
,
96 &dwBytPerSec
, &dwFreeCl
, &dwTotCl
))
98 ConErrPrintf (_T("Invalid drive %s:\n"), szDrive
);
102 uliSize
.QuadPart
= dwSecPerCl
* dwBytPerSec
* dwTotCl
;
103 ConvertULargeInteger (uliSize
, szTotal
, 40);
105 uliSize
.QuadPart
= dwSecPerCl
* dwBytPerSec
* (dwTotCl
- dwFreeCl
);
106 ConvertULargeInteger (uliSize
, szUsed
, 40);
108 uliSize
.QuadPart
= dwSecPerCl
* dwBytPerSec
* dwFreeCl
;
109 ConvertULargeInteger (uliSize
, szFree
, 40);
111 ConOutPrintf (_T("\n"
112 " Volume in drive %s is %-11s Serial number is %s\n"
113 " %16s bytes total disk space\n"
115 " %16s bytes free\n"),
116 szDrive
, szVolume
, szSerial
,
117 szTotal
, szUsed
, szFree
);
121 INT
CommandFree (LPTSTR cmd
, LPTSTR param
)
124 TCHAR szDefPath
[MAX_PATH
];
128 if (!_tcsncmp (param
, _T("/?"), 2))
130 ConOutPuts (_T("Displays drive information.\n"
132 "FREE [drive: ...]"));
136 if (!param
|| *param
== _T('\0'))
138 GetCurrentDirectory (MAX_PATH
, szDefPath
);
139 szDefPath
[2] = _T('\0');
145 arg
= split (szParam
, &argc
, FALSE
);
147 for (i
= 0; i
< argc
; i
++)
148 PrintDiskInfo (arg
[i
]);
155 #endif /* INCLUDE_CMD_FREE */