wcscmp and %S take NULL terminated strings. A UNICODE_STRING is never
guaranteed to be NULL terminated. The wcscmp should stop because the dir1
string is terminated, however your debug statement later could go on for
some time.
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Winston Loh
Sent: Thursday, March 14, 2002 3:10 AM
To: File Systems Developers
Subject: [ntfsd] RE: changing IRP_MN_QUERY_DIRECTORY in filter driver
Thanks for the tip. I have tried this but unfortunately, it seems to go
into aninfinite loop. Could someone please tell me what is wrong with the
following
piece of code?
FileObject = currentIrpStack->FileObject;
…
if (wcscmp(FileObject->FileName.Buffer, L"\dir1\") == 0) {
OBJECT_ATTRIBUTES objatt;
UNICODE_STRING objname;
HANDLE fhandle;
IO_STATUS_BLOCK fiosb;
PFILE_OBJECT fobject;
RtlInitUnicodeString(&objname, L"\??\C:\dir2\");
InitializeObjectAttributes(&objatt, &objname,
OBJ_CASE_INSENSITIVE, NULL, NULL);
ZwOpenFile(&fhandle, FILE_LIST_DIRECTORY, &objatt, &fiosb,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE);
ObReferenceObjectByHandle(fhandle, FILE_READ_DATA, NULL,
KernelMode, &fobject, NULL);
DbgPrint((“new file object name is %S\n”, fobject->FileName.Buffer));
currentIrpStack->FileObject = fobject;
}
…
IoCallDriver…
What happens is that there seems to be multiple request for the
IO_MN_QUERY_DIRECTORY with the original C:\dir1 being passed through. I
suspect that the filter will then change the file object to the one
specified bymy code but then instead of the result being sent back to the
application,
theapplication seems to be waiting forever and continuously issuing new
query
directory calls.
Thanks in advance for your help.
What you are doing is wrong. The name in the FileObject->FileName
field has to do with the name of the file represented by the given file
object. This field is only valid during the create IRP and should not
be accessed at any other time. Changing it after create has no effect.
If you want to return the contents of a different directory you need to
open that other directory, get the file object for that open, and then
change the file object field in the irp stack to this alternate file
object.
Neal Christiansen
This posting is provided “AS IS” with no warranties, and confers no
rights.
-----Original Message-----
From: Winston Loh [mailto:xxxxx@comp.nus.edu.sg]
Sent: Wednesday, March 13, 2002 01:24 AM
To: File Systems Developers
Subject: [ntfsd] changing IRP_MN_QUERY_DIRECTORY in filter driver
Hi all,
I am trying to change the directory query such that it displays the
results ofa different directory to certain requesting programs. For
example, if a
program A queries the contents of a directory say c:\dir1, I want to
be able
to redirect the request to a different directory say c:\dir2 or
perhaps even
d:\dir2. Note that a different program B might not redirect c:\dir1
to c:\dir2so it is not a junction point. The program A should also
not know that
it isquerying c:\dir2 and not c:\dir1.
I have found that the name of the directory being queried is stored in
FileObject->FileName. Assuming that the request is still headed for
the same
volume, I tried to change the contents of this field to reflect a
different
directory name. However, even when this has been changed, the program
still lists the contents of the original directory and not the
contents of thenew directory. What am I missing here? What else
would I need to change
other than FileObject->FileName? Also, if the query is to be
performed on a
different volume, can I simply change the device object to the
appropriate
device object when calling the IoCallDriver function?
Thanks in advance.
You are currently subscribed to ntfsd as: xxxxx@Windows.Microsoft.com
To unsubscribe send a blank email to %%email.unsub%%
You are currently subscribed to ntfsd as: xxxxx@comp.nus.edu.sg To
unsubscribe send a blank email to %%email.unsub%%
You are currently subscribed to ntfsd as: xxxxx@legato.com
To unsubscribe send a blank email to %%email.unsub%%