1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS DiskPart
3c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4c2c66affSColin Finck * FILE: base/system/diskpart/filesystems.c
5c2c66affSColin Finck * PURPOSE: Manages all the partitions of the OS in an interactive way.
6c2c66affSColin Finck * PROGRAMMERS: Lee Schroeder
7c2c66affSColin Finck */
8c2c66affSColin Finck
9c2c66affSColin Finck #include "diskpart.h"
10c2c66affSColin Finck
11be88af54SEric Kohl #define NDEBUG
12be88af54SEric Kohl #include <debug.h>
13be88af54SEric Kohl
14f79ec61bSEric Kohl static
15f79ec61bSEric Kohl BOOL
ShowFileSystemInfo(PVOLENTRY VolumeEntry)16*cb582efdSEric Kohl ShowFileSystemInfo(
17f79ec61bSEric Kohl PVOLENTRY VolumeEntry)
18f79ec61bSEric Kohl {
19f79ec61bSEric Kohl WCHAR VolumeNameBuffer[MAX_PATH];
20f79ec61bSEric Kohl UNICODE_STRING VolumeName;
21f79ec61bSEric Kohl HANDLE VolumeHandle;
22f79ec61bSEric Kohl OBJECT_ATTRIBUTES ObjectAttributes;
23f79ec61bSEric Kohl IO_STATUS_BLOCK IoStatusBlock;
24f79ec61bSEric Kohl ULONG ulSize, ulClusterSize = 0;
25f79ec61bSEric Kohl FILE_FS_FULL_SIZE_INFORMATION SizeInfo;
26f79ec61bSEric Kohl FILE_FS_FULL_SIZE_INFORMATION FullSizeInfo;
27f79ec61bSEric Kohl PFILE_FS_ATTRIBUTE_INFORMATION pAttributeInfo = NULL;
28f79ec61bSEric Kohl NTSTATUS Status;
29*cb582efdSEric Kohl BOOL Result = TRUE;
30f79ec61bSEric Kohl
31f79ec61bSEric Kohl wcscpy(VolumeNameBuffer, VolumeEntry->DeviceName);
32f79ec61bSEric Kohl wcscat(VolumeNameBuffer, L"\\");
33f79ec61bSEric Kohl
34f79ec61bSEric Kohl RtlInitUnicodeString(&VolumeName, VolumeNameBuffer);
35f79ec61bSEric Kohl
36f79ec61bSEric Kohl InitializeObjectAttributes(&ObjectAttributes,
37f79ec61bSEric Kohl &VolumeName,
38f79ec61bSEric Kohl 0,
39f79ec61bSEric Kohl NULL,
40f79ec61bSEric Kohl NULL);
41f79ec61bSEric Kohl
42f79ec61bSEric Kohl Status = NtOpenFile(&VolumeHandle,
43f79ec61bSEric Kohl SYNCHRONIZE,
44f79ec61bSEric Kohl &ObjectAttributes,
45f79ec61bSEric Kohl &IoStatusBlock,
46f79ec61bSEric Kohl 0,
47f79ec61bSEric Kohl FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_FOR_BACKUP_INTENT);
48f79ec61bSEric Kohl if (!NT_SUCCESS(Status))
49f79ec61bSEric Kohl {
50f79ec61bSEric Kohl if (Status == STATUS_NO_MEDIA_IN_DEVICE)
51f79ec61bSEric Kohl {
52f79ec61bSEric Kohl ConResPuts(StdOut, IDS_ERROR_NO_MEDIUM);
53f79ec61bSEric Kohl return FALSE;
54f79ec61bSEric Kohl }
55f79ec61bSEric Kohl else if (Status == STATUS_UNRECOGNIZED_VOLUME)
56f79ec61bSEric Kohl {
57f79ec61bSEric Kohl ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
58f79ec61bSEric Kohl ConPuts(StdOut, L"\n");
59f79ec61bSEric Kohl ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, L"RAW");
60f79ec61bSEric Kohl ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, 512);
61f79ec61bSEric Kohl }
62f79ec61bSEric Kohl
63f79ec61bSEric Kohl return TRUE;
64f79ec61bSEric Kohl }
65f79ec61bSEric Kohl
66f79ec61bSEric Kohl ulSize = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 255 * sizeof(WCHAR);
67f79ec61bSEric Kohl pAttributeInfo = RtlAllocateHeap(RtlGetProcessHeap(),
68f79ec61bSEric Kohl HEAP_ZERO_MEMORY,
69f79ec61bSEric Kohl ulSize);
70*cb582efdSEric Kohl if (pAttributeInfo == NULL)
71*cb582efdSEric Kohl {
72*cb582efdSEric Kohl Result = FALSE;
73*cb582efdSEric Kohl goto done;
74*cb582efdSEric Kohl }
75f79ec61bSEric Kohl
76f79ec61bSEric Kohl Status = NtQueryVolumeInformationFile(VolumeHandle,
77f79ec61bSEric Kohl &IoStatusBlock,
78f79ec61bSEric Kohl pAttributeInfo,
79f79ec61bSEric Kohl ulSize,
80f79ec61bSEric Kohl FileFsAttributeInformation);
81*cb582efdSEric Kohl if (!NT_SUCCESS(Status))
82*cb582efdSEric Kohl {
83*cb582efdSEric Kohl Result = FALSE;
84*cb582efdSEric Kohl goto done;
85*cb582efdSEric Kohl }
86f79ec61bSEric Kohl
87f79ec61bSEric Kohl Status = NtQueryVolumeInformationFile(VolumeHandle,
88f79ec61bSEric Kohl &IoStatusBlock,
89f79ec61bSEric Kohl &FullSizeInfo,
90f79ec61bSEric Kohl sizeof(FILE_FS_FULL_SIZE_INFORMATION),
91f79ec61bSEric Kohl FileFsFullSizeInformation);
92f79ec61bSEric Kohl if (NT_SUCCESS(Status))
93f79ec61bSEric Kohl {
94f79ec61bSEric Kohl ulClusterSize = FullSizeInfo.BytesPerSector * FullSizeInfo.SectorsPerAllocationUnit;
95f79ec61bSEric Kohl }
96f79ec61bSEric Kohl else
97f79ec61bSEric Kohl {
98f79ec61bSEric Kohl Status = NtQueryVolumeInformationFile(VolumeHandle,
99f79ec61bSEric Kohl &IoStatusBlock,
100f79ec61bSEric Kohl &SizeInfo,
101f79ec61bSEric Kohl sizeof(FILE_FS_SIZE_INFORMATION),
102f79ec61bSEric Kohl FileFsSizeInformation);
103f79ec61bSEric Kohl if (NT_SUCCESS(Status))
104f79ec61bSEric Kohl {
105f79ec61bSEric Kohl ulClusterSize = SizeInfo.BytesPerSector * SizeInfo.SectorsPerAllocationUnit;
106f79ec61bSEric Kohl }
107f79ec61bSEric Kohl }
108f79ec61bSEric Kohl
109f79ec61bSEric Kohl
110f79ec61bSEric Kohl ConResPuts(StdOut, IDS_FILESYSTEMS_CURRENT);
111f79ec61bSEric Kohl ConPuts(StdOut, L"\n");
112f79ec61bSEric Kohl
113f79ec61bSEric Kohl ConResPrintf(StdOut, IDS_FILESYSTEMS_TYPE, pAttributeInfo->FileSystemName);
114f79ec61bSEric Kohl ConResPrintf(StdOut, IDS_FILESYSTEMS_CLUSTERSIZE, ulClusterSize);
115*cb582efdSEric Kohl ConPuts(StdOut, L"\n");
116f79ec61bSEric Kohl
117*cb582efdSEric Kohl done:
118f79ec61bSEric Kohl if (pAttributeInfo)
119f79ec61bSEric Kohl RtlFreeHeap(RtlGetProcessHeap(), 0, pAttributeInfo);
120f79ec61bSEric Kohl
121f79ec61bSEric Kohl NtClose(VolumeHandle);
122f79ec61bSEric Kohl
123*cb582efdSEric Kohl return Result;
124*cb582efdSEric Kohl }
125*cb582efdSEric Kohl
126*cb582efdSEric Kohl static
127*cb582efdSEric Kohl VOID
ShowInstalledFileSystems(VOID)128*cb582efdSEric Kohl ShowInstalledFileSystems(VOID)
129*cb582efdSEric Kohl {
130*cb582efdSEric Kohl WCHAR szBuffer[256];
131*cb582efdSEric Kohl BOOLEAN ret;
132*cb582efdSEric Kohl DWORD dwIndex;
133*cb582efdSEric Kohl UCHAR uMajor, uMinor;
134*cb582efdSEric Kohl BOOLEAN bLatest;
135*cb582efdSEric Kohl
136*cb582efdSEric Kohl ConResPuts(StdOut, IDS_FILESYSTEMS_FORMATTING);
137*cb582efdSEric Kohl
138*cb582efdSEric Kohl for (dwIndex = 0; ; dwIndex++)
139*cb582efdSEric Kohl {
140*cb582efdSEric Kohl ret = QueryAvailableFileSystemFormat(dwIndex,
141*cb582efdSEric Kohl szBuffer,
142*cb582efdSEric Kohl &uMajor,
143*cb582efdSEric Kohl &uMinor,
144*cb582efdSEric Kohl &bLatest);
145*cb582efdSEric Kohl if (ret == FALSE)
146*cb582efdSEric Kohl break;
147*cb582efdSEric Kohl
148*cb582efdSEric Kohl ConPrintf(StdOut, L" %s\n", szBuffer);
149*cb582efdSEric Kohl }
150*cb582efdSEric Kohl
151*cb582efdSEric Kohl ConPuts(StdOut, L"\n");
152f79ec61bSEric Kohl }
153be88af54SEric Kohl
154be88af54SEric Kohl BOOL
filesystems_main(_In_ INT argc,_In_ PWSTR * argv)155be88af54SEric Kohl filesystems_main(
156be88af54SEric Kohl _In_ INT argc,
157be88af54SEric Kohl _In_ PWSTR *argv)
158c2c66affSColin Finck {
159be88af54SEric Kohl if (CurrentVolume == NULL)
160be88af54SEric Kohl {
161be88af54SEric Kohl ConResPuts(StdOut, IDS_SELECT_NO_VOLUME);
162be88af54SEric Kohl return TRUE;
163be88af54SEric Kohl }
164be88af54SEric Kohl
165be88af54SEric Kohl ConPuts(StdOut, L"\n");
166be88af54SEric Kohl
167*cb582efdSEric Kohl if (ShowFileSystemInfo(CurrentVolume))
168f79ec61bSEric Kohl {
169*cb582efdSEric Kohl ShowInstalledFileSystems();
170f79ec61bSEric Kohl }
171f79ec61bSEric Kohl
172c2c66affSColin Finck return TRUE;
173c2c66affSColin Finck }
174