ReactOS 0.4.16-dev-319-g6cf4263
wcache_lib.h
Go to the documentation of this file.
1
2// Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3// All rights reserved
4// This file was released under the GPLv2 on June 2015.
6
7#ifndef __CDRW_WCACHE_LIB_H__
8#define __CDRW_WCACHE_LIB_H__
9
10extern "C" {
11
12#include "platform.h"
13
14#ifdef _CONSOLE
15#include "env_spec_w32.h"
16#else
17//#include "env_spec.h"
18#endif
19
20#define WCACHE_BOUND_CHECKS
21
23 IN PVOID Buffer, // Target buffer
25 IN lba_t Lba,
26 OUT PSIZE_T WrittenBytes,
28
30 IN PVOID Buffer, // Target buffer
32 IN lba_t Lba,
35
37 IN PVOID WContext,
38 IN PVOID Buffer, // Target buffer
40 IN lba_t Lba,
41 OUT PSIZE_T WrittenBytes,
42 IN BOOLEAN FreeBuffer);
43
45 IN PVOID WContext,
46 IN PVOID Buffer, // Source buffer
48 IN lba_t Lba,
50
51/*typedef BOOLEAN (*PCHECK_BLOCK) (IN PVOID Context,
52 IN lba_t Lba);*/
53
54#define WCACHE_BLOCK_USED 0x01
55#define WCACHE_BLOCK_ZERO 0x02
56#define WCACHE_BLOCK_BAD 0x04
57
59 IN lba_t Lba);
60
62 IN lba_t Lba,
63 IN PULONG RelocTab,
64 IN ULONG BCount);
65
66#define WCACHE_ERROR_READ 0x0001
67#define WCACHE_ERROR_WRITE 0x0002
68#define WCACHE_ERROR_INTERNAL 0x0003
69
70#define WCACHE_W_OP FALSE
71#define WCACHE_R_OP TRUE
72
73typedef struct _WCACHE_ERROR_CONTEXT {
78 union {
79 struct {
84 struct {
90 };
92
94 IN PWCACHE_ERROR_CONTEXT ErrorInfo);
95// array of pointers to cached data
96// each entry corresponds to logical block on disk
97typedef struct _W_CACHE_ENTRY {
98 union {
101 };
103
104// array of pointers to cache frames
105// each frame corresponds to extent of logical blocks
106typedef struct _W_CACHE_FRAME {
109 //ULONG WriteCount; // number of modified packets in cache frame, is always 0, shall be removed
110 ULONG UpdateCount; // number of updates in cache frame
111 ULONG AccessCount; // number of accesses to cache frame
113
114// memory type for cached blocks
115#define CACHED_BLOCK_MEMORY_TYPE PagedPool
116#define MAX_TRIES_FOR_NA 3
117
118#define WCACHE_ADDR_MASK 0xfffffff8
119#define WCACHE_FLAG_MASK 0x00000007
120#define WCACHE_FLAG_MODIFIED 0x00000001
121#define WCACHE_FLAG_ZERO 0x00000002
122#define WCACHE_FLAG_BAD 0x00000004
123
124#define WCACHE_MODE_ROM 0x00000000 // read only (CD-ROM)
125#define WCACHE_MODE_RW 0x00000001 // rewritable (CD-RW)
126#define WCACHE_MODE_R 0x00000002 // WORM (CD-R)
127#define WCACHE_MODE_RAM 0x00000003 // random writable device (HDD)
128#define WCACHE_MODE_EWR 0x00000004 // ERASE-cycle required (MO)
129#define WCACHE_MODE_MAX WCACHE_MODE_RAM
130
131#define PH_TMP_BUFFER 1
132
133struct _W_CACHE_ASYNC;
134
135typedef struct _W_CACHE {
136 // cache tables
138 PW_CACHE_FRAME FrameList; // pointer to list of Frames
139 lba_t* CachedBlocksList; // sorted list of cached blocks
140 lba_t* CachedFramesList; // sorted list of cached frames
141 lba_t* CachedModifiedBlocksList; // sorted list of cached modified blocks
142 // settings & current state
150 ULONG PacketSize; // number of blocks in packet
154 ULONG WriteCount; // number of modified packets in cache
157 ULONG Mode; // RO/WOR/RW/EWR
158
167
171 // callbacks
179 // sync resource
181// BOOLEAN WCResInit;
182 // preallocated tmp buffers
186
188
189#define WCACHE_INVALID_LBA ((lba_t)(-1))
190
191#define WCACHE_CACHE_WHOLE_PACKET 0x01
192#define WCACHE_DO_NOT_COMPARE 0x02
193#define WCACHE_CHAINED_IO 0x04
194#define WCACHE_MARK_BAD_BLOCKS 0x08
195#define WCACHE_RO_BAD_BLOCKS 0x10
196#define WCACHE_NO_WRITE_THROUGH 0x20
197
198#define WCACHE_VALID_FLAGS (WCACHE_CACHE_WHOLE_PACKET | \
199 WCACHE_DO_NOT_COMPARE | \
200 WCACHE_CHAINED_IO | \
201 WCACHE_MARK_BAD_BLOCKS | \
202 WCACHE_RO_BAD_BLOCKS | \
203 WCACHE_NO_WRITE_THROUGH)
204
205#define WCACHE_INVALID_FLAGS (0xffffffff)
206
207// init cache
209 IN ULONG MaxFrames,
210 IN ULONG MaxBlocks,
211 IN SIZE_T MaxBytesToRead,
212 IN ULONG PacketSizeSh, // number of blocks in packet (bit shift)
213 IN ULONG BlockSizeSh, // bit shift
214 IN ULONG BlocksPerFrameSh,// bit shift
215 IN lba_t FirstLba,
216 IN lba_t LastLba,
217 IN ULONG Mode,
218 IN ULONG Flags,
219 IN ULONG FramesToKeepFree,
220 IN PWRITE_BLOCK WriteProc,
221 IN PREAD_BLOCK ReadProc,
222 IN PWRITE_BLOCK_ASYNC WriteProcAsync,
223 IN PREAD_BLOCK_ASYNC ReadProcAsync,
224 IN PCHECK_BLOCK CheckUsedProc,
225 IN PUPDATE_RELOC UpdateRelocProc,
226 IN PWC_ERROR_HANDLER ErrorHandlerProc);
227// write cached
231 IN lba_t Lba,
232 IN ULONG BCount,
233 OUT PSIZE_T WrittenBytes,
234 IN BOOLEAN CachedOnly);
235// read cached
239 IN lba_t Lba,
240 IN ULONG BCount,
242 IN BOOLEAN CachedOnly);
243// flush blocks
246 IN lba_t Lba,
247 IN ULONG BCount);
248// discard blocks
251 IN lba_t Lba,
252 IN ULONG BCount);
253// flush whole cache
256// purge whole cache
259// free structures
261
262// check if initialized
264
265// direct access to cached data
268 IN lba_t Lba,
269 IN BOOLEAN Modified,
270 OUT PCHAR* CachedBlock,
271 IN BOOLEAN CachedOnly);
272// release resources after direct access
275// release resources before direct access
279// check if requested extent completly cached
281 IN lba_t Lba,
282 IN ULONG BCount);
283
284// change cache media mode
286 IN ULONG Mode);
287//
289//
291//
294
297 IN lba_t ReqLba,
298 IN ULONG BCount);
299
301 IN ULONG SetFlags,
302 IN ULONG ClrFlags);
303
304};
305
306// complete async request (callback)
309
310#endif // __CDRW_WCACHE_LIB_H__
unsigned char BOOLEAN
unsigned int uint32
Definition: types.h:32
Definition: bufpool.h:45
uint32 lba_t
Definition: platform.h:20
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define OSSTATUS
Definition: env_spec_w32.h:57
ULONG ERESOURCE
Definition: env_spec_w32.h:594
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
Status
Definition: gdiplustypes.h:25
_In_ ULONG Mode
Definition: hubbusif.h:303
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
This file contains the definitions and functions of the Mbed TLS platform abstraction layer.
Definition: fatfs.h:173
struct _WCACHE_ERROR_CONTEXT::@965::@968 Internal
struct _WCACHE_ERROR_CONTEXT::@965::@967 ReadWrite
Definition: wcache_lib.h:97
PCHAR Sector
Definition: wcache_lib.h:99
UCHAR Flags
Definition: wcache_lib.h:100
ULONG AccessCount
Definition: wcache_lib.h:111
PW_CACHE_ENTRY Frame
Definition: wcache_lib.h:107
ULONG BlockCount
Definition: wcache_lib.h:108
ULONG UpdateCount
Definition: wcache_lib.h:110
ULONG Tag
Definition: wcache_lib.h:137
ULONG MaxFrames
Definition: wcache_lib.h:149
PULONG reloc_tab
Definition: wcache_lib.h:185
BOOLEAN CacheWholePacket
Definition: wcache_lib.h:160
PCHECK_BLOCK CheckUsedProc
Definition: wcache_lib.h:176
lba_t * CachedModifiedBlocksList
Definition: wcache_lib.h:141
PREAD_BLOCK_ASYNC ReadProcAsync
Definition: wcache_lib.h:175
ULONG BlocksPerFrame
Definition: wcache_lib.h:143
BOOLEAN DoNotCompare
Definition: wcache_lib.h:161
ULONG BlocksPerFrameSh
Definition: wcache_lib.h:144
BOOLEAN NoWriteBB
Definition: wcache_lib.h:164
ULONG BlockSizeSh
Definition: wcache_lib.h:153
lba_t FirstLba
Definition: wcache_lib.h:155
ULONG Mode
Definition: wcache_lib.h:157
ULONG BlockSize
Definition: wcache_lib.h:152
ULONG MaxBytesToRead
Definition: wcache_lib.h:147
ULONG FramesToKeepFree
Definition: wcache_lib.h:170
PUPDATE_RELOC UpdateRelocProc
Definition: wcache_lib.h:177
ULONG PacketSizeSh
Definition: wcache_lib.h:151
PW_CACHE_FRAME FrameList
Definition: wcache_lib.h:138
ULONG PacketSize
Definition: wcache_lib.h:150
ULONG MaxBlocks
Definition: wcache_lib.h:146
BOOLEAN NoWriteThrough
Definition: wcache_lib.h:165
ULONG BlockCount
Definition: wcache_lib.h:145
ULONG RBalance
Definition: wcache_lib.h:168
ULONG WriteCount
Definition: wcache_lib.h:154
PCHAR tmp_buff
Definition: wcache_lib.h:183
BOOLEAN RememberBB
Definition: wcache_lib.h:163
ERESOURCE WCacheLock
Definition: wcache_lib.h:180
PWC_ERROR_HANDLER ErrorHandlerProc
Definition: wcache_lib.h:178
PWRITE_BLOCK WriteProc
Definition: wcache_lib.h:172
UCHAR Padding[2]
Definition: wcache_lib.h:166
lba_t * CachedBlocksList
Definition: wcache_lib.h:139
ULONG FrameCount
Definition: wcache_lib.h:148
PREAD_BLOCK ReadProc
Definition: wcache_lib.h:173
PCHAR tmp_buff_r
Definition: wcache_lib.h:184
lba_t * CachedFramesList
Definition: wcache_lib.h:140
ULONG Flags
Definition: wcache_lib.h:159
lba_t LastLba
Definition: wcache_lib.h:156
PWRITE_BLOCK_ASYNC WriteProcAsync
Definition: wcache_lib.h:174
ULONG WBalance
Definition: wcache_lib.h:169
BOOLEAN Chained
Definition: wcache_lib.h:162
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
uint32_t * PULONG
Definition: typedefs.h:59
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#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
OSSTATUS WCacheWriteBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN PCHAR Buffer, IN lba_t Lba, IN ULONG BCount, OUT PSIZE_T WrittenBytes, IN BOOLEAN CachedOnly)
struct _W_CACHE_FRAME W_CACHE_FRAME
VOID WCacheFlushAll__(IN PW_CACHE Cache, IN PVOID Context)
OSSTATUS WCacheStartDirect__(IN PW_CACHE Cache, IN PVOID Context, IN BOOLEAN Exclusive)
BOOLEAN WCacheIsInitialized__(IN PW_CACHE Cache)
ULONG WCacheGetWriteBlockCount__(IN PW_CACHE Cache)
VOID WCacheDiscardBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
OSSTATUS WCacheFlushBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
OSSTATUS(* PWRITE_BLOCK)(IN PVOID Context, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN uint32 Flags)
Definition: wcache_lib.h:22
struct _W_CACHE_ENTRY W_CACHE_ENTRY
VOID WCacheRelease__(IN PW_CACHE Cache)
OSSTATUS WCacheInit__(IN PW_CACHE Cache, IN ULONG MaxFrames, IN ULONG MaxBlocks, IN SIZE_T MaxBytesToRead, IN ULONG PacketSizeSh, IN ULONG BlockSizeSh, IN ULONG BlocksPerFrameSh, IN lba_t FirstLba, IN lba_t LastLba, IN ULONG Mode, IN ULONG Flags, IN ULONG FramesToKeepFree, IN PWRITE_BLOCK WriteProc, IN PREAD_BLOCK ReadProc, IN PWRITE_BLOCK_ASYNC WriteProcAsync, IN PREAD_BLOCK_ASYNC ReadProcAsync, IN PCHECK_BLOCK CheckUsedProc, IN PUPDATE_RELOC UpdateRelocProc, IN PWC_ERROR_HANDLER ErrorHandlerProc)
Definition: wcache_lib.cpp:116
struct _W_CACHE W_CACHE
VOID WCacheSyncReloc__(IN PW_CACHE Cache, IN PVOID Context)
ULONG(* PCHECK_BLOCK)(IN PVOID Context, IN lba_t Lba)
Definition: wcache_lib.h:58
OSSTATUS(* PREAD_BLOCK)(IN PVOID Context, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T ReadBytes, IN uint32 Flags)
Definition: wcache_lib.h:29
OSSTATUS(* PWC_ERROR_HANDLER)(IN PVOID Context, IN PWCACHE_ERROR_CONTEXT ErrorInfo)
Definition: wcache_lib.h:93
OSSTATUS(* PWRITE_BLOCK_ASYNC)(IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN BOOLEAN FreeBuffer)
Definition: wcache_lib.h:36
struct _WCACHE_ERROR_CONTEXT WCACHE_ERROR_CONTEXT
OSSTATUS WCacheReadBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN PCHAR Buffer, IN lba_t Lba, IN ULONG BCount, OUT PSIZE_T ReadBytes, IN BOOLEAN CachedOnly)
OSSTATUS(* PUPDATE_RELOC)(IN PVOID Context, IN lba_t Lba, IN PULONG RelocTab, IN ULONG BCount)
Definition: wcache_lib.h:61
OSSTATUS WCacheCompleteAsync__(IN PVOID WContext, IN OSSTATUS Status)
struct _W_CACHE_ENTRY * PW_CACHE_ENTRY
VOID WCachePurgeAll__(IN PW_CACHE Cache, IN PVOID Context)
OSSTATUS(* PREAD_BLOCK_ASYNC)(IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T ReadBytes)
Definition: wcache_lib.h:44
OSSTATUS WCacheDirect__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN BOOLEAN Modified, OUT PCHAR *CachedBlock, IN BOOLEAN CachedOnly)
OSSTATUS WCacheEODirect__(IN PW_CACHE Cache, IN PVOID Context)
ULONG WCacheGetMode__(IN PW_CACHE Cache)
struct _WCACHE_ERROR_CONTEXT * PWCACHE_ERROR_CONTEXT
BOOLEAN WCacheIsCached__(IN PW_CACHE Cache, IN lba_t Lba, IN ULONG BCount)
OSSTATUS WCacheSetMode__(IN PW_CACHE Cache, IN ULONG Mode)
ULONG WCacheChFlags__(IN PW_CACHE Cache, IN ULONG SetFlags, IN ULONG ClrFlags)
struct _W_CACHE * PW_CACHE
struct _W_CACHE_FRAME * PW_CACHE_FRAME
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned char UCHAR
Definition: xmlstorage.h:181