150 likes | 485 Views
Modifying Parameters. Changing Operation Parameters. Only fields in FLT_CALLBACK_DATA.Iopb structure can be changed Includes TargetInstance , TargetFileObject , and operation specific parameters (including buffer address and MDL)
E N D
Modifying Parameters © 2004 Microsoft Corporation. All rights reserved.
Changing Operation Parameters • Only fields in FLT_CALLBACK_DATA.Iopb structure can be changed • Includes TargetInstance, TargetFileObject, and operation specific parameters (including buffer address and MDL) • TargetInstance can only be changed to an instance of your filter at the same altitude on another volume • TargetFileObject must be to a file on the same volume as TargetInstance • MajorFunction may not be changed – generate another IO © 2004 Microsoft Corporation. All rights reserved.
Changing Operation Parameters (cont) • FltSetCallbackDataDirty() • Must be called to signify that parameters have been changed • If FLT_CALLBACK_DATA is not marked DIRTY, changes are ignored • FltClearCallbackDataDirty() • FltIsCallbackDataDirty() © 2004 Microsoft Corporation. All rights reserved.
Changing Operation Parameters (cont) • Parameters received in postOperation callback are the parameters received in preOperation • These parameters DO NOT reflect any parameter changes filter may have made • If filter needs to know changes made to parameters in postOperation callback, it should record the changes in the context passed from the preOperation callback © 2004 Microsoft Corporation. All rights reserved.
Changing Operation Parameters (cont) • FLT_CALLBACK_DATA.IoStatus may also be changed • This is an exception to the previous rule • May be changed in pre operation callback if completing the operation • May be changed in post operation callback if undoing operation • If changing a successful operation to a failure, it is filters responsibility to undo the operation • Do not need to call FLT_SET_CALLBACK_DATA_DIRTY() © 2004 Microsoft Corporation. All rights reserved.
Swapping Buffers • Always keep the MDL and buffer fields in sync • After making a buffer or MDL change, always call FltSetCallbackDataDirty() • Never change the state of the FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag • Should only be set by Filter Manager © 2004 Microsoft Corporation. All rights reserved.
Swapping Buffers (cont) • If you swap buffers you must have a postOperation callback • Do not free the Buffer or MDL you are replacing • Do not free MDLs you have successfully inserted into a callback data structure • FltMgr will free them for you • In your postOperation callback, free the buffer you allocated • Again, do not free the MDL © 2004 Microsoft Corporation. All rights reserved.
Swapping Buffers (cont) • IRP operation • IfFLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is set: • New buffer must be allocated from nonPaged pool • Set the MDL field to NULL • Call FLT_SET_CALLBACK_DATA_DIRTY() • If FLTFL_CALLBACK_DATA_SYSTEM_BUFFER flag is not set: • New buffer can be from paged or nonPaged pool • PagingIO operation buffers must be from nonPaged pool • Always create and set a MDL • See MmBuildMdlForNonPagedPool() • CallFLT_SET_CALLBACK_DATA_DIRTY() © 2004 Microsoft Corporation. All rights reserved.
Swapping Buffers (cont) • FastIO • New buffer can be from paged or nonPaged pool • Set the MDL to NULL • MDL should already be NULL • Call FltSetCallbackDataDirty() © 2004 Microsoft Corporation. All rights reserved.
Swapping Buffers (cont) • WARNING: Non-Cached IO operations • MM violates the rule that the length of non-cached IO operations must be rounded to a sector boundary • The file systems round the length up to the next sector size below the filter • When swapping buffers in this scenario, the filter must round the length up to the sector size (use SectorSize field in DeviceObject) before allocating/copying data. • If you don’t the system may crash or you may corrupt the file © 2004 Microsoft Corporation. All rights reserved.
Swapped Buffer Support Routines • FltGetSwappedBufferMdlAddress() • Only callable from postOperation callback • Returns the MDL for the buffer that you set in the preOperation callback • This may return NULL • FltRetainSwappedBufferMdlAddress() • Only callable from postOperation callback • Tells FltMgr to not free the current operations MDL • It is now the filters responsibility to free this MDL © 2004 Microsoft Corporation. All rights reserved.
Unloading Filters with Swapped Buffers • These operations are not “drainable” • Instead, the operation is canceled • After canceling, FltMgr waits for the operation to complete. • Whether the operation has a cancel routine or not, it is assumed it will complete soon © 2004 Microsoft Corporation. All rights reserved.
Sample • See the SwapBuffers minifilter sample © 2004 Microsoft Corporation. All rights reserved.