Imported bzip2 modified to build a decompression only dll for use by the ramdisk...
[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 #include "config.h"
18
19 #ifdef INCLUDE_CMD_LABEL
20
21 #include <windows.h>
22 #include <tchar.h>
23 #include <string.h>
24 #include <ctype.h>
25
26 #include "cmd.h"
27
28
29 INT cmd_label (LPTSTR cmd, LPTSTR param)
30 {
31 TCHAR szRootPath[] = _T("A:\\");
32 TCHAR szLabel[80];
33 TCHAR szOldLabel[80];
34 DWORD dwSerialNr;
35 LPTSTR *arg;
36 INT args;
37
38 /* set empty label string */
39 szLabel[0] = _T('\0');
40
41 /* print help */
42 if (!_tcsncmp (param, _T("/?"), 2))
43 {
44 ConOutPuts (_T("Displays or changes drive label.\n\n"
45 "LABEL [drive:][label]"));
46 return 0;
47 }
48
49 /* get parameters */
50 arg = split (param, &args);
51
52 if (args > 2)
53 {
54 /* too many parameters */
55 error_too_many_parameters (arg[args - 1]);
56 freep (arg);
57 return 1;
58 }
59
60 if (args == 0)
61 {
62 /* get label of current drive */
63 TCHAR szCurPath[MAX_PATH];
64 GetCurrentDirectory (MAX_PATH, szCurPath);
65 szRootPath[0] = szCurPath[0];
66 }
67 else
68 {
69 if ((_tcslen (arg[0]) >= 2) && (arg[0][1] == _T(':')))
70 {
71 szRootPath[0] = toupper (*arg[0]);
72 if (args == 2)
73 _tcsncpy (szLabel, arg[1], 12);
74 }
75 else
76 {
77 TCHAR szCurPath[MAX_PATH];
78 GetCurrentDirectory (MAX_PATH, szCurPath);
79 szRootPath[0] = szCurPath[0];
80 _tcsncpy (szLabel, arg[0], 12);
81 }
82 }
83
84 /* check root path */
85 if (!IsValidPathName (szRootPath))
86 {
87 error_invalid_drive ();
88 freep (arg);
89 return 1;
90 }
91
92 GetVolumeInformation (szRootPath, szOldLabel, 80, &dwSerialNr,
93 NULL, NULL, NULL, 0);
94
95 /* print drive info */
96 ConOutPrintf (_T("Volume in drive %c:"), _totupper (szRootPath[0]));
97
98 if (szOldLabel[0] != _T('\0'))
99 ConOutPrintf (_T(" is %s\n"), szOldLabel);
100 else
101 ConOutPrintf (_T(" has no label\n"));
102
103 /* print the volume serial number */
104 ConOutPrintf (_T("Volume Serial Number is %04X-%04X\n"),
105 HIWORD(dwSerialNr), LOWORD(dwSerialNr));
106
107 if (szLabel[0] == _T('\0'))
108 {
109 ConOutPrintf (_T("Drive label (11 Characters, ENTER if none)? "));
110 ConInString (szLabel, 80);
111 }
112
113 SetVolumeLabel (szRootPath, szLabel);
114
115 freep (arg);
116
117 return 0;
118 }
119
120 #endif /* INCLUDE_CMD_LABEL */