2004-06-21 04:11:44 +00:00
|
|
|
/* $Id: pin.c,v 1.15 2004/06/21 04:11:44 ion Exp $
|
2001-10-10 21:49:15 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: ntoskrnl/cc/pin.c
|
|
|
|
* PURPOSE: Implements cache managers pinning interface
|
|
|
|
* PROGRAMMER: Hartmut Birr
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 05.10.2001
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
#include <ddk/ntifs.h>
|
|
|
|
#include <internal/mm.h>
|
|
|
|
#include <internal/cc.h>
|
|
|
|
#include <internal/pool.h>
|
|
|
|
#include <internal/io.h>
|
|
|
|
#include <ntos/minmax.h>
|
2001-10-10 21:49:15 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <internal/debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
|
|
|
|
|
2003-01-11 15:22:31 +00:00
|
|
|
extern NPAGED_LOOKASIDE_LIST iBcbLookasideList;
|
2001-10-10 21:49:15 +00:00
|
|
|
|
2003-01-11 15:22:31 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
2001-10-10 21:49:15 +00:00
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-10-10 21:49:15 +00:00
|
|
|
BOOLEAN STDCALL
|
2002-07-17 21:04:57 +00:00
|
|
|
CcMapData (IN PFILE_OBJECT FileObject,
|
|
|
|
IN PLARGE_INTEGER FileOffset,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN Wait,
|
|
|
|
OUT PVOID *pBcb,
|
|
|
|
OUT PVOID *pBuffer)
|
2001-10-10 21:49:15 +00:00
|
|
|
{
|
2002-07-17 21:04:57 +00:00
|
|
|
ULONG ReadOffset;
|
|
|
|
BOOLEAN Valid;
|
2002-09-08 10:23:54 +00:00
|
|
|
PBCB Bcb;
|
|
|
|
PCACHE_SEGMENT CacheSeg;
|
2002-07-17 21:04:57 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PINTERNAL_BCB iBcb;
|
|
|
|
ULONG ROffset;
|
|
|
|
|
|
|
|
DPRINT("CcMapData(FileObject %x, FileOffset %d, Length %d, Wait %d,"
|
|
|
|
" pBcb %x, pBuffer %x)\n", FileObject, (ULONG)FileOffset->QuadPart,
|
|
|
|
Length, Wait, pBcb, pBuffer);
|
|
|
|
|
2003-12-30 18:52:06 +00:00
|
|
|
ReadOffset = (ULONG)FileOffset->QuadPart;
|
2003-06-07 Casper S. Hornstrup <chorns@users.sourceforge.net>
Changes for compiling with w32api
* include/ddk/cctypes.h (PREACTOS_COMMON_FCB_HEADER): Remove.
(FSRTL_COMMON_FCB_HEADER): Add.
* include/ddk/iotypes.h (FILE_OBJECT): Rename field
SectionObjectPointers to SectionObjectPointer.
* ntoskrnl/cc/copy.c, ntoskrnl/cc/misc.c, ntoskrnl/cc/pin.c,
ntoskrnl/cc/view.c, ntoskrnl/io/rawfs.c, ntoskrnl/mm/section.c,
drivers/fs/cdfs/cleanup.c, drivers/fs/cdfs/fcb.c,
drivers/fs/cdfs/fsctl.c, drivers/fs/ntfs/fcb.c, drivers/fs/ntfs/fsctl.c,
drivers/fs/vfat/close.c, drivers/fs/vfat/create.c,
drivers/fs/vfat/finfo.c, drivers/fs/vfat/fcb.c, drivers/fs/vfat/fsctl.c:
Use new FILE_OBJECT structure.
* drivers/fs/cdfs/cdfs.h, drivers/fs/ntfs/ntfs.h, drivers/fs/vfat/vfat.h:
Use new FSRTL_COMMON_FCB_HEADER structure.
* drivers/net/afd/include/afd.h (FSRTL_COMMON_FCB_HEADER): Remove.
* include/ddk/ketypes.h (KQUEUE): Match w32api structure.
* ntoskrnl/ke/queue.c, ntoskrnl/ke/wait.c: Use new structure.
* ntoskrnl/ke/spinlock.c (KeAcquireSpinLockAtDpcLevel,
KeReleaseSpinLockFromDpcLevel): Undefine before declaring.
svn path=/trunk/; revision=4865
2003-06-07 11:34:36 +00:00
|
|
|
Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
|
2002-12-15 Casper S. Hornstrup <chorns@users.sourceforge.net>
* drivers/fs/vfat/cleanup.c (VfatCleanupFile): Only uninitialize caching
when initialized.
* drivers/fs/vfat/fcb.c (vfatReleaseFCB): Ditto.
* lib/kernel32/mem/section.c (CreateFileMappingW): Pass NULL as
MaximumSize to NtCreateSection if dwMaximumSizeHigh and dwMaximumSizeLow
are both 0.
* ntoskrnl/cc/pin.c (CcMapData): Assert if Bcb is NULL.
* ntoskrnl/cc/view.c (CcRosReleaseCacheSegment, CcRosLookupCacheSegment,
CcRosMarkDirtyCacheSegment, CcRosUnmapCacheSegment,
CcRosCreateCacheSegment, CcRosGetCacheSegmentChain,
CcRosGetCacheSegment, CcRosRequestCacheSegment, CcFlushCache,
CcRosDeleteFileCache, CcRosReferenceCache, CcRosDereferenceCache,
CcRosReleaseFileCache, CcGetFileObjectFromSectionPtrs): Ditto.
* ntoskrnl/mm/section.c (MiReadPage): Assert if Fcb->Bcb is NULL.
(MmCreateDataFileSection): Make sure caching is initialized for the file
stream.
svn path=/trunk/; revision=3879
2002-12-15 17:01:52 +00:00
|
|
|
assert(Bcb);
|
|
|
|
|
2002-07-17 21:04:57 +00:00
|
|
|
DPRINT("AllocationSize %d, FileSize %d\n",
|
2001-10-10 21:49:15 +00:00
|
|
|
(ULONG)Bcb->AllocationSize.QuadPart,
|
|
|
|
(ULONG)Bcb->FileSize.QuadPart);
|
2002-07-17 21:04:57 +00:00
|
|
|
|
|
|
|
if (ReadOffset % Bcb->CacheSegmentSize + Length > Bcb->CacheSegmentSize)
|
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
ROffset = ROUND_DOWN (ReadOffset, Bcb->CacheSegmentSize);
|
|
|
|
Status = CcRosRequestCacheSegment(Bcb,
|
|
|
|
ROffset,
|
|
|
|
pBuffer,
|
|
|
|
&Valid,
|
|
|
|
&CacheSeg);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (!Valid)
|
|
|
|
{
|
2001-10-10 21:49:15 +00:00
|
|
|
if (!Wait)
|
2002-07-17 21:04:57 +00:00
|
|
|
{
|
2001-12-29 14:32:22 +00:00
|
|
|
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
|
2002-07-17 21:04:57 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2001-10-10 21:49:15 +00:00
|
|
|
if (!NT_SUCCESS(ReadCacheSegment(CacheSeg)))
|
2002-07-17 21:04:57 +00:00
|
|
|
{
|
2002-10-02 19:23:42 +00:00
|
|
|
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
|
2002-07-17 21:04:57 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
2003-12-30 18:52:06 +00:00
|
|
|
#if defined(__GNUC__)
|
2002-07-17 21:04:57 +00:00
|
|
|
*pBuffer += ReadOffset % Bcb->CacheSegmentSize;
|
2003-12-30 18:52:06 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
char* pTemp = *pBuffer;
|
|
|
|
pTemp += ReadOffset % Bcb->CacheSegmentSize;
|
|
|
|
*pBuffer = pTemp;
|
|
|
|
}
|
|
|
|
#endif
|
2003-01-11 15:22:31 +00:00
|
|
|
iBcb = ExAllocateFromNPagedLookasideList(&iBcbLookasideList);
|
2002-07-17 21:04:57 +00:00
|
|
|
if (iBcb == NULL)
|
|
|
|
{
|
|
|
|
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-01-11 15:22:31 +00:00
|
|
|
memset(iBcb, 0, sizeof(INTERNAL_BCB));
|
2002-07-17 21:04:57 +00:00
|
|
|
iBcb->CacheSegment = CacheSeg;
|
2002-08-14 20:58:39 +00:00
|
|
|
iBcb->Dirty = FALSE;
|
2002-07-17 21:04:57 +00:00
|
|
|
iBcb->PFCB.MappedLength = Length;
|
|
|
|
iBcb->PFCB.MappedFileOffset.QuadPart = FileOffset->QuadPart;
|
|
|
|
*pBcb = (PVOID)iBcb;
|
|
|
|
return(TRUE);
|
2001-10-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
2004-06-21 04:11:44 +00:00
|
|
|
* @unimplemented
|
2003-07-10 06:27:13 +00:00
|
|
|
*/
|
2004-06-21 04:11:44 +00:00
|
|
|
BOOLEAN
|
|
|
|
STDCALL
|
|
|
|
CcPinMappedData (
|
|
|
|
IN PFILE_OBJECT FileObject,
|
|
|
|
IN PLARGE_INTEGER FileOffset,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN Wait,
|
|
|
|
OUT PVOID * Bcb
|
|
|
|
)
|
2001-10-10 21:49:15 +00:00
|
|
|
{
|
2004-06-21 04:11:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
STDCALL
|
|
|
|
CcPinRead (
|
|
|
|
IN PFILE_OBJECT FileObject,
|
|
|
|
IN PLARGE_INTEGER FileOffset,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN Wait,
|
|
|
|
OUT PVOID * Bcb,
|
|
|
|
OUT PVOID * Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
STDCALL
|
|
|
|
CcPreparePinWrite (
|
|
|
|
IN PFILE_OBJECT FileObject,
|
|
|
|
IN PLARGE_INTEGER FileOffset,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN BOOLEAN Zero,
|
|
|
|
IN BOOLEAN Wait,
|
|
|
|
OUT PVOID * Bcb,
|
|
|
|
OUT PVOID * Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return FALSE;
|
2001-10-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-10-10 21:49:15 +00:00
|
|
|
VOID STDCALL
|
2002-07-17 21:04:57 +00:00
|
|
|
CcSetDirtyPinnedData (IN PVOID Bcb,
|
|
|
|
IN PLARGE_INTEGER Lsn)
|
2001-10-10 21:49:15 +00:00
|
|
|
{
|
|
|
|
PINTERNAL_BCB iBcb = Bcb;
|
2002-08-14 20:58:39 +00:00
|
|
|
iBcb->Dirty = TRUE;
|
2001-10-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
2004-06-21 04:11:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID STDCALL
|
|
|
|
CcUnpinData (IN PVOID Bcb)
|
|
|
|
{
|
|
|
|
PINTERNAL_BCB iBcb = Bcb;
|
|
|
|
CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE,
|
|
|
|
iBcb->Dirty, FALSE);
|
|
|
|
ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
STDCALL
|
|
|
|
CcUnpinDataForThread (
|
|
|
|
IN PVOID Bcb,
|
|
|
|
IN ERESOURCE_THREAD ResourceThreadId
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|