ReactOS  0.4.13-dev-551-gf37fb1f
Interface.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/interface.c
5 * PURPOSE: Implements the driver interface
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 #define VALID_FAST_IO_DISPATCH_HANDLER(_FastIoDispatchPtr, _FieldName) \
21  (((_FastIoDispatchPtr) != NULL) && \
22  (((_FastIoDispatchPtr)->SizeOfFastIoDispatch) >= \
23  (FIELD_OFFSET(FAST_IO_DISPATCH, _FieldName) + sizeof(void *))) && \
24  ((_FastIoDispatchPtr)->_FieldName != NULL))
25 
26 #define IS_MY_DEVICE_OBJECT(_devObj) \
27  (((_devObj) != NULL) && \
28  ((_devObj)->DriverObject == Dispatcher::DriverObject) && \
29  ((_devObj)->DeviceExtension != NULL))
30 
32 extern LIST_ENTRY FilterList;
34 
35 
36 DRIVER_INITIALIZE DriverEntry;
38 NTAPI
42 );
43 
44 static
48 );
49 
50 static
55  _Out_ PDEVICE_OBJECT *AttachedToDeviceObject
56 );
57 
58 static
59 VOID
62 );
63 
64 static
65 BOOLEAN
68  _In_opt_ PDEVICE_OBJECT *AttachedDeviceObject
69 );
70 
71 static
75 );
76 
77 static
82 );
83 
84 static
88 );
89 
90 DRIVER_FS_NOTIFICATION FltpFsNotification;
91 VOID
92 NTAPI
96 );
97 
99 NTAPI
103 );
104 
105 NTSTATUS
106 NTAPI
107 FltpCreate(
110 );
111 
112 NTSTATUS
113 NTAPI
117 );
118 
119 NTSTATUS
120 NTAPI
124 );
125 
126 BOOLEAN
127 NTAPI
131  _In_ ULONG Length,
132  _In_ BOOLEAN Wait,
137 );
138 
139 
140 BOOLEAN
141 NTAPI
145  _In_ ULONG Length,
146  _In_ BOOLEAN Wait,
151 );
152 
153 BOOLEAN
154 NTAPI
158  _In_ ULONG Length,
159  _In_ BOOLEAN Wait,
161  _In_ PVOID Buffer,
164 );
165 
166 BOOLEAN
167 NTAPI
170  _In_ BOOLEAN Wait,
174 );
175 
176 BOOLEAN
177 NTAPI
180  _In_ BOOLEAN Wait,
184 );
185 
186 BOOLEAN
187 NTAPI
193  _In_ ULONG Key,
198 );
199 
200 BOOLEAN
201 NTAPI
207  _In_ ULONG Key,
210 );
211 
212 BOOLEAN
213 NTAPI
219 );
220 
221 BOOLEAN
222 NTAPI
226  _In_ ULONG Key,
229 );
230 
231 BOOLEAN
232 NTAPI
235  _In_ BOOLEAN Wait,
243 );
244 
245 VOID
246 NTAPI
250 );
251 
252 BOOLEAN
253 NTAPI
256  _In_ BOOLEAN Wait,
260 );
261 
262 BOOLEAN
263 NTAPI
267  _In_ ULONG Length,
272 );
273 
274 BOOLEAN
275 NTAPI
280 );
281 
282 BOOLEAN
283 NTAPI
287  _In_ ULONG Length,
292 );
293 
294 BOOLEAN
295 NTAPI
301 );
302 
303 BOOLEAN
304 NTAPI
308  _In_ ULONG Length,
316 );
317 
318 BOOLEAN
319 NTAPI
323  _In_ ULONG Length,
325  _In_ PVOID Buffer,
331 );
332 
333 BOOLEAN
334 NTAPI
339 );
340 
341 BOOLEAN
342 NTAPI
348 );
349 
350 BOOLEAN
351 NTAPI
353  _Inout_ PIRP Irp,
356 );
357 
358 
359 
360 #ifdef ALLOC_PRAGMA
361 #pragma alloc_text(INIT, DriverEntry)
362 #pragma alloc_text(INIT, SetupDispatchAndCallbacksTables)
363 #pragma alloc_text(PAGE, FltpAttachDeviceObject)
364 #pragma alloc_text(PAGE, FltpIsAttachedToDevice)
365 #pragma alloc_text(PAGE, FltpEnumerateFileSystemVolumes)
366 #pragma alloc_text(PAGE, FltpAttachToFileSystemDevice)
367 #pragma alloc_text(PAGE, FltpDetachFromFileSystemDevice)
368 #pragma alloc_text(PAGE, FltpFsNotification)
369 #pragma alloc_text(PAGE, FltpCreate)
370 #pragma alloc_text(PAGE, FltpFsControl)
371 #pragma alloc_text(PAGE, FltpDeviceControl)
372 #pragma alloc_text(PAGE, FltpFastIoRead)
373 #pragma alloc_text(PAGE, FltpFastIoWrite)
374 #pragma alloc_text(PAGE, FltpFastIoQueryBasicInfo)
375 #pragma alloc_text(PAGE, FltpFastIoQueryStandardInfo)
376 #pragma alloc_text(PAGE, FltpFastIoLock)
377 #pragma alloc_text(PAGE, FltpFastIoUnlockSingle)
378 #pragma alloc_text(PAGE, FltpFastIoUnlockAll)
379 #pragma alloc_text(PAGE, FltpFastIoUnlockAllByKey)
380 #pragma alloc_text(PAGE, FltpFastIoDeviceControl)
381 #pragma alloc_text(PAGE, FltpFastIoDetachDevice)
382 #pragma alloc_text(PAGE, FltpFastIoQueryNetworkOpenInfo)
383 #pragma alloc_text(PAGE, FltpFastIoMdlRead)
384 #pragma alloc_text(PAGE, FltpFastIoMdlReadComplete)
385 #pragma alloc_text(PAGE, FltpFastIoPrepareMdlWrite)
386 #pragma alloc_text(PAGE, FltpFastIoMdlWriteComplete)
387 #pragma alloc_text(PAGE, FltpFastIoReadCompressed)
388 #pragma alloc_text(PAGE, FltpFastIoWriteCompressed)
389 #pragma alloc_text(PAGE, FltpFastIoMdlReadCompleteCompressed)
390 #pragma alloc_text(PAGE, FltpFastIoMdlWriteCompleteCompressed)
391 #pragma alloc_text(PAGE, FltpFastIoQueryOpen)
392 #endif
393 
394 
395 
397 
398 
400 {
404 
406 
407 
408 /* DISPATCH ROUTINES **********************************************/
409 
410 NTSTATUS
411 NTAPI
414 {
417  __debugbreak();
418  return STATUS_SUCCESS;
419 }
420 
421 VOID
422 NTAPI
426 {
430  __debugbreak();
431 }
432 
433 NTSTATUS
434 NTAPI
436  _Inout_ PIRP Irp)
437 {
438  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
439  PIO_STACK_LOCATION StackPtr;
441 
442  DeviceExtension = DeviceObject->DeviceExtension;
443 
444  /* Check if this is a request for us */
446  {
448  FLT_ASSERT(DeviceExtension == NULL);
449 
450  /* Hand it off to our internal handler */
452  if (Status != STATUS_REPARSE)
453  {
454  Irp->IoStatus.Status = Status;
455  Irp->IoStatus.Information = 0;
457  }
458  return Status;
459  }
460 
461  /* Check if this is a request for a the messaging device */
463  {
464  /* Hand off to our internal routine */
466  }
467 
468  FLT_ASSERT(DeviceExtension &&
469  DeviceExtension->AttachedToDeviceObject);
470 
471  StackPtr = IoGetCurrentIrpStackLocation(Irp);
472  if (StackPtr->MajorFunction == IRP_MJ_SHUTDOWN)
473  {
474  // handle shutdown request
475  }
476 
477  DPRINT1("Received %X from %wZ\n", StackPtr->MajorFunction, &DeviceExtension->DeviceName);
478 
479  /* Just pass the IRP down the stack */
481  return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
482 }
483 
484 NTSTATUS
485 NTAPI
487  _Inout_ PIRP Irp)
488 {
489  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
490 
491  PAGED_CODE();
492 
493  DeviceExtension = DeviceObject->DeviceExtension;
494 
495  /* Check if this is a request for us */
497  {
499  FLT_ASSERT(DeviceExtension == NULL);
500 
501  /* Someone wants a handle to the fltmgr, allow it */
502  Irp->IoStatus.Status = STATUS_SUCCESS;
503  Irp->IoStatus.Information = 0;
505  return STATUS_SUCCESS;
506  }
507 
508  /* Check if this is a request for a the new comms connection */
510  {
511  /* Hand off to our internal routine */
512  return FltpMsgCreate(DeviceObject, Irp);
513  }
514 
515  FLT_ASSERT(DeviceExtension &&
516  DeviceExtension->AttachedToDeviceObject);
517 
518  DPRINT1("Received create from %wZ (%lu)\n", &DeviceExtension->DeviceName, PsGetCurrentProcessId());
519 
520  /* Just pass the IRP down the stack */
522  return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
523 }
524 
525 NTSTATUS
526 NTAPI
528  _Inout_ PIRP Irp)
529 {
530  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
531 
532  PAGED_CODE();
533 
534  /* Check if this is a request for us */
536  {
537  /* We don't handle this request */
538  Irp->IoStatus.Information = 0;
539  Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
542  }
543 
544  DeviceExtension = DeviceObject->DeviceExtension;
545 
546  FLT_ASSERT(DeviceExtension &&
547  DeviceExtension->AttachedToDeviceObject);
548 
549  /* Just pass the IRP down the stack */
551  return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
552 }
553 
554 NTSTATUS
555 NTAPI
557  _Inout_ PIRP Irp)
558 {
559  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
561 
562  /* Check if the request was meant for us */
564  {
566  if (Status != STATUS_REPARSE)
567  {
568  Irp->IoStatus.Status = Status;
569  Irp->IoStatus.Information = 0;
571  }
572 
573  return Status;
574  }
575 
576  DeviceExtension = DeviceObject->DeviceExtension;
577 
578  FLT_ASSERT(DeviceExtension &&
579  DeviceExtension->AttachedToDeviceObject);
580 
581  /* Just pass the IRP down the stack */
583  return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
584 }
585 
586 
587 
588 /* FASTIO ROUTINES ************************************************/
589 
590 BOOLEAN
591 NTAPI
594  _In_ ULONG Length,
595  _In_ BOOLEAN Wait,
600 
601 {
602  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
603  PDEVICE_OBJECT AttachedDeviceObject;
605 
606  PAGED_CODE();
607 
608  /* If it doesn't have a device extension, then it's not our device object */
610  {
611  /* Fail the call */
613  IoStatus->Information = 0;
614  return TRUE;
615  }
616 
617  DeviceExtension = DeviceObject->DeviceExtension;
618  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
619 
620  /* Get the device that we attached to */
621  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
622  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
623 
624  /* Make sure our FastIo table is valid */
626  {
627  /* Forward the call onto the device we attached to */
629  FileOffset,
630  Length,
631  Wait,
632  LockKey,
634  IoStatus,
635  AttachedDeviceObject);
636  }
637 
638  /* We failed to handle the request, send it down the slow path */
639  FLT_ASSERT(FALSE);
640  return FALSE;
641 }
642 
643 BOOLEAN
644 NTAPI
647  _In_ ULONG Length,
648  _In_ BOOLEAN Wait,
653 {
654  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
655  PDEVICE_OBJECT AttachedDeviceObject;
657 
658  PAGED_CODE();
659 
660  /* If it doesn't have a device extension, then it's not our device object */
662  {
663  /* Fail the call */
665  IoStatus->Information = 0;
666  return TRUE;
667  }
668 
669  DeviceExtension = DeviceObject->DeviceExtension;
670  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
671 
672  /* Get the device that we attached to */
673  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
674  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
675 
676  /* Make sure our FastIo table is valid */
678  {
679  /* Forward the call onto the device we attached to */
681  FileOffset,
682  Length,
683  Wait,
684  LockKey,
685  Buffer,
686  IoStatus,
687  AttachedDeviceObject);
688  }
689 
690  /* We failed to handle the request, send it down the slow path */
691  FLT_ASSERT(FALSE);
692  return FALSE;
693 }
694 
695 BOOLEAN
696 NTAPI
699  _In_ ULONG Length,
700  _In_ BOOLEAN Wait,
702  _In_ PVOID Buffer,
705 {
706  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
707  PDEVICE_OBJECT AttachedDeviceObject;
709 
710  PAGED_CODE();
711 
712  /* If it doesn't have a device extension, then it's not our device object */
714  {
715  /* Fail the call */
717  IoStatus->Information = 0;
718  return TRUE;
719  }
720 
721  DeviceExtension = DeviceObject->DeviceExtension;
722  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
723 
724  /* Get the device that we attached to */
725  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
726  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
727 
728  /* Make sure our FastIo table is valid */
730  {
731  /* Forward the call onto the device we attached to */
733  FileOffset,
734  Length,
735  Wait,
736  LockKey,
737  Buffer,
738  IoStatus,
739  AttachedDeviceObject);
740  }
741 
742  /* We failed to handle the request, send it down the slow path */
743  FLT_ASSERT(FALSE);
744  return FALSE;
745 }
746 
747 BOOLEAN
748 NTAPI
750  _In_ BOOLEAN Wait,
754 {
755  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
756  PDEVICE_OBJECT AttachedDeviceObject;
758 
759  PAGED_CODE();
760 
761  /* If it doesn't have a device extension, then it's not our device object */
763  {
764  /* Fail the call */
766  IoStatus->Information = 0;
767  return TRUE;
768  }
769 
770  DeviceExtension = DeviceObject->DeviceExtension;
771  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
772 
773  /* Get the device that we attached to */
774  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
775  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
776 
777  /* Make sure our FastIo table is valid */
779  {
780  /* Forward the call onto the device we attached to */
782  Wait,
783  Buffer,
784  IoStatus,
785  AttachedDeviceObject);
786  }
787 
788  /* We failed to handle the request, send it down the slow path */
789  FLT_ASSERT(FALSE);
790  return FALSE;
791 }
792 
793 BOOLEAN
794 NTAPI
796  _In_ BOOLEAN Wait,
800 {
801  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
802  PDEVICE_OBJECT AttachedDeviceObject;
804 
805  PAGED_CODE();
806 
807  /* If it doesn't have a device extension, then it's not our device object */
809  {
810  /* Fail the call */
812  IoStatus->Information = 0;
813  return TRUE;
814  }
815 
816  DeviceExtension = DeviceObject->DeviceExtension;
817  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
818 
819  /* Get the device that we attached to */
820  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
821  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
822 
823  /* Make sure our FastIo table is valid */
825  {
826  /* Forward the call onto the device we attached to */
828  Wait,
829  Buffer,
830  IoStatus,
831  AttachedDeviceObject);
832  }
833 
834  /* We failed to handle the request, send it down the slow path */
835  FLT_ASSERT(FALSE);
836  return FALSE;
837 }
838 
839 BOOLEAN
840 NTAPI
845  _In_ ULONG Key,
850 {
851  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
852  PDEVICE_OBJECT AttachedDeviceObject;
854 
855  PAGED_CODE();
856 
857  /* If it doesn't have a device extension, then it's not our device object */
859  {
860  /* Fail the call */
862  IoStatus->Information = 0;
863  return TRUE;
864  }
865 
866  DeviceExtension = DeviceObject->DeviceExtension;
867  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
868 
869  /* Get the device that we attached to */
870  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
871  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
872 
873  /* Make sure our FastIo table is valid */
875  {
876  /* Forward the call onto the device we attached to */
878  FileOffset,
879  Length,
880  ProcessId,
881  Key,
884  IoStatus,
885  AttachedDeviceObject);
886  }
887 
888  /* We failed to handle the request, send it down the slow path */
889  FLT_ASSERT(FALSE);
890  return FALSE;
891 }
892 
893 BOOLEAN
894 NTAPI
899  _In_ ULONG Key,
902 {
903  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
904  PDEVICE_OBJECT AttachedDeviceObject;
906 
907  PAGED_CODE();
908 
909  /* If it doesn't have a device extension, then it's not our device object */
911  {
912  /* Fail the call */
914  IoStatus->Information = 0;
915  return TRUE;
916  }
917 
918  DeviceExtension = DeviceObject->DeviceExtension;
919  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
920 
921  /* Get the device that we attached to */
922  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
923  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
924 
925  /* Make sure our FastIo table is valid */
927  {
928  /* Forward the call onto the device we attached to */
930  FileOffset,
931  Length,
932  ProcessId,
933  Key,
934  IoStatus,
935  AttachedDeviceObject);
936  }
937 
938  /* We failed to handle the request, send it down the slow path */
939  FLT_ASSERT(FALSE);
940  return FALSE;
941 }
942 
943 BOOLEAN
944 NTAPI
949 
950 {
951  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
952  PDEVICE_OBJECT AttachedDeviceObject;
954 
955  PAGED_CODE();
956 
957  /* If it doesn't have a device extension, then it's not our device object */
959  {
960  /* Fail the call */
962  IoStatus->Information = 0;
963  return TRUE;
964  }
965 
966  DeviceExtension = DeviceObject->DeviceExtension;
967  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
968 
969  /* Get the device that we attached to */
970  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
971  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
972 
973  /* Make sure our FastIo table is valid */
975  {
976  /* Forward the call onto the device we attached to */
978  ProcessId,
979  IoStatus,
980  AttachedDeviceObject);
981  }
982 
983  /* We failed to handle the request, send it down the slow path */
984  FLT_ASSERT(FALSE);
985  return FALSE;
986 }
987 
988 BOOLEAN
989 NTAPI
992  _In_ ULONG Key,
995 {
996  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
997  PDEVICE_OBJECT AttachedDeviceObject;
999 
1000  PAGED_CODE();
1001 
1002  /* If it doesn't have a device extension, then it's not our device object */
1004  {
1005  /* Fail the call */
1007  IoStatus->Information = 0;
1008  return TRUE;
1009  }
1010 
1011  DeviceExtension = DeviceObject->DeviceExtension;
1012  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1013 
1014  /* Get the device that we attached to */
1015  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1016  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1017 
1018  /* Make sure our FastIo table is valid */
1020  {
1021  /* Forward the call onto the device we attached to */
1023  ProcessId,
1024  Key,
1025  IoStatus,
1026  AttachedDeviceObject);
1027  }
1028 
1029  /* We failed to handle the request, send it down the slow path */
1030  FLT_ASSERT(FALSE);
1031  return FALSE;
1032 }
1033 
1034 BOOLEAN
1035 NTAPI
1037  _In_ BOOLEAN Wait,
1045 {
1046  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1047  PDEVICE_OBJECT AttachedDeviceObject;
1049 
1050  PAGED_CODE();
1051 
1052  /* If it doesn't have a device extension, then it's not our device object */
1054  {
1055  /* Fail the request, send it down the slow path */
1056  return FALSE;
1057  }
1058 
1059  DeviceExtension = DeviceObject->DeviceExtension;
1060  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1061 
1062  /* Get the device that we attached to */
1063  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1064  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1065 
1066  /* Make sure our FastIo table is valid */
1068  {
1069  /* Forward the call onto the device we attached to */
1071  Wait,
1072  InputBuffer,
1074  OutputBuffer,
1076  IoControlCode,
1077  IoStatus,
1078  AttachedDeviceObject);
1079  }
1080 
1081  /* We failed to handle the request, send it down the slow path */
1082  FLT_ASSERT(FALSE);
1083  return FALSE;
1084 }
1085 
1086 VOID
1087 NTAPI
1089 {
1090  PDETACH_DEVICE_WORK_ITEM DetachDeviceWorkItem = Parameter;
1091 
1092  /* Run any cleanup routines */
1093  FltpCleanupDeviceObject(DetachDeviceWorkItem->SourceDevice);
1094 
1095  /* Detach from the target device */
1096  IoDetachDevice(DetachDeviceWorkItem->TargetDevice);
1097 
1098  /* Delete the source */
1099  IoDeleteDevice(DetachDeviceWorkItem->SourceDevice);
1100 
1101  /* Free the pool we allocated in FltpFastIoDetachDevice */
1102  ExFreePoolWithTag(DetachDeviceWorkItem, 0x1234);
1103 }
1104 
1105 VOID
1106 NTAPI
1109 {
1110  PDETACH_DEVICE_WORK_ITEM DetachDeviceWorkItem;
1111 
1112  PAGED_CODE();
1113 
1114  /*
1115  * Detaching and deleting devices is a lot of work and takes too long
1116  * to be a worthwhile FastIo candidate, so we defer this call to speed
1117  * it up. There's no return value so we're okay to do this.
1118  */
1119 
1120  /* Allocate the work item and it's corresponding data */
1121  DetachDeviceWorkItem = ExAllocatePoolWithTag(NonPagedPool,
1122  sizeof(DETACH_DEVICE_WORK_ITEM),
1123  0x1234);
1124  if (DetachDeviceWorkItem)
1125  {
1126  /* Initialize the work item */
1127  ExInitializeWorkItem(&DetachDeviceWorkItem->WorkItem,
1129  DetachDeviceWorkItem);
1130 
1131  /* Queue the work item and return the call */
1132  ExQueueWorkItem(&DetachDeviceWorkItem->WorkItem,
1134  }
1135  else
1136  {
1137  /* We failed to defer, just cleanup here */
1141  }
1142 
1143 }
1144 
1145 BOOLEAN
1146 NTAPI
1148  _In_ BOOLEAN Wait,
1152 {
1153  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1154  PDEVICE_OBJECT AttachedDeviceObject;
1156 
1157  PAGED_CODE();
1158 
1159  /* If it doesn't have a device extension, then it's not our device object */
1161  {
1162  /* Fail the call */
1164  IoStatus->Information = 0;
1165  return TRUE;
1166  }
1167 
1168  DeviceExtension = DeviceObject->DeviceExtension;
1169  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1170 
1171  /* Get the device that we attached to */
1172  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1173  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1174 
1175  /* Make sure our FastIo table is valid */
1177  {
1178  /* Forward the call onto the device we attached to */
1180  Wait,
1181  Buffer,
1182  IoStatus,
1183  AttachedDeviceObject);
1184  }
1185 
1186  /* We failed to handle the request, send it down the slow path */
1187  FLT_ASSERT(FALSE);
1188  return FALSE;
1189 }
1190 
1191 BOOLEAN
1192 NTAPI
1195  _In_ ULONG Length,
1196  _In_ ULONG LockKey,
1197  _Out_ PMDL *MdlChain,
1200 {
1201  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1202  PDEVICE_OBJECT AttachedDeviceObject;
1204 
1205  PAGED_CODE();
1206 
1207  /* If it doesn't have a device extension, then it's not our device object */
1209  {
1210  /* Fail the call */
1212  IoStatus->Information = 0;
1213  return TRUE;
1214  }
1215 
1216  DeviceExtension = DeviceObject->DeviceExtension;
1217  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1218 
1219  /* Get the device that we attached to */
1220  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1221  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1222 
1223  /* Make sure our FastIo table is valid */
1225  {
1226  /* Forward the call onto the device we attached to */
1228  FileOffset,
1229  Length,
1230  LockKey,
1231  MdlChain,
1232  IoStatus,
1233  AttachedDeviceObject);
1234  }
1235 
1236  /* We failed to handle the request, send it down the slow path */
1237  FLT_ASSERT(FALSE);
1238  return FALSE;
1239 }
1240 
1241 BOOLEAN
1242 NTAPI
1244  _In_ PMDL MdlChain,
1246 
1247 {
1248  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1249  PDEVICE_OBJECT AttachedDeviceObject;
1251 
1252  PAGED_CODE();
1253 
1254  /* If it doesn't have a device extension, then it's not our device object */
1256  {
1257  /* Fail the request, send it down the slow path */
1258  return FALSE;
1259  }
1260 
1261  DeviceExtension = DeviceObject->DeviceExtension;
1262  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1263 
1264  /* Get the device that we attached to */
1265  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1266  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1267 
1268  /* Make sure our FastIo table is valid */
1270  {
1271  /* Forward the call onto the device we attached to */
1273  MdlChain,
1274  AttachedDeviceObject);
1275  }
1276 
1277  /* We failed to handle the request, send it down the slow path */
1278  FLT_ASSERT(FALSE);
1279  return FALSE;
1280 }
1281 
1282 BOOLEAN
1283 NTAPI
1286  _In_ ULONG Length,
1287  _In_ ULONG LockKey,
1288  _Out_ PMDL *MdlChain,
1291 {
1292  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1293  PDEVICE_OBJECT AttachedDeviceObject;
1295 
1296  PAGED_CODE();
1297 
1298  /* If it doesn't have a device extension, then it's not our device object */
1300  {
1301  /* Fail the call */
1303  IoStatus->Information = 0;
1304  return TRUE;
1305  }
1306 
1307  DeviceExtension = DeviceObject->DeviceExtension;
1308  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1309 
1310  /* Get the device that we attached to */
1311  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1312  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1313 
1314  /* Make sure our FastIo table is valid */
1316  {
1317  /* Forward the call onto the device we attached to */
1319  FileOffset,
1320  Length,
1321  LockKey,
1322  MdlChain,
1323  IoStatus,
1324  AttachedDeviceObject);
1325  }
1326 
1327  /* We failed to handle the request, send it down the slow path */
1328  FLT_ASSERT(FALSE);
1329  return FALSE;
1330 }
1331 
1332 BOOLEAN
1333 NTAPI
1336  _In_ PMDL MdlChain,
1338 {
1339  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1340  PDEVICE_OBJECT AttachedDeviceObject;
1342 
1343  PAGED_CODE();
1344 
1345  /* If it doesn't have a device extension, then it's not our device object */
1347  {
1348  /* Fail the request, send it down the slow path */
1349  return FALSE;
1350  }
1351 
1352  DeviceExtension = DeviceObject->DeviceExtension;
1353  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1354 
1355  /* Get the device that we attached to */
1356  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1357  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1358 
1359  /* Make sure our FastIo table is valid */
1361  {
1362  /* Forward the call onto the device we attached to */
1364  FileOffset,
1365  MdlChain,
1366  AttachedDeviceObject);
1367  }
1368 
1369  /* We failed to handle the request, send it down the slow path */
1370  FLT_ASSERT(FALSE);
1371  return FALSE;
1372 }
1373 
1374 BOOLEAN
1375 NTAPI
1378  _In_ ULONG Length,
1379  _In_ ULONG LockKey,
1380  _Out_ PVOID Buffer,
1381  _Out_ PMDL *MdlChain,
1386 {
1387  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1388  PDEVICE_OBJECT AttachedDeviceObject;
1390 
1391  PAGED_CODE();
1392 
1393  /* If it doesn't have a device extension, then it's not our device object */
1395  {
1396  /* Fail the request, send it down the slow path */
1397  return FALSE;
1398  }
1399 
1400  DeviceExtension = DeviceObject->DeviceExtension;
1401  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1402 
1403  /* Get the device that we attached to */
1404  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1405  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1406 
1407  /* Make sure our FastIo table is valid */
1409  {
1410  /* Forward the call onto the device we attached to */
1412  FileOffset,
1413  Length,
1414  LockKey,
1415  Buffer,
1416  MdlChain,
1417  IoStatus,
1420  AttachedDeviceObject);
1421  }
1422 
1423  /* We failed to handle the request, send it down the slow path */
1424  FLT_ASSERT(FALSE);
1425  return FALSE;
1426 }
1427 
1428 BOOLEAN
1429 NTAPI
1432  _In_ ULONG Length,
1433  _In_ ULONG LockKey,
1434  _In_ PVOID Buffer,
1435  _Out_ PMDL *MdlChain,
1440 {
1441  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1442  PDEVICE_OBJECT AttachedDeviceObject;
1444 
1445  PAGED_CODE();
1446 
1447  /* If it doesn't have a device extension, then it's not our device object */
1449  {
1450  /* Fail the request, send it down the slow path */
1451  return FALSE;
1452  }
1453 
1454  DeviceExtension = DeviceObject->DeviceExtension;
1455  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1456 
1457  /* Get the device that we attached to */
1458  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1459  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1460 
1461  /* Make sure our FastIo table is valid */
1463  {
1464  /* Forward the call onto the device we attached to */
1466  FileOffset,
1467  Length,
1468  LockKey,
1469  Buffer,
1470  MdlChain,
1471  IoStatus,
1474  AttachedDeviceObject);
1475  }
1476 
1477  /* We failed to handle the request, send it down the slow path */
1478  FLT_ASSERT(FALSE);
1479  return FALSE;
1480 }
1481 
1482 BOOLEAN
1483 NTAPI
1485  _In_ PMDL MdlChain,
1487 {
1488  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1489  PDEVICE_OBJECT AttachedDeviceObject;
1491 
1492  PAGED_CODE();
1493 
1494  /* If it doesn't have a device extension, then it's not our device object */
1496  {
1497  return FALSE;
1498  }
1499 
1500  DeviceExtension = DeviceObject->DeviceExtension;
1501  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1502 
1503  /* Get the device that we attached to */
1504  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1505  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1506 
1507  /* Make sure our FastIo table is valid */
1509  {
1510  /* Forward the call onto the device we attached to */
1512  MdlChain,
1513  AttachedDeviceObject);
1514  }
1515 
1516  /* We failed to handle the request, send it down the slow path */
1517  FLT_ASSERT(FALSE);
1518  return FALSE;
1519 }
1520 
1521 BOOLEAN
1522 NTAPI
1525  _In_ PMDL MdlChain,
1527 {
1528  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1529  PDEVICE_OBJECT AttachedDeviceObject;
1531 
1532  PAGED_CODE();
1533 
1534  /* If it doesn't have a device extension, then it's not our device object */
1536  {
1537  return FALSE;
1538  }
1539 
1540  DeviceExtension = DeviceObject->DeviceExtension;
1541  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1542 
1543  /* Get the device that we attached to */
1544  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1545  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1546 
1547  /* Make sure our FastIo table is valid */
1549  {
1550  /* Forward the call onto the device we attached to */
1552  FileOffset,
1553  MdlChain,
1554  AttachedDeviceObject);
1555  }
1556 
1557  /* We failed to handle the request, send it down the slow path */
1558  FLT_ASSERT(FALSE);
1559  return FALSE;
1560 }
1561 
1562 BOOLEAN
1563 NTAPI
1567 {
1568  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1569  PDEVICE_OBJECT AttachedDeviceObject;
1571  BOOLEAN Success;
1572 
1573  PAGED_CODE();
1574 
1575  /* If it doesn't have a device extension, then it's not our device object */
1577  {
1578  return FALSE;
1579  }
1580 
1581  DeviceExtension = DeviceObject->DeviceExtension;
1582  FLT_ASSERT(DeviceExtension->AttachedToDeviceObject);
1583 
1584  /* Get the device that we attached to */
1585  AttachedDeviceObject = DeviceExtension->AttachedToDeviceObject;
1586  FastIoDispatch = AttachedDeviceObject->DriverObject->FastIoDispatch;
1587 
1588  /* Make sure our FastIo table is valid */
1590  {
1592 
1593  /* Update the stack to contain the correct device for the next filter */
1594  StackPtr->DeviceObject = AttachedDeviceObject;
1595 
1596  /* Now forward the call */
1599  AttachedDeviceObject);
1600 
1601  /* Restore the DeviceObject as we found it */
1602  StackPtr->DeviceObject = DeviceObject;
1603  return Success;
1604  }
1605 
1606  /* We failed to handle the request, send it down the slow path */
1607  FLT_ASSERT(FALSE);
1608  return FALSE;
1609 }
1610 
1611 
1612 
1613 /* FUNCTIONS **********************************************/
1614 
1615 static
1616 VOID
1618 {
1619  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1620 
1621  DeviceExtension = DeviceObject->DeviceExtension;
1622  if (DeviceExtension)
1623  {
1624  // cleanup device extension
1625  }
1626 }
1627 
1628 static
1629 NTSTATUS
1632  _Out_ PDEVICE_OBJECT *AttachedToDeviceObject)
1633 {
1634  NTSTATUS Status;
1635 
1636  PAGED_CODE();
1637 
1638  /* Before attaching, copy the flags from the device we're going to attach to */
1640  {
1642  }
1644  {
1646  }
1648  {
1649  SetFlag(TargetDevice->Characteristics, FILE_DEVICE_SECURE_OPEN);
1650  }
1651 
1652  /* Attach this device to the top of the driver stack */
1654  TargetDevice,
1655  AttachedToDeviceObject);
1656 
1657  return Status;
1658 }
1659 
1660 static
1661 BOOLEAN
1663  _In_opt_ PDEVICE_OBJECT *AttachedDeviceObject)
1664 {
1665  PDEVICE_OBJECT CurrentDeviceObject;
1667 
1668  PAGED_CODE();
1669 
1670  /* Initialize the return pointer */
1671  if (AttachedDeviceObject) *AttachedDeviceObject = NULL;
1672 
1673  /* Start by getting the top level device in the chain */
1674  CurrentDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
1675 
1676  /* Loop while there are attached devices */
1677  while (CurrentDeviceObject)
1678  {
1679  /* Check if this device driver matches ours */
1680  if (CurrentDeviceObject->DriverObject == DriverData.DriverObject)
1681  {
1682  FLT_ASSERT(CurrentDeviceObject->DeviceExtension != NULL);
1683 
1684  /* We're attached, return the device object if the caller asked for it */
1685  if (AttachedDeviceObject)
1686  {
1687  *AttachedDeviceObject = CurrentDeviceObject;
1688  }
1689  else
1690  {
1691  /* We aren't returning the reference, so decrement the count */
1692  ObDereferenceObject(CurrentDeviceObject);
1693  }
1694 
1695  return TRUE;
1696  }
1697 
1698  /* Get the next device in the chain */
1699  NextDeviceObject = IoGetLowerDeviceObject(CurrentDeviceObject);
1700 
1701  /* Decrement the count on the last device before we update the pointer */
1702  ObDereferenceObject(CurrentDeviceObject);
1703  CurrentDeviceObject = NextDeviceObject;
1704  }
1705 
1706  return FALSE;
1707 }
1708 
1709 static
1710 NTSTATUS
1712 {
1713  PFLTMGR_DEVICE_EXTENSION NewDeviceExtension;
1714  PDEVICE_OBJECT BaseDeviceObject;
1715  PDEVICE_OBJECT NewDeviceObject;
1717  PDEVICE_OBJECT StorageStackDeviceObject;
1719  ULONG NumDevices;
1720  ULONG i;
1721  NTSTATUS Status;
1722 
1723  PAGED_CODE();
1724 
1725  /* Get the base device */
1726  BaseDeviceObject = IoGetDeviceAttachmentBaseRef(DeviceObject);
1727 
1728  /* get the number of device object linked to the base file system */
1729  Status = IoEnumerateDeviceObjectList(BaseDeviceObject->DriverObject,
1730  NULL,
1731  0,
1732  &NumDevices);
1733  if (Status != STATUS_BUFFER_TOO_SMALL) return Status;
1734 
1735  /* Add a few more slots in case the size changed between calls and allocate some memory to hold the pointers */
1736  NumDevices += 4;
1738  (NumDevices * sizeof(PDEVICE_OBJECT)),
1741 
1742  /* Now get all the device objects that this base driver has created */
1743  Status = IoEnumerateDeviceObjectList(BaseDeviceObject->DriverObject,
1744  DeviceList,
1745  (NumDevices * sizeof(PDEVICE_OBJECT)),
1746  &NumDevices);
1747  if (!NT_SUCCESS(Status))
1748  {
1750  return Status;
1751  }
1752 
1753  /* Loop through all the devices looking for ones to attach to */
1754  for (i = 0; i < NumDevices; i++)
1755  {
1757  StorageStackDeviceObject = NULL;
1758  NewDeviceObject = NULL;
1759 
1760  /* Ignore the device we passed in, and devices of the wrong type */
1761  if ((DeviceList[i] == BaseDeviceObject) ||
1762  (DeviceList[i]->DeviceType != BaseDeviceObject->DeviceType))
1763  {
1764  goto CleanupAndNext;
1765  }
1766 
1767  /* Ignore this device if we're already attached to it */
1769  {
1770  goto CleanupAndNext;
1771  }
1772 
1773 
1774  /*
1775  * If the device has a name, it must be a control device.
1776  * This handles drivers with more then one control device (like FastFat)
1777  */
1779  if (NT_SUCCESS(Status) && DeviceName.Length > 0)
1780  {
1781  goto CleanupAndNext;
1782  }
1783 
1784  /*
1785  * Try to get the storage stack (disk) device object associated with
1786  * this file system device object. Ignore the device if we don't have one
1787  */
1789  &StorageStackDeviceObject);
1790  if (!NT_SUCCESS(Status))
1791  {
1792  goto CleanupAndNext;
1793  }
1794 
1795 
1796  /*
1797  * TODO: Don't attach to shadow copy volumes,
1798  * ros doesn't have any so it's not an issues yet
1799  */
1800 
1801  /*
1802  * We're far enough to be ready to attach, create a device
1803  * object which we'll use to do so
1804  */
1806  sizeof(FLTMGR_DEVICE_EXTENSION),
1807  NULL,
1809  0,
1810  FALSE,
1811  &NewDeviceObject);
1812  if (!NT_SUCCESS(Status))
1813  {
1814  goto CleanupAndNext;
1815  }
1816 
1817  /* Get the device extension for this new object and store our disk object there */
1818  NewDeviceExtension = NewDeviceObject->DeviceExtension;
1819  NewDeviceExtension->StorageStackDeviceObject = StorageStackDeviceObject;
1820 
1821  /* Lookup and store the device name for the storage stack */
1822  RtlInitEmptyUnicodeString(&NewDeviceExtension->DeviceName,
1823  NewDeviceExtension->DeviceNameBuffer,
1824  sizeof(NewDeviceExtension->DeviceNameBuffer));
1825  FltpGetObjectName(StorageStackDeviceObject,
1826  &NewDeviceExtension->DeviceName);
1827 
1828 
1829  /* Grab the attach lock before we attempt to attach */
1831 
1832  /* Check again that we aren't already attached. It may have changed since our last check */
1834  {
1835  FLT_ASSERT(NewDeviceObject->DriverObject == DriverData.DriverObject);
1836 
1837  /* Finally, attach to the volume */
1839  NewDeviceObject,
1840  &NewDeviceExtension->AttachedToDeviceObject);
1841  if (NT_SUCCESS(Status))
1842  {
1843  /* Clean the initializing flag so other filters can attach to our device object */
1844  ClearFlag(NewDeviceObject->Flags, DO_DEVICE_INITIALIZING);
1845  }
1846  }
1847  else
1848  {
1849  /* We're already attached. Just cleanup */
1851  }
1852 
1854 
1855 CleanupAndNext:
1856 
1857  if (!NT_SUCCESS(Status))
1858  {
1859  if (NewDeviceObject)
1860  {
1861  FltpCleanupDeviceObject(NewDeviceObject);
1862  IoDeleteDevice(NewDeviceObject);
1863  }
1864  }
1865 
1866  if (StorageStackDeviceObject)
1867  {
1868  /* A ref was added for us when we attached, so we can deref ours now */
1869  ObDereferenceObject(StorageStackDeviceObject);
1870  }
1871 
1872  /* Remove the ref which was added by IoEnumerateDeviceObjectList */
1874 
1875  /* Free the buffer that FltpGetBaseDeviceObjectName added */
1877 
1878  }
1879 
1880  /* Free the memory we allocated for the list */
1882 
1883  return STATUS_SUCCESS;
1884 }
1885 
1886 static
1887 NTSTATUS
1890 {
1891  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1892  PDEVICE_OBJECT NewDeviceObject;
1894  UNICODE_STRING FileSystemDeviceName;
1895  UNICODE_STRING FsRecDeviceName;
1896  NTSTATUS Status;
1897 
1898  PAGED_CODE();
1899 
1900  /* Only handle device types we're interested in */
1901  if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
1904  {
1905  return STATUS_SUCCESS;
1906  }
1907 
1908  /* Setup the buffer to hold the device name */
1909  RtlInitEmptyUnicodeString(&FileSystemDeviceName,
1910  Buffer,
1911  MAX_DEVNAME_LENGTH * sizeof(WCHAR));
1912 
1913  /* Get the the name of the file system device */
1914  Status = FltpGetObjectName(DeviceObject->DriverObject, &FileSystemDeviceName);
1915  if (!NT_SUCCESS(Status)) return Status;
1916 
1917  DPRINT("Found device %wZ, checking if we need to attach...\n", &FileSystemDeviceName);
1918 
1919  /* Build up the name of the file system recognizer device */
1920  RtlInitUnicodeString(&FsRecDeviceName, L"\\FileSystem\\Fs_Rec");
1921 
1922  /* We don't attach to recognizer devices, so bail if this is one */
1923  if (RtlCompareUnicodeString(&FileSystemDeviceName, &FsRecDeviceName, TRUE) == 0)
1924  {
1925  return STATUS_SUCCESS;
1926  }
1927 
1928  /* Create a device object which we can attach to this file system */
1930  sizeof(FLTMGR_DEVICE_EXTENSION),
1931  NULL,
1932  DeviceObject->DeviceType,
1933  0,
1934  FALSE,
1935  &NewDeviceObject);
1936  if (!NT_SUCCESS(Status))
1937  {
1938  DPRINT1("Failed to create a DO for attaching to a FS : 0x%X\n", Status);
1939  return Status;
1940  }
1941 
1942  /* Cast the device extension to something we understand */
1943  DeviceExtension = NewDeviceObject->DeviceExtension;
1944 
1945  /* Attach this device to the top of the driver stack and store the DO we attached to in the DE */
1946  Status = FltpAttachDeviceObject(NewDeviceObject,
1947  DeviceObject,
1948  &DeviceExtension->AttachedToDeviceObject);
1949  if (NT_SUCCESS(Status))
1950  {
1951  DPRINT("Attached to %wZ\n", &FileSystemDeviceName);
1952  }
1953  else
1954  {
1955  DPRINT1("Failed to attach to the driver stack : 0x%X\n", Status);
1956  goto Cleanup;
1957  }
1958 
1959  /* Setup the unicode string buffer and copy the device name to the device extension */
1960  RtlInitEmptyUnicodeString(&DeviceExtension->DeviceName,
1961  DeviceExtension->DeviceNameBuffer,
1962  MAX_DEVNAME_LENGTH * sizeof(WCHAR));
1963  RtlCopyUnicodeString(&DeviceExtension->DeviceName, DeviceName);
1964 
1965  /* We're done, remove the initializing flag */
1966  ClearFlag(NewDeviceObject->Flags, DO_DEVICE_INITIALIZING);
1967 
1968  /* Look for existing mounted devices for this file system */
1970  if (!NT_SUCCESS(Status))
1971  {
1972  DPRINT1("Failed to enumerate file system volumes for this file system : 0x%X\n", Status);
1973  IoDetachDevice(DeviceExtension->AttachedToDeviceObject);
1974  }
1975 
1976 Cleanup:
1977 
1978  if (!NT_SUCCESS(Status))
1979  {
1980  IoDeleteDevice(NewDeviceObject);
1981  }
1982 
1983  return Status;
1984 }
1985 
1986 static
1987 LONG_PTR
1989 {
1990  PDEVICE_OBJECT AttachedDevice, NextDevice;
1991  PFLTMGR_DEVICE_EXTENSION DeviceExtension;
1992  LONG_PTR Count;
1993 
1994  PAGED_CODE();
1995 
1996  /* Get the top device in the chain and increment the ref count on it */
1997  AttachedDevice = IoGetAttachedDeviceReference(DeviceObject);
1998 
1999  /* Loop all attached devices looking for our file system driver */
2000  while (AttachedDevice->DriverObject != DriverData.DriverObject)
2001  {
2002  FLT_ASSERT(AttachedDevice != NULL);
2003 
2004  /* Get the next lower device object. This adds a ref on NextDevice */
2005  NextDevice = IoGetLowerDeviceObject(AttachedDevice);
2006 
2007  /* Remove the reference we added */
2008  Count = ObDereferenceObject(AttachedDevice);
2009 
2010  /* Bail if this is the last one */
2011  if (NextDevice == NULL) return Count;
2012 
2013  /* Try the next one */
2014  AttachedDevice = NextDevice;
2015  }
2016 
2017 
2018  DeviceExtension = AttachedDevice->DeviceExtension;
2019  if (DeviceExtension)
2020  {
2021  //
2022  // FIXME: Put any device extension cleanup code here
2023  //
2024  }
2025 
2026  /* Detach the device from the chain and delete the object */
2028  IoDeleteDevice(AttachedDevice);
2029 
2030  /* Remove the reference we added so the delete can complete */
2031  return ObDereferenceObject(AttachedDevice);
2032 }
2033 
2034 DRIVER_FS_NOTIFICATION FltpFsNotification;
2035 VOID
2036 NTAPI
2039 {
2041  NTSTATUS Status;
2042 
2043  PAGED_CODE();
2044 
2045  /* Set an empty string */
2047 
2048  /* Get the name of the lowest device object on the stack */
2050  if (NT_SUCCESS(Status))
2051  {
2052  /* Check if it's attaching or detaching */
2053  if (FsActive)
2054  {
2055  /* Run the attach routine */
2057  }
2058  else
2059  {
2060  /* Run the detach routine */
2062  }
2063 
2064  /* Free the buffer which FltpGetBaseDeviceObjectName allocated */
2066  }
2067 }
2068 
2069 DRIVER_INITIALIZE DriverEntry;
2070 NTSTATUS
2071 NTAPI
2074 {
2075  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\FileSystem\\Filters\\"DRIVER_NAME);
2076  PDEVICE_OBJECT RawDeviceObject;
2078  PFILE_OBJECT RawFileObject;
2080  UNICODE_STRING SymLink;
2081 
2082  NTSTATUS Status;
2083 
2086 
2087  /* Save the registry key for this driver */
2095 
2096  /* Do some initialization */
2098 
2099  /* Create the main filter manager device object */
2101  0,
2102  &DeviceName,
2105  FALSE,
2106  &DeviceObject);
2107  if (!NT_SUCCESS(Status))
2108  {
2109  DPRINT1("fltmgr IoCreateDevice failed. Status = %X\n", Status);
2110  goto Cleanup;
2111  }
2112 
2113  /* Store a global reference so we can access from callbacks */
2115 
2116  /* Generate the symbolic link name */
2117  RtlInitUnicodeString(&SymLink, L"\\??\\"DRIVER_NAME);
2118  Status = IoCreateSymbolicLink(&SymLink, &DeviceName);
2119  if (!NT_SUCCESS(Status)) goto Cleanup;
2120 
2121  /* Create the callbacks for the dispatch table, FastIo and FS callbacks */
2123  if (!NT_SUCCESS(Status)) goto Cleanup;
2124 
2125  /* Initialize the comms objects */
2127  if (!NT_SUCCESS(Status)) goto Cleanup;
2128 
2129  /* Register for notifications when a new file system is loaded. This also enumerates any existing file systems */
2131  FLT_ASSERT(Status != STATUS_DEVICE_ALREADY_ATTACHED); // Windows checks for this, I'm not sure how it can happen. Needs investigation??
2132  if (!NT_SUCCESS(Status)) goto Cleanup;
2133 
2136 
2137  /* IoRegisterFsRegistrationChange isn't notified about the raw file systems, so we attach to them manually */
2138  RtlInitUnicodeString(&ObjectName, L"\\Device\\RawDisk");
2141  &RawFileObject,
2142  &RawDeviceObject);
2143  if (NT_SUCCESS(Status))
2144  {
2145  FltpFsNotification(RawDeviceObject, TRUE);
2146  ObDereferenceObject(RawFileObject);
2147  }
2148 
2149  RtlInitUnicodeString(&ObjectName, L"\\Device\\RawCdRom");
2152  &RawFileObject,
2153  &RawDeviceObject);
2154  if (NT_SUCCESS(Status))
2155  {
2156  FltpFsNotification(RawDeviceObject, TRUE);
2157  ObDereferenceObject(RawFileObject);
2158  }
2159 
2160  /* We're done, clear the initializing flag */
2163 
2164 Cleanup:
2165 
2166  if (!NT_SUCCESS(Status))
2167  {
2169  {
2172  }
2173 
2174  IoDeleteSymbolicLink(&SymLink);
2175 
2176  if (DeviceObject)
2178 
2181  }
2182 
2183  return Status;
2184 }
2185 
2186 
2187 static
2188 NTSTATUS
2190 {
2193  ULONG i;
2194 
2195  /* Plug all the IRPs */
2196  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
2197  {
2199  }
2200 
2201  /* Override the ones we're interested in */
2207 
2208  /* The FastIo dispatch table is stored in the pool along with a tag */
2211 
2212  /* Fill out the FastIo table */
2236 
2237  /* Store the FastIo table for internal and our access */
2240 
2241  /* Initialize the callback table */
2242  Callbacks.SizeOfFsFilterCallbacks = sizeof(FS_FILTER_CALLBACKS);
2243  Callbacks.PreAcquireForSectionSynchronization = FltpPreFsFilterOperation;
2244  Callbacks.PostAcquireForSectionSynchronization = FltpPostFsFilterOperation;
2245  Callbacks.PreReleaseForSectionSynchronization = FltpPreFsFilterOperation;
2246  Callbacks.PostReleaseForSectionSynchronization = FltpPostFsFilterOperation;
2247  Callbacks.PreAcquireForCcFlush = FltpPreFsFilterOperation;
2248  Callbacks.PostAcquireForCcFlush = FltpPostFsFilterOperation;
2249  Callbacks.PreReleaseForCcFlush = FltpPreFsFilterOperation;
2250  Callbacks.PostReleaseForCcFlush = FltpPostFsFilterOperation;
2251  Callbacks.PreAcquireForModifiedPageWriter = FltpPreFsFilterOperation;
2252  Callbacks.PostAcquireForModifiedPageWriter = FltpPostFsFilterOperation;
2253  Callbacks.PreReleaseForModifiedPageWriter = FltpPreFsFilterOperation;
2254  Callbacks.PostReleaseForModifiedPageWriter = FltpPostFsFilterOperation;
2255 
2256  /* Register our callbacks */
2258 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_DEVICE_ALREADY_ATTACHED
Definition: ntstatus.h:278
static NTSTATUS FltpAttachDeviceObject(_In_ PDEVICE_OBJECT SourceDevice, _In_ PDEVICE_OBJECT TargetDevice, _Out_ PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: Interface.c:1630
#define FM_TAG_DEV_OBJ_PTRS
Definition: fltmgr.h:17
BOOLEAN NTAPI FltpFastIoMdlReadCompleteCompressed(_In_ PFILE_OBJECT FileObject, _In_ PMDL MdlChain, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1484
#define FM_TAG_DISPATCH_TABLE
Definition: fltmgr.h:15
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle
Definition: iotypes.h:1696
PDRIVER_OBJECT DriverObject
Definition: fltmgr.h:29
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MJ_CREATE_MAILSLOT
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
BOOLEAN NTAPI FltpFastIoReadCompressed(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PMDL *MdlChain, _Out_ PIO_STATUS_BLOCK IoStatus, _Out_ PCOMPRESSED_DATA_INFO CompressedDataInfo, _In_ ULONG CompressedDataInfoLength, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1376
_Out_ PFILE_NETWORK_OPEN_INFORMATION NetworkInformation
Definition: iotypes.h:1659
LIST_ENTRY FilterList
Definition: Filter.c:24
USHORT MaximumLength
Definition: env_spec_w32.h:370
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:688
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define IRP_MJ_SHUTDOWN
VOID FltpFreeUnicodeString(_In_ PUNICODE_STRING String)
Definition: Lib.c:24
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
struct _DETACH_DEVICE_WORK_ITEM * PDETACH_DEVICE_WORK_ITEM
DeviceType
Definition: mmdrv.h:41
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _Outptr_ PMDL * MdlChain
Definition: fsrtlfuncs.h:46
#define IRP_MJ_MAXIMUM_FUNCTION
FAST_MUTEX FilterAttachLock
Definition: fltmgr.h:37
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI FltpCreate(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Interface.c:486
static LONG_PTR FltpDetachFromFileSystemDevice(_In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1988
BOOLEAN NTAPI FltpFastIoMdlReadComplete(_In_ PFILE_OBJECT FileObject, _In_ PMDL MdlChain, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1243
PFAST_IO_MDL_READ MdlRead
Definition: iotypes.h:1705
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite
Definition: iotypes.h:1707
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
PFAST_IO_UNLOCK_ALL FastIoUnlockAll
Definition: iotypes.h:1697
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1295
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1434
ERESOURCE FilterListLock
Definition: Filter.c:25
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT SourceDevice
Definition: iofuncs.h:688
PDEVICE_OBJECT CommsDeviceObject
Definition: Messaging.c:22
PDEVICE_OBJECT StorageStackDeviceObject
Definition: fltmgr.h:47
static NTSTATUS FltpEnumerateFileSystemVolumes(_In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1711
PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo
Definition: iotypes.h:1703
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
BOOLEAN NTAPI FltpFastIoMdlRead(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ ULONG LockKey, _Out_ PMDL *MdlChain, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1193
WCHAR DeviceName[]
Definition: adapter.cpp:21
_In_ PVOID Parameter
Definition: ldrtypes.h:240
PFAST_IO_READ_COMPRESSED FastIoReadCompressed
Definition: iotypes.h:1709
BOOLEAN NTAPI FltpFastIoRead(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:645
NTSTATUS NTAPI IoEnumerateDeviceObjectList(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT *DeviceObjectList, IN ULONG DeviceObjectListSize, OUT PULONG ActualNumberDeviceObjects)
Definition: device.c:1321
PFAST_IO_MDL_READ_COMPLETE MdlReadComplete
Definition: iotypes.h:1706
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
UNICODE_STRING DeviceName
Definition: fltmgr.h:51
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN CheckForReadOperation
Definition: fatprocs.h:2650
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define _In_opt_
Definition: no_sal2.h:213
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1418
PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed
Definition: iotypes.h:1711
BOOLEAN NTAPI FltpFastIoWriteCompressed(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ ULONG LockKey, _In_ PVOID Buffer, _Out_ PMDL *MdlChain, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PCOMPRESSED_DATA_INFO CompressedDataInfo, _In_ ULONG CompressedDataInfoLength, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1430
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
PFAST_IO_DETACH_DEVICE FastIoDetachDevice
Definition: iotypes.h:1702
DRIVER_DATA DriverData
Definition: Interface.c:396
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FM_TAG_REGISTRY_DATA
Definition: fltmgr.h:16
NTSTATUS NTAPI FltpPreFsFilterOperation(_In_ PFS_FILTER_CALLBACK_DATA Data, _Out_ PVOID *CompletionContext)
Definition: Interface.c:412
PFAST_IO_QUERY_OPEN FastIoQueryOpen
Definition: iotypes.h:1713
PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo
Definition: iotypes.h:1693
NTSTATUS FltpGetBaseDeviceObjectName(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PUNICODE_STRING ObjectName)
Definition: Object.c:245
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
Definition: fatprocs.h:2697
struct _DETACH_DEVICE_WORK_ITEM DETACH_DEVICE_WORK_ITEM
_Unreferenced_parameter_ PVOID * CompletionContext
Definition: cdprocs.h:1130
struct _FAST_IO_DISPATCH FAST_IO_DISPATCH
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define DO_SYSTEM_BOOT_PARTITION
Definition: env_spec_w32.h:400
smooth NULL
Definition: ftsmooth.c:416
_IRQL_requires_same_ _In_ PKE_PROCESSOR_CHANGE_NOTIFY_CONTEXT _Inout_ PNTSTATUS OperationStatus
Definition: ketypes.h:360
NTSTATUS NTAPI FltpFsControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Interface.c:527
#define _Out_
Definition: no_sal2.h:323
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI FltpFastIoDeviceControl(_In_ PFILE_OBJECT FileObject, _In_ BOOLEAN Wait, _In_opt_ PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_opt_ PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ ULONG IoControlCode, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1036
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1506
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
BOOLEAN NTAPI FltpFastIoLock(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PLARGE_INTEGER Length, _In_ PEPROCESS ProcessId, _In_ ULONG Key, _In_ BOOLEAN FailImmediately, _In_ BOOLEAN ExclusiveLock, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:841
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _Out_ PVOID _Out_ PMDL _Out_ PIO_STATUS_BLOCK _Out_ struct _COMPRESSED_DATA_INFO _In_ ULONG CompressedDataInfoLength
Definition: iotypes.h:1614
BOOLEAN NTAPI FltpFastIoQueryBasicInfo(_In_ PFILE_OBJECT FileObject, _In_ BOOLEAN Wait, _Out_ PFILE_BASIC_INFORMATION Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:749
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1405
static VOID FltpCleanupDeviceObject(_In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1617
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
BOOLEAN NTAPI FltpFastIoQueryOpen(_Inout_ PIRP Irp, _Out_ PFILE_NETWORK_OPEN_INFORMATION NetworkInformation, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1564
BOOLEAN NTAPI FltpFastIoCheckIfPossible(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _In_ BOOLEAN CheckForReadOperation, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:592
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2650
VOID FASTCALL IofCompleteRequest(IN PIRP Irp, IN CCHAR PriorityBoost)
Definition: irp.c:1308
#define _Out_opt_
Definition: no_sal2.h:339
BOOLEAN NTAPI FltpFastIoMdlWriteComplete(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PMDL MdlChain, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1334
BOOLEAN NTAPI FltpFastIoUnlockAll(_In_ PFILE_OBJECT FileObject, _In_ PEPROCESS ProcessId, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:945
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
const struct winhelp_callbacks Callbacks
Definition: callback.c:161
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI FltpPostFsFilterOperation(_In_ PFS_FILTER_CALLBACK_DATA Data, _In_ NTSTATUS OperationStatus, _In_ PVOID CompletionContext)
Definition: Interface.c:423
BOOLEAN NTAPI FltpFastIoQueryNetworkOpenInfo(_In_ PFILE_OBJECT FileObject, _In_ BOOLEAN Wait, _Out_ PFILE_NETWORK_OPEN_INFORMATION Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1147
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define IRP_MJ_FILE_SYSTEM_CONTROL
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
DRIVER_FS_NOTIFICATION FltpFsNotification
Definition: Interface.c:90
PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey
Definition: iotypes.h:1698
_In_ BOOLEAN FsActive
Definition: iotypes.h:7003
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2866
#define _Inout_
Definition: no_sal2.h:244
NTSTATUS FltpMsgCreate(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Messaging.c:223
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN NTAPI FltpFastIoMdlWriteCompleteCompressed(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PMDL MdlChain, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1523
#define MAX_DEVNAME_LENGTH
Definition: fltmgr.h:24
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * NextDeviceObject
Definition: ndis.h:4640
NTSTATUS NTAPI FsRtlRegisterFileSystemFilterCallbacks(PDRIVER_OBJECT FilterDriverObject, PFS_FILTER_CALLBACKS Callbacks)
Definition: fastio.c:1947
PFAST_IO_LOCK FastIoLock
Definition: iotypes.h:1695
NTSTATUS FltpDeviceControlHandler(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Dispatch.c:37
NTSTATUS NTAPI IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject, OUT PDEVICE_OBJECT *DiskDeviceObject)
Definition: device.c:1452
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
PFAST_IO_DEVICE_CONTROL FastIoDeviceControl
Definition: iotypes.h:1699
#define DRIVER_NAME
Definition: ext2fs.h:136
BOOLEAN NTAPI FltpFastIoPrepareMdlWrite(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ ULONG LockKey, _Out_ PMDL *MdlChain, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:1284
Definition: typedefs.h:117
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
static const WCHAR Cleanup[]
Definition: register.c:80
PDEVICE_OBJECT DeviceObject
Definition: fltmgr.h:30
static NTSTATUS FltpAttachToFileSystemDevice(_In_ PDEVICE_OBJECT DeviceObject, _In_ PUNICODE_STRING DeviceName)
Definition: Interface.c:1888
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
struct _FS_FILTER_CALLBACKS FS_FILTER_CALLBACKS
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
DWORD DeviceType
Definition: utils.c:20
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1692
PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed
Definition: iotypes.h:1710
PDEVICE_LIST DeviceList
Definition: utils.c:27
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
NTSTATUS NTAPI FltpDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Interface.c:556
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_REPARSE
Definition: ntstatus.h:83
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:125
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo
Definition: iotypes.h:1694
NTSTATUS FltpDispatchHandler(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Dispatch.c:103
BOOLEAN NTAPI FltpFastIoUnlockAllByKey(_In_ PFILE_OBJECT FileObject, _In_ PVOID ProcessId, _In_ ULONG Key, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:990
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
DRIVER_INITIALIZE DriverEntry
Definition: Interface.c:36
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
Definition: fatprocs.h:2697
#define DPRINT1
Definition: precomp.h:8
NTSTATUS FltpMsgDispatch(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Messaging.c:256
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete
Definition: iotypes.h:1708
_In_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _Out_ PVOID _Out_ PMDL _Out_ PIO_STATUS_BLOCK _Out_ struct _COMPRESSED_DATA_INFO * CompressedDataInfo
Definition: iotypes.h:1614
PDEVICE_OBJECT AttachedToDeviceObject
Definition: fltmgr.h:44
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:108
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
VOID NTAPI FltpFastIoDetachDevice(_In_ PDEVICE_OBJECT SourceDevice, _In_ PDEVICE_OBJECT TargetDevice)
Definition: Interface.c:1107
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
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
PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible
Definition: iotypes.h:1690
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
BOOLEAN NTAPI FltpFastIoUnlockSingle(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PLARGE_INTEGER Length, _In_ PEPROCESS ProcessId, _In_ ULONG Key, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:895
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI FltpFastIoDetachDeviceWorker(_In_ PVOID Parameter)
Definition: Interface.c:1088
PDEVICE_OBJECT SourceDevice
Definition: Interface.c:402
BOOLEAN NTAPI FltpFastIoQueryStandardInfo(_In_ PFILE_OBJECT FileObject, _In_ BOOLEAN Wait, _Out_ PFILE_STANDARD_INFORMATION Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:795
NTSTATUS NTAPI FltpDispatch(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: Interface.c:435
return STATUS_SUCCESS
Definition: btrfs.c:2777
NTSTATUS FltpSetupCommunicationObjects(_In_ PDRIVER_OBJECT DriverObject)
Definition: Messaging.c:377
UNICODE_STRING ServiceKey
Definition: fltmgr.h:31
NTSTATUS FltpGetObjectName(_In_ PVOID Object, _Inout_ PUNICODE_STRING ObjectName)
Definition: Object.c:263
NTSTATUS NTAPI IoRegisterFsRegistrationChange(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_FS_NOTIFICATION DriverNotificationRoutine)
Definition: volume.c:1094
WCHAR DeviceNameBuffer[MAX_DEVNAME_LENGTH]
Definition: fltmgr.h:52
PDEVICE_OBJECT TargetDevice
Definition: Interface.c:403
PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed
Definition: iotypes.h:1712
BOOLEAN NTAPI FltpFastIoWrite(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _In_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
Definition: Interface.c:697
#define IRP_MJ_CREATE_NAMED_PIPE
PFAST_IO_DISPATCH FastIoDispatch
Definition: fltmgr.h:35
static NTSTATUS SetupDispatchAndCallbacksTables(_In_ PDRIVER_OBJECT DriverObject)
Definition: Interface.c:2189
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1689
static BOOLEAN FltpIsAttachedToDevice(_In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PDEVICE_OBJECT *AttachedDeviceObject)
Definition: Interface.c:1662
IN BOOLEAN Wait
Definition: fatprocs.h:1529
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
WORK_QUEUE_ITEM WorkItem
Definition: Interface.c:401