Implement FsRtlMdlRead, FsRtlMdlReadComplete, FsMdlReadCompleteDev, FsRtlMdlWRiteComplete, FsRtlMdlWriteCompleteDev, FsRtlPrepareMdlWrite, CcMdlReadCompleted, CcMdlWriteComplete, CcMdlReadCompleteDev

svn path=/trunk/; revision=15079
This commit is contained in:
Alex Ionescu 2005-05-07 15:19:33 +00:00
parent e18192ed67
commit 0abe7f6039
4 changed files with 415 additions and 295 deletions

View file

@ -1,4 +1,4 @@
/* $Id:$ /* $Id$
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -17,7 +17,7 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
@ -32,7 +32,7 @@ CcMdlRead (
UNIMPLEMENTED; UNIMPLEMENTED;
} }
/********************************************************************** /*
* NAME INTERNAL * NAME INTERNAL
* CcMdlReadCompleteDev@8 * CcMdlReadCompleteDev@8
* *
@ -49,15 +49,23 @@ CcMdlRead (
* Used by CcMdlReadComplete@8 and FsRtl * Used by CcMdlReadComplete@8 and FsRtl
* *
*/ */
VOID STDCALL VOID
STDCALL
CcMdlReadCompleteDev(IN PMDL MdlChain, CcMdlReadCompleteDev(IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject) IN PFILE_OBJECT FileObject)
{ {
UNIMPLEMENTED; PMDL Mdl;
/* Free MDLs */
while ((Mdl = MdlChain))
{
MdlChain = Mdl->Next;
MmUnlockPages(Mdl);
IoFreeMdl(Mdl);
}
} }
/*
/**********************************************************************
* NAME EXPORTED * NAME EXPORTED
* CcMdlReadComplete@8 * CcMdlReadComplete@8
* *
@ -71,30 +79,68 @@ CcMdlReadCompleteDev (IN PMDL MdlChain,
* NOTE * NOTE
* From Bo Branten's ntifs.h v13. * From Bo Branten's ntifs.h v13.
* *
* @unimplemented * @implemented
*/ */
VOID STDCALL VOID
STDCALL
CcMdlReadComplete(IN PFILE_OBJECT FileObject, CcMdlReadComplete(IN PFILE_OBJECT FileObject,
IN PMDL MdlChain) IN PMDL MdlChain)
{ {
PDEVICE_OBJECT DeviceObject = NULL; PDEVICE_OBJECT DeviceObject = NULL;
PFAST_IO_DISPATCH FastDispatch;
/* Get Fast Dispatch Data */
DeviceObject = IoGetRelatedDeviceObject(FileObject); DeviceObject = IoGetRelatedDeviceObject(FileObject);
/* FIXME: try fast I/O first */ FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
CcMdlReadCompleteDev (MdlChain,
/* Check if we support Fast Calls, and check this one */
if (FastDispatch && FastDispatch->MdlReadComplete)
{
/* Use the fast path */
FastDispatch->MdlReadComplete(FileObject,
MdlChain,
DeviceObject); DeviceObject);
} }
/* Use slow path */
CcMdlReadCompleteDev(MdlChain, FileObject);
}
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
CcMdlWriteComplete ( CcMdlWriteComplete(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain IN PMDL MdlChain)
) {
PDEVICE_OBJECT DeviceObject = NULL;
PFAST_IO_DISPATCH FastDispatch;
/* Get Fast Dispatch Data */
DeviceObject = IoGetRelatedDeviceObject(FileObject);
FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
/* Check if we support Fast Calls, and check this one */
if (FastDispatch && FastDispatch->MdlWriteComplete)
{
/* Use the fast path */
FastDispatch->MdlWriteComplete(FileObject,
FileOffset,
MdlChain,
DeviceObject);
}
/* Use slow path */
CcMdlWriteCompleteDev(FileOffset, MdlChain, FileObject);
}
VOID
STDCALL
CcMdlWriteCompleteDev(IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain,
IN PFILE_OBJECT FileObject)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }

View file

