update for HEAD-2003050101
[reactos.git] / 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 "config.h"
24
25 #ifdef INCLUDE_CMD_VOL
26
27 #include <windows.h>
28 #include <tchar.h>
29 #include <string.h>
30
31 #include "cmd.h"
32
33
34 static INT
35 PrintVolumeHeader (LPTSTR pszRootPath)
36 {
37         TCHAR szVolName[80];
38         DWORD dwSerialNr;
39
40         /* get the volume information of the drive */
41         if(!GetVolumeInformation (pszRootPath,
42                                   szVolName,
43                                   80,
44                                   &dwSerialNr,
45                                   NULL,
46                                   NULL,
47                                   NULL,
48                                   0))
49         {
50                 ErrorMessage (GetLastError (), _T(""));
51                 return 1;
52         }
53
54         /* print drive info */
55         ConOutPrintf (_T(" Volume in drive %c:"), pszRootPath[0]);
56
57         if (szVolName[0] != '\0')
58                 ConOutPrintf (_T(" is %s\n"),
59                               szVolName);
60         else
61                 ConOutPrintf (_T(" has no label\n"));
62
63         /* print the volume serial number */
64         ConOutPrintf (_T(" Volume Serial Number is %04X-%04X\n"),
65                       HIWORD(dwSerialNr),
66                       LOWORD(dwSerialNr));
67         return 0;
68 }
69
70
71 INT cmd_vol (LPTSTR cmd, LPTSTR param)
72 {
73         TCHAR szRootPath[] = _T("A:\\");
74         TCHAR szPath[MAX_PATH];
75
76         if (!_tcsncmp (param, _T("/?"), 2))
77         {
78                 ConOutPuts (_T("Displays the disk volume label and serial number, if they exist.\n\n"
79                             "VOL [drive:]"));
80                 return 0;
81         }
82
83         if (param[0] == _T('\0'))
84         {
85                 GetCurrentDirectory (MAX_PATH, szPath);
86                 szRootPath[0] = szPath[0];
87         }
88         else
89         {
90                 _tcsupr (param);
91                 if (param[1] == _T(':'))
92                         szRootPath[0] = param[0];
93                 else
94                 {
95                         error_invalid_drive ();
96                         return 1;
97                 }
98         }
99
100         if (!IsValidPathName (szRootPath))
101         {
102                 error_invalid_drive ();
103                 return 1;
104         }
105
106         /* print the header */
107         if (!PrintVolumeHeader (szRootPath))
108                 return 1;
109
110         return 0;
111 }
112
113 #endif