Implementing fds read and FILE_USE_FILE_POINTER_POSITION

Hi!

I’m running the DTM IFS Filter test from Microsoft, and I’m failing the ReadWriteTest, returning STATUS_END_OF_FILE instead of STATUS_SUCCESS. I went ahead and implemented the FILE_USE_FILE_POINTER_POSITION in my fsd create and read code, with the following code added:

In the IRP_MJ_CREATE code:

// Allow file system to keep track of current file offset position

if (BooleanFlagOn(pCreateFileRequest->Options, FILE_SYNCHRONOUS_IO_ALERT) ||
(BooleanFlagOn(pCreateFileRequest->Options, FILE_SYNCHRONOUS_IO_NONALERT)))
{
SetFlag(pFileObject->Flags, FO_SYNCHRONOUS_IO);
}

And then in the IRP_MJ_READ code:

#define UseFilePointerPosition(Pos) ((Pos.LowPart == FILE_WRITE_TO_END_OF_FILE) && \
(Pos.HighPart == FILE_USE_FILE_POINTER_POSITION ))

byteOffset = pIoStack->Parameters.Read.ByteOffset;

if (FlagOn(pFileObject->Flags, FO_SYNCHRONOUS_IO) && UseFilePointerPosition(byteOffset))
{
byteOffset = pFileObject->CurrentByteOffset;
}

Does this implementation for synchronous reads look correct? First I flag the file object as using synchronous I/O in the create call, and then based on that (based on what I’ve read) I adjust the byteOffset using the File Object if we’re using the FILE_USE_FILE_POINTER_POSITION flag.

More complete information-the DTM IFS Filter ReadWriteTest does the following:
ReadWriteTest. This test will test the reading from and writing to files that the file system manages. First, a synchronous file handle is opened to the test file and a buffer that is full of known data is written to the test file. Next, the data is read from the file and compared to the known data to see if it matches. If the data matches, the file pointer is reset to the beginning of the test file and the data is read again; this time, the parameter FILE_USE_FILE_POINTER_POSITION is specified as an offset to the read function. The handle is then closed. The test file is once again opened with a synchronous file handle and the data is read and checked once again. The file handle is then closed. A synchronous file handle is once again opened to the test file. A buffer that is full of known data is written to the test file, with the FILE_WRITE_TO_END_OF_FILE offset being specified to the write function. This write operation should append the data to the end of the test file. The file is read from and the data is checked. The file handle is then closed. Finally, an asynchronous file handle is opened to the test file and data is read from the file. A query is performed to make sure that the file pointer position did not change. The test is complete.

Also, does anyone know where one might get more specific information (like the source) of the DTM tests?

Thanks!

Steve

>In the IRP_MJ_CREATE code:

// Allow file system to keep track of current file offset position
if (BooleanFlagOn(pCreateFileRequest->Options, SYNCHRONOUS_IO_ALERT)
|| (BooleanFlagOn(pCreateFileRequest->Options, SYNCHRONOUS_IO_NONALERT)))
{
SetFlag(pFileObject->Flags, FO_SYNCHRONOUS_IO);
}

The flag FO_SYNCHRONOUS_IO is set by IO Manager for you.

UseFilePointerPosition(Pos) ((Pos.LowPart == FILE_WRITE_TO_END_OF_FILE) && \
(Pos.HighPart == FILE_USE_FILE_POINTER_POSITION ))

There is no define for HighPart of the position so you should use (-1). The test should be like.

synchronousIo = BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO);
If ((synchronousIO) &&
(Pos.LowPart == FILE_USE_FILE_POINTER_POSITION) &&
(Pos.HighPart == (-1)))
{
// read from current position
}

The FILE_WRITE_TO_END_OF_FILE is used only in write dispatch:
if ((synchronousIO) &&
(Pos.LowPart == FILE_USE_FILE_POINTER_POSITION) &&
(Pos.HighPart == (-1)))
{
// write to current pos
}
if ((synchronousIO) &&
(Pos.LowPart == FILE_WRITE_TO_END_OF_FILE) &&
(Pos.HighPart == (-1)))
{
// write to the end of file
}

-bg