ZwWriteFile does not Succeed at all?Please Help

S

Shalini

Hi All
My ZwWriteFile does not succeed at all.
ZwCreateFile works fine,ZwReadFile works fine but ZwWriteFile it always
gives me a NTSTATUS return of -1073741816 meaning invalid handle. I am not
able to figure it out why.
Could any one help me..
This is my source code.

RtlInitUnicodeString(&fileNameUnicodeString,
L"\\Device\\Harddisk0\\Partition0");
InitializeObjectAttributes( &objectAttributes, &fileNameUnicodeString,
OBJ_CASE_INSENSITIVE, NULL, NULL );

rc = ZwCreateFile(&hDevice, SYNCHRONIZE|FILE_ANY_ACCESS,
&objectAttributes, &IoStatus, NULL, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_CREATE,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE,
NULL, 0 ); //ALWAYS SUCCESS

RtlInitUnicodeString(&fileNameUnicodeString,
L"\\Device\\Harddisk0\\Partition0");
InitializeObjectAttributes( &objectAttributes1, &fileNameUnicodeString,
OBJ_CASE_INSENSITIVE, NULL, NULL );


rc = ZwCreateFile(&hDevice1, SYNCHRONIZE|FILE_WRITE_DATA,
&objectAttributes1, &IoStatus1, NULL, 0, 0,
FILE_OPEN,

FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE|FILE_WRITE_THROUGH,
NULL, 0 ); //ALWAYS SUCCESS



if(hDevice!=NULL)
{

oFilePos.CurrentByteOffset.QuadPart=data_offset;

rc=ZwSetInformationFile(hDevice,&IoStatus,&oFilePos,sizeof(FILE_POSITION_INF
ORMATION),FilePositionInformation);

rc=ZwReadFile(hDevice,
NULL,
NULL,
NULL,
&IoStatus,
szBuffer,
512,
NULL,
NULL
); //ALWAYS SUCCESS



//ReadFile(hDevice,szBuffer,512,&dwRead,NULL);
//memcpy(szBuffer,&Cnt,sizeof(int));
RtlCopyMemory(szBuffer,&tCnt,sizeof(int));

//SetFilePointerEx(hDevice,liDataOffSet,&liNewDataOffSet,FILE_BEGIN);
oFilePos.CurrentByteOffset.QuadPart=data_offset;

rc=ZwSetInformationFile(hDevice,&IoStatus,&oFilePos,sizeof(FILE_POSITION_INF
ORMATION),FilePositionInformation);

oFilePos.CurrentByteOffset.QuadPart=offset;

rc=ZwSetInformationFile(hDevice1,&IoStatus1,&oFilePos,sizeof(FILE_POSITION_I
NFORMATION),FilePositionInformation);

//WriteFile(hDevice,szBuffer,512,&dwWritten,NULL);
LARGE_INTEGER oLargePointer;
oLargePointer.LowPart=FILE_USE_FILE_POINTER_POSITION;
oLargePointer.HighPart=-1;

rc=ZwWriteFile(&hDevice1,
NULL,
NULL,
NULL,
&IoStatus1,
szBuffer,
512,
&oLargePointer,
NULL); //ALWAYS FAILURE


Please give me some suggestions
Regards and expecting ur replies
Shal
 
E

Eliyas Yakub [MSFT]

rc=ZwWriteFile(&hDevice1, <--------- You are passing address of the
file handle. Remove the ampersand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top