Problem with NtOpenFile()

Hi all. I’m writing a POSIX subsystem for Windows NT, and I’m currently
stuck with the dirent (directory entries enumeration) functions.
Specifically, here’s the failing function:

DIR *_Wopendir(const wchar_t *dirname)
{
OBJECT_ATTRIBUTES oaDirAttribs;
struct __internal_DIR * lpidData;
IO_STATUS_BLOCK isbStatus;
UNICODE_STRING wstrNativePath;
NTSTATUS nErrCode;

wstrNativePath.Buffer = __malloc(0xFFFF);

if(wstrNativePath.Buffer == 0)
{
ERR(“__malloc(%d) failed”, 0xFFFF);
errno = ENOMEM;
return (0);
}

wstrNativePath.MaximumLength = 0xFFFF;
wstrNativePath.Length = 0;

/* convert POSIX path into NT path */
if(!_PdxPosixPathNameToNtPathName((LPWSTR)dirname, &wstrNativePath, NULL))
{
ERR(“_PdxPosixPathNameToNtPathName failed, errno %d”, errno);
return (0);
}

/* allocate private data */
lpidData = __malloc(sizeof(struct __internal_DIR));

if(lpidData == 0)
{
/* failure */
ERR(“__malloc(%d) failed”, sizeof(struct __internal_DIR));
errno = ENOMEM;
return (0);
}

/* set private data’s signature */
lpidData->signature = IDIR_MAGIC;

/* set generic object attributes */
oaDirAttribs.Length = sizeof(OBJECT_ATTRIBUTES);
oaDirAttribs.RootDirectory = NULL;
oaDirAttribs.ObjectName = &wstrNativePath;
oaDirAttribs.Attributes = 0;
oaDirAttribs.SecurityDescriptor = NULL;
oaDirAttribs.SecurityQualityOfService = NULL;

__free(wstrNativePath.Buffer);

/* open the directory */
nErrCode = NtOpenFile
(
&lpidData->dirhandle,
FILE_LIST_DIRECTORY,
&oaDirAttribs,
&isbStatus,
FILE_OPEN_IF,
OPEN_EXISTING
);

/* failure */
if(!NT_SUCCESS(nErrCode))
{
ERR(“NtOpenFile() failed with status %#X”, nErrCode);
/* free internal buffer */
__free(lpidData);
/* set errno */
errno = __status_to_errno(nErrCode);
/* fail */
return (0);
}

/* success */
return ((DIR *)lpidData);

}

the function always dies with:

“psxdll.dll:ERR:dirent/opendir.c:104:_Wopendir():
NtOpenFile() failed with status 0XC000003B”

(0XC000003B is STATUS_OBJECT_PATH_SYNTAX_BAD)

I really can’t understand what am I doing wrong here. If dirname is “/”
(like it currently is in my test app), _PdxPosixPathNameToNtPathName()
correctly translates it into "??\D:" (since I temporarily hardcoded the
POSIX root to “??\D:”). Isn’t "??\D:" a correct directory path? or am I
passing some other wrong parameter?

Any help would be appreciated


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com