ReactOS  0.4.14-dev-50-g13bb5e2
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 
33 CcCopyRead can be called for a region of any size and alignment, so we must
34 crawl the cache space, focusing one cache stripe after another and using
35 RtlCopyMemory to copy the input data into the cache. In constrained memory,
36 pages faulted into new stripes are often taken from old stripes, causing the
37 old stripes to be flushed right away. In the case of many short buffered in
38 order writes, like the ones generated by stdio, this can be really efficient.
39 
40 */
41 BOOLEAN
42 NTAPI
45  IN ULONG Length,
46  IN BOOLEAN Wait,
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",
57  FileObject,
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 
81  if (!CcPinRead(FileObject,
82  &CacheOffset,
83  ReadLen,
85  &Bcb,
86  (PVOID*)&ReadBuffer))
87  {
88  IoStatus->Status = STATUS_UNSUCCESSFUL;
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;
104  CcUnpinData(Bcb);
105  }
106 
107  IoStatus->Status = STATUS_SUCCESS;
108  IoStatus->Information = Length;
109 
110  DPRINT("Done with CcCopyRead\n");
111 
112  return TRUE;
113 }
114 
115 VOID
116 NTAPI
119  IN ULONG Length,
120  IN ULONG PageCount,
121  OUT PVOID Buffer,
123 {
125 }
126 
127 BOOLEAN
128 NTAPI
131  IN ULONG Length,
132  IN BOOLEAN Wait,
133  IN PVOID Buffer)
134 {
135  INT Count = 0;
136  BOOLEAN Result;
137  PNOCC_BCB Bcb;
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",
147  FileObject,
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;
194  CcUnpinData(Bcb);
195  }
196 
197  DPRINT("Done with CcCopyWrite\n");
198 
199  return TRUE;
200 }
201 
202 VOID
203 NTAPI
206  IN ULONG Length,
207  IN PVOID Buffer)
208 {
210 }
211 
212 BOOLEAN
213 NTAPI
215  IN ULONG BytesToWrite,
216  IN BOOLEAN Wait,
217  IN UCHAR Retrying)
218 {
220  return FALSE;
221 }
222 
223 VOID
224 NTAPI
226  IN PCC_POST_DEFERRED_WRITE PostRoutine,
227  IN PVOID Context1,
228  IN PVOID Context2,
229  IN ULONG BytesToWrite,
230  IN BOOLEAN Retrying)
231 {
233 }
234 
235 /* EOF */
signed char * PCHAR
Definition: retypes.h:7
#define IN
Definition: typedefs.h:38
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
ULONG CcFastReadNoWait
Definition: copysup.c:23
ULONG CcFastMdlReadWait
Definition: copysup.c:19
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_NOT_MAPPED_DATA
Definition: udferr_usr.h:157
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
ULONG CcFastReadNotPossible
Definition: copysup.c:21
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define PIN_WAIT
Definition: newcc.h:3
int32_t INT
Definition: typedefs.h:56
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
T MIN(T a, T b)
Definition: polytest.cpp:79
ULONG CcFastReadWait
Definition: copysup.c:22
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID(NTAPI * PCC_POST_DEFERRED_WRITE)(_In_ PVOID Context1, _In_ PVOID Context2)
Definition: cctypes.h:66
struct _LARGE_INTEGER::@2201 u
unsigned char BOOLEAN
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define PCHAR
Definition: match.c:90
#define CACHE_STRIPE
Definition: newcc.h:128
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN UCHAR Retrying)
Definition: copysup.c:214
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
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_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
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 LowPart
Definition: typedefs.h:104
ULONG CcFastReadResourceMiss
Definition: copysup.c:24
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT _In_ PTDI_PNP_CONTEXT Context2
Definition: tdikrnl.h:1094
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
#define PIN_IF_BCB
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT Context1
Definition: tdikrnl.h:1094
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define DPRINT1
Definition: precomp.h:8
#define OUT
Definition: typedefs.h:39
ULONG CcFastMdlReadNotPossible
Definition: copysup.c:20
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
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
VOID NTAPI CcFastCopyWrite(IN PFILE_OBJECT FileObject, IN ULONG FileOffset, IN ULONG Length, IN PVOID Buffer)
Definition: copysup.c:204
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
LONGLONG QuadPart
Definition: typedefs.h:112
IN BOOLEAN Wait
Definition: fatprocs.h:1529