@ -1,19 +1,25 @@
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS Kernel
* FILE: ntoskrnl/fs/mdl.c * FILE: ntoskrnl/fs/mdl.c
* PURPOSE: No purpose listed. * PURPOSE: Cached MDL Access Helper Routines for File System Drivers
* *
* PROGRAMMERS: No programmer listed. * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
*/ */
/* INCLUDES ****************************************************************/
#include <ntoskrnl.h> #include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLOBALS *******************************************************************/
extern ULONG CcFastReadResourceMiss; extern ULONG CcFastReadResourceMiss;
extern ULONG CcFastReadNoWait; extern ULONG CcFastReadNoWait;
/* FUNCTIONS *****************************************************************/
/* /*
* @implemented * @implemented
*/ */
@ -54,8 +60,7 @@ FsRtlIncrementCcFastReadNoWait( VOID )
CcFastReadNoWait++; CcFastReadNoWait++;
} }
/*
/**********************************************************************
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlRead@24 * FsRtlMdlRead@24
* *
@ -65,24 +70,59 @@ FsRtlIncrementCcFastReadNoWait( VOID )
* *
* RETURN VALUE * RETURN VALUE
* *
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlRead ( FsRtlMdlRead(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN ULONG Length,
IN ULONG LockKey, IN ULONG LockKey,
OUT PMDL *MdlChain, OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus OUT PIO_STATUS_BLOCK IoStatus)
)
{ {
return FALSE; /* FIXME: call FsRtlMdlReadDev ? */ PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
PFAST_IO_DISPATCH FastDispatch;
/* Get Device Object and Fast Calls */
DeviceObject = IoGetRelatedDeviceObject(FileObject);
FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
/* Check if we support Fast Calls, and check this one */
if (FastDispatch && FastDispatch->MdlRead)
{
/* Use the fast path */
return FastDispatch->MdlRead(FileObject,
FileOffset,
Length,
LockKey,
MdlChain,
IoStatus,
DeviceObject);
} }
/* Get the Base File System (Volume) and Fast Calls */
BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
/********************************************************************** /* If the Base Device Object has its own FastDispatch Routine, fail */
if (FastDispatch && FastDispatch->MdlRead &&
BaseDeviceObject != DeviceObject)
{
return FALSE;
}
/* No fast path, use slow path */
return FsRtlMdlReadDev(FileObject,
FileOffset,
Length,
LockKey,
MdlChain,
IoStatus,
DeviceObject);
}
/*
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlReadComplete@8 * FsRtlMdlReadComplete@8
* *
@ -92,77 +132,46 @@ FsRtlMdlRead (
* *
* RETURN VALUE * RETURN VALUE
* *
* @unimplemented * @implemented
*/ */
BOOLEAN STDCALL BOOLEAN
STDCALL
FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject, FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject,
IN OUT PMDL Mdl) IN OUT PMDL MdlChain)
{ {
PDEVICE_OBJECT DeviceObject [2] = {NULL}; PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
PDRIVER_OBJECT DriverObject = NULL; PFAST_IO_DISPATCH FastDispatch;
/* /* Get Device Object and Fast Calls */
* Try fast I/O first DeviceObject = IoGetRelatedDeviceObject(FileObject);
*/ FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
DeviceObject [0] = IoGetRelatedDeviceObject (FileObject);
DriverObject = DeviceObject [0]->DriverObject; /* Check if we support Fast Calls, and check this one */
if (NULL != DriverObject->FastIoDispatch) if (FastDispatch && FastDispatch->MdlReadComplete)
{ {
#if 0 /* Use the fast path */
if (IRP_MJ_READ <= DriverObject->FastIoDispatch->Count) return FastDispatch->MdlReadComplete(FileObject,
MdlChain,
DeviceObject);
}
/* Get the Base File System (Volume) and Fast Calls */
BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
/* If the Base Device Object has its own FastDispatch Routine, fail */
if (FastDispatch && FastDispatch->MdlReadComplete &&
BaseDeviceObject != DeviceObject)
{ {
return FALSE; return FALSE;
} }
if (NULL == DriverObject->FastIoDispatch->Dispatch [IRP_MJ_READ])
{ /* No fast path, use slow path */
return FALSE; return FsRtlMdlReadCompleteDev(FileObject, MdlChain, DeviceObject);
}
return DriverObject->FastIoDispatch->Dispatch
[IRP_MJ_READ] (
Mdl,
NULL /* FIXME: how to get the IRP? */
);
#endif
}
/*
* Default I/O path
*/
DeviceObject [1] = IoGetBaseFileSystemDeviceObject (FileObject);
/*
* Did IoGetBaseFileSystemDeviceObject ()
* returned the same device
* IoGetRelatedDeviceObject () returned?
*/
if (DeviceObject [1] != DeviceObject [0])
{
#if 0
DriverObject = DeviceObject [1]->DriverObject;
if (NULL != DriverObject->FastIoDispatch)
{
/*
* Check if the driver provides
* IRP_MJ_READ.
*/
if (IRP_MJ_READ <= DriverObject->FastIoDispatch->Count)
{
if (NULL == DriverObject->FastIoDispatch->Dispatch [IRP_MJ_READ])
{
return FALSE;
}
}
}
#endif
DeviceObject [0] = DeviceObject [1];
}
return FsRtlMdlReadCompleteDev (
FileObject,
Mdl,
DeviceObject [0]
);
} }
/********************************************************************** /*
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlReadCompleteDev@12 * FsRtlMdlReadCompleteDev@12
* *
@ -180,19 +189,16 @@ FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject,
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlReadCompleteDev ( FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PMDL MdlChain, IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject IN PDEVICE_OBJECT DeviceObject)
)
{ {
FileObject = FileObject; /* unused parameter */ /* Call the Cache Manager */
CcMdlReadCompleteDev (MdlChain, DeviceObject); CcMdlReadCompleteDev(MdlChain, FileObject);
return TRUE; return TRUE;
} }
/*
/**********************************************************************
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlReadDev@28 * FsRtlMdlReadDev@28
* *
@ -206,21 +212,20 @@ FsRtlMdlReadCompleteDev (
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlReadDev ( FsRtlMdlReadDev(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN ULONG Length,
IN ULONG LockKey, IN ULONG LockKey,
OUT PMDL *MdlChain, OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus, OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject IN PDEVICE_OBJECT DeviceObject)
)
{ {
UNIMPLEMENTED;
return FALSE; return FALSE;
} }
/********************************************************************** /*
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlWriteComplete@12 * FsRtlMdlWriteComplete@12
* *
@ -230,21 +235,50 @@ FsRtlMdlReadDev (
* *
* RETURN VALUE * RETURN VALUE
* *
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlWriteComplete ( FsRtlMdlWriteComplete(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain IN PMDL MdlChain)
)
{ {
return FALSE; /* FIXME: call FsRtlMdlWriteCompleteDev ? */ PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
PFAST_IO_DISPATCH FastDispatch;
/* Get Device Object and Fast Calls */
DeviceObject = IoGetRelatedDeviceObject(FileObject);
FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
/* Check if we support Fast Calls, and check this one */
if (FastDispatch && FastDispatch->MdlWriteComplete)
{
/* Use the fast path */
return FastDispatch->MdlWriteComplete(FileObject,
FileOffset,
MdlChain,
DeviceObject);
} }
/* Get the Base File System (Volume) and Fast Calls */
BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
/********************************************************************** /* If the Base Device Object has its own FastDispatch Routine, fail */
if (FastDispatch && FastDispatch->MdlWriteComplete &&
BaseDeviceObject != DeviceObject)
{
return FALSE;
}
/* No fast path, use slow path */
return FsRtlMdlWriteCompleteDev(FileObject,
FileOffset,
MdlChain,
DeviceObject);
}
/*
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlWriteCompleteDev@16 * FsRtlMdlWriteCompleteDev@16
* *
@ -254,22 +288,22 @@ FsRtlMdlWriteComplete (
* *
* RETURN VALUE * RETURN VALUE
* *
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlWriteCompleteDev ( FsRtlMdlWriteCompleteDev(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain, IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject IN PDEVICE_OBJECT DeviceObject)
)
{ {
return FALSE; /* Call the Cache Manager */
CcMdlWriteCompleteDev(FileOffset, MdlChain, FileObject);
return TRUE;
} }
/********************************************************************** /*
* NAME EXPORTED * NAME EXPORTED
* FsRtlPrepareMdlWrite@24 * FsRtlPrepareMdlWrite@24
* *
@ -279,24 +313,59 @@ FsRtlMdlWriteCompleteDev (
* *
* RETURN VALUE * RETURN VALUE
* *
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlPrepareMdlWrite ( FsRtlPrepareMdlWrite(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN ULONG Length,
IN ULONG LockKey, IN ULONG LockKey,
OUT PMDL *MdlChain, OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus OUT PIO_STATUS_BLOCK IoStatus)
)
{ {
return FALSE; /* call FsRtlPrepareMdlWriteDev ? */ PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
PFAST_IO_DISPATCH FastDispatch;
/* Get Device Object and Fast Calls */
DeviceObject = IoGetRelatedDeviceObject(FileObject);
FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
/* Check if we support Fast Calls, and check this one */
if (FastDispatch && FastDispatch->PrepareMdlWrite)
{
/* Use the fast path */
return FastDispatch->PrepareMdlWrite(FileObject,
FileOffset,
Length,
LockKey,
MdlChain,
IoStatus,
DeviceObject);
} }
/* Get the Base File System (Volume) and Fast Calls */
BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
/********************************************************************** /* If the Base Device Object has its own FastDispatch Routine, fail */
if (FastDispatch && FastDispatch->PrepareMdlWrite &&
BaseDeviceObject != DeviceObject)
{
return FALSE;
}
/* No fast path, use slow path */
return FsRtlPrepareMdlWriteDev(FileObject,
FileOffset,
Length,
LockKey,
MdlChain,
IoStatus,
DeviceObject);
}
/*
* NAME EXPORTED * NAME EXPORTED
* FsRtlPrepareMdlWriteDev@28 * FsRtlPrepareMdlWriteDev@28
* *
@ -310,16 +379,15 @@ FsRtlPrepareMdlWrite (
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlPrepareMdlWriteDev ( FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN ULONG Length,
IN ULONG LockKey, IN ULONG LockKey,
OUT PMDL *MdlChain, OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus, OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject IN PDEVICE_OBJECT DeviceObject)
)
{ {
UNIMPLEMENTED;
return FALSE; return FALSE;
} }

View file

@ -62,9 +62,16 @@ typedef struct _INTERNAL_BCB
CSHORT RefCount; /* (At offset 0x34 on WinNT4) */ CSHORT RefCount; /* (At offset 0x34 on WinNT4) */
} INTERNAL_BCB, *PINTERNAL_BCB; } INTERNAL_BCB, *PINTERNAL_BCB;
VOID STDCALL VOID
STDCALL
CcMdlReadCompleteDev(IN PMDL MdlChain, CcMdlReadCompleteDev(IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject); IN PFILE_OBJECT FileObject);
VOID
STDCALL
CcMdlWriteCompleteDev(IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain,
IN PFILE_OBJECT FileObject);
NTSTATUS NTSTATUS
CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment); CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment);

