ReactOS 0.4.15-dev-8138-g1e75ea8
volinfo.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYRIGHT.TXT
3 * PROJECT: Ext2 File System Driver for WinNT/2K/XP
4 * FILE: volinfo.c
5 * PROGRAMMER: Matt Wu <mattwu@163.com>
6 * HOMEPAGE: http://www.ext2fsd.com
7 * UPDATE HISTORY:
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "ext2fs.h"
13
14/* GLOBALS ***************************************************************/
15
17
18/* DEFINITIONS *************************************************************/
19
20#ifdef ALLOC_PRAGMA
21#pragma alloc_text(PAGE, Ext2QueryVolumeInformation)
22#pragma alloc_text(PAGE, Ext2SetVolumeInformation)
23#endif
24
25
28{
31 PIRP Irp = NULL;
32 PIO_STACK_LOCATION IoStackLocation = NULL;
37 BOOLEAN VcbResourceAcquired = FALSE;
38
39 _SEH2_TRY {
40
41 ASSERT(IrpContext != NULL);
42 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
43 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
44
45 DeviceObject = IrpContext->DeviceObject;
46
47 //
48 // This request is not allowed on the main device object
49 //
53 }
54
55 Vcb = (PEXT2_VCB) DeviceObject->DeviceExtension;
56 ASSERT(Vcb != NULL);
57 ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
58 (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
59
60 if (!IsMounted(Vcb)) {
63 }
64
66 &Vcb->MainResource,
67 IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT)
68 )) {
69
72 }
73 VcbResourceAcquired = TRUE;
74
75 Irp = IrpContext->Irp;
76 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
78 IoStackLocation->Parameters.QueryVolume.FsInformationClass;
79
80 Length = IoStackLocation->Parameters.QueryVolume.Length;
81 Buffer = Irp->AssociatedIrp.SystemBuffer;
82
84
85 switch (FsInformationClass) {
86
88 {
90 ULONG VolumeLabelLength;
92
93 if (Length < sizeof(FILE_FS_VOLUME_INFORMATION)) {
96 }
97
99 FsVolInfo->VolumeCreationTime.QuadPart = 0;
100 FsVolInfo->VolumeSerialNumber = Vcb->Vpb->SerialNumber;
101 VolumeLabelLength = Vcb->Vpb->VolumeLabelLength;
102 FsVolInfo->VolumeLabelLength = VolumeLabelLength;
103 /* We don't support ObjectId */
104 FsVolInfo->SupportsObjects = FALSE;
105
107 + VolumeLabelLength - sizeof(WCHAR);
108
109 if (Length < RequiredLength) {
110 Irp->IoStatus.Information =
114 }
115
116 RtlCopyMemory(FsVolInfo->VolumeLabel, Vcb->Vpb->VolumeLabel, Vcb->Vpb->VolumeLabelLength);
117
118 Irp->IoStatus.Information = RequiredLength;
120 }
121 break;
122
124 {
125 PFILE_FS_SIZE_INFORMATION FsSizeInfo;
126
127 if (Length < sizeof(FILE_FS_SIZE_INFORMATION)) {
130 }
131
132 FsSizeInfo = (PFILE_FS_SIZE_INFORMATION) Buffer;
133 FsSizeInfo->TotalAllocationUnits.QuadPart =
137 FsSizeInfo->SectorsPerAllocationUnit =
138 Vcb->BlockSize / Vcb->DiskGeometry.BytesPerSector;
139 FsSizeInfo->BytesPerSector =
140 Vcb->DiskGeometry.BytesPerSector;
141
142 Irp->IoStatus.Information = sizeof(FILE_FS_SIZE_INFORMATION);
144 }
145 break;
146
148 {
150
151 if (Length < sizeof(FILE_FS_DEVICE_INFORMATION)) {
154 }
155
157 FsDevInfo->DeviceType =
158 Vcb->TargetDeviceObject->DeviceType;
159
160 if (FsDevInfo->DeviceType != FILE_DEVICE_DISK) {
161 DbgBreak();
162 }
163
164 FsDevInfo->Characteristics =
165 Vcb->TargetDeviceObject->Characteristics;
166
167 if (IsVcbReadOnly(Vcb)) {
168 SetFlag( FsDevInfo->Characteristics,
170 }
171
172 Irp->IoStatus.Information = sizeof(FILE_FS_DEVICE_INFORMATION);
174 }
175 break;
176
178 {
181
185 }
186
187 FsAttrInfo =
192 if (IsVcbReadOnly(Vcb)) {
194 }
196 FsAttrInfo->FileSystemNameLength = 8;
197
199 8 - sizeof(WCHAR);
200
201 if (Length < RequiredLength) {
202 Irp->IoStatus.Information =
206 }
207
208 if (IsFlagOn(SUPER_BLOCK->s_feature_incompat, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
209 RtlCopyMemory(FsAttrInfo->FileSystemName, L"EXT4\0", 10);
210 } else if (Vcb->IsExt3fs) {
211 RtlCopyMemory(FsAttrInfo->FileSystemName, L"EXT3\0", 10);
212 } else {
213 RtlCopyMemory(FsAttrInfo->FileSystemName, L"EXT2\0", 10);
214 }
215
216 Irp->IoStatus.Information = RequiredLength;
218 }
219 break;
220
221#if (_WIN32_WINNT >= 0x0500)
222
224 {
226
230 }
231
233
234 /*
235 typedef struct _FILE_FS_FULL_SIZE_INFORMATION {
236 LARGE_INTEGER TotalAllocationUnits;
237 LARGE_INTEGER CallerAvailableAllocationUnits;
238 LARGE_INTEGER ActualAvailableAllocationUnits;
239 ULONG SectorsPerAllocationUnit;
240 ULONG BytesPerSector;
241 } FILE_FS_FULL_SIZE_INFORMATION, *PFILE_FS_FULL_SIZE_INFORMATION;
242 */
243
244 {
247
250
251 /* - Vcb->SuperBlock->s_r_blocks_count; */
254 }
255
257 Vcb->BlockSize / Vcb->DiskGeometry.BytesPerSector;
258
259 PFFFSI->BytesPerSector = Vcb->DiskGeometry.BytesPerSector;
260
261 Irp->IoStatus.Information = sizeof(FILE_FS_FULL_SIZE_INFORMATION);
263 }
264 break;
265
266#endif // (_WIN32_WINNT >= 0x0500)
267
268 default:
270 break;
271 }
272
273 } _SEH2_FINALLY {
274
275 if (VcbResourceAcquired) {
276 ExReleaseResourceLite(&Vcb->MainResource);
277 }
278
279 if (!IrpContext->ExceptionInProgress) {
280 if (Status == STATUS_PENDING) {
281 Ext2QueueRequest(IrpContext);
282 } else {
283 Ext2CompleteIrpContext(IrpContext, Status);
284 }
285 }
286 } _SEH2_END;
287
288 return Status;
289}
290
293{
297 PIRP Irp;
298 PIO_STACK_LOCATION IoStackLocation;
300 BOOLEAN VcbResourceAcquired = FALSE;
301
302 _SEH2_TRY {
303
304 ASSERT(IrpContext != NULL);
305
306 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
307 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
308
309 DeviceObject = IrpContext->DeviceObject;
310
311 //
312 // This request is not allowed on the main device object
313 //
317 }
318
319 Vcb = (PEXT2_VCB) DeviceObject->DeviceExtension;
320 ASSERT(Vcb != NULL);
321 ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
322 (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
324
325 if (IsVcbReadOnly(Vcb)) {
328 }
329
331 &Vcb->MainResource, TRUE)) {
334 }
335 VcbResourceAcquired = TRUE;
336
337 Ext2VerifyVcb(IrpContext, Vcb);
338
339 Irp = IrpContext->Irp;
340 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
341
342 //Notes: SetVolume is not defined in ntddk.h of win2k ddk,
343 // But it's same to QueryVolume ....
345 IoStackLocation->Parameters./*SetVolume*/QueryVolume.FsInformationClass;
346
347 switch (FsInformationClass) {
348
350 {
351 PFILE_FS_LABEL_INFORMATION VolLabelInfo = NULL;
352 ULONG VolLabelLen;
354
356
357 VolLabelInfo = (PFILE_FS_LABEL_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
358 VolLabelLen = VolLabelInfo->VolumeLabelLength;
359
360 if (VolLabelLen > (16 * sizeof(WCHAR))) {
363 }
364
365 RtlCopyMemory( Vcb->Vpb->VolumeLabel,
366 VolLabelInfo->VolumeLabel,
367 VolLabelLen );
368
369 RtlZeroMemory(Vcb->SuperBlock->s_volume_name, 16);
370 LabelName.Buffer = VolLabelInfo->VolumeLabel;
371 LabelName.MaximumLength = (USHORT)16 * sizeof(WCHAR);
372 LabelName.Length = (USHORT)VolLabelLen;
373
374 OemName.Buffer = SUPER_BLOCK->s_volume_name;
375 OemName.Length = 0;
376 OemName.MaximumLength = 16;
377
379 Vcb->Vpb->VolumeLabelLength = (USHORT) VolLabelLen;
380
381 if (Ext2SaveSuper(IrpContext, Vcb)) {
383 }
384
385 Irp->IoStatus.Information = 0;
386 }
387 break;
388
389 default:
391 }
392
393 } _SEH2_FINALLY {
394
395 if (VcbResourceAcquired) {
396 ExReleaseResourceLite(&Vcb->MainResource);
397 }
398
399 if (!IrpContext->ExceptionInProgress) {
400 if (Status == STATUS_PENDING) {
401 Ext2QueueRequest(IrpContext);
402 } else {
403 Ext2CompleteIrpContext(IrpContext, Status);
404 }
405 }
406 } _SEH2_END;
407
408 return Status;
409}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
@ LabelName
Definition: asmpp.cpp:94
LONG NTSTATUS
Definition: precomp.h:26
#define EXT2_NAME_LEN
Definition: ext2.h:156
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
PEXT2_GLOBAL Ext2Global
Definition: init.c:16
NTSTATUS Ext2QueryVolumeInformation(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: volinfo.c:27
NTSTATUS Ext2SetVolumeInformation(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: volinfo.c:292
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
static ext3_fsblk_t ext3_blocks_count(struct ext3_super_block *es)
Definition: ext2fs.h:1745
static ext3_fsblk_t ext3_free_blocks_count(struct ext3_super_block *es)
Definition: ext2fs.h:1757
@ EXT2ICX
Definition: ext2fs.h:465
@ EXT2VCB
Definition: ext2fs.h:462
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:814
#define IsMounted(Vcb)
Definition: ext2fs.h:812
#define IsExt2FsDevice(DO)
Definition: ext2fs.h:616
NTSTATUS Ext2QueueRequest(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: dispatch.c:158
#define SUPER_BLOCK
Definition: ext2fs.h:90
VOID Ext2VerifyVcb(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: fsctl.c:2277
BOOLEAN Ext2SaveSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:67
#define DbgBreak()
Definition: ext2fs.h:46
struct _EXT2_VCB * PEXT2_VCB
NTSTATUS Ext2UnicodeToOEM(IN PEXT2_VCB Vcb, IN OUT POEM_STRING Oem, IN PUNICODE_STRING Unicode)
Definition: misc.c:261
NTSTATUS Ext2CompleteIrpContext(IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:32
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define EXT4_FEATURE_INCOMPAT_EXTENTS
Definition: ext3_fs.h:709
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1304
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1330
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
@ FileFsDeviceInformation
Definition: from_kernel.h:222
@ FileFsLabelInformation
Definition: from_kernel.h:220
@ FileFsAttributeInformation
Definition: from_kernel.h:223
@ FileFsVolumeInformation
Definition: from_kernel.h:219
@ FileFsSizeInformation
Definition: from_kernel.h:221
struct _FILE_FS_ATTRIBUTE_INFORMATION * PFILE_FS_ATTRIBUTE_INFORMATION
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
#define FILE_CASE_SENSITIVE_SEARCH
Definition: from_kernel.h:233
enum _FSINFOCLASS FS_INFORMATION_CLASS
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
struct _FILE_FS_FULL_SIZE_INFORMATION * PFILE_FS_FULL_SIZE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
struct _FILE_FS_SIZE_INFORMATION * PFILE_FS_SIZE_INFORMATION
Status
Definition: gdiplustypes.h:25
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
struct _FILE_FS_DEVICE_INFORMATION * PFILE_FS_DEVICE_INFORMATION
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_READ_ONLY_DEVICE
Definition: nt_native.h:808
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:747
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define Vcb
Definition: cdprocs.h:1415
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
struct _FILE_FS_VOLUME_INFORMATION * PFILE_FS_VOLUME_INFORMATION
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
LARGE_INTEGER VolumeCreationTime
Definition: winioctl.h:408
struct _IO_STACK_LOCATION::@3983::@3996 QueryVolume
union _IO_STACK_LOCATION::@1568 Parameters
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156
STRING OEM_STRING
Definition: umtypes.h:203
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:30
struct _FILE_FS_LABEL_INFORMATION * PFILE_FS_LABEL_INFORMATION
__wchar_t WCHAR
Definition: xmlstorage.h:180