Is it possible to open a file in a device driver ? If so what
do I use instead of CreateFile, WriteFile, CloseHandle?

t.

Re: How to open a file ? by Don

Don
Thu Oct 13 08:00:23 CDT 2005

Look at the Zw calls in the DDK. There are equivalents to create, read,
write, close. Be aware there are limitations on this if your driver is a
boot start driver, or if it is part of the storage stack.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



<support> wrote in message news:%23EX03U$zFHA.1264@tk2msftngp13.phx.gbl...
> Is it possible to open a file in a device driver ? If so what
> do I use instead of CreateFile, WriteFile, CloseHandle?
>
> t.
>
>



Re: How to open a file ? by conjonh

conjonh
Thu Oct 13 08:11:00 CDT 2005

Something like this is what you need:

UNICODE_STRING us;
IOSB iosb;
HANDLE hFile = NULL;
OBJECT_ATTRIBUTES oa;
NTSTATUS stat;

us.Buffer =L"\\??\\C:\\logfile.txt";
us.Length = wcslen(us.Buffer) * sizeof(WCHAR);
us.MaximumLength = us.Length + sizeof(WCHAR);


InitializeObjectAttributes(&oa,&us,NULL,NULL,NULL);


stat = ZwCreateFile(
&hFile,
GENERIC_WRITE,
&oa,
&iosb,
0,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_DIRECTORY_FILE,
NULL,
0);
Look it up in the DDK doc.

Cheers,
Con


Re: How to open a file ? by support>

support>
Thu Oct 13 09:24:48 CDT 2005


thanks guys, I shall try this sample code, it's what I wanted.
thanks.




Re: How to open a file ? by Bill

Bill
Thu Oct 13 20:00:47 CDT 2005

BTW, it is generally not recommended to open a file from kernel-mode.
Usually, a user-mode component such as an application or service in
communication with a kernel mode component is better to handle the file I/O.
Keep the complexity in user-mode. Not mandatory, but usual.

Bill M.


<support> wrote in message news:%23EX03U$zFHA.1264@tk2msftngp13.phx.gbl...
> Is it possible to open a file in a device driver ? If so what
> do I use instead of CreateFile, WriteFile, CloseHandle?
>
> t.
>
>