According to the documentation I’ve been able to find - such as
http://mvb.saic.com/freeware/vmslt97b/ntstuff/native.txt - I can open
a directory, then use that directory handle as an argument to
InitializeObjectAttributes along with a relative filename. Doing this,
however, results in STATUS_INVALID_HANDLE. Is this facility really
restricted to “object directories” (i.e. not “directory files”), and
this documentation is wrong? Or do I need to do something else? (Yes,
the directory is opened with FILE_TRAVERSE access.)
"Using the OBJECT_ATTRIBUTES structure, there are two possible ways
to open the file “fred.txt” in the directory C:\temp. Either
you build a UNICODE_STRING for ObjectName that contains the fully
qualified file path specification, such as
“\DosDevices\C:\Temp\fred.txt” or else you first open the
directory “\DosDevices\C:\Temp" via a CreateFile() request,
obtaining a handle to this open (directory) file. You then
build a UNICODE_STRING for ObjectName that contains just the file
name portion “fred.txt” and pass it, along with the handle to the
open directory to InitializeObjectAttributes().” (from the above
link)
James.
This technique is widely used by all command-line apps which opens the
relative pathnames. In fact, this is how the notion of the “current directory”
exists in Windows.
I think that your problem is due to specifying the wrong desired access or
disposition while opening a directory.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “James”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, August 18, 2004 4:46 PM
Subject: [ntdev] Directory relative ZwCreateFile
> According to the documentation I’ve been able to find - such as
> http://mvb.saic.com/freeware/vmslt97b/ntstuff/native.txt - I can open
> a directory, then use that directory handle as an argument to
> InitializeObjectAttributes along with a relative filename. Doing this,
> however, results in STATUS_INVALID_HANDLE. Is this facility really
> restricted to “object directories” (i.e. not “directory files”), and
> this documentation is wrong? Or do I need to do something else? (Yes,
> the directory is opened with FILE_TRAVERSE access.)
>
> "Using the OBJECT_ATTRIBUTES structure, there are two possible ways
> to open the file “fred.txt” in the directory C:\temp. Either
> you build a UNICODE_STRING for ObjectName that contains the fully
> qualified file path specification, such as
> “\DosDevices\C:\Temp\fred.txt” or else you first open the
> directory “\DosDevices\C:\Temp" via a CreateFile() request,
> obtaining a handle to this open (directory) file. You then
> build a UNICODE_STRING for ObjectName that contains just the file
> name portion “fred.txt” and pass it, along with the handle to the
> open directory to InitializeObjectAttributes().” (from the above
> link)
>
>
> James.
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
On Wed, 18 Aug 2004 19:16:44 +0400, you wrote:
This technique is widely used by all command-line apps which opens the
relative pathnames. In fact, this is how the notion of the “current directory”
exists in Windows.
That’s what some comments implied, which is why I found it so bizarre
I couldn’t find a single item of documentation on the subject
anywhere!
I think that your problem is due to specifying the wrong desired access or
disposition while opening a directory.
Opening the directory is successful - the error appears when I try
opening a file within it. (I’ve done this successfully before when
opening a file on NTFS by ID using a handle on the volume…) The
question then is: what access do I need to specify to be able to use
the directory in this way? I thought FILE_TRAVERSE would suffice, but
no such luck - and adding FILE_LIST_DIRECTORY didn’t help either. Is
there any example code or useful documentation on the subject out
there?
(On a related note: If I open, say, C:\Example and use it as a root to
try opening “…\file.txt”, will this open C:\file.txt, or give an
error? The reference to “root directory” in the limited documentation
I’ve found would suggest the latter - but then, that same
documentation implied using a handle to a ‘real’ directory wouldn’t
work in the first place…)
James.
> the directory in this way? I thought FILE_TRAVERSE would suffice, but
no such luck - and adding FILE_LIST_DIRECTORY didn’t help either. Is
Try ZwOpenFile with:
DesiredAccess = FILE_TRAVERSE | SYNCHRONIZE
ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE
OpenOptions = FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
On Fri, 20 Aug 2004 05:24:16 +0400, you wrote:
> the directory in this way? I thought FILE_TRAVERSE would suffice, but
> no such luck - and adding FILE_LIST_DIRECTORY didn’t help either. Is
Try ZwOpenFile with:
DesiredAccess = FILE_TRAVERSE | SYNCHRONIZE
ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE
OpenOptions = FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
Thanks - it turns out the problem was stack corruption. My first
ZwCreateFile was producing a valid handle - which was then corrupted
before it reached the InitializeObjectAttributes for the second.
Programming gets very difficult when the values of your variables
change without being told to…
James.