[FSUTIL]
[reactos.git] / reactos / base / applications / cmdutils / fsutil / fsinfo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS FS utility tool
4 * FILE: base/applications/cmdutils/fsinfo.c
5 * PURPOSE: FSutil file systems information
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7 */
8
9 /* Add handlers here for subcommands */
10 static int DrivesMain(int argc, const TCHAR *argv[]);
11 static int DriveTypeMain(int argc, const TCHAR *argv[]);
12 static HandlerItem HandlersList[] =
13 {
14 /* Proc, name, help */
15 { DrivesMain, _T("drives"), _T("Enumerates the drives") },
16 { DriveTypeMain, _T("drivetype"), _T("Provides the type of a drive") },
17 };
18
19 static int
20 DrivesMain(int argc, const TCHAR *argv[])
21 {
22 UINT i;
23 DWORD Drives;
24
25 /* Get the drives bitmap */
26 Drives = GetLogicalDrives();
27 if (Drives == 0)
28 {
29 _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
30 return 1;
31 }
32
33 /* And output any found drive */
34 _ftprintf(stdout, _T("Drives:"));
35 for (i = 0; i < 26; i++)
36 {
37 if (Drives & (1 << i))
38 {
39 _ftprintf(stdout, _T(" %c:\\"), 'A' + i);
40 }
41 }
42 _ftprintf(stdout, _T("\n"));
43
44 return 0;
45 }
46
47 static int
48 DriveTypeMain(int argc, const TCHAR *argv[])
49 {
50 UINT Type;
51
52 /* We need a volume (letter) */
53 if (argc < 2)
54 {
55 _ftprintf(stderr, _T("Usage: fsutil fsinfo drivetype <volume>\n"));
56 _ftprintf(stderr, _T("\tFor example: fsutil fsinfo drivetype c:\n"));
57 return 1;
58 }
59
60 /* Get its drive type and make it readable */
61 Type = GetDriveType(argv[1]);
62 switch (Type)
63 {
64 case DRIVE_UNKNOWN:
65 _ftprintf(stdout, _T("%s - unknown drive type\n"), argv[1]);
66 break;
67
68 case DRIVE_NO_ROOT_DIR:
69 _ftprintf(stdout, _T("%s - not a root directory\n"), argv[1]);
70 break;
71
72 case DRIVE_REMOVABLE:
73 _ftprintf(stdout, _T("%s - removable drive\n"), argv[1]);
74 break;
75
76 case DRIVE_FIXED:
77 _ftprintf(stdout, _T("%s - fixed drive\n"), argv[1]);
78 break;
79
80 case DRIVE_REMOTE:
81 _ftprintf(stdout, _T("%s - remote or network drive\n"), argv[1]);
82 break;
83
84 case DRIVE_CDROM:
85 _ftprintf(stdout, _T("%s - CD-ROM drive\n"), argv[1]);
86 break;
87
88 case DRIVE_RAMDISK:
89 _ftprintf(stdout, _T("%s - RAM disk drive\n"), argv[1]);
90 break;
91 }
92
93 return 0;
94 }
95
96 static void
97 PrintUsage(const TCHAR * Command)
98 {
99 PrintDefaultUsage(_T(" FSINFO "), Command, (HandlerItem *)&HandlersList,
100 (sizeof(HandlersList) / sizeof(HandlersList[0])));
101 }
102
103 int
104 FsInfoMain(int argc, const TCHAR *argv[])
105 {
106 return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
107 (sizeof(HandlersList) / sizeof(HandlersList[0])),
108 PrintUsage);
109 }