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

Enumerate the \?? (\DosDevices) directory

289 views
Skip to first unread message

Magnus Wennergren

unread,
Jun 20, 1999, 3:00:00 AM6/20/99
to
I am currently writning a COM-redirector for Windows NT. When I create the
symbolic links in my DriverEntry, I need to know which COMx names that are
already in use. If I try to create a link that already exist, the system
crashes.

Is there a way to enumerate the symbolic links from my kernel-mode driver?

/Magnus

Lukasz Foltyn

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Try to use ZwQuerySymbolicLinkObject, to test if a symbolic
link already exists.
Prototype is:

NTSYSAPI NTSTATUS NTAPI ZwQuerySymbolicLinkObject( HANDLE Handle,
PUNICODE_STRING
LinkName, PUINT SymLinkLen );


Lukasz Foltyn


Magnus Wennergren <magnus.w...@axis.com> wrote in message
news:7kj3tr$ff...@news.ajou.ac.kr...

Jamey kirby

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Use QueryDosDevice()

Walter Oney

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Jamey kirby wrote:
> Use QueryDosDevice()

But he wanted to do it in kernel-mode...

What people usually do is just construct names in a loop and wait until
IoCreateDevice or IoCreateSymbolicLink succeeds. Neither of them should
crash the system just because given an existing name -- they return an
error status.

--
Walter Oney
http://www.oneysoft.com

Jamey kirby

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Ooops... :)

Walter Oney wrote in message <376FB27D...@oneysoft.com>...

Jamey kirby

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Here is code I use to enumerate drive letters in KM. Maybe this can be
adopted

// FindAvailableDriveLetter()
NTSTATUS FindAvailableDriveLetter
(
PUCHAR DriveLetter
)
{
NTSTATUS ntStatus;

UNICODE_STRING ntUnicodeString;
CCHAR ntNameBuffer[MAXIMUM_FILENAME_LENGTH];
STRING ntNameString;
OBJECT_ATTRIBUTES attributes;
HANDLE directoryHandle;
HANDLE linkHandle = NULL;
ULONG i;

PAGED_CODE();

// Open the Win32 object name-space directory
RtlInitUnicodeString(&ntUnicodeString, (PWCHAR)L"\\DosDevices");

InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
);

ntStatus = ZwOpenDirectoryObject
(
&directoryHandle,
DIRECTORY_QUERY,
&attributes
);

if (!NT_SUCCESS(ntStatus))
{
RtlInitUnicodeString(&ntUnicodeString, (PWCHAR)L"\\??");

InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
);

ntStatus = ZwOpenDirectoryObject
(
&directoryHandle,
DIRECTORY_QUERY,
&attributes
);

if (!NT_SUCCESS(ntStatus))
{
goto FindAvailableDriveLetterExit;
}
}

// Open symbolic link object(s)
for (i = 2; i < 26; i++)
{
sprintf(ntNameBuffer, "%C:", i + 'A');
RtlInitString(&ntNameString, ntNameBuffer);

ntStatus = RtlAnsiStringToUnicodeString
(
&ntUnicodeString,
&ntNameString,
TRUE
);

if (!NT_SUCCESS(ntStatus))
break;


InitializeObjectAttributes
(
&attributes,
&ntUnicodeString,
OBJ_CASE_INSENSITIVE,
directoryHandle,
NULL
);

ntStatus = ZwOpenSymbolicLinkObject
(
&linkHandle,
SYMBOLIC_LINK_QUERY,
&attributes
);

if (!NT_SUCCESS(ntStatus))
{
*DriveLetter = (CHAR)((CHAR)i + (CHAR)'A');
ntStatus = STATUS_SUCCESS;
}
else
{
ZwClose(linkHandle);
ntStatus = STATUS_OBJECT_NAME_COLLISION;
}

RtlFreeUnicodeString(&ntUnicodeString);

if (NT_SUCCESS(ntStatus))
break;
}

ZwClose(directoryHandle);

FindAvailableDriveLetterExit:

return (ntStatus);

0 new messages