Hi all,
For those of you out there who have done or are doing data
modifying/encrypting filters, I was wondering if anyone has come up with
a reliable and/or good method for determining the file size in the
paging I/O paths. An example is in order:
-during a paging I/O write, I see a 4k write for example (offset 0,
length 4096), which could possibly contain the last byte of the file
-in the dispatch path for the write, I don’t know what the EOF actually
is, only the filesystem knows
-how can I determine this so that I can perform operations involving the
file data that may depend on this information?
In addition, I have seen people on this list say that tracking file size
in a filter-owned variable is an option, but it seems like keeping this
atomically synchronized with the filesystem’s file size would be very
complicated, possibly causing performance and/or synch problems, because
filter specific locks would surely be involved. I would like to send
down a QUERY_INFO, but then the FCB resources may be acquired already,
and this could cause a deadlock. Simply plucking the size out of the
FCB seems unreasonable, considering that the locks in the FCB are there
to synch access to this information in the first place, and NTFS uses 64
bit file sizes, which can’t be atomically read/written anyway.
A while ago on this list on a thread relating to this question, Nick
Ryan said:
“Maintaining file size in your own private variable works but does not
buy you anything you can use during paging I/O. Since it would be
protected by your own lock and not the filesystem’s, it won’t change
atomically with the FCB filesize. What if the added portion of a newly
extended file is immediately flushed by the filesystem after having
updated the FCB filesize? You may mistreat that I/O since your private
variable will not be updated yet.
It appears that we must resign ourselves to being completely file-size
unaware during our paging I/O handlers, whatever changes to our
algorithms that entails.”
So, should I resign myself to only using an algorithm that is
independent of the file size in the paging I/O path (as Nick says), or
has anyone done this successfully? Is there a definitive answer for
this issue?
Thanks,
Matt