Re: Question about paths and \DosDevicesDate: Thu, 23 Apr 2009 11:04:17 +0200

The following KB explains how to manipulate with pathes in kernel:
http://support.microsoft.com/kb/891805 . The fact that it is documented
means it would not be “deleted”. Btw, it actually refers to DosDevices being
not always the best solution, as namespace might not be created at early
boot (just in case your driver is loaded at boot time).


Volodymyr M. Shcherbyna, blog: http://www.shcherbyna.com/
(This posting is provided “AS IS” with no warranties, and confers no
rights)
“Jonathon” wrote in message news:xxxxx@ntdev…
> Hey All,
>
> I have a driver that receives a path from user-land. The path is stored
> in
> a PUNICODE_STRING and is something like: "c:\myFolder". I need to call
> InitializeObjectAttributes(…) with this path which takes the object name.
> If I pass the path I receive from the user into this function, it cannot
> locate the name because it is not valid. Currently, my code prefixes the
> user path with “\DosDevices" so that when I call
> InitializeObjectAttributes, it is able to find it.
>
> My question though is whether this is the cleanest approach for doing
> this?
> and also, can I gaurantee that “\DosDevices" will exist on all machines?
> From my understanding, \DosDevices\ is a symbolic link to ?? so it can be
> deleted at any time right? Is there a way to automatically convert this
> user
> path to its object equivalent?
>
> Thanks
>
> J
>
>
> Code:
>
> UNICODE_STRING pstrRootObjPath;
> RtlInitUnicodeString(&pstrRootObjPath, L”\DosDevices”);
>
> // Not really sure the appropriate arguments to pass as the 3rd argument!?
> OBJECT_ATTRIBUTES oaRoot;
> InitializeObjectAttributes(&oaRoot,
> const_cast<punicode_string>(&pstrRootObjPath), NULL, NULL, NULL);
>
> HANDLE hRootDirectoryObject = NULL;
> ulStatus = ZwCreateDirectoryObject(&hRootDirectoryObject,
> DIRECTORY_TRAVERSE
> | DIRECTORY_QUERY, &oaRoot);
>
> // using root object to search for the user’s specified object
> OBJECT_ATTRIBUTES oa;
> InitializeObjectAttributes(&oa, const_cast<punicode_string>(pstrUserPath),
> OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, hRootDirectoryObject,
> NULL);
>
> ZwClose(hRootDirectoryObject);
>
> …
> …
></punicode_string></punicode_string>