xref: /reactos/ntoskrnl/cache/newcc.h (revision 40462c92)
1 #pragma once
2 
3 typedef struct _NOCC_BCB
4 {
5     /* Public part */
6     PUBLIC_BCB Bcb;
7 
8     struct _NOCC_CACHE_MAP *Map;
9     PROS_SECTION_OBJECT SectionObject;
10     LARGE_INTEGER FileOffset;
11     ULONG Length;
12     PVOID BaseAddress;
13     BOOLEAN Dirty;
14     PVOID OwnerPointer;
15 
16     /* Reference counts */
17     ULONG RefCount;
18 
19     LIST_ENTRY ThisFileList;
20 
21     KEVENT ExclusiveWait;
22     ULONG ExclusiveWaiter;
23     BOOLEAN Exclusive;
24 } NOCC_BCB, *PNOCC_BCB;
25 
26 typedef struct _NOCC_CACHE_MAP
27 {
28     LIST_ENTRY Entry;
29     LIST_ENTRY AssociatedBcb;
30     LIST_ENTRY PrivateCacheMaps;
31     ULONG NumberOfMaps;
32     ULONG RefCount;
33     CC_FILE_SIZES FileSizes;
34     CACHE_MANAGER_CALLBACKS Callbacks;
35     PVOID LazyContext;
36     PVOID LogHandle;
37     PFLUSH_TO_LSN FlushToLsn;
38     ULONG ReadAheadGranularity;
39 } NOCC_CACHE_MAP, *PNOCC_CACHE_MAP;
40 
41 VOID
42 NTAPI
43 CcPfInitializePrefetcher(VOID);
44 
45 VOID
46 NTAPI
47 CcMdlReadComplete2(IN PFILE_OBJECT FileObject,
48                    IN PMDL MemoryDescriptorList);
49 
50 VOID
51 NTAPI
52 CcMdlWriteComplete2(IN PFILE_OBJECT FileObject,
53                     IN PLARGE_INTEGER FileOffset,
54                     IN PMDL MdlChain);
55 
56 VOID
57 NTAPI
58 CcInitView(VOID);
59 
60 BOOLEAN
61 NTAPI
62 CcpUnpinData(PNOCC_BCB Bcb,
63              BOOLEAN ActuallyRelease);
64 
65 BOOLEAN
66 NTAPI
67 CcInitializeCacheManager(VOID);
68 
69 VOID
70 NTAPI
71 CcShutdownSystem(VOID);
72 
73 VOID
74 NTAPI
75 CcInitCacheZeroPage(VOID);
76 
77 /* Called by section.c */
78 BOOLEAN
79 NTAPI
80 CcFlushImageSection(PSECTION_OBJECT_POINTERS SectionObjectPointer,
81                     MMFLUSH_TYPE FlushType);
82 
83 VOID
84 NTAPI
85 _CcpFlushCache(IN PNOCC_CACHE_MAP Map,
86                IN OPTIONAL PLARGE_INTEGER FileOffset,
87                IN ULONG Length,
88                OUT OPTIONAL PIO_STATUS_BLOCK IoStatus,
89                BOOLEAN Delete,
90                const char *File,
91                int Line);
92 
93 #define CcpFlushCache(M,F,L,I,D) _CcpFlushCache(M,F,L,I,D,__FILE__,__LINE__)
94 
95 BOOLEAN
96 NTAPI
97 CcGetFileSizes(PFILE_OBJECT FileObject,
98                PCC_FILE_SIZES FileSizes);
99 
100 ULONG
101 NTAPI
102 CcpCountCacheSections(PNOCC_CACHE_MAP Map);
103 
104 BOOLEAN
105 NTAPI
106 CcpAcquireFileLock(PNOCC_CACHE_MAP Map);
107 
108 VOID
109 NTAPI
110 CcpReleaseFileLock(PNOCC_CACHE_MAP Map);
111 
112 /*
113  * Macro for generic cache manage bugchecking. Note that this macro assumes
114  * that the file name including extension is always longer than 4 characters.
115  */
116 #define KEBUGCHECKCC \
117     KEBUGCHECKEX(CACHE_MANAGER, \
118     (*(ULONG*)(__FILE__ + sizeof(__FILE__) - 4) << 16) | \
119     (__LINE__ & 0xFFFF), 0, 0, 0)
120 
121 /* Private data */
122 
123 #define CACHE_SINGLE_FILE_MAX (16)
124 #define CACHE_OVERALL_SIZE    (32 * 1024 * 1024)
125 #define CACHE_STRIPE          VACB_MAPPING_GRANULARITY
126 #define CACHE_SHIFT           18
127 #define CACHE_NUM_SECTIONS    (CACHE_OVERALL_SIZE / CACHE_STRIPE)
128 #define CACHE_ROUND_UP(x)     (((x) + (CACHE_STRIPE-1)) & ~(CACHE_STRIPE-1))
129 #define CACHE_ROUND_DOWN(x)   ((x) & ~(CACHE_STRIPE-1))
130 #define INVALID_CACHE         ((ULONG)~0)
131 
132 extern NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS];
133 extern PRTL_BITMAP CcCacheBitmap;
134 extern FAST_MUTEX CcMutex;
135 extern KEVENT CcDeleteEvent;
136 extern ULONG CcCacheClockHand;
137 extern LIST_ENTRY CcPendingUnmap;
138 extern KEVENT CcpLazyWriteEvent;
139 
140 #define CcpLock() _CcpLock(__FILE__,__LINE__)
141 #define CcpUnlock() _CcpUnlock(__FILE__,__LINE__)
142 
143 extern VOID _CcpLock(const char *file, int line);
144 extern VOID _CcpUnlock(const char *file, int line);
145 
146 extern VOID CcpReferenceCache(ULONG Sector);
147 extern VOID CcpDereferenceCache(ULONG Sector, BOOLEAN Immediate);
148 
149 BOOLEAN
150 NTAPI
151 CcpMapData(IN PFILE_OBJECT FileObject,
152            IN PLARGE_INTEGER FileOffset,
153            IN ULONG Length,
154            IN ULONG Flags,
155            OUT PVOID *BcbResult,
156            OUT PVOID *Buffer);
157 
158 BOOLEAN
159 NTAPI
160 CcpPinMappedData(IN PNOCC_CACHE_MAP Map,
161                  IN PLARGE_INTEGER FileOffset,
162                  IN ULONG Length,
163                  IN ULONG Flags,
164                  IN OUT PVOID *Bcb);
165