1212#include <debug.h>
1313
1414static
15- BOOL
15+ VOID
1616ShowFileSystemInfo (
17- PVOLENTRY VolumeEntry )
17+ _In_ PVOLENTRY VolumeEntry )
1818{
19- WCHAR VolumeNameBuffer [MAX_PATH ];
20- UNICODE_STRING VolumeName ;
21- HANDLE VolumeHandle ;
22- OBJECT_ATTRIBUTES ObjectAttributes ;
23- IO_STATUS_BLOCK IoStatusBlock ;
24- ULONG ulSize , ulClusterSize = 0 ;
25- FILE_FS_FULL_SIZE_INFORMATION SizeInfo ;
26- FILE_FS_FULL_SIZE_INFORMATION FullSizeInfo ;
27- PFILE_FS_ATTRIBUTE_INFORMATION pAttributeInfo = NULL ;
28- NTSTATUS Status ;
29- BOOL Result = TRUE;
30-
31- wcscpy (VolumeNameBuffer , VolumeEntry -> DeviceName );
32- wcscat (VolumeNameBuffer , L"\\" );
33-
34- RtlInitUnicodeString (& VolumeName , VolumeNameBuffer );
35-
36- InitializeObjectAttributes (& ObjectAttributes ,
37- & VolumeName ,
38- 0 ,
39- NULL ,
40- NULL );
41-
42- Status = NtOpenFile (& VolumeHandle ,
43- SYNCHRONIZE ,
44- & ObjectAttributes ,
45- & IoStatusBlock ,
46- 0 ,
47- FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT );
48- if (!NT_SUCCESS (Status ))
49- {
50- if (Status == STATUS_NO_MEDIA_IN_DEVICE )
51- {
52- ConResPuts (StdOut , IDS_ERROR_NO_MEDIUM );
53- return FALSE;
54- }
55- else if (Status == STATUS_UNRECOGNIZED_VOLUME )
56- {
57- ConResPuts (StdOut , IDS_FILESYSTEMS_CURRENT );
58- ConPuts (StdOut , L"\n" );
59- ConResPrintf (StdOut , IDS_FILESYSTEMS_TYPE , L"RAW" );
60- ConResPrintf (StdOut , IDS_FILESYSTEMS_CLUSTERSIZE , 512 );
61- }
19+ WCHAR szBuffer [32 ];
20+ PWSTR pszSizeUnit = L"" ;
21+ ULONG ulClusterSize ;
6222
63- return TRUE;
64- }
65-
66- ulSize = sizeof (FILE_FS_ATTRIBUTE_INFORMATION ) + 255 * sizeof (WCHAR );
67- pAttributeInfo = RtlAllocateHeap (RtlGetProcessHeap (),
68- HEAP_ZERO_MEMORY ,
69- ulSize );
70- if (pAttributeInfo == NULL )
71- {
72- Result = FALSE;
73- goto done ;
74- }
23+ ConResPuts (StdOut , IDS_FILESYSTEMS_CURRENT );
24+ ConPuts (StdOut , L"\n" );
7525
76- Status = NtQueryVolumeInformationFile (VolumeHandle ,
77- & IoStatusBlock ,
78- pAttributeInfo ,
79- ulSize ,
80- FileFsAttributeInformation );
81- if (!NT_SUCCESS (Status ))
82- {
83- Result = FALSE;
84- goto done ;
85- }
26+ ConResPrintf (StdOut , IDS_FILESYSTEMS_TYPE , VolumeEntry -> pszFilesystem );
8627
87- Status = NtQueryVolumeInformationFile (VolumeHandle ,
88- & IoStatusBlock ,
89- & FullSizeInfo ,
90- sizeof (FILE_FS_FULL_SIZE_INFORMATION ),
91- FileFsFullSizeInformation );
92- if (NT_SUCCESS (Status ))
28+ ulClusterSize = VolumeEntry -> SectorsPerAllocationUnit * VolumeEntry -> BytesPerSector ;
29+ if (ulClusterSize >= SIZE_10MB ) /* 10 MB */
9330 {
94- ulClusterSize = FullSizeInfo .BytesPerSector * FullSizeInfo .SectorsPerAllocationUnit ;
31+ ulClusterSize = RoundingDivide (ulClusterSize , SIZE_1MB );
32+ pszSizeUnit = L"MB" ;
9533 }
96- else
34+ else if ( ulClusterSize >= SIZE_10KB ) /* 10 KB */
9735 {
98- Status = NtQueryVolumeInformationFile (VolumeHandle ,
99- & IoStatusBlock ,
100- & SizeInfo ,
101- sizeof (FILE_FS_SIZE_INFORMATION ),
102- FileFsSizeInformation );
103- if (NT_SUCCESS (Status ))
104- {
105- ulClusterSize = SizeInfo .BytesPerSector * SizeInfo .SectorsPerAllocationUnit ;
106- }
36+ ulClusterSize = RoundingDivide (ulClusterSize , SIZE_1KB );
37+ pszSizeUnit = L"KB" ;
10738 }
10839
109-
110- ConResPuts (StdOut , IDS_FILESYSTEMS_CURRENT );
111- ConPuts (StdOut , L"\n" );
112-
113- ConResPrintf (StdOut , IDS_FILESYSTEMS_TYPE , pAttributeInfo -> FileSystemName );
114- ConResPrintf (StdOut , IDS_FILESYSTEMS_CLUSTERSIZE , ulClusterSize );
40+ wsprintf (szBuffer , L"%lu %s" , ulClusterSize , pszSizeUnit );
41+ ConResPrintf (StdOut , IDS_FILESYSTEMS_CLUSTERSIZE , szBuffer );
42+ ConResPrintf (StdOut , IDS_FILESYSTEMS_SERIAL_NUMBER , VolumeEntry -> SerialNumber );
11543 ConPuts (StdOut , L"\n" );
116-
117- done :
118- if (pAttributeInfo )
119- RtlFreeHeap (RtlGetProcessHeap (), 0 , pAttributeInfo );
120-
121- NtClose (VolumeHandle );
122-
123- return Result ;
12444}
12545
46+
12647static
12748VOID
128- ShowInstalledFileSystems (VOID )
49+ ShowInstalledFileSystems (
50+ _In_ PVOLENTRY VolumeEntry )
12951{
13052 WCHAR szBuffer [256 ];
53+ WCHAR szDefault [32 ];
13154 BOOLEAN ret ;
13255 DWORD dwIndex ;
13356 UCHAR uMajor , uMinor ;
13457 BOOLEAN bLatest ;
13558
59+ LoadStringW (GetModuleHandle (NULL ),
60+ IDS_FILESYSTEMS_DEFAULT ,
61+ szDefault , ARRAYSIZE (szDefault ));
62+
13663 ConResPuts (StdOut , IDS_FILESYSTEMS_FORMATTING );
64+ ConPuts (StdOut , L"\n" );
13765
13866 for (dwIndex = 0 ; ; dwIndex ++ )
13967 {
14068 ret = QueryAvailableFileSystemFormat (dwIndex ,
14169 szBuffer ,
14270 & uMajor ,
14371 & uMinor ,
144- & bLatest );
72+ & bLatest );
14573 if (ret == FALSE)
14674 break ;
14775
148- ConPrintf ( StdOut , L" %s\n" , szBuffer );
149- }
76+ if ( wcscmp ( szBuffer , L"FAT" ) == 0 )
77+ wcscat ( szBuffer , szDefault );
15078
151- ConPuts (StdOut , L"\n" );
79+ ConResPrintf (StdOut , IDS_FILESYSTEMS_TYPE , szBuffer );
80+ wcscpy (szBuffer , L"-" );
81+ ConResPrintf (StdOut , IDS_FILESYSTEMS_CLUSTERSIZE , szBuffer );
82+ ConPuts (StdOut , L"\n" );
83+ }
15284}
15385
86+
15487BOOL
15588filesystems_main (
15689 _In_ INT argc ,
@@ -164,10 +97,8 @@ filesystems_main(
16497
16598 ConPuts (StdOut , L"\n" );
16699
167- if (ShowFileSystemInfo (CurrentVolume ))
168- {
169- ShowInstalledFileSystems ();
170- }
100+ ShowFileSystemInfo (CurrentVolume );
101+ ShowInstalledFileSystems (CurrentVolume );
171102
172103 return TRUE;
173104}
0 commit comments