ReactOS  0.4.13-dev-698-g77671f0
Volume.c
Go to the documentation of this file.
1 /*
2 * PROJECT: Filesystem Filter Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filters/fltmgr/Context.c
5 * PURPOSE: Contains routines for the volume
6 * PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
7 */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include "fltmgr.h"
12 #include "fltmgrint.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 
18 /* DATA *********************************************************************/
19 
20 
21 
22 /* EXPORTED FUNCTIONS ******************************************************/
23 
25 FLTAPI
31 )
32 {
33  ULONG BufferRequired;
35  PCHAR Ptr;
37 
38  /* Calculate the required buffer size */
39  BufferRequired = sizeof(FLT_VOLUME_PROPERTIES) +
40  Volume->CDODriverName.Length +
41  Volume->DeviceName.Length +
42  Volume->CDODeviceName.Length;
43 
44  /* If we don't have enough buffer to fill in the fixed struct, return with the required size */
46  {
47  *LengthReturned = BufferRequired;
49  }
50 
51  /* Clear out the buffer */
52  RtlZeroMemory(VolumeProperties, sizeof(FLT_VOLUME_PROPERTIES));
53 
54  /* Fill in the fixed data */
55  VolumeProperties->DeviceType = Volume->DeviceObject->DeviceType;
56  VolumeProperties->DeviceObjectFlags = Volume->DeviceObject->Flags;
57  VolumeProperties->AlignmentRequirement = Volume->DeviceObject->AlignmentRequirement;
58  VolumeProperties->SectorSize = Volume->DeviceObject->SectorSize;
59  if (Volume->DiskDeviceObject)
60  {
61  VolumeProperties->DeviceCharacteristics = Volume->DiskDeviceObject->Characteristics;
62  }
63  else
64  {
65  VolumeProperties->DeviceCharacteristics = Volume->DeviceObject->Characteristics;
66  }
67 
68  /* So far we've written the fixed struct data */
70  Ptr = (PCHAR)(VolumeProperties + 1);
71 
72  /* Make sure we have enough room to add the dynamic data */
73  if (VolumePropertiesLength >= BufferRequired)
74  {
75  /* Add the FS device name */
76  VolumeProperties->FileSystemDeviceName.Length = 0;
77  VolumeProperties->FileSystemDeviceName.MaximumLength = Volume->CDODeviceName.Length;
78  VolumeProperties->FileSystemDeviceName.Buffer = (PWCH)Ptr;
79  RtlCopyUnicodeString(&VolumeProperties->FileSystemDeviceName, &Volume->CDODeviceName);
80  Ptr += VolumeProperties->FileSystemDeviceName.Length;
81 
82  /* Add the driver name */
83  VolumeProperties->FileSystemDriverName.Length = 0;
84  VolumeProperties->FileSystemDriverName.MaximumLength = Volume->CDODriverName.Length;
85  VolumeProperties->FileSystemDriverName.Buffer = (PWCH)Ptr;
86  RtlCopyUnicodeString(&VolumeProperties->FileSystemDriverName, &Volume->CDODriverName);
87  Ptr += VolumeProperties->FileSystemDriverName.Length;
88 
89  /* Add the volume name */
90  VolumeProperties->RealDeviceName.Length = 0;
91  VolumeProperties->RealDeviceName.MaximumLength = Volume->DeviceName.Length;
92  VolumeProperties->RealDeviceName.Buffer = (PWCH)Ptr;
93  RtlCopyUnicodeString(&VolumeProperties->RealDeviceName, &Volume->DeviceName);
94 
95  BytesWritten = BufferRequired;
96 
98  }
99  else
100  {
102  }
103 
104  /* Set the number of bytes we wrote and return */
106  return Status;
107 }
108 
109 
110 NTSTATUS
111 FLTAPI
117 {
118  ULONG i;
119  PFLTP_FRAME Frame;
121  PLIST_ENTRY ListEntry;
122  ULONG NumberOfVolumes = 0;
124 
125  PAGED_CODE();
126 
127  Frame = Filter->Frame;
128 
129  /* Lock the attached volumes list */
132 
133  /* If it's not empty */
134  if (!IsListEmpty(&Frame->AttachedVolumes.rList))
135  {
136  /* Browse every entry */
137  for (ListEntry = Frame->AttachedVolumes.rList.Flink;
138  ListEntry != &Frame->AttachedVolumes.rList;
139  ListEntry = ListEntry->Flink)
140  {
141  /* Get the volume */
142  Volume = CONTAINING_RECORD(ListEntry, FLT_VOLUME, Base.PrimaryLink);
143 
144  /* If there's still room in the output buffer */
145  if (NumberOfVolumes < VolumeListSize)
146  {
147  /* Reference the volume and return it */
149  VolumeList[NumberOfVolumes] = Volume;
150  }
151 
152  /* We returned one more volume */
153  ++NumberOfVolumes;
154  }
155  }
156 
157  /* Release the list */
160 
161  /* If we want to return more volumes than we can */
162  if (NumberOfVolumes > VolumeListSize)
163  {
164  /* We will clear output */
165  for (i = 0; i < VolumeListSize; ++i)
166  {
167  FltObjectDereference(VolumeList[i]);
168  VolumeList[i] = NULL;
169  }
170 
171  /* And set failure status */
173  }
174 
175  /* Always return the max amount of volumes we want to return */
176  *NumberVolumesReturned = NumberOfVolumes;
177 
178  /* Done */
179  return Status;
180 }
181 
182 NTSTATUS
183 FLTAPI
188 {
190  return STATUS_NOT_IMPLEMENTED;
191 }
192 
193 NTSTATUS
194 FLTAPI
200 {
202  return STATUS_NOT_IMPLEMENTED;
203 }
204 
205 NTSTATUS
206 FLTAPI
211 {
213 
214  /* Check if caller just probes for size */
215  if (VolumeName == NULL)
216  {
217  /* Totally broken call */
218  if (BufferSizeNeeded == NULL)
219  {
221  }
222 
223  /* Return the appropriate size and quit */
224  *BufferSizeNeeded = Volume->DeviceName.Length;
226  }
227 
228  /* We have an output buffer! Assume it's too small */
230 
231  /* If we have output size, fill it */
232  if (BufferSizeNeeded != NULL)
233  {
234  *BufferSizeNeeded = Volume->DeviceName.Length;
235  }
236 
237  /* Init that we didn't return a thing */
238  VolumeName->Length = 0;
239 
240  /* If we have enough room, copy and return success */
241  if (VolumeName->MaximumLength >= Volume->DeviceName.Length)
242  {
243  RtlCopyUnicodeString(VolumeName, &Volume->DeviceName);
245  }
246 
247  return Status;
248 }
249 
250 
251 /* INTERNAL FUNCTIONS ******************************************************/
signed char * PCHAR
Definition: retypes.h:7
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING _Out_opt_ PULONG BufferSizeNeeded
Definition: fltkernel.h:1117
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define _Out_writes_bytes_to_opt_(size, count)
Definition: no_sal2.h:375
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
VOID FLTAPI FltObjectDereference(_Inout_ PVOID Object)
Definition: Object.c:53
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2343
_Must_inspect_result_ _In_ ULONG _Out_ PULONG NumberVolumesReturned
Definition: fltkernel.h:1793
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_opt_ PCUNICODE_STRING _Outptr_opt_result_maybenull_ PFLT_INSTANCE * RetInstance
Definition: fltkernel.h:1162
NTSTATUS FLTAPI FltEnumerateVolumes(_In_ PFLT_FILTER Filter, _Out_writes_to_opt_(VolumeListSize, *NumberVolumesReturned) PFLT_VOLUME *VolumeList, _In_ ULONG VolumeListSize, _Out_ PULONG NumberVolumesReturned)
Definition: Volume.c:112
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define PAGED_CODE()
Definition: video.h:57
#define _In_opt_
Definition: no_sal2.h:213
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_In_ ULONG VolumePropertiesLength
Definition: fltkernel.h:1735
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1802
FLT_RESOURCE_LIST_HEAD AttachedVolumes
Definition: fltmgrint.h:80
NTSTATUS FLTAPI FltDetachVolume(_Inout_ PFLT_FILTER Filter, _Inout_ PFLT_VOLUME Volume, _In_opt_ PCUNICODE_STRING InstanceName)
Definition: Volume.c:184
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FILE_INFORMATION_CLASS _Out_opt_ PULONG LengthReturned
Definition: fltkernel.h:1306
#define _Out_
Definition: no_sal2.h:323
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define PCHAR
Definition: match.c:90
PFLTP_FRAME Frame
Definition: fltmgrint.h:99
#define _Out_opt_
Definition: no_sal2.h:339
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define _Inout_
Definition: no_sal2.h:244
NTSTATUS FLTAPI FltGetVolumeProperties(_In_ PFLT_VOLUME Volume, _Out_writes_bytes_to_opt_(VolumePropertiesLength, *LengthReturned) PFLT_VOLUME_PROPERTIES VolumeProperties, _In_ ULONG VolumePropertiesLength, _Out_ PULONG LengthReturned)
Definition: Volume.c:26
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
WCHAR * PWCH
Definition: ntbasedef.h:417
NTSTATUS FLTAPI FltAttachVolume(_Inout_ PFLT_FILTER Filter, _Inout_ PFLT_VOLUME Volume, _In_opt_ PCUNICODE_STRING InstanceName, _Outptr_opt_result_maybenull_ PFLT_INSTANCE *RetInstance)
Definition: Volume.c:195
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
NTSTATUS FLTAPI FltObjectReference(_Inout_ PVOID Object)
Definition: Object.c:41
#define _Out_writes_to_opt_(size, count)
Definition: no_sal2.h:379
_Must_inspect_result_ _In_ ULONG VolumeListSize
Definition: fltkernel.h:1793
#define _Outptr_opt_result_maybenull_
Definition: no_sal2.h:410
unsigned int * PULONG
Definition: retypes.h:1
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
Definition: fltkernel.h:1117
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_opt_ PCUNICODE_STRING InstanceName
Definition: fltkernel.h:1162
NTSTATUS FLTAPI FltGetVolumeName(_In_ PFLT_VOLUME Volume, _Inout_opt_ PUNICODE_STRING VolumeName, _Out_opt_ PULONG BufferSizeNeeded)
Definition: Volume.c:207
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2777
struct _FLT_VOLUME_PROPERTIES FLT_VOLUME_PROPERTIES
#define _Inout_opt_
Definition: no_sal2.h:258