filter driver : header (or footer) in a file

hi,

I want to add a header (or footer) in a file with my filter driver. this
problem has been largely discused in this forum, and most of people
advise to put it at the end of the file.
Today I’m not sure if I woult put it the end or the begining, I’m trying
the two and the only problem I have when putting it at the begining (put
it at the end wil need more work to me, perhaps will you see a message
from me in near future) is to understand how the FSD determine the size
of the file it writes.

What I do : I send an IRP (IRP_MJ_WRITE) with IRP_NOCACHE |
IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO flags to write the header (512
bytes length) in the Create (or at the first Write) but the size of the
file doesn’t change. If I try to write a file of 10 bytes, it should
result in a file of 522 bytes. But it’s always 10 bytes (where I find
the 10 first bytes of the header) … My problem is to have different
file size in the FSD and in the cache.

I’ve tried to patch the AllocationSize, FileSize and ValidDataLength in
the FsContext (after getting Resource and PagingIoResource) but it works
only when IoGetTopLevelIRP()==NULL (so it doesn’t work in my case).
moreover I find it quite strange to do that so brutally (even if it’s so
frequent in a filter driver …).

Please help me in understanding how file size works.
thx