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