1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
8 Module Name: Filter.cpp
12 Contains code to handle register file system notification and attach to
23 // define the file specific bug-check id
24 #define UDF_BUG_CHECK_ID UDF_FILE_FILTER
27 UDFCheckOtherFS(PDEVICE_OBJECT deviceObject
) {
28 PFILTER_DEV_EXTENSION FilterDevExt
;
29 PDEVICE_OBJECT filterDeviceObject
;
34 // Acquire GlobalDataResource
35 UDFAcquireResourceExclusive(&(UDFGlobalData
.GlobalDataResource
), TRUE
);
37 if (!NT_SUCCESS(RC
= IoCreateDevice(
38 UDFGlobalData
.DriverObject
, // our driver object
39 sizeof(FILTER_DEV_EXTENSION
), // don't need an extension
41 NULL
, // name - can be used to
43 // see the R.Nagar's book
44 // for alternate choices
45 FILE_DEVICE_CD_ROM_FILE_SYSTEM
,
46 0, // no special characteristics
47 // do not want this as an
48 // exclusive device, though
51 &filterDeviceObject
))) {
52 // failed to create a filter device object, leave ...
53 // Release the global resource.
54 UDFReleaseResource( &(UDFGlobalData
.GlobalDataResource
) );
57 FilterDevExt
= (PFILTER_DEV_EXTENSION
)filterDeviceObject
->DeviceExtension
;
58 // Zero it out (typically this has already been done by the I/O
59 // Manager but it does not hurt to do it again)!
60 RtlZeroMemory(FilterDevExt
, sizeof(FILTER_DEV_EXTENSION
));
62 // Initialize the signature fields
63 FilterDevExt
->NodeIdentifier
.NodeType
= UDF_NODE_TYPE_FILTER_DEVOBJ
;
64 FilterDevExt
->NodeIdentifier
.NodeSize
= sizeof(FILTER_DEV_EXTENSION
);
66 UDFPrint(("UDFCheckOtherFS: Attaching filter devobj %x to FS devobj %x \n",filterDeviceObject
,deviceObject
));
67 deviceObject
= IoGetAttachedDevice( deviceObject
);
68 UDFPrint(("UDFCheckOtherFS: top devobj is %x \n",deviceObject
));
69 FilterDevExt
->lowerFSDeviceObject
= deviceObject
;
71 RC
= IoAttachDeviceByPointer( filterDeviceObject
, deviceObject
);
72 if (!NT_SUCCESS(RC
)) {
73 IoDeleteDevice( filterDeviceObject
);
75 filterDeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
77 // Release the global resource.
78 UDFReleaseResource( &(UDFGlobalData
.GlobalDataResource
) );
82 UDFCheckOtherFSByName(PCWSTR DeviceObjectName
) {
83 PFILE_OBJECT fileObject
;
84 PDEVICE_OBJECT deviceObject
;
85 UNICODE_STRING nameString
;
88 UDFPrint(("UDFCheckOtherFSByName: trying %s \n",DeviceObjectName
));
90 RtlInitUnicodeString( &nameString
, DeviceObjectName
);
91 RC
= IoGetDeviceObjectPointer(
98 if (!NT_SUCCESS(RC
)) {
99 UDFPrint(("UDFCheckOtherFSByName: error %x while calling IoGetDeviceObjectPointer \n",RC
));
103 UDFCheckOtherFS(deviceObject
);
105 ObDereferenceObject( fileObject
);
112 IN PDEVICE_OBJECT DeviceObject
,
120 This routine is invoked whenever a file system has either registered or
121 unregistered itself as an active file system.
123 For the former case, this routine creates a device object and attaches it
124 to the specified file system's device object. This allows this driver
125 to filter all requests to that file system.
127 For the latter case, this file system's device object is located,
128 detached, and deleted. This removes this file system as a filter for
129 the specified file system.
133 DeviceObject - Pointer to the file system's device object.
135 FsActive - bolean indicating whether the file system has registered
136 (TRUE) or unregistered (FALSE) itself as an active file system.
145 // Begin by determine whether or not the file system is a cdrom-based file
146 // system. If not, then this driver is not concerned with it.
147 if (DeviceObject
->DeviceType
!= FILE_DEVICE_CD_ROM_FILE_SYSTEM
) {
151 // Begin by determining whether this file system is registering or
152 // unregistering as an active file system.
154 UDFPrint(("UDFFSNotification \n"));
155 UDFCheckOtherFS(DeviceObject
);