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