Enumerate FileObject(s) from FSContext

I see on osr that every FileObject opened on the same data stream share the same FSContext, I wan’t to know if there is a way to enumerate/count every FileObject from the FSContext, or if I need to attach a stream_context to every successfully IRP_MJ_CREATE with a reference counter and sync state, to do some processing on the last FileObject IRP_MJ_CLEANUP ? (I can’t use IRP_MJ_CLOSE because I resend IRP on the last cleanup).

And if the stream_context is the only way, is it a good practice to follow every FileObject with stream_context ?

Drivers informations:
driver type → FS-Minifilter
minimal os requirements → Windows 7
used FS type → NTFS, FAT, FAT32, ExFAT, ReFS

I wan’t to know if there is a way to enumerate/count every FileObject from the FSContext
Only if you build one yourself (by attaching a StreamHandleContext to each file object and link them to a StreamContext associated with the stream. Thats what I have always done.

I think that you may be confused (and need to revise) the different between a StreamContext (one per Stream on disk) and StreamHandleContext (one per file object)

You might also want to consider using the context lifetimes.

Thanks for your reply.

I will do it with some reference counter, I can’t use the context lifetimes because I need to process my routine just before the object is being torn down, inside the last IRP_MJ_CLEANUP on the stream.

And using StreamHandleContext on every FileObject I see is too much for my project, I don’t need to know every FileObject, just the last close on the stream.