I have a log file which is written by my driver using a system worker
routine. Every once in a while (maybe 10 times in the last few years), I’ll
notice that Windows Explorer will say that the file is 0 KB, but yet, I’ll
then open it up, and it will be large (a few KB, but I think once it was 20
KB or so). I’ll then look back at Windows Explorer and it will list the
proper size. I looked at my code, and it’s doing a ZwWriteFile every line
(100 bytes or so), so I’m not buffering the data. Furthermore, the
information in the file will sometimes be days old, so the system has
certainly had a chance to flush the cache out to disk at some point.
Another person reported that they also saw the wrong file size in Windows
Explorer, but goes further in that they first opened this file, saw a line
that gets written at midnight (and that’s all), and then closed it and
reopened it, and then saw all of the data.
The odd thing is that this only happens rarely – it works correctly the
vast majority of time.
I don’t see how this could be my driver doing it, but maybe some setting
when I open the file or write it or something like that? Below is how I
create it and write to it.
Thanks in advance for any suggestions!
InitializeObjectAttributes ( &ObjectAttributes,
&FullFileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
CreateOptions = FILE_SYNCHRONOUS_IO_NONALERT;
ntStatus = ZwCreateFile( &NtFileHandle,
SYNCHRONIZE |
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
// alloc size = none
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN_IF,
CreateOptions,
NULL, // eabuffer
0 ); // ealength
Status = ZwWriteFile( deviceExtension->ErrorTextFileHandle,
NULL,
NULL,
NULL,
&IoStatus,
ConsumerDataBuffer,
ConsumerDataSize,
0,
NULL );