Added Eric Kohl's port of freedos command
[reactos.git] / rosapps / cmd / label.c
1 /*
2 * LABEL.C - label internal command.
3 *
4 *
5 * History:
6 *
7 * 10-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
8 * Started.
9 *
10 * 11-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
11 * Finished.
12 *
13 * 19-Jan-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
14 * Unicode ready!
15 */
16
17 #define WIN32_LEAN_AND_MEAN
18
19 #include "config.h"
20
21 #ifdef INCLUDE_CMD_LABEL
22
23 #include <windows.h>
24 #include <tchar.h>
25 #include <string.h>
26
27 #include "cmd.h"
28
29
30 INT cmd_label (LPTSTR cmd, LPTSTR param)
31 {
32 TCHAR szRootPath[] = _T("A:\\");
33 TCHAR szLabel[80];
34 TCHAR szOldLabel[80];
35 DWORD dwSerialNr;
36 LPTSTR *arg;
37 INT args;
38
39 /* set empty label string */
40 szLabel[0] = _T('\0');
41
42 /* print help */
43 if (!_tcsncmp (param, _T("/?"), 2))
44 {
45 ConOutPuts (_T("Displays or changes drive label.\n\n"
46 "LABEL [drive:][label]"));
47 return 0;
48 }
49
50 /* get parameters */
51 arg = split (param, &args);
52
53 if (args > 2)
54 {
55 /* too many parameters */
56 error_too_many_parameters (arg[args - 1]);
57 freep (arg);
58 return 1;
59 }
60
61 if (args == 0)
62 {
63 /* get label of current drive */
64 TCHAR szCurPath[MAX_PATH];
65 GetCurrentDirectory (MAX_PATH, szCurPath);
66 szRootPath[0] = szCurPath[0];
67 }
68 else
69 {
70 if ((_tcslen (arg[0]) >= 2) && (arg[0][1] == _T(':')))
71 {
72 szRootPath[0] = toupper (*arg[0]);
73 if (args == 2)
74 _tcsncpy (szLabel, arg[1], 12);
75 }
76 else
77 {
78 TCHAR szCurPath[MAX_PATH];
79 GetCurrentDirectory (MAX_PATH, szCurPath);
80 szRootPath[0] = szCurPath[0];
81 _tcsncpy (szLabel, arg[0], 12);
82 }
83 }
84
85 /* check root path */
86 if (!IsValidPathName (szRootPath))
87 {
88 error_invalid_drive ();
89 freep (arg);
90 return 1;
91 }
92
93 GetVolumeInformation (szRootPath, szOldLabel, 80, &dwSerialNr,
94 NULL, NULL, NULL, 0);
95
96 /* print drive info */
97 ConOutPrintf (_T("Volume in drive %c:"), _totupper (szRootPath[0]));
98
99 if (szOldLabel[0] != _T('\0'))
100 ConOutPrintf (_T(" is %s\n"), szOldLabel);
101 else
102 ConOutPrintf (_T(" has no label\n"));
103
104 /* print the volume serial number */
105 ConOutPrintf (_T("Volume Serial Number is %04X-%04X\n"),
106 HIWORD(dwSerialNr), LOWORD(dwSerialNr));
107
108 if (szLabel[0] == _T('\0'))
109 {
110 ConOutPrintf (_T("Drive label (11 Characters, ENTER if none)? "));
111 ConInString (szLabel, 80);
112 }
113
114 SetVolumeLabel (szRootPath, szLabel);
115
116 freep (arg);
117
118 return 0;
119 }
120
121 #endif /* INCLUDE_CMD_LABEL */