Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with ZwCreateFile()

277 views
Skip to first unread message

Reiner Ziegler

unread,
Dec 22, 2002, 10:36:05 AM12/22/02
to
Hi,

I want to put trace information from my driver into a log-file.
But I have a BIG problem with the ZwCreateFile()-Call!
It returns always an error code of STATUS_OBJECT_NAME_INVALID.
The filename which I generated has the format which the DDK-docs demands!
Following is my code:

// -----
HANDLE hFile;
NTSTATUS ntStatus;
OBJECT_ATTRIBUTES stObjAttr;
IO_STATUS_BLOCK stIoStatus;
UNICODE_STRING strTemp;
wchar_t* pwszFile = L"\\??\\C:\\Temp\\test.dat";

strTemp.Length = strTemp.MaximumLength =
(wcslen(pwszFile) * sizeof(wchar_t)) + 2;
strTemp.Buffer = pwszFile;
RtlZeroMemory(&stObjAttr, sizeof(OBJECT_ATTRIBUTES));
RtlZeroMemory(&stIoStatus, sizeof(IO_STATUS_BLOCK));
InitializeObjectAttributes(&stObjAttr,
&strTemp,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
ntStatus = ZwCreateFile(&hFile,
FILE_WRITE_DATA,
&stObjAttr,
&stIoStatus,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_CREATE |
FILE_OVERWRITE_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
// ----

Anyone who has an idea?

Thanks

Reiner


Tom Stewart

unread,
Dec 23, 2002, 8:38:48 AM12/23/02
to
I believe the name needs 2 actual backslashes at the beginning, so in C you
must use 4, i.e. \\\\??\<etc>

--
Tom

"Reiner Ziegler" <reiner....@mail.regio.net> wrote in message
news:uv#pB$cqCHA.1808@TK2MSFTNGP09...

Reiner Ziegler

unread,
Dec 23, 2002, 9:26:28 AM12/23/02
to
Tom,

sorry, but thats not the reason. This is not an UNC-Path.
I've always tried this.

regards

Reiner
"Tom Stewart" <tast...@msdn.microsoft.com> schrieb im Newsbeitrag
news:OgwpaioqCHA.2548@TK2MSFTNGP10...

Tom Stewart

unread,
Dec 23, 2002, 2:07:47 PM12/23/02
to
I'm not *that* naive. I was going on the CreateFile documentation, which
shows how to (from app space) use the notation. Here's the doc:

Windows NT/2000/XP: In the ANSI version of this function, the name is
limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide
characters, call the Unicode version of the function and prepend "\\?\" to
the path.

Suggests perhaps the double question mark is wrong. So perhaps you should be
using "double backslash question mark backslash" which would in C be
"quadruple backslash question mark double backslash." Anyway, good luck.

--
Tom

"Reiner Ziegler" <reiner....@mail.regio.net> wrote in message

news:O2jQN9oqCHA.456@TK2MSFTNGP09...

Carl Appellof

unread,
Dec 31, 2002, 1:11:19 PM12/31/02
to
You must set the Length part of the UNICODE_STRING to include only the bytes
making up the name, NOT including the trailing NULL.

And the confusion about the number of question marks and backslash
characters arises because you're talking about two different things. The
"\\\\?\\C:\\" rule that Tom Stuart espouses only applies to the Win32 API,
and how to go beyond the MAX_PATH limitation for file names. But
ZwCreateFile isn't part of the Win32 API, so that rule doesn't apply.
Instead, you use "\\??\\C:" to indicate that ZwCreateFile should use the NT
Object manager's top level "??" directory to look up a symbolic link
corresponding to "C:" to build the real internal NT object name for the
create. So your original example was almost correct, except for the length
of the string.

By the way, I would just use RtlInitUnicodeString(&strTemp, pwszFile) to set
up the UNICODE_STRING

Carl Appellof

"Reiner Ziegler" <reiner....@mail.regio.net> wrote in message
news:uv#pB$cqCHA.1808@TK2MSFTNGP09...

Tom Stewart

unread,
Jan 9, 2003, 12:32:57 PM1/9/03
to
Sorry for any confusion, and thanks for the explanation!
--
Tom

"Carl Appellof" <carl.a...@nospam.veritas.com> wrote in message
news:OizrTiPsCHA.868@TK2MSFTNGP12...

0 new messages