Hi,

Sometime I receive the value STATUS_INVALID_PARAMETER from ZwWriteFile, my
device work in Win 2000/XP.
I create a file with ZwCreateFile (I use the OBJ_KERNEL_HANDLE)
I call ZwWriteFile from a WorkItem, so I'm at Passive_Level.

This is my code:

// Create the file and in hFile I have the handle
ntStatus = MyCreateFile (&fileNameUnicodeString, &hFile, FILE_OVERWRITE_IF);

After I queue a WorkItem for write in my file

// My code in WorkItem:

// I use PagedPool because I'm at IRQL PASSIVE_LEVEL (WorkItem)
pNewbuff = ExAllocatePool( PagedPool, BytesAvailable);

ntStatus = WriteFile (hFile, (PVOID) pNewbuff, BytesAvailable,
&dwBytesWrite2, NULL);

Sometime ntStatus = STATUS_SUCCES, when I stress my device ntStatus is
STATUS_INVALID_PARAMETER

Do you have an idea ?


These are my function MyCreateFile and WriteFile:

NTSTATUS MyCreateFile (IN PUNICODE_STRING pUniFileName, OUT PHANDLE
p_ntFileHandle, int TypeDisposition)
{
NTSTATUS ntStatus;
OBJECT_ATTRIBUTES oa;
IO_STATUS_BLOCK ioStatus;

InitializeObjectAttributes( &oa, pUniFileName, OBJ_CASE_INSENSITIVE |
OBJ_KERNEL_HANDLE, NULL, NULL );

ntStatus = ZwCreateFile( p_ntFileHandle, GENERIC_READ | GENERIC_WRITE |
SYNCHRONIZE,
&oa, &ioStatus, NULL, FILE_ATTRIBUTE_NORMAL, 0,
TypeDisposition, FILE_NON_DIRECTORY_FILE | FILE_SEQUENTIAL_ONLY |
FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );


if( !NT_SUCCESS( ntStatus ) ) {
DbgPrint(("Could not creAte file, status: %x\n", ntStatus ));
}
else DbgPrint(("file create handle: %x\n", *p_ntFileHandle));

return ntStatus;
}



NTSTATUS WriteFile (HANDLE hFile, PVOID lpdat, DWORD size, DWORD
*dwBytesRead, PVOID p1)
{
NTSTATUS ntStatus;
IO_STATUS_BLOCK ioStatus;

ntStatus = ZwWriteFile (hFile, NULL, NULL, NULL, &ioStatus, lpdat, size,
NULL, NULL);

*dwBytesRead = (DWORD)ioStatus.Information;

return ntStatus;
}


Best regards
Gian