I don't really agreee with Rogan's answer, as the file could very well be locked by any other process before notepad.
That is not the issue here or at least not how you should look at this problem.
If you want to notepad to have a certain view of A.txt, simply use notepad's FILE_OBJECT and do the writing yourself from the kernel. Just remember to use ObReferenceObjectByPointer and ask for the WRITE access. Since access mode will be kernel mode you will be allowed.
Alternatively if you really want it to be done by your service, open the file yourself, from the driver and provide a handle to your service. Opening the file from kernel mode could supress share modes and so on, you will need to read the documentation for FltCreateFileEx2 to make sure you have all the necessary parameters.
Use ObOpenObjectByPointer on the FileObject you have just opened and access mode UserMode. Make sure you will be attached to your user-mode's process address space via KeStackAttachProcess.
Order of operations in PostCreate:
- FltCreateFileEx2(the_file, ignore_share_access, etcc )
- KeStackAttachProcess(your_service_eprocess)
- ObOpenObjectByPointer(UserMode=access_mode) -> now your um process has a handle to the file
- KeUnstackDetachProcess()
- Send the HANDLE pointer to the user-mode process as now it is able to use it.
- Wait for the user mode service to write the data and also close the handle
Dereference the FileObject obtained as well as close the handle from FltCreateFileEx2.
- Let the Create go for Notepad
- Profit.
Good luck.