Use FileGetString instead of ReadFile, because ReadFile doesn't return a null termina...
[reactos.git] / reactos / subsys / system / cmd / vol.c
1 /*
2 * VOL.C - vol internal command.
3 *
4 *
5 * History:
6 *
7 * 03-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
8 * Replaced DOS calls by Win32 calls.
9 *
10 * 08-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
11 * Added help text ("/?").
12 *
13 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
14 * Cleanup.
15 *
16 * 18-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
17 * Unicode ready!
18 *
19 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 * Redirection ready!
21 */
22
23 #include <precomp.h>
24 #include "resource.h"
25
26 #ifdef INCLUDE_CMD_VOL
27
28
29 static INT
30 PrintVolumeHeader (LPTSTR pszRootPath)
31 {
32 TCHAR szMsg[RC_STRING_MAX_SIZE];
33 TCHAR szVolName[80];
34 DWORD dwSerialNr;
35
36 /* get the volume information of the drive */
37 if(!GetVolumeInformation (pszRootPath,
38 szVolName,
39 80,
40 &dwSerialNr,
41 NULL,
42 NULL,
43 NULL,
44 0))
45 {
46 ErrorMessage (GetLastError (), _T(""));
47 return 1;
48 }
49
50 /* print drive info */
51 if (szVolName[0] != '\0')
52 {
53 LoadString(CMD_ModuleHandle, STRING_VOL_HELP1, szMsg, RC_STRING_MAX_SIZE);
54 ConOutPrintf(szMsg, pszRootPath[0],szVolName);
55 }
56 else
57 {
58 LoadString(CMD_ModuleHandle, STRING_VOL_HELP2, szMsg, RC_STRING_MAX_SIZE);
59 ConOutPrintf(szMsg, pszRootPath[0]);
60 }
61
62 /* print the volume serial number */
63 LoadString(CMD_ModuleHandle, STRING_VOL_HELP3, szMsg, RC_STRING_MAX_SIZE);
64 ConOutPrintf(szMsg, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
65 return 0;
66 }
67
68
69 INT cmd_vol (LPTSTR cmd, LPTSTR param)
70 {
71 TCHAR szRootPath[] = _T("A:\\");
72 TCHAR szPath[MAX_PATH];
73
74 if (!_tcsncmp (param, _T("/?"), 2))
75 {
76 ConOutResPaging(TRUE,STRING_VOL_HELP4);
77 return 0;
78 }
79
80 nErrorLevel = 0;
81
82 if (param[0] == _T('\0'))
83 {
84 GetCurrentDirectory (MAX_PATH, szPath);
85 szRootPath[0] = szPath[0];
86 }
87 else
88 {
89 _tcsupr (param);
90 if (param[1] == _T(':'))
91 szRootPath[0] = param[0];
92 else
93 {
94 error_invalid_drive ();
95 nErrorLevel = 1;
96 return 1;
97 }
98 }
99
100 if (!IsValidPathName (szRootPath))
101 {
102 error_invalid_drive ();
103 nErrorLevel = 1;
104 return 1;
105 }
106
107 /* print the header */
108 if (!PrintVolumeHeader (szRootPath))
109 {
110 return 1;
111 }
112
113 return 0;
114 }
115
116 #endif