Writing to a file from a device driver!
-
Hey fellas, Right now I am pretty much stuck at a point :-( I am modifying a device driver and well I don't really have much prior experience doing such stuff. For debugging reasons I need to write some data to a disk file. For this purpose I am using the following code :-
/*nish-start*/
NTSTATUS Status;
LARGE_INTEGER ByteOffset;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES InitializedAttributes;
UNICODE_STRING ustr;
HANDLE handle;
WCHAR fname[] = L"\\??\\D:\\Output.txt";RtlInitUnicodeString(&ustr,fname);
InitializeObjectAttributes(&InitializedAttributes,&ustr,0, 0, NULL);
Status = ZwCreateFile(
&handle,GENERIC_WRITE|SYNCHRONIZE,
&InitializedAttributes,
&IoStatusBlock,
0,FILE_ATTRIBUTE_NORMAL,
0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE|
FILE_WRITE_THROUGH|
FILE_SYNCHRONOUS_IO_ALERT,
NULL,0);
ByteOffset.QuadPart = 0;
ZwWriteFile(handle,NULL,NULL,NULL,&IoStatusBlock,
data,512,NULL,NULL);
ZwClose(handle);
/*nish-end*/My problem is that the file is not getting created at all! Can anyone tell me what I doing wrong here? Regards, Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
Hey fellas, Right now I am pretty much stuck at a point :-( I am modifying a device driver and well I don't really have much prior experience doing such stuff. For debugging reasons I need to write some data to a disk file. For this purpose I am using the following code :-
/*nish-start*/
NTSTATUS Status;
LARGE_INTEGER ByteOffset;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES InitializedAttributes;
UNICODE_STRING ustr;
HANDLE handle;
WCHAR fname[] = L"\\??\\D:\\Output.txt";RtlInitUnicodeString(&ustr,fname);
InitializeObjectAttributes(&InitializedAttributes,&ustr,0, 0, NULL);
Status = ZwCreateFile(
&handle,GENERIC_WRITE|SYNCHRONIZE,
&InitializedAttributes,
&IoStatusBlock,
0,FILE_ATTRIBUTE_NORMAL,
0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE|
FILE_WRITE_THROUGH|
FILE_SYNCHRONOUS_IO_ALERT,
NULL,0);
ByteOffset.QuadPart = 0;
ZwWriteFile(handle,NULL,NULL,NULL,&IoStatusBlock,
data,512,NULL,NULL);
ZwClose(handle);
/*nish-end*/My problem is that the file is not getting created at all! Can anyone tell me what I doing wrong here? Regards, Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
Hi Nish, if u have win2k ddk(ntddk) ,there u can find a sample at the following directory. root\ntddk\src\kernel\parclass\debug.c this file debug.c has a sample on how to create a file from the kernel device driver..u can compare u r program with this and check out where u r going out of wrong.. regards, shiv:)