ReactOS 0.4.16-dev-311-g9382aa2
rawfs.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for rawfs.c:

Go to the source code of this file.

Classes

struct  _VCB
 
struct  _VOLUME_DEVICE_OBJECT
 

Macros

#define NDEBUG
 
#define VCB_STATE_LOCKED   0x00000001
 
#define VCB_STATE_DISMOUNTED   0x00000002
 

Typedefs

typedef struct _VCB VCB
 
typedef struct _VCBPVCB
 
typedef struct _VOLUME_DEVICE_OBJECT VOLUME_DEVICE_OBJECT
 
typedef struct _VOLUME_DEVICE_OBJECTPVOLUME_DEVICE_OBJECT
 

Functions

NTSTATUS NTAPI RawInitializeVcb (IN OUT PVCB Vcb, IN PDEVICE_OBJECT TargetDeviceObject, IN PVPB Vpb)
 
BOOLEAN NTAPI RawCheckForDismount (IN PVCB Vcb, IN BOOLEAN CreateOperation)
 
NTSTATUS NTAPI RawCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI RawClose (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawCreate (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawReadWriteDeviceControl (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawMountVolume (IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawUserFsCtrl (IN PIO_STACK_LOCATION IoStackLocation, IN PVCB Vcb)
 
NTSTATUS NTAPI RawFileSystemControl (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawQueryInformation (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawSetInformation (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawQueryFsVolumeInfo (IN PVCB Vcb, IN PFILE_FS_VOLUME_INFORMATION Buffer, IN OUT PULONG Length)
 
NTSTATUS NTAPI RawQueryFsSizeInfo (IN PVCB Vcb, IN PFILE_FS_SIZE_INFORMATION Buffer, IN OUT PULONG Length)
 
NTSTATUS NTAPI RawQueryFsDeviceInfo (IN PVCB Vcb, IN PFILE_FS_DEVICE_INFORMATION Buffer, IN OUT PULONG Length)
 
NTSTATUS NTAPI RawQueryFsAttributeInfo (IN PVCB Vcb, IN PFILE_FS_ATTRIBUTE_INFORMATION Buffer, IN OUT PULONG Length)
 
NTSTATUS NTAPI RawQueryVolumeInformation (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawCleanup (IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
 
NTSTATUS NTAPI RawDispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI RawShutdown (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI RawUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI RawFsDriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

PDEVICE_OBJECT RawDiskDeviceObject
 
PDEVICE_OBJECT RawCdromDeviceObject
 
PDEVICE_OBJECT RawTapeDeviceObject
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file rawfs.c.

◆ VCB_STATE_DISMOUNTED

#define VCB_STATE_DISMOUNTED   0x00000002

Definition at line 39 of file rawfs.c.

◆ VCB_STATE_LOCKED

#define VCB_STATE_LOCKED   0x00000001

Definition at line 38 of file rawfs.c.

Typedef Documentation

◆ PVCB

typedef struct _VCB * PVCB

◆ PVOLUME_DEVICE_OBJECT

◆ VCB

typedef struct _VCB VCB

◆ VOLUME_DEVICE_OBJECT

Function Documentation

◆ RawCheckForDismount()

BOOLEAN NTAPI RawCheckForDismount ( IN PVCB  Vcb,
IN BOOLEAN  CreateOperation 
)

Definition at line 80 of file rawfs.c.

82{
84 PVPB Vpb;
86
87 DPRINT("RawCheckForDismount(%p, %lu)\n", Vcb, CreateOperation);
88
89 ASSERT(KeReadStateMutant(&Vcb->Mutex) == 0);
90
91 /* Lock VPB */
93
94 /* Reference it and check if a create is being done */
95 Vpb = Vcb->Vpb;
96 if (Vcb->Vpb->ReferenceCount != CreateOperation)
97 {
98 /* Copy the VPB to our local own to prepare later dismount */
99 if (Vcb->LocalVpb != NULL)
100 {
101 RtlZeroMemory(Vcb->LocalVpb, sizeof(VPB));
102 Vcb->LocalVpb->Type = IO_TYPE_VPB;
103 Vcb->LocalVpb->Size = sizeof(VPB);
104 Vcb->LocalVpb->RealDevice = Vcb->Vpb->RealDevice;
105 Vcb->LocalVpb->DeviceObject = NULL;
106 Vcb->LocalVpb->Flags = Vcb->Vpb->Flags & VPB_REMOVE_PENDING;
107 Vcb->Vpb->RealDevice->Vpb = Vcb->LocalVpb;
108 Vcb->LocalVpb = NULL;
109 Vcb->Vpb->Flags |= VPB_PERSISTENT;
110 }
111
112 /* Don't do anything */
113 Delete = FALSE;
114 }
115 else
116 {
117 /* Otherwise, delete the volume */
118 Delete = TRUE;
119
120 /* Check if it has a VPB and unmount it */
121 if (Vpb->RealDevice->Vpb == Vpb)
122 {
123 Vpb->DeviceObject = NULL;
124 Vpb->Flags &= ~VPB_MOUNTED;
125 }
126 }
127
128 /* Release the VPB lock */
130
131 /* If we were to delete, delete the volume */
132 if (Delete)
133 {
134 /* Release our Vcb lock to be able delete us */
135 KeReleaseMutex(&Vcb->Mutex, FALSE);
136
137 /* If we have a local VPB, we'll have to delete it
138 * but we won't dismount us - something went bad before
139 */
140 if (Vcb->LocalVpb)
141 {
142 ExFreePool(Vcb->LocalVpb);
143 }
144 /* Otherwise, delete any of the available VPB if its reference count is zero */
145 else if (Vcb->Vpb->ReferenceCount == 0)
146 {
147 ExFreePool(Vcb->Vpb);
148 }
149
150 /* Dismount our device if possible */
151 ObDereferenceObject(Vcb->TargetDeviceObject);
154 Vcb));
155 }
156
157 return Delete;
158}
unsigned char BOOLEAN
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1676
static void CreateOperation(FILE *Out, unsigned Bpp, PROPINFO RopInfo, unsigned SourceBpp, unsigned Bits)
Definition: gendib.c:247
#define ASSERT(a)
Definition: mode.c:44
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1215
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1204
LONG NTAPI KeReadStateMutant(IN PKMUTANT Mutant)
Definition: mutex.c:87
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
#define Vcb
Definition: cdprocs.h:1415
#define DPRINT
Definition: sndvol32.h:73
PVPB Vpb
Definition: cdstruc.h:511
Definition: iotypes.h:189
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define IO_TYPE_VPB
#define VPB_PERSISTENT
Definition: iotypes.h:1809
struct _VPB VPB
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by RawCleanup(), RawClose(), RawCreate(), and RawFileSystemControl().

◆ RawCleanup()

NTSTATUS NTAPI RawCleanup ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 1012 of file rawfs.c.

1015{
1017 PAGED_CODE();
1018
1019 DPRINT("RawCleanup(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
1020
1021 /* Make sure we can clean up */
1023 Executive,
1024 KernelMode,
1025 FALSE,
1026 NULL);
1028
1029 /* Remove shared access */
1030 IoRemoveShareAccess(IoStackLocation->FileObject, &Vcb->ShareAccess);
1031
1032 /* Check if we're to dismount */
1033 if (Vcb->VcbState & VCB_STATE_DISMOUNTED)
1034 {
1035 ASSERT(Vcb->OpenCount == 1);
1037 }
1038
1039 KeReleaseMutex(&Vcb->Mutex, FALSE);
1040 Irp->IoStatus.Status = STATUS_SUCCESS;
1042 return STATUS_SUCCESS;
1043}
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
Status
Definition: gdiplustypes.h:25
#define KernelMode
Definition: asm.h:34
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3478
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI RawCheckForDismount(IN PVCB Vcb, IN BOOLEAN CreateOperation)
Definition: rawfs.c:80
#define VCB_STATE_DISMOUNTED
Definition: rawfs.c:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IO_DISK_INCREMENT
Definition: iotypes.h:600
@ Executive
Definition: ketypes.h:415

Referenced by RawDispatch().

◆ RawClose()

NTSTATUS NTAPI RawClose ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 189 of file rawfs.c.

192{
194 PAGED_CODE();
195
196 DPRINT("RawClose(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
197
198 /* If its a stream, not much to do */
199 if (IoStackLocation->FileObject->Flags & FO_STREAM_FILE)
200 {
201 Irp->IoStatus.Status = STATUS_SUCCESS;
203 return STATUS_SUCCESS;
204 }
205
206 /* Make sure we can clean up */
208 Executive,
210 FALSE,
211 NULL);
213
214 /* Decrease the open count and check if this is a dismount */
215 Vcb->OpenCount--;
216 if (Vcb->OpenCount != 0 || !RawCheckForDismount(Vcb, FALSE))
217 {
218 KeReleaseMutex(&Vcb->Mutex, FALSE);
219 }
220
221 /* Complete the request */
222 Irp->IoStatus.Status = STATUS_SUCCESS;
224 return STATUS_SUCCESS;
225}
#define FO_STREAM_FILE
Definition: iotypes.h:1783

Referenced by RawDispatch().

◆ RawCompletionRoutine()

NTSTATUS NTAPI RawCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 162 of file rawfs.c.

165{
167
168 DPRINT("RawCompletionRoutine(%p, %p, %p)\n", DeviceObject, Irp, Context);
169
170 /* Check if this was a valid sync R/W request */
171 if (((IoStackLocation->MajorFunction == IRP_MJ_READ) ||
172 (IoStackLocation->MajorFunction == IRP_MJ_WRITE)) &&
173 ((IoStackLocation->FileObject)) &&
174 (FlagOn(IoStackLocation->FileObject->Flags, FO_SYNCHRONOUS_IO)) &&
175 (NT_SUCCESS(Irp->IoStatus.Status)))
176 {
177 /* Update byte offset */
178 IoStackLocation->FileObject->CurrentByteOffset.QuadPart +=
179 Irp->IoStatus.Information;
180 }
181
182 /* Mark the IRP Pending if it was */
183 if (Irp->PendingReturned) IoMarkIrpPending(Irp);
184 return STATUS_SUCCESS;
185}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
IoMarkIrpPending(Irp)
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776

Referenced by RawReadWriteDeviceControl().

◆ RawCreate()

NTSTATUS NTAPI RawCreate ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 229 of file rawfs.c.

232{
237 PAGED_CODE();
238
239 DPRINT("RawCreate(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
240
241 /* Make sure we can clean up */
243 Executive,
245 FALSE,
246 NULL);
248
249 /* Check if this is a valid non-directory file open */
250 if ((!(IoStackLocation->FileObject) ||
251 !(IoStackLocation->FileObject->FileName.Length)) &&
252 ((IoStackLocation->Parameters.Create.Options >> 24) == FILE_OPEN) &&
253 (!(IoStackLocation->Parameters.Create.Options & FILE_DIRECTORY_FILE)))
254 {
255 /* Make sure the VCB isn't locked */
256 if (Vcb->VcbState & VCB_STATE_LOCKED)
257 {
258 /* Refuse the operation */
260 Irp->IoStatus.Information = 0;
261 }
262 else if (Vcb->VcbState & VCB_STATE_DISMOUNTED)
263 {
264 /* Refuse the operation */
266 Irp->IoStatus.Information = 0;
267 }
268 else
269 {
270 /* Setup share access */
271 ShareAccess = IoStackLocation->Parameters.Create.ShareAccess;
272 DesiredAccess = IoStackLocation->Parameters.Create.
273 SecurityContext->DesiredAccess;
274
275 /* Check if this VCB was already opened */
276 if (Vcb->OpenCount > 0)
277 {
278 /* Try to see if we have access to it */
281 IoStackLocation->FileObject,
282 &Vcb->ShareAccess,
283 TRUE);
284 if (!NT_SUCCESS(Status)) Irp->IoStatus.Information = 0;
285 }
286
287 /* Make sure we have access */
288 if (NT_SUCCESS(Status))
289 {
290 /* Check if this is the first open */
291 if (!Vcb->OpenCount)
292 {
293 /* Set the share access */
296 IoStackLocation->FileObject,
297 &Vcb->ShareAccess);
298 }
299
300 /* Increase the open count and set the VPB */
301 Vcb->OpenCount++;
302 IoStackLocation->FileObject->Vpb = Vcb->Vpb;
303
304 /* Set IRP status and disable intermediate buffering */
306 Irp->IoStatus.Information = FILE_OPENED;
307 IoStackLocation->FileObject->Flags |=
309 }
310 }
311 }
312 else
313 {
314 /* Invalid create request */
316 Irp->IoStatus.Information = 0;
317 }
318
319 /* Check if the request failed */
320 if (!NT_SUCCESS(Status) && !Vcb->OpenCount)
321 {
322 /* Check if we can dismount the device */
324 }
325
326 /* In case of deletion, the mutex is already released */
327 if (!Deleted)
328 {
329 KeReleaseMutex(&Vcb->Mutex, FALSE);
330 }
331
332 /* Complete the request */
333 Irp->IoStatus.Status = Status;
335 return Status;
336}
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4147
#define FILE_OPEN
Definition: from_kernel.h:54
HRESULT Create([out]ITransactionReceiver **ppReceiver)
@ Deleted
Definition: kstypes.h:187
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define FILE_OPENED
Definition: nt_native.h:769
VOID NTAPI IoSetShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, OUT PSHARE_ACCESS ShareAccess)
Definition: file.c:3517
NTSTATUS NTAPI IoCheckShareAccess(IN ACCESS_MASK DesiredAccess, IN ULONG DesiredShareAccess, IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess, IN BOOLEAN Update)
Definition: file.c:3390
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:747
unsigned short USHORT
Definition: pedump.c:61
#define VCB_STATE_LOCKED
Definition: rawfs.c:38
union _IO_STACK_LOCATION::@1580 Parameters
struct _IO_STACK_LOCATION::@3979::@3980 Create
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1778

Referenced by RawDispatch().

◆ RawDispatch()

NTSTATUS NTAPI RawDispatch ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1047 of file rawfs.c.

1049{
1052 PIO_STACK_LOCATION IoStackLocation;
1053 PVCB Vcb;
1054 PAGED_CODE();
1055
1056 DPRINT("RawDispatch(%p, %p)\n", DeviceObject, Irp);
1057
1058 /* Get the stack location */
1059 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
1060
1061 /* Differentiate between Volume DO and FS DO */
1062 if ((DeviceObject->Size == sizeof(DEVICE_OBJECT)) &&
1063 !((IoStackLocation->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL) &&
1064 (IoStackLocation->MinorFunction == IRP_MN_MOUNT_VOLUME)))
1065 {
1066 /* This is an FS DO. Stub out the common calls */
1067 if ((IoStackLocation->MajorFunction == IRP_MJ_CREATE) ||
1068 (IoStackLocation->MajorFunction == IRP_MJ_CLEANUP) ||
1069 (IoStackLocation->MajorFunction == IRP_MJ_CLOSE))
1070 {
1071 /* Return success for them */
1073 }
1074 else
1075 {
1076 /* Anything else, we don't support */
1078 }
1079
1080 /* Complete the request */
1081 Irp->IoStatus.Status = Status;
1083 return Status;
1084 }
1085
1086 /* Otherwise, get our VCB and start handling the IRP */
1088 Vcb = &VolumeDeviceObject->Vcb;
1089
1090 /* Check what kind of IRP this is */
1091 switch (IoStackLocation->MajorFunction)
1092 {
1093 /* Cleanup request */
1094 case IRP_MJ_CLEANUP:
1095
1096 Status = RawCleanup(Vcb, Irp, IoStackLocation);
1097 break;
1098
1099 /* Close request */
1100 case IRP_MJ_CLOSE:
1101
1102 Status = RawClose(Vcb, Irp, IoStackLocation);
1103 break;
1104
1105 /* Create request */
1106 case IRP_MJ_CREATE:
1107
1108 Status = RawCreate(Vcb, Irp, IoStackLocation);
1109 break;
1110
1111 /* FSCTL request */
1113
1114 Status = RawFileSystemControl(Vcb, Irp, IoStackLocation);
1115 break;
1116
1117 /* R/W or IOCTL request */
1118 case IRP_MJ_READ:
1119 case IRP_MJ_WRITE:
1121
1122 Status = RawReadWriteDeviceControl(Vcb, Irp, IoStackLocation);
1123 break;
1124
1125 /* Information query request */
1127
1128 Status = RawQueryInformation(Vcb, Irp, IoStackLocation);
1129 break;
1130
1131 /* Information set request */
1133
1134 Status = RawSetInformation(Vcb, Irp, IoStackLocation);
1135 break;
1136
1137 /* Volume information request */
1139
1140 Status = RawQueryVolumeInformation(Vcb, Irp, IoStackLocation);
1141 break;
1142
1143 /* Unexpected request */
1144 default:
1145
1146 /* Anything else is pretty bad */
1148 }
1149
1150 /* Return the status */
1152 return Status;
1153}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1430
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
NTSTATUS NTAPI RawReadWriteDeviceControl(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:340
NTSTATUS NTAPI RawQueryVolumeInformation(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:952
NTSTATUS NTAPI RawCleanup(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:1012
NTSTATUS NTAPI RawQueryInformation(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:643
NTSTATUS NTAPI RawFileSystemControl(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:577
NTSTATUS NTAPI RawSetInformation(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:690
NTSTATUS NTAPI RawCreate(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:229
NTSTATUS NTAPI RawClose(IN PVCB Vcb, IN PIRP Irp, IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:189
struct _VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
Definition: cdstruc.h:498
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404
#define IRP_MJ_CLEANUP

Referenced by RawFsDriverEntry().

◆ RawFileSystemControl()

NTSTATUS NTAPI RawFileSystemControl ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 577 of file rawfs.c.

580{
582 PAGED_CODE();
583
584 DPRINT("RawFileSystemControl(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
585
586 /* Check the kinds of FSCTLs that we support */
587 switch (IoStackLocation->MinorFunction)
588 {
589 /* User-mode request */
591
592 /* Handle it */
593 Status = RawUserFsCtrl(IoStackLocation, Vcb);
594 break;
595
596 /* Mount request */
598
599 /* Mount the volume */
600 Status = RawMountVolume(IoStackLocation);
601 break;
602
604
605 /* Lock the device */
607 Executive,
609 FALSE,
610 NULL);
612
613 /* We don't do verifies */
615 Vcb->Vpb->RealDevice->Flags &= ~DO_VERIFY_VOLUME;
616
617 /* Check if we should delete the device */
618 if (Vcb->OpenCount != 0 || !RawCheckForDismount(Vcb, FALSE))
619 {
620 /* In case of deletion, the mutex is already released */
621 KeReleaseMutex(&Vcb->Mutex, FALSE);
622 }
623
624 /* We're done */
625 break;
626
627 /* Invalid request */
628 default:
629
630 /* Fail it */
632 break;
633 }
634
635 /* Complete the request */
636 Irp->IoStatus.Status = Status;
638 return Status;
639}
NTSTATUS NTAPI RawMountVolume(IN PIO_STACK_LOCATION IoStackLocation)
Definition: rawfs.c:381
NTSTATUS NTAPI RawUserFsCtrl(IN PIO_STACK_LOCATION IoStackLocation, IN PVCB Vcb)
Definition: rawfs.c:465
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4405
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4403

Referenced by RawDispatch().

◆ RawFsDriverEntry()

NTSTATUS NTAPI RawFsDriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 1193 of file rawfs.c.

1195{
1198
1200
1201 /* Create the raw disk device */
1202 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawDisk");
1204 0,
1205 &DeviceName,
1207 0,
1208 FALSE,
1210 if (!NT_SUCCESS(Status))
1211 {
1212 return Status;
1213 }
1214
1215 /* Create the raw CDROM device */
1216 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawCdRom");
1218 0,
1219 &DeviceName,
1221 0,
1222 FALSE,
1224 if (!NT_SUCCESS(Status))
1225 {
1227 return Status;
1228 }
1229
1230 /* Create the raw tape device */
1231 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawTape");
1233 0,
1234 &DeviceName,
1236 0,
1237 FALSE,
1239 if (!NT_SUCCESS(Status))
1240 {
1243 return Status;
1244 }
1245
1246 /* Set Direct I/O for all devices */
1250
1251 /* Set generic stubs */
1252 DriverObject->MajorFunction[IRP_MJ_CREATE] =
1253 DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
1254 DriverObject->MajorFunction[IRP_MJ_CLOSE] =
1255 DriverObject->MajorFunction[IRP_MJ_READ] =
1256 DriverObject->MajorFunction[IRP_MJ_WRITE] =
1257 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
1258 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
1262
1263 /* Shutdown and unload */
1264 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = RawShutdown;
1265 DriverObject->DriverUnload = RawUnload;
1266
1267 /* Register the file systems */
1271
1272#if 0 // FIXME: DriverUnload is never called
1273 /* Reference device objects */
1277#endif
1278 return STATUS_SUCCESS;
1279}
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:53
#define FILE_DEVICE_TAPE_FILE_SYSTEM
Definition: winioctl.h:77
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:48
NTSTATUS NTAPI RawShutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: rawfs.c:1157
PDEVICE_OBJECT RawCdromDeviceObject
Definition: rawfs.c:43
PDEVICE_OBJECT RawTapeDeviceObject
Definition: rawfs.c:43
PDEVICE_OBJECT RawDiskDeviceObject
Definition: rawfs.c:43
VOID NTAPI RawUnload(IN PDRIVER_OBJECT DriverObject)
Definition: rawfs.c:1180
NTSTATUS NTAPI RawDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: rawfs.c:1047
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IRP_MJ_SHUTDOWN
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopInitializeBootDrivers().

◆ RawInitializeVcb()

NTSTATUS NTAPI RawInitializeVcb ( IN OUT PVCB  Vcb,
IN PDEVICE_OBJECT  TargetDeviceObject,
IN PVPB  Vpb 
)

Definition at line 49 of file rawfs.c.

52{
54
55 PAGED_CODE();
56
57 DPRINT("RawInitializeVcb(%p, %p, %p)\n", Vcb, TargetDeviceObject, Vpb);
58
59 /* Clear it */
60 RtlZeroMemory(Vcb, sizeof(VCB));
61
62 /* Associate to system objects */
63 Vcb->TargetDeviceObject = TargetDeviceObject;
64 Vcb->Vpb = Vpb;
65
66 /* Initialize the lock */
67 KeInitializeMutex(&Vcb->Mutex, 0);
68
69 Vcb->LocalVpb = ExAllocatePoolWithTag(NonPagedPool, sizeof(VPB), ' waR');
70 if (Vcb->LocalVpb == NULL)
71 {
73 }
74
75 return Status;
76}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1675
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by RawMountVolume().

◆ RawMountVolume()

NTSTATUS NTAPI RawMountVolume ( IN PIO_STACK_LOCATION  IoStackLocation)

Definition at line 381 of file rawfs.c.

382{
387 PAGED_CODE();
388
389 DPRINT("RawMountVolume(%p)\n", IoStackLocation);
390
391 /* Remember our owner */
392 DeviceObject = IoStackLocation->Parameters.MountVolume.DeviceObject;
393
394 /* Create the volume */
396 sizeof(VOLUME_DEVICE_OBJECT) -
397 sizeof(DEVICE_OBJECT),
398 NULL,
400 0,
401 FALSE,
403 if (!NT_SUCCESS(Status)) return Status;
404
405 /* Use highest alignment requirement */
406 Volume->DeviceObject.AlignmentRequirement = max(DeviceObject->
408 Volume->DeviceObject.
410
411 /* Setup the VCB */
413 IoStackLocation->Parameters.MountVolume.DeviceObject,
414 IoStackLocation->Parameters.MountVolume.Vpb);
415 if (!NT_SUCCESS(Status))
416 {
418 return Status;
419 }
420
421 /* Set dummy label and serial number */
422 Volume->Vcb.Vpb->SerialNumber = 0xFFFFFFFF;
423 Volume->Vcb.Vpb->VolumeLabelLength = 0;
424
425 /* Setup the DO */
426 Volume->Vcb.Vpb->DeviceObject = &Volume->DeviceObject;
427 Volume->DeviceObject.StackSize = DeviceObject->StackSize + 1;
428 Volume->DeviceObject.SectorSize = DeviceObject->SectorSize;
429 Volume->DeviceObject.Flags |= DO_DIRECT_IO;
430 Volume->DeviceObject.Flags &= ~DO_DEVICE_INITIALIZING;
431
432 /* Try to get associated FO (for notification) */
434 {
436 &(Volume->DeviceObject));
437 }
439 {
440 /* Get the exception code */
442 }
443 _SEH2_END;
444
445 /* If failed, delete devive */
446 if (!NT_SUCCESS(Status))
447 {
449 return Status;
450 }
451
452 /* Increment OpenCount by two to avoid dismount when RawClose() will be called on ObDereferenceObject() */
453 Volume->Vcb.OpenCount += 2;
454 /* Notify for successful mount */
456 /* It's not opened anymore, decrease the reference count to 0 to make FileObject being released */
458 Volume->Vcb.OpenCount -= 2;
459
460 return Status;
461}
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
UNICODE_STRING Volume
Definition: fltkernel.h:1172
#define FSRTL_VOLUME_MOUNT
Definition: ntifs_ex.h:444
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
PFILE_OBJECT NTAPI IoCreateStreamFileObjectLite(IN PFILE_OBJECT FileObject OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL)
Definition: file.c:3199
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
NTSTATUS NTAPI RawInitializeVcb(IN OUT PVCB Vcb, IN PDEVICE_OBJECT TargetDeviceObject, IN PVPB Vpb)
Definition: rawfs.c:49
#define max(a, b)
Definition: svc.c:63
_In_ WDFDEVICE _In_ ULONG AlignmentRequirement
Definition: wdfdevice.h:2854
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
* PFILE_OBJECT
Definition: iotypes.h:1998

Referenced by RawFileSystemControl().

◆ RawQueryFsAttributeInfo()

NTSTATUS NTAPI RawQueryFsAttributeInfo ( IN PVCB  Vcb,
IN PFILE_FS_ATTRIBUTE_INFORMATION  Buffer,
IN OUT PULONG  Length 
)

Definition at line 924 of file rawfs.c.

927{
928 const WCHAR szRawFSName[] = L"RAW";
930 PAGED_CODE();
931
932 DPRINT("RawQueryFsAttributeInfo(%p, %p, %p)\n", Vcb, Buffer, Length);
933
934 /* Check if the buffer is large enough for our name ("RAW") */
936 FileSystemName[sizeof(szRawFSName) / sizeof(szRawFSName[0])]);
938
939 /* Output the data */
940 Buffer->FileSystemAttributes = 0;
941 Buffer->MaximumComponentNameLength = 0;
942 Buffer->FileSystemNameLength = 6;
943 RtlCopyMemory(&Buffer->FileSystemName[0], szRawFSName, sizeof(szRawFSName));
944
945 /* Return length and success */
947 return STATUS_SUCCESS;
948}
Definition: bufpool.h:45
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by RawQueryVolumeInformation().

◆ RawQueryFsDeviceInfo()

NTSTATUS NTAPI RawQueryFsDeviceInfo ( IN PVCB  Vcb,
IN PFILE_FS_DEVICE_INFORMATION  Buffer,
IN OUT PULONG  Length 
)

Definition at line 897 of file rawfs.c.

900{
901 PAGED_CODE();
902
903 DPRINT("RawQueryFsDeviceInfo(%p, %p, %p)\n", Vcb, Buffer, Length);
904
905 /* Validate buffer */
906 if (*Length < sizeof(FILE_FS_DEVICE_INFORMATION))
907 {
908 /* Fail */
910 }
911
912 /* Clear buffer and write information */
914 Buffer->DeviceType = FILE_DEVICE_DISK;
915 Buffer->Characteristics = Vcb->TargetDeviceObject->Characteristics;
916
917 /* Return length and success */
919 return STATUS_SUCCESS;
920}
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_DEVICE_DISK
Definition: winioctl.h:52

Referenced by RawQueryVolumeInformation().

◆ RawQueryFsSizeInfo()

NTSTATUS NTAPI RawQueryFsSizeInfo ( IN PVCB  Vcb,
IN PFILE_FS_SIZE_INFORMATION  Buffer,
IN OUT PULONG  Length 
)

Definition at line 758 of file rawfs.c.

761{
762 PIRP Irp;
766 PDEVICE_OBJECT RealDevice;
767 DISK_GEOMETRY DiskGeometry;
768 PARTITION_INFORMATION PartitionInformation;
769 BOOLEAN DiskHasPartitions;
770 PAGED_CODE();
771
772 DPRINT("RawQueryFsSizeInfo(%p, %p, %p)\n", Vcb, Buffer, Length);
773
774 /* Validate the buffer */
775 if (*Length < sizeof(FILE_FS_SIZE_INFORMATION))
776 {
777 /* Fail */
779 }
780
781 /* Clear the buffer, initialize the event and set the DO */
784 RealDevice = Vcb->Vpb->RealDevice;
785
786 /* Build query IRP */
788 RealDevice,
789 NULL,
790 0,
791 &DiskGeometry,
792 sizeof(DISK_GEOMETRY),
793 FALSE,
794 &Event,
797
798 /* Call driver and check if we're pending */
799 Status = IoCallDriver(RealDevice, Irp);
800 if (Status == STATUS_PENDING)
801 {
802 /* Wait on driver to finish */
804 Executive,
806 FALSE,
807 NULL);
809 }
810
811 /* Fail if we couldn't get CHS data */
812 if (!NT_SUCCESS(Status))
813 {
814 *Length = 0;
815 return Status;
816 }
817
818 /* Check if this is a floppy */
819 if (FlagOn(RealDevice->Characteristics, FILE_FLOPPY_DISKETTE))
820 {
821 /* Floppies don't have partitions */
822 DiskHasPartitions = FALSE;
823 }
824 else
825 {
826 /* Setup query IRP */
829 RealDevice,
830 NULL,
831 0,
832 &PartitionInformation,
833 sizeof(PARTITION_INFORMATION),
834 FALSE,
835 &Event,
838
839 /* Call driver and check if we're pending */
840 Status = IoCallDriver(RealDevice, Irp);
841 if (Status == STATUS_PENDING)
842 {
843 /* Wait on driver to finish */
845 Executive,
847 FALSE,
848 NULL);
850 }
851
852 /* If this was an invalid request, then the disk is not partitioned */
854 {
855 DiskHasPartitions = FALSE;
856 }
857 else
858 {
859 /* Otherwise, it must be */
861 DiskHasPartitions = TRUE;
862 }
863 }
864
865 /* Set sector data */
866 Buffer->BytesPerSector = DiskGeometry.BytesPerSector;
867 Buffer->SectorsPerAllocationUnit = 1;
868
869 /* Calculate allocation units */
870 if (DiskHasPartitions)
871 {
872 /* Use partition data */
873 Buffer->TotalAllocationUnits =
875 DiskGeometry.BytesPerSector,
876 NULL);
877 }
878 else
879 {
880 /* Use CHS */
881 Buffer->TotalAllocationUnits =
883 DiskGeometry.TracksPerCylinder *
884 DiskGeometry.SectorsPerTrack);
885 }
886
887 /* Set available units */
888 Buffer->AvailableAllocationUnits = Buffer->TotalAllocationUnits;
889
890 /* Return length and success */
892 return STATUS_SUCCESS;
893}
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
NTSYSAPI LONGLONG WINAPI RtlExtendedIntegerMultiply(LONGLONG, INT)
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
@ NotificationEvent
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IoCallDriver
Definition: irp.c:1225
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:400
ULONG TracksPerCylinder
Definition: ntdddisk.h:402
ULONG SectorsPerTrack
Definition: ntdddisk.h:403
ULONG BytesPerSector
Definition: ntdddisk.h:404
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:409

Referenced by RawQueryVolumeInformation().

◆ RawQueryFsVolumeInfo()

NTSTATUS NTAPI RawQueryFsVolumeInfo ( IN PVCB  Vcb,
IN PFILE_FS_VOLUME_INFORMATION  Buffer,
IN OUT PULONG  Length 
)

Definition at line 737 of file rawfs.c.

740{
741 PAGED_CODE();
742
743 DPRINT("RawQueryFsVolumeInfo(%p, %p, %p)\n", Vcb, Buffer, Length);
744
745 /* Clear the buffer and stub it out */
747 Buffer->VolumeSerialNumber = Vcb->Vpb->SerialNumber;
748 Buffer->SupportsObjects = FALSE;
749 Buffer->VolumeLabelLength = 0;
750
751 /* Return length and success */
753 return STATUS_SUCCESS;
754}

Referenced by RawQueryVolumeInformation().

◆ RawQueryInformation()

NTSTATUS NTAPI RawQueryInformation ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 643 of file rawfs.c.

646{
650 PAGED_CODE();
651
652 DPRINT("RawQueryInformation(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
653
654 /* Get information from the IRP */
655 Length = &IoStackLocation->Parameters.QueryFile.Length;
656 Buffer = Irp->AssociatedIrp.SystemBuffer;
657
658 /* We only handle this request */
659 if (IoStackLocation->Parameters.QueryFile.FileInformationClass ==
661 {
662 /* Validate buffer size */
663 if (*Length < sizeof(FILE_POSITION_INFORMATION))
664 {
665 /* Invalid, fail */
666 Irp->IoStatus.Information = 0;
668 }
669 else
670 {
671 /* Get offset and update length */
672 Buffer->CurrentByteOffset = IoStackLocation->FileObject->
673 CurrentByteOffset;
675
676 /* Set IRP Status information */
677 Irp->IoStatus.Information = sizeof(FILE_POSITION_INFORMATION);
679 }
680 }
681
682 /* Complete it */
683 Irp->IoStatus.Status = Status;
685 return Status;
686}
@ FilePositionInformation
Definition: from_kernel.h:75
struct _FILE_POSITION_INFORMATION FILE_POSITION_INFORMATION
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by RawDispatch().

◆ RawQueryVolumeInformation()

NTSTATUS NTAPI RawQueryVolumeInformation ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 952 of file rawfs.c.

955{
959 PAGED_CODE();
960
961 DPRINT("RawQueryVolumeInformation(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
962
963 /* Get IRP Data */
964 Length = IoStackLocation->Parameters.QueryVolume.Length;
965 Buffer = Irp->AssociatedIrp.SystemBuffer;
966
967 /* Check the kind of request */
968 switch (IoStackLocation->Parameters.QueryVolume.FsInformationClass)
969 {
970 /* Volume information request */
972
974 break;
975
976 /* File system size invormation */
978
980 break;
981
982 /* Device information */
984
986 break;
987
988 /* Attribute information */
990
992 break;
993
994 /* Invalid request */
995 default:
996
997 /* Fail it */
999 break;
1000 }
1001
1002 /* Set status and complete the request */
1003 Irp->IoStatus.Information = IoStackLocation->
1004 Parameters.QueryVolume.Length - Length;
1005 Irp->IoStatus.Status = Status;
1007 return Status;
1008}
@ FileFsDeviceInformation
Definition: from_kernel.h:222
@ FileFsAttributeInformation
Definition: from_kernel.h:223
@ FileFsVolumeInformation
Definition: from_kernel.h:219
@ FileFsSizeInformation
Definition: from_kernel.h:221
NTSTATUS NTAPI RawQueryFsDeviceInfo(IN PVCB Vcb, IN PFILE_FS_DEVICE_INFORMATION Buffer, IN OUT PULONG Length)
Definition: rawfs.c:897
NTSTATUS NTAPI RawQueryFsVolumeInfo(IN PVCB Vcb, IN PFILE_FS_VOLUME_INFORMATION Buffer, IN OUT PULONG Length)
Definition: rawfs.c:737
NTSTATUS NTAPI RawQueryFsSizeInfo(IN PVCB Vcb, IN PFILE_FS_SIZE_INFORMATION Buffer, IN OUT PULONG Length)
Definition: rawfs.c:758
NTSTATUS NTAPI RawQueryFsAttributeInfo(IN PVCB Vcb, IN PFILE_FS_ATTRIBUTE_INFORMATION Buffer, IN OUT PULONG Length)
Definition: rawfs.c:924
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

Referenced by RawDispatch().

◆ RawReadWriteDeviceControl()

NTSTATUS NTAPI RawReadWriteDeviceControl ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 340 of file rawfs.c.

343{
345 PAGED_CODE();
346
347 DPRINT("RawReadWriteDeviceControl(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
348
349 /* Don't do anything if the request was 0 bytes */
350 if (((IoStackLocation->MajorFunction == IRP_MJ_READ) ||
351 (IoStackLocation->MajorFunction == IRP_MJ_WRITE)) &&
352 !(IoStackLocation->Parameters.Read.Length))
353 {
354 /* Complete it */
355 Irp->IoStatus.Status = STATUS_SUCCESS;
357 return STATUS_SUCCESS;
358 }
359
360 /* Copy the IRP stack location */
362
363 /* Disable verifies */
365
366 /* Setup a completion routine */
369 NULL,
370 TRUE,
371 TRUE,
372 TRUE);
373
374 /* Call the next driver and exit */
375 Status = IoCallDriver(Vcb->TargetDeviceObject, Irp);
376 return Status;
377}
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
NTSTATUS NTAPI RawCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: rawfs.c:162
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1823

Referenced by RawDispatch().

◆ RawSetInformation()

NTSTATUS NTAPI RawSetInformation ( IN PVCB  Vcb,
IN PIRP  Irp,
IN PIO_STACK_LOCATION  IoStackLocation 
)

Definition at line 690 of file rawfs.c.

693{
697 PAGED_CODE();
698
699 DPRINT("RawSetInformation(%p, %p, %p)\n", Vcb, Irp, IoStackLocation);
700
701 /* Get information from the IRP */
702 Buffer = Irp->AssociatedIrp.SystemBuffer;
703
704 /* We only handle this request */
705 if (IoStackLocation->Parameters.QueryFile.FileInformationClass ==
707 {
708 /* Get the DO */
709 DeviceObject = IoGetRelatedDeviceObject(IoStackLocation->FileObject);
710
711 /* Make sure the offset is aligned */
712 if ((Buffer->CurrentByteOffset.LowPart &
713 DeviceObject->AlignmentRequirement))
714 {
715 /* It's not, fail */
717 }
718 else
719 {
720 /* Otherwise, set offset */
721 IoStackLocation->FileObject->CurrentByteOffset = Buffer->
722 CurrentByteOffset;
723
724 /* Set IRP Status information */
726 }
727 }
728
729 /* Complete it */
730 Irp->IoStatus.Status = Status;
732 return Status;
733}
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539

Referenced by RawDispatch().

◆ RawShutdown()

NTSTATUS NTAPI RawShutdown ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 1157 of file rawfs.c.

1159{
1160 /* Unregister file systems */
1161#if 0 // FIXME: This freezes ROS at shutdown. PnP Problem?
1165
1166 /* Delete the devices */
1170#endif
1171
1172 /* Complete the request */
1173 Irp->IoStatus.Status = STATUS_SUCCESS;
1175 return STATUS_SUCCESS;
1176}
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1056

Referenced by RawFsDriverEntry().

◆ RawUnload()

VOID NTAPI RawUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 1180 of file rawfs.c.

1181{
1182#if 0 // FIXME: DriverUnload is never called
1183 /* Dereference device objects */
1187#endif
1188}

Referenced by RawFsDriverEntry().

◆ RawUserFsCtrl()

NTSTATUS NTAPI RawUserFsCtrl ( IN PIO_STACK_LOCATION  IoStackLocation,
IN PVCB  Vcb 
)

Definition at line 465 of file rawfs.c.

467{
469 PAGED_CODE();
470
471 DPRINT("RawUserFsCtrl(%p, %p)\n", IoStackLocation, Vcb);
472
473 /* Lock the device */
475 Executive,
477 FALSE,
478 NULL);
480
481 /* Check what kind of request this is */
482 switch (IoStackLocation->Parameters.FileSystemControl.FsControlCode)
483 {
484 /* Oplock requests */
489
490 /* We don't handle them */
492 break;
493
494 /* Lock request */
496
497 /* Make sure we're not locked, and that we're alone */
498 if (!(Vcb->VcbState & VCB_STATE_LOCKED) && (Vcb->OpenCount == 1))
499 {
500 /* Lock the VCB */
501 Vcb->VcbState |= VCB_STATE_LOCKED;
503 }
504 else
505 {
506 /* Otherwise, we can't do this */
508 }
509 break;
510
511 /* Unlock request */
513
514 /* Make sure we're locked */
515 if (!(Vcb->VcbState & VCB_STATE_LOCKED))
516 {
517 /* Let caller know we're not */
519 }
520 else
521 {
522 /* Unlock the VCB */
523 Vcb->VcbState &= ~VCB_STATE_LOCKED;
525 }
526 break;
527
528 /* Dismount request */
530
531 /* Make sure we're locked */
532 if (Vcb->VcbState & VCB_STATE_LOCKED)
533 {
534 /* Do nothing, just return success */
536 }
537 else
538 {
539 /* We can't dismount, device not locked */
541 }
542 break;
543
544 /* Unknown request */
545 default:
546
547 /* Fail */
549 break;
550 }
551
552 /* Unlock device */
553 KeReleaseMutex(&Vcb->Mutex, FALSE);
554
555 /* In case of status change, notify */
556 switch (IoStackLocation->Parameters.FileSystemControl.FsControlCode)
557 {
560 break;
562 if (NT_SUCCESS(Status))
563 {
564 FsRtlNotifyVolumeEvent(IoStackLocation->FileObject, FSRTL_VOLUME_UNLOCK);
565 }
566 break;
569 break;
570 }
571
572 return Status;
573}
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define FSCTL_OPLOCK_BREAK_NOTIFY
Definition: nt_native.h:831
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE
Definition: nt_native.h:829
#define FSCTL_REQUEST_OPLOCK_LEVEL_1
Definition: nt_native.h:826
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_REQUEST_OPLOCK_LEVEL_2
Definition: nt_native.h:827
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
#define FSRTL_VOLUME_LOCK
Definition: ntifs_ex.h:441
#define FSRTL_VOLUME_DISMOUNT_FAILED
Definition: ntifs_ex.h:440
#define FSRTL_VOLUME_DISMOUNT
Definition: ntifs_ex.h:439
#define FSRTL_VOLUME_LOCK_FAILED
Definition: ntifs_ex.h:442
#define STATUS_NOT_LOCKED
Definition: ntstatus.h:279

Referenced by RawFileSystemControl().

Variable Documentation

◆ RawCdromDeviceObject

PDEVICE_OBJECT RawCdromDeviceObject

Definition at line 43 of file rawfs.c.

Referenced by RawFsDriverEntry(), RawShutdown(), and RawUnload().

◆ RawDiskDeviceObject

PDEVICE_OBJECT RawDiskDeviceObject

Definition at line 43 of file rawfs.c.

Referenced by RawFsDriverEntry(), RawMountVolume(), RawShutdown(), and RawUnload().

◆ RawTapeDeviceObject

PDEVICE_OBJECT RawTapeDeviceObject

Definition at line 43 of file rawfs.c.

Referenced by RawFsDriverEntry(), RawShutdown(), and RawUnload().