ReactOS 0.4.16-dev-250-g3ecd236
copysup.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/cache/copysup.c
5 * PURPOSE: Logging and configuration routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <ntoskrnl.h>
12#include "newcc.h"
13#include "section/newmm.h"
14#define NDEBUG
15#include <debug.h>
16
17/* GLOBALS ********************************************************************/
18
25
26#define TAG_COPY_READ TAG('C', 'o', 'p', 'y')
27#define TAG_COPY_WRITE TAG('R', 'i', 't', 'e')
28
29/* FUNCTIONS ******************************************************************/
30
31/*
32
33CcCopyRead can be called for a region of any size and alignment, so we must
34crawl the cache space, focusing one cache stripe after another and using
35RtlCopyMemory to copy the input data into the cache. In constrained memory,
36pages faulted into new stripes are often taken from old stripes, causing the
37old stripes to be flushed right away. In the case of many short buffered in
38order writes, like the ones generated by stdio, this can be really efficient.
39
40*/
49{
51 ULONG ReadLen;
52 PVOID Bcb;
53 PCHAR BufferTarget = (PCHAR)Buffer;
54 LARGE_INTEGER CacheOffset, EndOfExtent, NextOffset;
55
56 DPRINT("CcCopyRead(%x,%x,%d,%d,%x)\n",
58 FileOffset->LowPart,
59 Length,
60 Wait,
61 Buffer);
62
63 CacheOffset.QuadPart = FileOffset->QuadPart;
64 EndOfExtent.QuadPart = FileOffset->QuadPart + Length;
65
66 while (CacheOffset.QuadPart < EndOfExtent.QuadPart)
67 {
68 NextOffset.QuadPart = CacheOffset.QuadPart;
69 NextOffset.LowPart = (NextOffset.LowPart + CACHE_STRIPE) & ~(CACHE_STRIPE-1);
70 ReadLen = EndOfExtent.QuadPart - CacheOffset.QuadPart;
71 if (CacheOffset.QuadPart + ReadLen > NextOffset.QuadPart)
72 {
73 ReadLen = NextOffset.QuadPart - CacheOffset.QuadPart;
74 }
75
76 DPRINT("Reading %d bytes in this go (at %08x%08x)\n",
77 ReadLen,
78 CacheOffset.HighPart,
79 CacheOffset.LowPart);
80
82 &CacheOffset,
83 ReadLen,
85 &Bcb,
86 (PVOID*)&ReadBuffer))
87 {
89 IoStatus->Information = 0;
90 DPRINT("Failed CcCopyRead\n");
91 return FALSE;
92 }
93
94 DPRINT("Copying %d bytes at %08x%08x\n",
95 ReadLen,
96 CacheOffset.HighPart,
97 CacheOffset.LowPart);
98
99 RtlCopyMemory(BufferTarget, ReadBuffer, ReadLen);
100
101 BufferTarget += ReadLen;
102
103 CacheOffset = NextOffset;
105 }
106
107 IoStatus->Status = STATUS_SUCCESS;
108 IoStatus->Information = Length;
109
110 DPRINT("Done with CcCopyRead\n");
111
112 return TRUE;
113}
114
115VOID
116NTAPI
120 IN ULONG PageCount,
123{
125}
126
128NTAPI
134{
135 INT Count = 0;
138 PVOID WriteBuf;
139 ULONG WriteLen;
140 LARGE_INTEGER CurrentOffset = *FileOffset;
141 LARGE_INTEGER EndOffset;
142 LARGE_INTEGER NextOffset;
143
144 EndOffset.QuadPart = CurrentOffset.QuadPart + Length;
145
146 DPRINT("CcCopyWrite(%x,%x,%d,%d,%x)\n",
148 FileOffset->LowPart,
149 Length,
150 Wait,
151 Buffer);
152
153 while (CurrentOffset.QuadPart < EndOffset.QuadPart)
154 {
155 NextOffset.HighPart = CurrentOffset.HighPart;
156 NextOffset.LowPart = (CurrentOffset.LowPart + CACHE_STRIPE) & ~(CACHE_STRIPE - 1);
157 DPRINT("NextOffset %08x%08x\n", NextOffset.u.HighPart, NextOffset.u.LowPart);
158 WriteLen = MIN(NextOffset.QuadPart - CurrentOffset.QuadPart, Length);
159
160 DPRINT("Copying %x bytes from %08x%08x\n",
161 WriteLen,
162 CurrentOffset.u.HighPart,
163 CurrentOffset.u.LowPart);
164
165 DPRINT("CcPreparePinWrite\n");
166
168 &CurrentOffset,
169 WriteLen,
170 FALSE,
172 (PVOID *)&Bcb, &WriteBuf);
173
174 DPRINT("Result %s %x %x\n", Result ? "TRUE" : "FALSE", Bcb, WriteBuf);
175 if (!Result)
176 {
177 DPRINT1("CcPreparePinWrite Failed?\n");
178 if (Wait)
180 else
181 return FALSE;
182 }
183
184 DPRINT("Copying actual memory to BCB#%x (@%x) (from buffer at %x)\n",
186 WriteBuf,
187 Bcb->BaseAddress);
188
189 RtlCopyMemory(WriteBuf, ((PCHAR)Buffer) + Count, WriteLen);
190 Count += WriteLen;
191 Length -= WriteLen;
192 CurrentOffset = NextOffset;
193 Bcb->Dirty = TRUE;
195 }
196
197 DPRINT("Done with CcCopyWrite\n");
198
199 return TRUE;
200}
201
202VOID
203NTAPI
208{
210}
211
213NTAPI
215 IN ULONG BytesToWrite,
217 IN UCHAR Retrying)
218{
220 return FALSE;
221}
222
223VOID
224NTAPI
226 IN PCC_POST_DEFERRED_WRITE PostRoutine,
229 IN ULONG BytesToWrite,
230 IN BOOLEAN Retrying)
231{
233}
234
235/* EOF */
unsigned char BOOLEAN
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
#define MIN(x, y)
Definition: rdesktop.h:171
#define DPRINT1
Definition: precomp.h:8
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:415
#define PCHAR
Definition: match.c:90
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
#define CACHE_STRIPE
Definition: newcc.h:123
int Count
Definition: noreturn.cpp:7
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define PIN_IF_BCB
#define PIN_WAIT
VOID NTAPI CcFastCopyWrite(IN PFILE_OBJECT FileObject, IN ULONG FileOffset, IN ULONG Length, IN PVOID Buffer)
Definition: copysup.c:204
ULONG CcFastMdlReadNotPossible
Definition: copysup.c:20
ULONG CcFastReadResourceMiss
Definition: copysup.c:24
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN UCHAR Retrying)
Definition: copysup.c:214
ULONG CcFastReadNoWait
Definition: copysup.c:23
BOOLEAN NTAPI CcCopyRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus)
Definition: copysup.c:43
ULONG CcFastReadNotPossible
Definition: copysup.c:21
ULONG CcFastMdlReadWait
Definition: copysup.c:19
VOID NTAPI CcFastCopyRead(IN PFILE_OBJECT FileObject, IN ULONG FileOffset, IN ULONG Length, IN ULONG PageCount, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus)
Definition: copysup.c:117
ULONG CcFastReadWait
Definition: copysup.c:22
VOID NTAPI CcDeferWrite(IN PFILE_OBJECT FileObject, IN PCC_POST_DEFERRED_WRITE PostRoutine, IN PVOID Context1, IN PVOID Context2, IN ULONG BytesToWrite, IN BOOLEAN Retrying)
Definition: copysup.c:225
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
BOOLEAN NTAPI CcPreparePinWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Zero, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:827
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
Definition: newcc.h:4
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT Context1
Definition: tdikrnl.h:1095
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT _In_ PTDI_PNP_CONTEXT Context2
Definition: tdikrnl.h:1096
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_NOT_MAPPED_DATA
Definition: udferr_usr.h:157
LONGLONG QuadPart
Definition: typedefs.h:114
struct _LARGE_INTEGER::@2302 u
ULONG LowPart
Definition: typedefs.h:106
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
VOID(NTAPI * PCC_POST_DEFERRED_WRITE)(_In_ PVOID Context1, _In_ PVOID Context2)
Definition: cctypes.h:66
* PFILE_OBJECT
Definition: iotypes.h:1998
unsigned char UCHAR
Definition: xmlstorage.h:181