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,11 +17,11 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
CcMdlRead ( CcMdlRead(
IN PFILE_OBJECT FileObject, IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN ULONG Length,
@ -32,71 +32,117 @@ CcMdlRead (
UNIMPLEMENTED; UNIMPLEMENTED;
} }
/********************************************************************** /*
* NAME INTERNAL * NAME INTERNAL
* CcMdlReadCompleteDev@8 * CcMdlReadCompleteDev@8
* *
* DESCRIPTION * DESCRIPTION
* *
* ARGUMENTS * ARGUMENTS
* MdlChain * MdlChain
* DeviceObject * DeviceObject
* *
* RETURN VALUE * RETURN VALUE
* None. * None.
* *
* NOTE * NOTE
* Used by CcMdlReadComplete@8 and FsRtl * Used by CcMdlReadComplete@8 and FsRtl
* *
*/ */
VOID STDCALL VOID
CcMdlReadCompleteDev (IN PMDL MdlChain, STDCALL
IN PDEVICE_OBJECT DeviceObject) CcMdlReadCompleteDev(IN PMDL MdlChain,
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
* *
* DESCRIPTION * DESCRIPTION
* *
* ARGUMENTS * ARGUMENTS
* *
* RETURN VALUE * RETURN VALUE
* None. * None.
* *
* NOTE * NOTE
* From Bo Branten's ntifs.h v13. * From Bo Branten's ntifs.h v13.
* *
* @unimplemented * @implemented
*/
VOID STDCALL
CcMdlReadComplete (IN PFILE_OBJECT FileObject,
IN PMDL MdlChain)
{
PDEVICE_OBJECT DeviceObject = NULL;
DeviceObject = IoGetRelatedDeviceObject (FileObject);
/* FIXME: try fast I/O first */
CcMdlReadCompleteDev (MdlChain,
DeviceObject);
}
/*
* @unimplemented
*/ */
VOID VOID
STDCALL STDCALL
CcMdlWriteComplete ( CcMdlReadComplete(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject, IN PMDL MdlChain)
IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain
)
{ {
UNIMPLEMENTED; 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->MdlReadComplete)
{
/* Use the fast path */
FastDispatch->MdlReadComplete(FileObject,
MdlChain,
DeviceObject);
}
/* Use slow path */
CcMdlReadCompleteDev(MdlChain, FileObject);
}
/*
* @implemented
*/
VOID
STDCALL
CcMdlWriteComplete(IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
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;
} }
/* /*

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,10 +60,9 @@ FsRtlIncrementCcFastReadNoWait( VOID )
CcFastReadNoWait++; CcFastReadNoWait++;
} }
/*
/********************************************************************** * NAME EXPORTED
* NAME EXPORTED * FsRtlMdlRead@24
* FsRtlMdlRead@24
* *
* DESCRIPTION * DESCRIPTION
* *
@ -65,26 +70,61 @@ 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
* *
* DESCRIPTION * DESCRIPTION
* *
@ -92,79 +132,48 @@ 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,
return FALSE; DeviceObject);
} }
if (NULL == DriverObject->FastIoDispatch->Dispatch [IRP_MJ_READ])
{ /* Get the Base File System (Volume) and Fast Calls */
return FALSE; BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
} FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
return DriverObject->FastIoDispatch->Dispatch
[IRP_MJ_READ] ( /* If the Base Device Object has its own FastDispatch Routine, fail */
Mdl, if (FastDispatch && FastDispatch->MdlReadComplete &&
NULL /* FIXME: how to get the IRP? */ BaseDeviceObject != DeviceObject)
); {
#endif return FALSE;
} }
/*
* Default I/O path /* No fast path, use slow path */
*/ return FsRtlMdlReadCompleteDev(FileObject, MdlChain, DeviceObject);
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
* *
* DESCRIPTION * DESCRIPTION
* *
@ -173,28 +182,25 @@ FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject,
* RETURN VALUE * RETURN VALUE
* *
* NOTE * NOTE
* From Bo Branten's ntifs.h v13. * From Bo Branten's ntifs.h v13.
* (CcMdlReadCompleteDev declared in internal/cc.h) * (CcMdlReadCompleteDev declared in internal/cc.h)
* *
* @implemented * @implemented
*/ */
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
* *
* DESCRIPTION * DESCRIPTION
* *
@ -206,23 +212,162 @@ 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
)
{ {
return FALSE; UNIMPLEMENTED;
return FALSE;
} }
/********************************************************************** /*
* NAME EXPORTED * NAME EXPORTED
* FsRtlMdlWriteComplete@12 * FsRtlMdlWriteComplete@12
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @implemented
*/
BOOLEAN
STDCALL
FsRtlMdlWriteComplete(IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain)
{
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
* FsRtlMdlWriteCompleteDev@16
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @implemented
*/
BOOLEAN
STDCALL
FsRtlMdlWriteCompleteDev(IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject)
{
/* Call the Cache Manager */
CcMdlWriteCompleteDev(FileOffset, MdlChain, FileObject);
return TRUE;
}
/*
* NAME EXPORTED
* FsRtlPrepareMdlWrite@24
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @implemented
*/
BOOLEAN
STDCALL
FsRtlPrepareMdlWrite(IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN ULONG Length,
IN ULONG LockKey,
OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus)
{
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
* FsRtlPrepareMdlWriteDev@28
* *
* DESCRIPTION * DESCRIPTION
* *
@ -234,93 +379,16 @@ FsRtlMdlReadDev (
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
FsRtlMdlWriteComplete ( FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject,
IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset,
IN PLARGE_INTEGER FileOffset, IN ULONG Length,
IN PMDL MdlChain IN ULONG LockKey,
) OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject)
{ {
return FALSE; /* FIXME: call FsRtlMdlWriteCompleteDev ? */ UNIMPLEMENTED;
} return FALSE;
/**********************************************************************
* NAME EXPORTED
* FsRtlMdlWriteCompleteDev@16
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @unimplemented
*/
BOOLEAN
STDCALL
FsRtlMdlWriteCompleteDev (
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN PMDL MdlChain,
IN PDEVICE_OBJECT DeviceObject
)
{
return FALSE;
}
/**********************************************************************
* NAME EXPORTED
* FsRtlPrepareMdlWrite@24
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @unimplemented
*/
BOOLEAN
STDCALL
FsRtlPrepareMdlWrite (
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN ULONG Length,
IN ULONG LockKey,
OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus
)
{
return FALSE; /* call FsRtlPrepareMdlWriteDev ? */
}
/**********************************************************************
* NAME EXPORTED
* FsRtlPrepareMdlWriteDev@28
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* @unimplemented
*/
BOOLEAN
STDCALL
FsRtlPrepareMdlWriteDev (
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN ULONG Length,
IN ULONG LockKey,
OUT PMDL *MdlChain,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject
)
{
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
CcMdlReadCompleteDev (IN PMDL MdlChain, STDCALL
IN PDEVICE_OBJECT DeviceObject); CcMdlReadCompleteDev(IN PMDL MdlChain,
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 */