none
How to copy the PCFLT_RELATED_OBJECTS instance in the PostOPCreate call back RRS feed

  • Question

  • All, Forgive me I am familiar with the c++ API, If I want to duplicate the PCFLT_RELATED_OBJECTS instance in the PostOPCreate call back,  I didn't know if I can use the RtlCopyMemory to make it. thanks.
    Tuesday, September 17, 2013 6:31 AM

Answers

  • I don't think you can. As far as I understand the PCFLT_RELATED_OBJECTS parameter is a pointer to a local stack object on the caller's stack, and it stops to exist the moment the callback returns.

    • Proposed as answer by Tsang Chan Tuesday, September 17, 2013 9:48 AM
    • Marked as answer by Doron Holan [MSFT] Tuesday, September 17, 2013 1:54 PM
    Tuesday, September 17, 2013 9:47 AM
  • You don't do this!  Grab the context pointers for the items you care about and put them in your own structure, anything else is madness.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, September 17, 2013 11:08 AM

All replies

  • This structure is allocated by the Filter Manager, you can simply hold a pointer to it and it will remain valid for the duration of the callback. You should not use it after the callback returns.

    Tsang Chan

    Tuesday, September 17, 2013 7:29 AM
  • Hi Tsang,

    I need pass this instance of PCFLT_RELATED_OBJECTS as a parameter to the PFLT_DEFERRED_IO_WORKITEM_ROUTINE,But as the MSDN says, If I want to pass the additional parameter to WorkItem Routine, I should include them in the Context parameter, So for this case , I should define my context including a member field PCFLT_RELATED_OBJECTS , and pass it to WorkItem Routine. The purpose of duplication is just avoiding the original instance disappear after returning value in the PostOpCreate call back.

    And one more thing, Of course I want a deep copy of the instance which is a totally different pointer and memory to hold it. 

    Thanks.



    • Edited by wq187731 Tuesday, September 17, 2013 7:43 AM
    Tuesday, September 17, 2013 7:40 AM
  • I don't think you can. As far as I understand the PCFLT_RELATED_OBJECTS parameter is a pointer to a local stack object on the caller's stack, and it stops to exist the moment the callback returns.

    • Proposed as answer by Tsang Chan Tuesday, September 17, 2013 9:48 AM
    • Marked as answer by Doron Holan [MSFT] Tuesday, September 17, 2013 1:54 PM
    Tuesday, September 17, 2013 9:47 AM
  • You don't do this!  Grab the context pointers for the items you care about and put them in your own structure, anything else is madness.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, September 17, 2013 11:08 AM
  • Hi Tsang,

    I had tried RtlCopyMemory, But seems it didn't successfully copy the instance before the callback returns. Please review the below screenshot. I didn't know if I missed something, Please review it . thanks.

    Tuesday, September 17, 2013 11:17 AM
  • Hi Don,

    Could you please kindly write some pseudo-code to show what should to do with it. I have little confuse with it . If there has some code to demo, It will be more easy to understand! Thanks.

    Best Regards

    Joe Wang

    Wednesday, September 18, 2013 2:33 AM
  • What call are you trying to issue that needs the structure?  Mostly this is an input to you, and you use the ability to get a specific context.  So the real question is what are you trying to do?


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, September 18, 2013 1:05 PM
  • Actually I want to pass the PCFLT_RELATED_OBJECTS to the PFLT_DEFERRED_IO_WORKITEM_ROUTINE, and try to get the PCFLT_RELATED_OBJECTS->Instance, PCFLT_RELATED_OBJECTS->Filter, PCFLT_RELATED_OBJECTS->FileObject in the WorkItem Routine. So I need to duplicate PCFLT_RELATED_OBJECTS and try to include it in the context of WorkItem Routine. please review blow code in my project. thanks.

    //For query the original file information

    status = FltQueryInformationFile(
    FltObjects->Instance,
    Data->Iopb->TargetFileObject,
    &fileStandardInformation,
    sizeof(FILE_STANDARD_INFORMATION),
    FileStandardInformation,
    &returnedLength
    );

    //For creating file 

    status = FltCreateFile(
    FltObjects->Filter,
    NULL,
    &tempDeletedHandle,
    GENERIC_WRITE,
    &tempDeletedObject,
    &ioStatusTempDeleted,
    &allocate,
    FILE_ATTRIBUTE_NORMAL,
    0,
    FILE_CREATE,
    FILE_NON_DIRECTORY_FILE,
    NULL,
    0,
    0
    );

    //for reading the original file

    status = FltReadFile(
    FltObjects->Instance,
    //Data->Iopb->TargetFileObject,
    FltObjects->FileObject,
    &offset,
    1000,
    pFileBuffer,
    FLTFL_IO_OPERATION_NON_CACHED |   
                                   FLTFL_IO_OPERATION_DO_NOT_UPDATE_BYTE_OFFSET,
    &bytesRead ,
    NULL,
    NULL
    );

    Friday, September 20, 2013 1:46 AM