View file

@ -157,7 +157,10 @@ SaveTrapFrameForKDB_Return:
mov [edi+KTHREAD_KERNEL_STACK], esp mov [edi+KTHREAD_KERNEL_STACK], esp
mov esp, [esi+KTHREAD_KERNEL_STACK] mov esp, [esi+KTHREAD_KERNEL_STACK]
/* Change the address space */ /*
* Sadly, ROS memory management is screwed up, so
* we must change the address space here.
*/
mov eax, [esi+KTHREAD_APCSTATE_PROCESS] mov eax, [esi+KTHREAD_APCSTATE_PROCESS]
mov eax, [eax+KPROCESS_DIRECTORY_TABLE_BASE] mov eax, [eax+KPROCESS_DIRECTORY_TABLE_BASE]
mov cr3, eax mov cr3, eax
@ -201,10 +204,6 @@ NoLdt:
/* Set current IOPM offset in the TSS */ /* Set current IOPM offset in the TSS */
mov [ebp+KTSS_IOMAPBASE], cx mov [ebp+KTSS_IOMAPBASE], cx
/* Change the address space */
mov eax, [edi+KPROCESS_DIRECTORY_TABLE_BASE]
mov cr3, eax
SameProcess: SameProcess:
/* Set the TEB */ /* Set the TEB */