[KMTESTS:KE]
[reactos.git] / rostests / kmtests / npfs / NpfsVolumeInfo.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite NPFS volume information test
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <kmt_test.h>
9 #include "npfs.h"
10
11 #define MAX_INSTANCES 1
12 #define IN_QUOTA 4096
13 #define OUT_QUOTA 4096
14
15 static
16 VOID
17 TestVolumeInfo(
18 IN HANDLE ServerHandle)
19 {
20 NTSTATUS Status;
21 IO_STATUS_BLOCK IoStatusBlock;
22 FILE_FS_SIZE_INFORMATION FileFsSizeInfo;
23 FILE_FS_DEVICE_INFORMATION FileFsDeviceInfo;
24 FILE_FS_FULL_SIZE_INFORMATION FileFsFullSizeInfo;
25
26 struct {
27 FILE_FS_VOLUME_INFORMATION;
28 WCHAR PartialName[10];
29 } VolumeInfo;
30
31 struct {
32 FILE_FS_ATTRIBUTE_INFORMATION;
33 WCHAR PartialName[6];
34 } AttributeInfo;
35
36 RtlFillMemory(&VolumeInfo, sizeof(VolumeInfo), 0xFF);
37 Status = ZwQueryVolumeInformationFile(ServerHandle,
38 &IoStatusBlock,
39 &VolumeInfo,
40 sizeof(VolumeInfo),
41 FileFsVolumeInformation);
42 ok_eq_hex(Status, STATUS_SUCCESS);
43 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
44 ok_eq_long(VolumeInfo.VolumeCreationTime.LowPart, 0);
45 ok_eq_long(VolumeInfo.VolumeCreationTime.HighPart, 0);
46 ok_eq_ulong(VolumeInfo.VolumeSerialNumber, 0);
47 ok_bool_false(VolumeInfo.SupportsObjects, "VolumeInfo.SupportsObjects");
48 ok_eq_ulong(VolumeInfo.VolumeLabelLength, 18);
49 ok_eq_size(RtlCompareMemory(VolumeInfo.VolumeLabel, L"NamedPipe", 18), 18);
50 ok_eq_wchar(VolumeInfo.VolumeLabel[9], 0xFFFF);
51 ok_eq_ulong(IoStatusBlock.Information, (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + 9 * sizeof(WCHAR)));
52
53 RtlFillMemory(&VolumeInfo, sizeof(VolumeInfo), 0xFF);
54 Status = ZwQueryVolumeInformationFile(ServerHandle,
55 &IoStatusBlock,
56 &VolumeInfo,
57 sizeof(FILE_FS_VOLUME_INFORMATION) + 2 * sizeof(WCHAR),
58 FileFsVolumeInformation);
59 ok_eq_hex(Status, STATUS_BUFFER_OVERFLOW);
60 ok_eq_hex(IoStatusBlock.Status, STATUS_BUFFER_OVERFLOW);
61 ok_eq_long(VolumeInfo.VolumeCreationTime.LowPart, 0);
62 ok_eq_long(VolumeInfo.VolumeCreationTime.HighPart, 0);
63 ok_eq_ulong(VolumeInfo.VolumeSerialNumber, 0);
64 ok_bool_false(VolumeInfo.SupportsObjects, "VolumeInfo.SupportsObjects");
65 ok_eq_ulong(VolumeInfo.VolumeLabelLength, 18);
66 ok_eq_size(RtlCompareMemory(VolumeInfo.VolumeLabel, L"NamedP", 10), 10);
67 ok_eq_wchar(VolumeInfo.VolumeLabel[5], 0xFFFF);
68 ok_eq_ulong(IoStatusBlock.Information, (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + 5 * sizeof(WCHAR)));
69
70 RtlFillMemory(&FileFsSizeInfo, sizeof(FileFsSizeInfo), 0xFF);
71 Status = ZwQueryVolumeInformationFile(ServerHandle,
72 &IoStatusBlock,
73 &FileFsSizeInfo,
74 sizeof(FileFsSizeInfo),
75 FileFsSizeInformation);
76 ok_eq_hex(Status, STATUS_SUCCESS);
77 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
78 ok_eq_longlong(FileFsSizeInfo.TotalAllocationUnits.QuadPart, 0);
79 ok_eq_longlong(FileFsSizeInfo.AvailableAllocationUnits.QuadPart, 0);
80 ok_eq_ulong(FileFsSizeInfo.SectorsPerAllocationUnit, 1);
81 ok_eq_ulong(FileFsSizeInfo.BytesPerSector, 1);
82 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsSizeInfo));
83
84 RtlFillMemory(&FileFsSizeInfo, sizeof(FileFsSizeInfo), 0xFF);
85 Status = ZwQueryVolumeInformationFile(ServerHandle,
86 &IoStatusBlock,
87 &FileFsSizeInfo,
88 sizeof(FileFsSizeInfo) - 4,
89 FileFsSizeInformation);
90 ok_eq_hex(Status, STATUS_SUCCESS);
91 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
92 ok_eq_longlong(FileFsSizeInfo.TotalAllocationUnits.QuadPart, 0);
93 ok_eq_longlong(FileFsSizeInfo.AvailableAllocationUnits.QuadPart, 0);
94 ok_eq_ulong(FileFsSizeInfo.SectorsPerAllocationUnit, 1);
95 ok_eq_ulong(FileFsSizeInfo.BytesPerSector, 1);
96 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsSizeInfo));
97
98 RtlFillMemory(&FileFsDeviceInfo, sizeof(FileFsDeviceInfo), 0xFF);
99 Status = ZwQueryVolumeInformationFile(ServerHandle,
100 &IoStatusBlock,
101 &FileFsDeviceInfo,
102 sizeof(FileFsDeviceInfo),
103 FileFsDeviceInformation);
104 ok_eq_hex(Status, STATUS_SUCCESS);
105 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
106 ok_eq_ulong(FileFsDeviceInfo.Characteristics, 0);
107 ok_eq_ulong(FileFsDeviceInfo.DeviceType, FILE_DEVICE_NAMED_PIPE);
108 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsDeviceInfo));
109
110 RtlFillMemory(&FileFsDeviceInfo, sizeof(FileFsDeviceInfo), 0xFF);
111 Status = ZwQueryVolumeInformationFile(ServerHandle,
112 &IoStatusBlock,
113 &FileFsDeviceInfo,
114 sizeof(FileFsDeviceInfo) - 4,
115 FileFsDeviceInformation);
116 ok_eq_hex(Status, STATUS_SUCCESS);
117 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
118 ok_eq_ulong(FileFsDeviceInfo.Characteristics, 0);
119 ok_eq_ulong(FileFsDeviceInfo.DeviceType, FILE_DEVICE_NAMED_PIPE);
120 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsDeviceInfo));
121
122 RtlFillMemory(&AttributeInfo, sizeof(AttributeInfo), 0xFF);
123 Status = ZwQueryVolumeInformationFile(ServerHandle,
124 &IoStatusBlock,
125 &AttributeInfo,
126 sizeof(AttributeInfo),
127 FileFsAttributeInformation);
128 ok_eq_hex(Status, STATUS_SUCCESS);
129 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
130 ok_eq_ulong(AttributeInfo.FileSystemAttributes, FILE_CASE_PRESERVED_NAMES);
131 ok_eq_long(AttributeInfo.MaximumComponentNameLength, 0xFFFFFFFF);
132 ok_eq_ulong(AttributeInfo.FileSystemNameLength, 8);
133 ok_eq_size(RtlCompareMemory(AttributeInfo.FileSystemName, L"NPFS", 8), 8);
134 ok_eq_wchar(AttributeInfo.FileSystemName[4], 0xFFFF);
135 ok_eq_ulong(IoStatusBlock.Information, 20);
136
137 RtlFillMemory(&AttributeInfo, sizeof(AttributeInfo), 0xFF);
138 Status = ZwQueryVolumeInformationFile(ServerHandle,
139 &IoStatusBlock,
140 &AttributeInfo,
141 sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 2 * sizeof(WCHAR),
142 FileFsAttributeInformation);
143 ok_eq_hex(Status, STATUS_SUCCESS);
144 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
145 ok_eq_ulong(AttributeInfo.FileSystemAttributes, FILE_CASE_PRESERVED_NAMES);
146 ok_eq_long(AttributeInfo.MaximumComponentNameLength, 0xFFFFFFFF);
147 ok_eq_ulong(AttributeInfo.FileSystemNameLength, 8);
148 ok_eq_size(RtlCompareMemory(AttributeInfo.FileSystemName, L"NPFS", 8), 8);
149 ok_eq_wchar(AttributeInfo.FileSystemName[4], 0xFFFF);
150 ok_eq_ulong(IoStatusBlock.Information, 20);
151
152 RtlFillMemory(&FileFsFullSizeInfo, sizeof(FileFsFullSizeInfo), 0xFF);
153 Status = ZwQueryVolumeInformationFile(ServerHandle,
154 &IoStatusBlock,
155 &FileFsFullSizeInfo,
156 sizeof(FileFsFullSizeInfo),
157 FileFsFullSizeInformation);
158 ok_eq_hex(Status, STATUS_SUCCESS);
159 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
160 ok_eq_longlong(FileFsFullSizeInfo.TotalAllocationUnits.QuadPart, 0);
161 ok_eq_longlong(FileFsFullSizeInfo.CallerAvailableAllocationUnits.QuadPart, 0);
162 ok_eq_longlong(FileFsFullSizeInfo.ActualAvailableAllocationUnits.QuadPart, 0);
163 ok_eq_ulong(FileFsFullSizeInfo.SectorsPerAllocationUnit, 0);
164 ok_eq_ulong(FileFsFullSizeInfo.BytesPerSector, 0);
165 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsFullSizeInfo));
166
167 RtlFillMemory(&FileFsFullSizeInfo, sizeof(FileFsFullSizeInfo), 0xFF);
168 Status = ZwQueryVolumeInformationFile(ServerHandle,
169 &IoStatusBlock,
170 &FileFsFullSizeInfo,
171 sizeof(FileFsFullSizeInfo) - 4,
172 FileFsFullSizeInformation);
173 ok_eq_hex(Status, STATUS_SUCCESS);
174 ok_eq_hex(IoStatusBlock.Status, STATUS_SUCCESS);
175 ok_eq_longlong(FileFsFullSizeInfo.TotalAllocationUnits.QuadPart, 0);
176 ok_eq_longlong(FileFsFullSizeInfo.CallerAvailableAllocationUnits.QuadPart, 0);
177 ok_eq_longlong(FileFsFullSizeInfo.ActualAvailableAllocationUnits.QuadPart, 0);
178 ok_eq_ulong(FileFsFullSizeInfo.SectorsPerAllocationUnit, 0);
179 ok_eq_ulong(FileFsFullSizeInfo.BytesPerSector, 0);
180 ok_eq_ulong(IoStatusBlock.Information, sizeof(FileFsFullSizeInfo));
181 }
182
183 static KSTART_ROUTINE RunTest;
184 static
185 VOID
186 NTAPI
187 RunTest(
188 IN PVOID Context)
189 {
190 NTSTATUS Status;
191 HANDLE ServerHandle;
192
193 UNREFERENCED_PARAMETER(Context);
194
195 ServerHandle = INVALID_HANDLE_VALUE;
196 Status = NpCreatePipe(&ServerHandle,
197 DEVICE_NAMED_PIPE L"\\KmtestNpfsVolumeInfoTestPipe",
198 BYTE_STREAM, QUEUE, BYTE_STREAM, DUPLEX,
199 MAX_INSTANCES,
200 IN_QUOTA,
201 OUT_QUOTA);
202 ok_eq_hex(Status, STATUS_SUCCESS);
203 ok(ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "ServerHandle = %p\n", ServerHandle);
204 if (!skip(NT_SUCCESS(Status) && ServerHandle != NULL && ServerHandle != INVALID_HANDLE_VALUE, "No pipe\n"))
205 {
206 TestVolumeInfo(ServerHandle);
207 ObCloseHandle(ServerHandle, KernelMode);
208 }
209 }
210
211 START_TEST(NpfsVolumeInfo)
212 {
213 PKTHREAD Thread;
214
215 Thread = KmtStartThread(RunTest, NULL);
216 KmtFinishThread(Thread, NULL);
217 }