- Reworked NtfsAllocateIrpContext to avoid working with null IRP....

- Rewritten NtfsFsdDirectoryControl (using IrpContext, etc)

svn path=/trunk/; revision=32621
This commit is contained in:
Pierre Schweitzer 2008-03-09 13:58:25 +00:00
parent 8083445324
commit 7d27fdf54b
2 changed files with 52 additions and 31 deletions

View file

@ -477,10 +477,11 @@ CdfsGetBothDirectoryInformation(PFCB Fcb,
} }
#endif #endif
static NTSTATUS NTSTATUS
NtfsQueryDirectory(PDEVICE_OBJECT DeviceObject, NtfsQueryDirectory(PNTFS_IRP_CONTEXT IrpContext)
PIRP Irp)
{ {
PIRP Irp;
PDEVICE_OBJECT DeviceObject;
PDEVICE_EXTENSION DeviceExtension; PDEVICE_EXTENSION DeviceExtension;
LONG BufferLength = 0; LONG BufferLength = 0;
PUNICODE_STRING SearchPattern = NULL; PUNICODE_STRING SearchPattern = NULL;
@ -498,6 +499,10 @@ NtfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
DPRINT1("NtfsQueryDirectory() called\n"); DPRINT1("NtfsQueryDirectory() called\n");
ASSERT(IrpContext);
Irp = IrpContext->Irp;
DeviceObject = IrpContext->DeviceObject;
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
Stack = IoGetCurrentIrpStackLocation(Irp); Stack = IoGetCurrentIrpStackLocation(Irp);
FileObject = Stack->FileObject; FileObject = Stack->FileObject;
@ -672,18 +677,24 @@ NTSTATUS NTAPI
NtfsFsdDirectoryControl(PDEVICE_OBJECT DeviceObject, NtfsFsdDirectoryControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
PIO_STACK_LOCATION Stack; PNTFS_IRP_CONTEXT IrpContext = NULL;
NTSTATUS Status; NTSTATUS Status = STATUS_UNSUCCESSFUL;
DPRINT1("NtfsDirectoryControl() called\n"); DPRINT1("NtfsDirectoryControl() called\n");
Stack = IoGetCurrentIrpStackLocation(Irp); FsRtlEnterFileSystem();
ASSERT(DeviceObject);
ASSERT(Irp);
switch (Stack->MinorFunction) NtfsIsIrpTopLevel(Irp);
IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp);
if (IrpContext)
{
switch (IrpContext->MinorFunction)
{ {
case IRP_MN_QUERY_DIRECTORY: case IRP_MN_QUERY_DIRECTORY:
Status = NtfsQueryDirectory(DeviceObject, Status = NtfsQueryDirectory(IrpContext);
Irp);
break; break;
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
@ -692,17 +703,23 @@ NtfsFsdDirectoryControl(PDEVICE_OBJECT DeviceObject,
break; break;
default: default:
DPRINT1("NTFS: MinorFunction %d\n", Stack->MinorFunction);
Status = STATUS_INVALID_DEVICE_REQUEST; Status = STATUS_INVALID_DEVICE_REQUEST;
break; break;
} }
}
else
Status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT); IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Status); if (IrpContext)
ExFreePoolWithTag(IrpContext, TAG('N', 'I', 'R', 'P'));
IoSetTopLevelIrp(NULL);
FsRtlExitFileSystem();
return Status;
} }
/* EOF */ /* EOF */

View file

@ -74,20 +74,24 @@ NtfsAllocateIrpContext(PDEVICE_OBJECT DeviceObject,
TRACE_(NTFS, "NtfsAllocateIrpContext()\n"); TRACE_(NTFS, "NtfsAllocateIrpContext()\n");
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
IrpContext = (PNTFS_IRP_CONTEXT)ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_IRP_CONTEXT), TAG('N', 'I', 'R', 'P')); IrpContext = (PNTFS_IRP_CONTEXT)ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_IRP_CONTEXT), TAG('N', 'I', 'R', 'P'));
if (IrpContext == NULL) if (IrpContext == NULL)
return NULL; return NULL;
RtlZeroMemory(IrpContext, sizeof(NTFS_IRP_CONTEXT)); RtlZeroMemory(IrpContext, sizeof(NTFS_IRP_CONTEXT));
IrpContext->Identifier.Type = NTFS_TYPE_IRP_CONTEST; IrpContext->Identifier.Type = NTFS_TYPE_IRP_CONTEST;
IrpContext->Identifier.Size = sizeof(NTFS_IRP_CONTEXT); IrpContext->Identifier.Size = sizeof(NTFS_IRP_CONTEXT);
IrpContext->Irp = Irp; IrpContext->Irp = Irp;
IrpContext->DeviceObject = DeviceObject;
if (Irp)
{
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
ASSERT(IoStackLocation);
IrpContext->MajorFunction = IoStackLocation->MajorFunction; IrpContext->MajorFunction = IoStackLocation->MajorFunction;
IrpContext->MinorFunction = IoStackLocation->MinorFunction; IrpContext->MinorFunction = IoStackLocation->MinorFunction;
IrpContext->DeviceObject = DeviceObject;
IrpContext->IsTopLevel = (IoGetTopLevelIrp() == Irp); IrpContext->IsTopLevel = (IoGetTopLevelIrp() == Irp);
}
return IrpContext; return IrpContext;
} }