Try using a Unicode string - the interface supports UNICODE only. I’m
not sure what it would do when presented with an ANSI string that it
thinks is a UNICODE string.
Regards,
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of valerino
Sent: Wednesday, September 29, 2004 12:21 PM
To: ntfsd redirect
Subject: Re:[ntfsd] Another weird thing about ZwQueryDirectoryFile
Uhm, something is really goin’ wrong. I can’t think of what’s wrong with
my code, i have tried to roll my own irp too, but still no success. I
specify a filemask, and it still returns all file entries as with
FileName = NULL.
Here is the code i use to roll the irp :
/***********************************************************************
/
NTSTATUS UtilBuildQueryDirectoryIrp( IN HANDLE FileHandle, char*
FileMask, PVOID FileInfoBuffer, ULONG FileInfoLength, BOOLEAN
RestartScan, BOOLEAN ReturnSingleEntry)
{
NTSTATUS Status;
PIRP irp = NULL;
PDEVICE_OBJECT pDeviceObject = NULL;
PFILE_OBJECT pFileObject = NULL;
ANSI_STRING asName;
PIO_STACK_LOCATION irpSp;
IO_STATUS_BLOCK Iosb;
KEVENT Event;
// get device from fileobject
ObReferenceObjectByHandle(FileHandle,FILE_ANY_ACCESS,
NULL,KernelMode,&pFileObject,NULL);
if (!pFileObject)
goto __exit;
// use base filesystem object directly
pDeviceObject = IoGetBaseFileSystemDeviceObject(pFileObject);
if (!pDeviceObject)
goto __exit;
// build irp
irp = IoAllocateIrp (pDeviceObject->StackSize,TRUE);
if (!irp)
goto __exit;
irpSp = IoGetNextIrpStackLocation(irp);
// fill irp params
irp->Tail.Overlay.Thread = PsGetCurrentThread();
KeInitializeEvent(&Event,NotificationEvent,FALSE);
irp->UserIosb = &Iosb;
irp->AssociatedIrp.SystemBuffer = (PVOID) NULL;
irp->MdlAddress = (PMDL) NULL;
irp->UserBuffer = FileInfoBuffer;
irp->UserEvent = NULL;
irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
irp->Overlay.AsynchronousParameters.UserApcContext = NULL;
irp->Tail.Overlay.AuxiliaryBuffer = NULL;
irp->AssociatedIrp.SystemBuffer = (PVOID) NULL;
irp->MdlAddress = (PMDL) NULL;
irp->Flags = (ULONG) (IRP_BUFFERED_IO | IRP_INPUT_OPERATION);
irpSp->Parameters.QueryDirectory.Length = FileInfoLength;
irpSp->Parameters.QueryDirectory.FileInformationClass =
FileDirectoryInformation;
irpSp->Parameters.QueryDirectory.FileIndex = 0;
irpSp = IoGetNextIrpStackLocation( irp );
irpSp->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
irpSp->MinorFunction = IRP_MN_QUERY_DIRECTORY;
irpSp->FileObject = pFileObject;
// set completion routine which just set event and
// return MORE_PROCESSING_REQUIRED
irpSp->Context = &Event;
irpSp->CompletionRoutine = UtilSetEventCompletionRoutine;
irpSp->Control = SL_INVOKE_ON_SUCCESS | SL_INVOKE_ON_ERROR |
SL_INVOKE_ON_CANCEL;
if (FileMask)
{
RtlInitAnsiString(&asName,FileMask);
irpSp->Parameters.QueryDirectory.FileName = &asName;
}
else
irpSp->Parameters.QueryDirectory.FileName = NULL;
if (RestartScan)
{
irpSp->Flags = SL_RESTART_SCAN;
}
if (ReturnSingleEntry)
{
irpSp->Flags |= SL_RETURN_SINGLE_ENTRY;
}
// fire IRP
Status = IoCallDriver (pDeviceObject,irp);
if (Status == STATUS_PENDING)
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
Status = irp->IoStatus.Status;
__exit:
if (pFileObject)
ObDereferenceObject(pFileObject);
if (irp)
IoFreeIrp (irp);
return Status;
}
/***********************************************************************
/
I call this function with :
Status = UtilBuildQueryDirectoryIrp(hCacheDir,“*.txt”,
FileInformationBuffer,FILEBLOCKINFOSIZE,TRUE,TRUE);
if (!NT_SUCCESS(Status) && (Status != STATUS_NO_MORE_FILES))
{
Status = STATUS_SUCCESS;
goto __exit;
}
// … process first returned buffer here …
// then loop for every other entries in the directory
while (TRUE)
{
// … process returned buffer here …
// go on next file
Status = UtilBuildQueryDirectoryIrp(hCacheDir,NULL,
FileInformationBuffer,FILEBLOCKINFOSIZE,FALSE,TRUE);
if (!NT_SUCCESS(Status))
{
if (Status == STATUS_NO_MORE_FILES)
{
Status = STATUS_SUCCESS;
}
break;
}
}
I think my implementation is the same as ZwQueryDirectoryFile, but still
the same result. Please tell me what’s wrong (i’d like to use
ZwQueryDirectoryFile directly, using my own irp was just a test).
Ah… i’ve used an ANSI_STRING for the filename, since i’ve found that
the OS cast it to a PSTRING ( = ANSI_STRING, from ntdef.h) when building
the irp. Still, if i use unicode, same result (as for
ZwQueryDirectoryFile).
waiting clues…
regards,
Valerio
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com