RE: How to query for a long filename using IRP_MJ_DIRECTO RY_CONTROL/IRP_MN_QUERY_DIRECTORY?

I was trying to query for a long filename from the filter driver(NT 4.0
and Win 2000) using IRP_MJ_DIRECTORY_CONTROL/IRP_MN_QUERY_DIRECTORY.
The IoCallDriver fails with NTFS returning an error code of "0xc000000d "
which maps to an invalid parameter(according to ntstatus.h). Here is the
part of a code which tries to query for a long filename. Is there any
other IRP parameter to be filled up or something already present in the
code needs to be modified? I have tried with various options but could not
find out the problem.
I have hardcoded the filenames and parent directory names(which contains
the file) for the purpose of testing how it works. Should original
FileObject be passed in OverLay field and parent dir name passed in
“ioStackLocation->FileObject”(in the code)? Currently, in the code both
the OverLay fileld and “ioStackLocation->FileObject” contains the parent
dir name(E:\longdir);

BOOLEAN QueryLongFileName( PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject,
PFILE_BOTH_DIR_INFORMATION FileName, ULONG
FileNameLength )
{
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION ioStackLocation;
STRING FileInfo={0,0,NULL};

KeInitializeEvent(&event, SynchronizationEvent, FALSE);
irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

// irp->UserBuffer=FileName;
irp->AssociatedIrp.SystemBuffer = FileName;
irp->UserEvent = &event;
irp->UserIosb = &IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->RequestorMode = KernelMode;
irp->Flags = 0;

RtlInitAnsiString(&FileInfo,“filenamelong.txt”);

RtlZeroMemory(FileObject->FileName.Buffer,FileObject->FileName.Length);
RtlCopyMemory(FileObject->FileName.Buffer,L"E:\longdir",wcslen(L"E:\longdir")*sizeof(WCHAR));

FileObject->FileName.Length=wcslen(L"E:\longdir")*sizeof(WCHAR);
FileObject->FileName.MaximumLength=FileObject->FileName.Length;

ioStackLocation = IoGetNextIrpStackLocation(irp);

ioStackLocation->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
ioStackLocation->MinorFunction = IRP_MN_QUERY_DIRECTORY;
ioStackLocation->DeviceObject = DeviceObject;
ioStackLocation->FileObject = FileObject;
ioStackLocation->Parameters.QueryDirectory.Length = FileNameLength;
ioStackLocation->Parameters.QueryDirectory.FileInformationClass =
FileBothDirectoryInformation;
ioStackLocation->Parameters.QueryDirectory.FileName = &FileInfo;

IoSetCompletionRoutine(irp, CompleteQuery, 0, TRUE, TRUE, TRUE);//
CompleteQuery takes care of freeing the IRP
IoCallDriver(DeviceObject, irp);
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);

}

Regards and TIA,
Vishnu

(1) Yes. Explorer uses this technique all of the time to match up long
name/short name as well as actual case of the file name.
(2) Not in the versions you are targeting.
(3) This can either be a file name you wish to find (not a path, just a
filename) or a regular expression (e.g., “*.doc” to find all of the DOC
files within the directory.) That name will be used to match the short OR
long file name.
(4) No. IRP_MJ_DIRECTORY_CONTROL is one of the functions managed by the
Flags field in the DEVICE_OBJECT. For most file systems this will be
neither I/O, so the data will be returned in the buffer pointed to by
Irp->Userbuffer.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: vishnu [mailto:xxxxx@lycos.com]
Sent: Tuesday, November 19, 2002 8:15 AM
To: File Systems Developers
Subject: [ntfsd] How to query for a long filename using
IRP_MJ_DIRECTORY_CONTROL/IRP_MN_QUERY_DIRECTORY?

I am writing a filter driver over NTFS for WIN NT 4.0 & win2K .I get a
short filename to the delete routine of the filter driver when the file is
deleted from the command prompt using del command.(Eg.
h:\testdir\longfilename.txt will be sent as h:\testdir\longfi~1.txt).
Suppose I want to query for the long filename by creating my own IRP and
filling in the QuerDirectory structure. I have the following queries.

  1. Is it possible to always get a long filename using
    IRP_MJ_DIRECTORY_CONTROL and filling in the appropriate IRP parameters?
  2. Is it possible to obtain long filename for a particular file directly
    i.e not querying the entire directory?
  3. what do I fill up in the “FileName”(a filename in particular for which
    I want the long name or the parent directory-Eg. In the above
    case,h:\testdir ? ) and “FileIndex”(I don’t know for what reason this
    field is used for) fields in the QueryDirectory structure?
  4. will AssociatedIrp.SystemBuffer always get the results of the query?

TIA,
Vishnu


You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to %%email.unsub%%