xref: /reactos/base/system/diskpart/filesystems.c (revision 1734f297)
1 /*
2  * PROJECT:         ReactOS DiskPart
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            base/system/diskpart/filesystems.c
5  * PURPOSE:         Manages all the partitions of the OS in an interactive way.
6  * PROGRAMMERS:     Lee Schroeder
7  */
8 
9 #include "diskpart.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 static
15 BOOL
16 GetFileSystemInfo(
17     PVOLENTRY VolumeEntry)
18 {
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 
30     wcscpy(VolumeNameBuffer, VolumeEntry->DeviceName);
31     wcscat(VolumeNameBuffer, L"\\");
32 
33     RtlInitUnicodeString(&VolumeName, VolumeNameBuffer);
34 
35     InitializeObjectAttributes(&ObjectAttributes,
36                                &VolumeName,
37                                0,
38                                NULL,
39                                NULL);
40 
41     Status = NtOpenFile(&VolumeHandle,
42                         SYNCHRONIZE,
43                         &ObjectAttributes,
44                         &IoStatusBlock,
45                         0,
46                         FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT);
47     if (!NT_SUCCESS(Status))
48     {
49         if (Status == STATUS_NO_MEDIA_IN_DEVICE)
50         {
51             ConResPuts(StdOut, IDS_ERROR_NO_MEDIUM);
52             return FALSE;
53         }
54         else if (Status == STATUS_UNRECOGNIZED_VOLUME)
55         {
56             ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
57             ConPuts(StdOut, L"\n");
58             ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, L"RAW");
59             ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, 512);
60         }
61 
62         return TRUE;
63     }
64 
65     ulSize = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 255 * sizeof(WCHAR);
66     pAttributeInfo = RtlAllocateHeap(RtlGetProcessHeap(),
67                                      HEAP_ZERO_MEMORY,
68                                      ulSize);
69 
70     Status = NtQueryVolumeInformationFile(VolumeHandle,
71                                           &IoStatusBlock,
72                                           pAttributeInfo,
73                                           ulSize,
74                                           FileFsAttributeInformation);
75 
76     Status = NtQueryVolumeInformationFile(VolumeHandle,
77                                           &IoStatusBlock,
78                                           &FullSizeInfo,
79                                           sizeof(FILE_FS_FULL_SIZE_INFORMATION),
80                                           FileFsFullSizeInformation);
81     if (NT_SUCCESS(Status))
82     {
83         ulClusterSize  = FullSizeInfo.BytesPerSector * FullSizeInfo.SectorsPerAllocationUnit;
84     }
85     else
86     {
87         Status = NtQueryVolumeInformationFile(VolumeHandle,
88                                               &IoStatusBlock,
89                                               &SizeInfo,
90                                               sizeof(FILE_FS_SIZE_INFORMATION),
91                                               FileFsSizeInformation);
92         if (NT_SUCCESS(Status))
93         {
94             ulClusterSize  = SizeInfo.BytesPerSector * SizeInfo.SectorsPerAllocationUnit;
95         }
96     }
97 
98 
99     ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
100     ConPuts(StdOut, L"\n");
101 
102     ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, pAttributeInfo->FileSystemName);
103     ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, ulClusterSize);
104 
105     if (pAttributeInfo)
106         RtlFreeHeap(RtlGetProcessHeap(), 0, pAttributeInfo);
107 
108     NtClose(VolumeHandle);
109 
110     return TRUE;
111 }
112 
113 BOOL
114 filesystems_main(
115     _In_ INT argc,
116     _In_ PWSTR *argv)
117 {
118     if (CurrentVolume == NULL)
119     {
120         ConResPuts(StdOut, IDS_SELECT_NO_VOLUME);
121         return TRUE;
122     }
123 
124     ConPuts(StdOut, L"\n");
125 
126     if (GetFileSystemInfo(CurrentVolume))
127     {
128         ConPuts(StdOut, L"\n");
129         ConResPuts(StdOut, IDS_FILESYSTEMS_FORMATTING);
130 
131         /* FIXME: List available file systems */
132 
133     }
134 
135     ConPuts(StdOut, L"\n");
136 
137     return TRUE;
138 }
139