ReactOS  0.4.14-dev-98-gb0d4763
wcache_lib.h
Go to the documentation of this file.
1 // 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 
10 extern "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,
27  IN uint32 Flags);
28 
30  IN PVOID Buffer, // Target buffer
32  IN lba_t Lba,
34  IN uint32 Flags);
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 
73 typedef struct _WCACHE_ERROR_CONTEXT {
78  union {
79  struct {
83  } ReadWrite;
84  struct {
89  } Internal;
90  };
92 
94  IN PWCACHE_ERROR_CONTEXT ErrorInfo);
95 // array of pointers to cached data
96 // each entry corresponds to logical block on disk
97 typedef struct _W_CACHE_ENTRY {
98  union {
101  };
103 
104 // array of pointers to cache frames
105 // each frame corresponds to extent of logical blocks
106 typedef 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 
133 struct _W_CACHE_ASYNC;
134 
135 typedef 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 
187 } W_CACHE, *PW_CACHE;
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
229  IN PVOID Context,
230  IN PCHAR Buffer,
231  IN lba_t Lba,
232  IN ULONG BCount,
233  OUT PSIZE_T WrittenBytes,
234  IN BOOLEAN CachedOnly);
235 // read cached
237  IN PVOID Context,
238  IN PCHAR Buffer,
239  IN lba_t Lba,
240  IN ULONG BCount,
242  IN BOOLEAN CachedOnly);
243 // flush blocks
245  IN PVOID Context,
246  IN lba_t Lba,
247  IN ULONG BCount);
248 // discard blocks
250  IN PVOID Context,
251  IN lba_t Lba,
252  IN ULONG BCount);
253 // flush whole cache
255  IN PVOID Context);
256 // purge whole cache
258  IN PVOID Context);
259 // free structures
261 
262 // check if initialized
264 
265 // direct access to cached data
267  IN PVOID Context,
268  IN lba_t Lba,
269  IN BOOLEAN Modified,
270  OUT PCHAR* CachedBlock,
271  IN BOOLEAN CachedOnly);
272 // release resources after direct access
274  IN PVOID Context);
275 // release resources before direct access
277  IN PVOID Context,
278  IN BOOLEAN Exclusive);
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 //
293  IN PVOID Context);
294 
296  IN PVOID Context,
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)
308  IN OSSTATUS Status);
309 
310 #endif // __CDRW_WCACHE_LIB_H__
struct _W_CACHE * PW_CACHE
signed char * PCHAR
Definition: retypes.h:7
UCHAR Padding[2]
Definition: wcache_lib.h:166
PCHAR tmp_buff
Definition: wcache_lib.h:183
#define IN
Definition: typedefs.h:38
struct _W_CACHE_FRAME * PW_CACHE_FRAME
struct _WCACHE_ERROR_CONTEXT * PWCACHE_ERROR_CONTEXT
OSSTATUS WCacheEODirect__(IN PW_CACHE Cache, IN PVOID Context)
VOID WCacheFlushAll__(IN PW_CACHE Cache, IN PVOID Context)
OSSTATUS WCacheCompleteAsync__(IN PVOID WContext, IN OSSTATUS Status)
_In_ ULONG Mode
Definition: hubbusif.h:303
Definition: fatfs.h:173
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 * PW_CACHE_ENTRY
struct _WCACHE_ERROR_CONTEXT WCACHE_ERROR_CONTEXT
PW_CACHE_ENTRY Frame
Definition: wcache_lib.h:107
unsigned int uint32
Definition: types.h:32
ULONG MaxFrames
Definition: wcache_lib.h:149
ULONG PacketSize
Definition: wcache_lib.h:150
ULONG FramesToKeepFree
Definition: wcache_lib.h:170
ULONG BlocksPerFrameSh
Definition: wcache_lib.h:144
VOID WCachePurgeAll__(IN PW_CACHE Cache, IN PVOID Context)
PWRITE_BLOCK WriteProc
Definition: wcache_lib.h:172
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
ULONG BlockSizeSh
Definition: wcache_lib.h:153
ULONG FrameCount
Definition: wcache_lib.h:148
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ERESOURCE WCacheLock
Definition: wcache_lib.h:180
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
#define OSSTATUS
Definition: env_spec_w32.h:57
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)
ULONG AccessCount
Definition: wcache_lib.h:111
PCHAR Sector
Definition: wcache_lib.h:99
ULONG(* PCHECK_BLOCK)(IN PVOID Context, IN lba_t Lba)
Definition: wcache_lib.h:58
BOOLEAN NoWriteThrough
Definition: wcache_lib.h:165
unsigned char BOOLEAN
ULONG WCacheGetWriteBlockCount__(IN PW_CACHE Cache)
ULONG MaxBytesToRead
Definition: wcache_lib.h:147
BOOLEAN DoNotCompare
Definition: wcache_lib.h:161
Definition: bufpool.h:45
ULONG BlockCount
Definition: wcache_lib.h:145
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
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
OSSTATUS WCacheDirect__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN BOOLEAN Modified, OUT PCHAR *CachedBlock, IN BOOLEAN CachedOnly)
BOOLEAN RememberBB
Definition: wcache_lib.h:163
PW_CACHE_FRAME FrameList
Definition: wcache_lib.h:138
OSSTATUS WCacheSetMode__(IN PW_CACHE Cache, IN ULONG Mode)
PREAD_BLOCK_ASYNC ReadProcAsync
Definition: wcache_lib.h:175
PCHECK_BLOCK CheckUsedProc
Definition: wcache_lib.h:176
PWC_ERROR_HANDLER ErrorHandlerProc
Definition: wcache_lib.h:178
VOID WCacheRelease__(IN PW_CACHE Cache)
PREAD_BLOCK ReadProc
Definition: wcache_lib.h:173
lba_t FirstLba
Definition: wcache_lib.h:155
OSSTATUS WCacheFlushBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
ULONG PacketSizeSh
Definition: wcache_lib.h:151
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: wcache_lib.h:97
ULONG UpdateCount
Definition: wcache_lib.h:110
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG WBalance
Definition: wcache_lib.h:169
ULONG RBalance
Definition: wcache_lib.h:168
ULONG BlockSize
Definition: wcache_lib.h:152
PWRITE_BLOCK_ASYNC WriteProcAsync
Definition: wcache_lib.h:174
lba_t * CachedBlocksList
Definition: wcache_lib.h:139
PUPDATE_RELOC UpdateRelocProc
Definition: wcache_lib.h:177
ULONG BlockCount
Definition: wcache_lib.h:108
lba_t * CachedFramesList
Definition: wcache_lib.h:140
struct _W_CACHE_FRAME W_CACHE_FRAME
OSSTATUS WCacheStartDirect__(IN PW_CACHE Cache, IN PVOID Context, IN BOOLEAN Exclusive)
BOOLEAN Chained
Definition: wcache_lib.h:162
BOOLEAN WCacheIsCached__(IN PW_CACHE Cache, IN lba_t Lba, IN ULONG BCount)
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
ULONG Flags
Definition: wcache_lib.h:159
VOID WCacheSyncReloc__(IN PW_CACHE Cache, IN PVOID Context)
ULONG WCacheChFlags__(IN PW_CACHE Cache, IN ULONG SetFlags, IN ULONG ClrFlags)
struct _WCACHE_ERROR_CONTEXT::@954::@956 ReadWrite
lba_t LastLba
Definition: wcache_lib.h:156
ULONG BlocksPerFrame
Definition: wcache_lib.h:143
unsigned int * PULONG
Definition: retypes.h:1
BOOLEAN NoWriteBB
Definition: wcache_lib.h:164
BOOLEAN WCacheIsInitialized__(IN PW_CACHE Cache)
ULONG Tag
Definition: wcache_lib.h:137
struct _W_CACHE W_CACHE
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
#define OUT
Definition: typedefs.h:39
struct tagContext Context
Definition: acpixf.h:1024
BOOLEAN CacheWholePacket
Definition: wcache_lib.h:160
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
ULONG MaxBlocks
Definition: wcache_lib.h:146
OSSTATUS(* PWC_ERROR_HANDLER)(IN PVOID Context, IN PWCACHE_ERROR_CONTEXT ErrorInfo)
Definition: wcache_lib.h:93
uint32 lba_t
Definition: platform.h:20
ULONG Mode
Definition: wcache_lib.h:157
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
VOID WCacheDiscardBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
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)
UCHAR Flags
Definition: wcache_lib.h:100
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
ULONG WCacheGetMode__(IN PW_CACHE Cache)
struct _WCACHE_ERROR_CONTEXT::@954::@957 Internal
ULONG WriteCount
Definition: wcache_lib.h:154
lba_t * CachedModifiedBlocksList
Definition: wcache_lib.h:141
PCHAR tmp_buff_r
Definition: wcache_lib.h:184
struct _W_CACHE_ENTRY W_CACHE_ENTRY
PULONG reloc_tab
Definition: wcache_lib.h:185
OSSTATUS(* PUPDATE_RELOC)(IN PVOID Context, IN lba_t Lba, IN PULONG RelocTab, IN ULONG BCount)
Definition: wcache_lib.h:61