[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 #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 int VolumeInfoMain(int argc, const TCHAR *argv[]);
15 static HandlerItem HandlersList[] =
16 {
17 /* Proc, name, help */
18 { DrivesMain, _T("drives"), _T("Enumerates the drives") },
19 { DriveTypeMain, _T("drivetype"), _T("Provides the type of a drive") },
20 { VolumeInfoMain, _T("volumeinfo"), _T("Provides informations about a volume") },
21 };
22
23 static int
24 DrivesMain(int argc, const TCHAR *argv[])
25 {
26 UINT i;
27 DWORD Drives;
28
29 /* Get the drives bitmap */
30 Drives = GetLogicalDrives();
31 if (Drives == 0)
32 {
33 PrintErrorMessage(GetLastError());
34 return 1;
35 }
36
37 /* And output any found drive */
38 _ftprintf(stdout, _T("Drives:"));
39 for (i = 0; i < 26; i++)
40 {
41 if (Drives & (1 << i))
42 {
43 _ftprintf(stdout, _T(" %c:\\"), 'A' + i);
44 }
45 }
46 _ftprintf(stdout, _T("\n"));
47
48 return 0;
49 }
50
51 static int
52 DriveTypeMain(int argc, const TCHAR *argv[])
53 {
54 UINT Type;
55
56 /* We need a volume (letter) */
57 if (argc < 2)
58 {
59 _ftprintf(stderr, _T("Usage: fsutil fsinfo drivetype <volume>\n"));
60 _ftprintf(stderr, _T("\tFor example: fsutil fsinfo drivetype c:\n"));
61 return 1;
62 }
63
64 /* Get its drive type and make it readable */
65 Type = GetDriveType(argv[1]);
66 switch (Type)
67 {
68 case DRIVE_UNKNOWN:
69 _ftprintf(stdout, _T("%s - unknown drive type\n"), argv[1]);
70 break;
71
72 case DRIVE_NO_ROOT_DIR:
73 _ftprintf(stdout, _T("%s - not a root directory\n"), argv[1]);
74 break;
75
76 case DRIVE_REMOVABLE:
77 _ftprintf(stdout, _T("%s - removable drive\n"), argv[1]);
78 break;
79
80 case DRIVE_FIXED:
81 _ftprintf(stdout, _T("%s - fixed drive\n"), argv[1]);
82 break;
83
84 case DRIVE_REMOTE:
85 _ftprintf(stdout, _T("%s - remote or network drive\n"), argv[1]);
86 break;
87
88 case DRIVE_CDROM:
89 _ftprintf(stdout, _T("%s - CD-ROM drive\n"), argv[1]);
90 break;
91
92 case DRIVE_RAMDISK:
93 _ftprintf(stdout, _T("%s - RAM disk drive\n"), argv[1]);
94 break;
95 }
96
97 return 0;
98 }
99
100 static int
101 VolumeInfoMain(int argc, const TCHAR *argv[])
102 {
103 DWORD Serial, MaxComponentLen, Flags;
104 TCHAR VolumeName[MAX_PATH + 1], FileSystem[MAX_PATH + 1];
105
106 #define HANDLE_FLAG(Flags, Flag, Desc) \
107 if (Flags & Flag) \
108 _ftprintf(stdout, Desc)
109
110 /* We need a volume (path) */
111 if (argc < 2)
112 {
113 _ftprintf(stderr, _T("Usage: fsutil fsinfo volumeinfo <volume_path>\n"));
114 _ftprintf(stderr, _T("\tFor example: fsutil fsinfo volumeinfo c:\\\n"));
115 return 1;
116 }
117
118 /* Gather information */
119 if (!GetVolumeInformation(argv[1], VolumeName, MAX_PATH + 1, &Serial,
120 &MaxComponentLen, &Flags, FileSystem, MAX_PATH + 1))
121 {
122 PrintErrorMessage(GetLastError());
123 return 1;
124 }
125
126 /* Display general information */
127 _ftprintf(stdout, _T("Volume name: %s\n"), VolumeName);
128 _ftprintf(stdout, _T("Volume serial number: 0x%x\n"), Serial);
129 _ftprintf(stdout, _T("Maximum component length: %u\n"), MaxComponentLen);
130 _ftprintf(stdout, _T("File system name: %s\n"), FileSystem);
131
132 /* Display specific flags */
133 HANDLE_FLAG(Flags, FILE_CASE_SENSITIVE_SEARCH, _T("Supports case-sensitive file names\n"));
134 HANDLE_FLAG(Flags, FILE_CASE_PRESERVED_NAMES, _T("Supports preserved case of file names\n"));
135 HANDLE_FLAG(Flags, FILE_UNICODE_ON_DISK, _T("Supports unicode file names\n"));
136 HANDLE_FLAG(Flags, FILE_PERSISTENT_ACLS, _T("Preserves and applies ACLs\n"));
137 HANDLE_FLAG(Flags, FILE_FILE_COMPRESSION, _T("Supports compression per file\n"));
138 HANDLE_FLAG(Flags, FILE_VOLUME_QUOTAS, _T("Supports disk quotas\n"));
139 HANDLE_FLAG(Flags, FILE_SUPPORTS_SPARSE_FILES, _T("Supports sparse files\n"));
140 HANDLE_FLAG(Flags, FILE_SUPPORTS_REPARSE_POINTS, _T("Supports reparse points\n"));
141 HANDLE_FLAG(Flags, FILE_VOLUME_IS_COMPRESSED, _T("Is a compressed volume\n"));
142 HANDLE_FLAG(Flags, FILE_SUPPORTS_OBJECT_IDS, _T("Supports object identifiers\n"));
143 HANDLE_FLAG(Flags, FILE_SUPPORTS_ENCRYPTION, _T("Supports the Encrypted File System (EFS)\n"));
144 HANDLE_FLAG(Flags, FILE_NAMED_STREAMS, _T("Supports named streams\n"));
145 HANDLE_FLAG(Flags, FILE_READ_ONLY_VOLUME, _T("Is a read-only volume\n"));
146 HANDLE_FLAG(Flags, FILE_SEQUENTIAL_WRITE_ONCE, _T("Supports a single sequential write\n"));
147 HANDLE_FLAG(Flags, FILE_SUPPORTS_TRANSACTIONS, _T("Supports transactions\n"));
148 HANDLE_FLAG(Flags, FILE_SUPPORTS_HARD_LINKS, _T("Supports hard links\n"));
149 HANDLE_FLAG(Flags, FILE_SUPPORTS_EXTENDED_ATTRIBUTES, _T("Supports extended attributes\n"));
150 HANDLE_FLAG(Flags, FILE_SUPPORTS_OPEN_BY_FILE_ID, _T("Supports opening files per file identifier\n"));
151 HANDLE_FLAG(Flags, FILE_SUPPORTS_USN_JOURNAL, _T("Supports Update Sequence Number (USN) journals\n"));
152 HANDLE_FLAG(Flags, FILE_DAX_VOLUME, _T("Is a direct access volume\n"));
153
154 #undef HANDLE_FLAGS
155
156 return 0;
157 }
158
159 static void
160 PrintUsage(const TCHAR * Command)
161 {
162 PrintDefaultUsage(_T(" FSINFO "), Command, (HandlerItem *)&HandlersList,
163 (sizeof(HandlersList) / sizeof(HandlersList[0])));
164 }
165
166 int
167 FsInfoMain(int argc, const TCHAR *argv[])
168 {
169 return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
170 (sizeof(HandlersList) / sizeof(HandlersList[0])),
171 PrintUsage);
172 }