1 / 13

Modifying Parameters

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)

najwa
Download Presentation

Modifying Parameters

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modifying Parameters © 2004 Microsoft Corporation. All rights reserved.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. Sample • See the SwapBuffers minifilter sample © 2004 Microsoft Corporation. All rights reserved.

More Related