ReactOS  0.4.13-dev-259-g5ca9c9c
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 {
30  PEXT2_VCB Vcb = NULL;
31  PIRP Irp = NULL;
32  PIO_STACK_LOCATION IoStackLocation = NULL;
33  PVOID Buffer;
34  ULONG Length;
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 
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 
98  FsVolInfo = (PFILE_FS_VOLUME_INFORMATION) Buffer;
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 =
113  _SEH2_LEAVE;
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)) {
129  _SEH2_LEAVE;
130  }
131 
132  FsSizeInfo = (PFILE_FS_SIZE_INFORMATION) Buffer;
133  FsSizeInfo->TotalAllocationUnits.QuadPart =
135  FsSizeInfo->AvailableAllocationUnits.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  {
149  PFILE_FS_DEVICE_INFORMATION FsDevInfo;
150 
151  if (Length < sizeof(FILE_FS_DEVICE_INFORMATION)) {
153  _SEH2_LEAVE;
154  }
155 
156  FsDevInfo = (PFILE_FS_DEVICE_INFORMATION) Buffer;
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 
182  if (Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION)) {
184  _SEH2_LEAVE;
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 =
205  _SEH2_LEAVE;
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 
227  if (Length < sizeof(FILE_FS_FULL_SIZE_INFORMATION)) {
229  _SEH2_LEAVE;
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 
256  PFFFSI->SectorsPerAllocationUnit =
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 
291 NTSTATUS
293 {
296  PEXT2_VCB Vcb = NULL;
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  //
316  _SEH2_LEAVE;
317  }
318 
320  ASSERT(Vcb != NULL);
321  ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
322  (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
323  ASSERT(IsMounted(Vcb));
324 
325  if (IsVcbReadOnly(Vcb)) {
327  _SEH2_LEAVE;
328  }
329 
331  &Vcb->MainResource, TRUE)) {
333  _SEH2_LEAVE;
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;
353  UNICODE_STRING LabelName ;
354 
356 
357  VolLabelInfo = (PFILE_FS_LABEL_INFORMATION) Irp->AssociatedIrp.SystemBuffer;
358  VolLabelLen = VolLabelInfo->VolumeLabelLength;
359 
360  if (VolLabelLen > (16 * sizeof(WCHAR))) {
362  _SEH2_LEAVE;
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 
378  Ext2UnicodeToOEM(Vcb, &OemName, &LabelName);
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 }
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
#define IN
Definition: typedefs.h:38
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
#define IsMounted(Vcb)
Definition: ext2fs.h:803
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1329
struct _FILE_FS_LABEL_INFORMATION * PFILE_FS_LABEL_INFORMATION
USHORT MaximumLength
Definition: env_spec_w32.h:370
BOOLEAN Ext2SaveSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:63
NTSTATUS Ext2QueryVolumeInformation(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: volinfo.c:27
_In_ PIRP Irp
Definition: csq.h:116
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
LONG NTSTATUS
Definition: precomp.h:26
struct _FILE_FS_FULL_SIZE_INFORMATION * PFILE_FS_FULL_SIZE_INFORMATION
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156
STRING OEM_STRING
Definition: umtypes.h:203
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
_SEH2_TRY
Definition: create.c:4250
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
NTSTATUS Ext2QueueRequest(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: dispatch.c:150
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
NTSTATUS Ext2UnicodeToOEM(IN PEXT2_VCB Vcb, IN OUT POEM_STRING Oem, IN PUNICODE_STRING Unicode)
Definition: misc.c:261
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
Definition: bufpool.h:45
#define SUPER_BLOCK
Definition: ext2fs.h:90
enum _FSINFOCLASS FS_INFORMATION_CLASS
#define EXT4_FEATURE_INCOMPAT_EXTENTS
Definition: ext3_fs.h:709
struct _FILE_FS_SIZE_INFORMATION * PFILE_FS_SIZE_INFORMATION
NTSTATUS Ext2SetVolumeInformation(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: volinfo.c:292
struct _FILE_FS_VOLUME_INFORMATION * PFILE_FS_VOLUME_INFORMATION
LARGE_INTEGER VolumeCreationTime
Definition: winioctl.h:408
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:805
#define FILE_CASE_SENSITIVE_SEARCH
Definition: from_kernel.h:233
#define Vcb
Definition: cdprocs.h:1425
struct _FILE_FS_ATTRIBUTE_INFORMATION * PFILE_FS_ATTRIBUTE_INFORMATION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static ext3_fsblk_t ext3_free_blocks_count(struct ext3_super_block *es)
Definition: ext2fs.h:1704
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS Ext2CompleteIrpContext(IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:32
#define EXT2_NAME_LEN
Definition: ext2.h:156
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
Status
Definition: gdiplustypes.h:24
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
unsigned short USHORT
Definition: pedump.c:61
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
_SEH2_FINALLY
Definition: create.c:4395
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
struct _FILE_FS_DEVICE_INFORMATION * PFILE_FS_DEVICE_INFORMATION
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:733
#define IsExt2FsDevice(DO)
Definition: ext2fs.h:607
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define DbgBreak()
Definition: ext2fs.h:46
struct _EXT2_VCB * PEXT2_VCB
#define _SEH2_LEAVE
Definition: filesup.c:20
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1294
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
static ext3_fsblk_t ext3_blocks_count(struct ext3_super_block *es)
Definition: ext2fs.h:1692
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2745
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
VOID Ext2VerifyVcb(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: fsctl.c:2277
#define FILE_READ_ONLY_DEVICE
Definition: nt_native.h:808
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270
LONGLONG QuadPart
Definition: typedefs.h:112
PEXT2_GLOBAL Ext2Global
Definition: init.c:16