Bytes read/written on paging I/O on EOF

Hi all,

I’m working on a file system driver (not a filter) which uses shadow file objects to from a different file system. I’ve been reading “Windows NT File System Internals” and I saw the following on page 268:

“Paging I/O read requests that start before the current end-of-file but extend beyond current end-of-file are truncated to the current end-of-file byte offset. However, the client must be careful to set the number of bytes written to be the same as the number of bytes initially requested (although no I/O was actually performed).”

So, this is what we have been doing so far. We complete paging I/O requests setting the IoStatus.Information with the original requested size (page aligned), even truncating the actual I/O to the current end-of-file. However, we’re now working on a intermittent issue that seems to be fixed if we complete paging I/O by setting Information to the truncated size. We also did a couple of tests with NTFS and FastFat and they’re also completing paging I/O with truncated size.

So, what is the correct to do on completing paging I/O (read/write) beyond EOF? Should we set IoStatus.Information to the original request size or truncate it to the EOF?

Thanks in advance,

Fernando Roberto da Silva
DriverEntry Kernel Development
http://www.driverentry.com.br

A quick glance at the FAT code indicates that it trims the ByteCount to match the EOF and that is the value returned in the Information field (see FatNonCachedIo in deviosup.c which is called from FatCommonWrite in this case).

Here’s the code that trims the length:

if ( PagingIo ) {

if (StartingVbo >= FileSize) {

DebugTrace( 0, Dbg, “PagingIo started beyond EOF.\n”, 0 );

Irp->IoStatus.Information = 0;

try_return( Status = STATUS_SUCCESS );
}

if (ByteCount > FileSize - StartingVbo) {

DebugTrace( 0, Dbg, “PagingIo extending beyond EOF.\n”, 0 );

ByteCount = FileSize - StartingVbo;
}
}

And then this value (ByteCount) gets passed into FatNonCachedIo, which sets it in the information field before it queues up the IRP.

Tony
OSR

Hi Tony,

I’m assuming we can do the same on our file system driver for paging read and paging write then. I was not confident on this because of that book statement. Do you remember any special case in which we should follow what the book recommends about this? I mean, set the original request size to IoStatus.Information.

Thanks for your help.

Fernando Roberto da Silva
DriverEntry Kernel Development
http://www.driverentry.com.br

It’s distinctly possible that the world has changed in the 15+ years since the book was written, but based upon my experiences in this area very recently, both NTFS and FAT truncate such I/O operations at the present time, so you shouldn’t break the VM system certainly.

Tony
OSR