ReactOS  0.4.15-dev-4857-g47842d7
wcache_lib.cpp File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _W_CACHE_ASYNC
 

Macros

#define ASYNC_STATE_NONE   0
 
#define ASYNC_STATE_READ_PRE   1
 
#define ASYNC_STATE_READ   2
 
#define ASYNC_STATE_WRITE_PRE   3
 
#define ASYNC_STATE_WRITE   4
 
#define ASYNC_STATE_DONE   5
 
#define ASYNC_CMD_NONE   0
 
#define ASYNC_CMD_READ   1
 
#define ASYNC_CMD_UPDATE   2
 
#define WCACHE_MAX_CHAIN   (0x10)
 
#define MEM_WCCTX_TAG   'xtCW'
 
#define MEM_WCFRM_TAG   'rfCW'
 
#define MEM_WCBUF_TAG   'fbCW'
 
#define USE_WC_PRINT
 
#define WcPrint   UDFPrint
 
#define WCLOCK_RES   1
 
#define WCacheSetModFlag(block_array, i)   *((PULONG)&(block_array[i].Sector)) |= WCACHE_FLAG_MODIFIED
 
#define WCacheClrModFlag(block_array, i)   *((PULONG)&(block_array[i].Sector)) &= ~WCACHE_FLAG_MODIFIED
 
#define WCacheGetModFlag(block_array, i)   (*((PULONG)&(block_array[i].Sector)) & WCACHE_FLAG_MODIFIED)
 
#define WCacheSectorAddr(block_array, i)   ((ULONG_PTR)(block_array[i].Sector) & WCACHE_ADDR_MASK)
 
#define WCacheFreeSector(frame, offs)
 

Typedefs

typedef struct _W_CACHE_ASYNC W_CACHE_ASYNC
 
typedef struct _W_CACHE_ASYNCPW_CACHE_ASYNC
 

Functions

OSSTATUS __fastcall WCacheCheckLimits (IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
 
OSSTATUS __fastcall WCacheCheckLimitsRAM (IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
 
OSSTATUS __fastcall WCacheCheckLimitsRW (IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
 
OSSTATUS __fastcall WCacheCheckLimitsR (IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
 
VOID __fastcall WCachePurgeAllRW (IN PW_CACHE Cache, IN PVOID Context)
 
VOID __fastcall WCacheFlushAllRW (IN PW_CACHE Cache, IN PVOID Context)
 
VOID __fastcall WCachePurgeAllR (IN PW_CACHE Cache, IN PVOID Context)
 
OSSTATUS __fastcall WCacheDecodeFlags (IN PW_CACHE Cache, IN ULONG Flags)
 
VOID WCacheUpdatePacketComplete (IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN BOOLEAN FreePacket=TRUE)
 
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)
 
LONGLONG WCacheRandom (VOID)
 
lba_t __fastcall WCacheFindLbaToRelease (IN PW_CACHE Cache)
 
lba_t __fastcall WCacheFindModifiedLbaToRelease (IN PW_CACHE Cache)
 
lba_t __fastcall WCacheFindFrameToRelease (IN PW_CACHE Cache)
 
ULONG WCacheGetSortedListIndex (IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
 
VOID __fastcall WCacheInsertRangeToList (IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
 
VOID __fastcall WCacheInsertItemToList (IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
 
VOID __fastcall WCacheRemoveRangeFromList (IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
 
VOID __fastcall WCacheRemoveItemFromList (IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
 
PW_CACHE_ENTRY __fastcall WCacheInitFrame (IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
 
VOID __fastcall WCacheRemoveFrame (IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
 
PW_CACHE_ASYNC WCacheAllocAsyncEntry (IN PW_CACHE Cache, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN ULONG BufferSize)
 
VOID WCacheFreeAsyncEntry (IN PW_CACHE Cache, PW_CACHE_ASYNC WContext)
 
OSSTATUS WCacheRaiseIoError (IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
 
OSSTATUS WCacheUpdatePacket (IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN PW_CACHE_ENTRY block_array, IN lba_t firstLba, IN lba_t Lba, IN ULONG BSh, IN ULONG BS, IN ULONG PS, IN ULONG PSs, IN PSIZE_T ReadBytes, IN BOOLEAN PrefereWrite, IN ULONG State)
 
VOID WCacheFreePacket (IN PW_CACHE Cache, IN ULONG frame, IN PW_CACHE_ENTRY block_array, IN ULONG offs, IN ULONG PSs)
 
OSSTATUS __fastcall WCacheFlushBlocksRAM (IN PW_CACHE Cache, IN PVOID Context, PW_CACHE_ENTRY block_array, lba_t *List, ULONG firstPos, ULONG lastPos, BOOLEAN Purge)
 
OSSTATUS __fastcall WCachePurgeAllRAM (IN PW_CACHE Cache, IN PVOID Context)
 
OSSTATUS __fastcall WCacheFlushAllRAM (IN PW_CACHE Cache, IN PVOID Context)
 
OSSTATUS WCachePreReadPacket__ (IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba)
 
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 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)
 
VOID WCacheFlushAll__ (IN PW_CACHE Cache, IN PVOID Context)
 
VOID WCachePurgeAll__ (IN PW_CACHE Cache, IN PVOID Context)
 
VOID WCacheRelease__ (IN PW_CACHE Cache)
 
BOOLEAN WCacheIsInitialized__ (IN PW_CACHE Cache)
 
OSSTATUS WCacheFlushBlocksRW (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 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)
 
OSSTATUS WCacheStartDirect__ (IN PW_CACHE Cache, IN PVOID Context, IN BOOLEAN Exclusive)
 
BOOLEAN WCacheIsCached__ (IN PW_CACHE Cache, IN lba_t Lba, IN ULONG BCount)
 
OSSTATUS WCacheSetMode__ (IN PW_CACHE Cache, IN ULONG Mode)
 
ULONG WCacheGetMode__ (IN PW_CACHE Cache)
 
ULONG WCacheGetWriteBlockCount__ (IN PW_CACHE Cache)
 
VOID WCacheSyncReloc__ (IN PW_CACHE Cache, IN PVOID Context)
 
VOID WCacheDiscardBlocks__ (IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
 
OSSTATUS WCacheCompleteAsync__ (IN PVOID WContext, IN OSSTATUS Status)
 
ULONG WCacheChFlags__ (IN PW_CACHE Cache, IN ULONG SetFlags, IN ULONG ClrFlags)
 

Variables

ULONG WCache_random
 

Macro Definition Documentation

◆ ASYNC_CMD_NONE

#define ASYNC_CMD_NONE   0

Definition at line 48 of file wcache_lib.cpp.

◆ ASYNC_CMD_READ

#define ASYNC_CMD_READ   1

Definition at line 49 of file wcache_lib.cpp.

◆ ASYNC_CMD_UPDATE

#define ASYNC_CMD_UPDATE   2

Definition at line 50 of file wcache_lib.cpp.

◆ ASYNC_STATE_DONE

#define ASYNC_STATE_DONE   5

Definition at line 46 of file wcache_lib.cpp.

◆ ASYNC_STATE_NONE

#define ASYNC_STATE_NONE   0

Definition at line 41 of file wcache_lib.cpp.

◆ ASYNC_STATE_READ

#define ASYNC_STATE_READ   2

Definition at line 43 of file wcache_lib.cpp.

◆ ASYNC_STATE_READ_PRE

#define ASYNC_STATE_READ_PRE   1

Definition at line 42 of file wcache_lib.cpp.

◆ ASYNC_STATE_WRITE

#define ASYNC_STATE_WRITE   4

Definition at line 45 of file wcache_lib.cpp.

◆ ASYNC_STATE_WRITE_PRE

#define ASYNC_STATE_WRITE_PRE   3

Definition at line 44 of file wcache_lib.cpp.

◆ MEM_WCBUF_TAG

#define MEM_WCBUF_TAG   'fbCW'

Definition at line 56 of file wcache_lib.cpp.

◆ MEM_WCCTX_TAG

#define MEM_WCCTX_TAG   'xtCW'

Definition at line 54 of file wcache_lib.cpp.

◆ MEM_WCFRM_TAG

#define MEM_WCFRM_TAG   'rfCW'

Definition at line 55 of file wcache_lib.cpp.

◆ USE_WC_PRINT

#define USE_WC_PRINT

Definition at line 58 of file wcache_lib.cpp.

◆ WCACHE_MAX_CHAIN

#define WCACHE_MAX_CHAIN   (0x10)

Definition at line 52 of file wcache_lib.cpp.

◆ WCacheClrModFlag

#define WCacheClrModFlag (   block_array,
  i 
)    *((PULONG)&(block_array[i].Sector)) &= ~WCACHE_FLAG_MODIFIED

Definition at line 819 of file wcache_lib.cpp.

◆ WCacheFreeSector

#define WCacheFreeSector (   frame,
  offs 
)
Value:
{ \
DbgFreePool((PVOID)WCacheSectorAddr(block_array, offs)); \
block_array[offs].Sector = NULL; \
Cache->FrameList[frame].BlockCount--; \
}
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
#define NULL
Definition: types.h:112

Definition at line 873 of file wcache_lib.cpp.

◆ WCacheGetModFlag

#define WCacheGetModFlag (   block_array,
  i 
)    (*((PULONG)&(block_array[i].Sector)) & WCACHE_FLAG_MODIFIED)

Definition at line 828 of file wcache_lib.cpp.

◆ WCacheSectorAddr

#define WCacheSectorAddr (   block_array,
  i 
)    ((ULONG_PTR)(block_array[i].Sector) & WCACHE_ADDR_MASK)

Definition at line 864 of file wcache_lib.cpp.

◆ WCacheSetModFlag

#define WCacheSetModFlag (   block_array,
  i 
)    *((PULONG)&(block_array[i].Sector)) |= WCACHE_FLAG_MODIFIED

Definition at line 811 of file wcache_lib.cpp.

◆ WCLOCK_RES

#define WCLOCK_RES   1

◆ WcPrint

#define WcPrint   UDFPrint

Definition at line 61 of file wcache_lib.cpp.

Typedef Documentation

◆ PW_CACHE_ASYNC

◆ W_CACHE_ASYNC

Function Documentation

◆ WCacheAllocAsyncEntry()

PW_CACHE_ASYNC WCacheAllocAsyncEntry ( IN PW_CACHE  Cache,
IN OUT PW_CACHE_ASYNC FirstWContext,
IN OUT PW_CACHE_ASYNC PrevWContext,
IN ULONG  BufferSize 
)

Definition at line 890 of file wcache_lib.cpp.

898 {
899  PW_CACHE_ASYNC WContext;
900  PCHAR Buffer;
901 
903  if(!WContext)
904  return NULL;
906  if(!Buffer) {
907  MyFreePool__(WContext);
908  return NULL;
909  }
910 
911  if(!Cache->Chained)
913  WContext->Cache = Cache;
914  if(*PrevWContext)
915  (*PrevWContext)->NextWContext = WContext;
916 // WContext->NextWContext = (*PrevWContext);
917  WContext->NextWContext = NULL;
918  WContext->Buffer = Buffer;
919  WContext->Buffer2 = Buffer+(Cache->Chained ? 0 : BufferSize);
920 
921  if(!(*FirstWContext))
922  (*FirstWContext) = WContext;
923  (*PrevWContext) = WContext;
924 
925  return WContext;
926 } // end WCacheAllocAsyncEntry()
signed char * PCHAR
Definition: retypes.h:7
PW_CACHE Cache
Definition: wcache_lib.cpp:70
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
Definition: fatfs.h:173
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define FALSE
Definition: types.h:117
#define MEM_WCCTX_TAG
Definition: wcache_lib.cpp:54
Definition: bufpool.h:45
#define PCHAR
Definition: match.c:90
#define MEM_WCBUF_TAG
Definition: wcache_lib.cpp:56
struct _W_CACHE_ASYNC * PW_CACHE_ASYNC
#define MyFreePool__(addr)
Definition: mem_tools.h:152
UDF_PH_CALL_CONTEXT PhContext
Definition: wcache_lib.cpp:67
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
struct _W_CACHE_ASYNC * NextWContext
Definition: wcache_lib.cpp:76
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251

Referenced by WCacheUpdatePacket().

◆ WCacheCheckLimits()

OSSTATUS __fastcall WCacheCheckLimits ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  ReqLba,
IN ULONG  BCount 
)

Definition at line 1300 of file wcache_lib.cpp.

1306 {
1307 /* if(!Cache->FrameCount || !Cache->BlockCount) {
1308  ASSERT(!Cache->FrameCount);
1309  ASSERT(!Cache->BlockCount);
1310  if(!Cache->FrameCount)
1311  return STATUS_SUCCESS;
1312  }*/
1313 
1314  // check if we have reached Frame or Block limit
1315  if(!Cache->FrameCount && !Cache->BlockCount) {
1316  return STATUS_SUCCESS;
1317  }
1318 
1319  // check for empty frames
1320  if(Cache->FrameCount > (Cache->MaxFrames*3)/4) {
1321  ULONG frame;
1322  ULONG i;
1323  for(i=Cache->FrameCount; i>0; i--) {
1324  frame = Cache->CachedFramesList[i-1];
1325  // check if frame is empty
1326  if(!(Cache->FrameList[frame].BlockCount)) {
1327  WCacheRemoveFrame(Cache, Context, frame);
1328  } else {
1329  ASSERT(Cache->FrameList[frame].Frame);
1330  }
1331  }
1332  }
1333 
1334  if(!Cache->BlockCount) {
1335  return STATUS_SUCCESS;
1336  }
1337 
1338  // invoke media-specific limit-checker
1339  switch(Cache->Mode) {
1340  case WCACHE_MODE_RAM:
1341  return WCacheCheckLimitsRAM(Cache, Context, ReqLba, BCount);
1342  case WCACHE_MODE_ROM:
1343  case WCACHE_MODE_RW:
1344  return WCacheCheckLimitsRW(Cache, Context, ReqLba, BCount);
1345  case WCACHE_MODE_R:
1346  return WCacheCheckLimitsR(Cache, Context, ReqLba, BCount);
1347  }
1349 } // end WCacheCheckLimits()
OSSTATUS __fastcall WCacheCheckLimitsRW(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
Definition: fatfs.h:173
OSSTATUS __fastcall WCacheCheckLimitsRAM(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
OSSTATUS __fastcall WCacheCheckLimitsR(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
#define WCACHE_MODE_RAM
Definition: wcache_lib.h:127
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
#define WCACHE_MODE_ROM
Definition: wcache_lib.h:124
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define WCACHE_MODE_RW
Definition: wcache_lib.h:125

Referenced by WCacheDirect__(), WCacheInitFrame(), WCacheReadBlocks__(), and WCacheWriteBlocks__().

◆ WCacheCheckLimitsR()

OSSTATUS __fastcall WCacheCheckLimitsR ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  ReqLba,
IN ULONG  BCount 
)

Definition at line 3189 of file wcache_lib.cpp.

3195 {
3196  ULONG frame;
3197  lba_t firstLba;
3198  lba_t* List = Cache->CachedBlocksList;
3199  lba_t Lba;
3200  PCHAR tmp_buff = Cache->tmp_buff;
3201  ULONG firstPos;
3202  ULONG BSh = Cache->BlockSizeSh;
3203  ULONG BS = Cache->BlockSize;
3204  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3205  ULONG PSs = Cache->PacketSize;
3206  ULONG i;
3207  PW_CACHE_ENTRY block_array;
3208  BOOLEAN mod;
3209  OSSTATUS status;
3210  SIZE_T ReadBytes;
3211  ULONG MaxReloc = Cache->PacketSize;
3212  PULONG reloc_tab = Cache->reloc_tab;
3213 
3214  // check if we try to read too much data
3215  if(BCount > Cache->MaxBlocks) {
3216  return STATUS_INVALID_PARAMETER;
3217  }
3218 
3219  // remove(flush) packets from entire frame(s)
3220  while( ((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
3221  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) ||
3222  (Cache->FrameCount >= Cache->MaxFrames) ) {
3223 
3224 WCCL_retry_1:
3225 
3227  if(Lba == WCACHE_INVALID_LBA) {
3228  ASSERT(!Cache->FrameCount);
3229  ASSERT(!Cache->BlockCount);
3230  break;
3231  }
3232  frame = Lba >> Cache->BlocksPerFrameSh;
3233  firstLba = frame << Cache->BlocksPerFrameSh;
3234  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
3235  block_array = Cache->FrameList[frame].Frame;
3236  if(!block_array) {
3238  }
3239  // check if modified
3240  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3241  // read/modify/write
3242  if(mod && (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3243  if(Cache->WriteCount < MaxReloc) goto WCCL_retry_1;
3244  firstPos = WCacheGetSortedListIndex(Cache->WriteCount, Cache->CachedModifiedBlocksList, Lba);
3245  if(!block_array) {
3247  }
3248  // prepare packet & reloc table
3249  for(i=0; i<MaxReloc; i++) {
3250  Lba = Cache->CachedModifiedBlocksList[firstPos];
3251  frame = Lba >> Cache->BlocksPerFrameSh;
3252  firstLba = frame << Cache->BlocksPerFrameSh;
3253  block_array = Cache->FrameList[frame].Frame;
3254  DbgCopyMemory(tmp_buff + (i << BSh),
3255  (PVOID)WCacheSectorAddr(block_array, Lba-firstLba),
3256  BS);
3257  reloc_tab[i] = Lba;
3258  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3259  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3260  // mark as non-cached & free pool
3261  WCacheFreeSector(frame, Lba-firstLba);
3262  // check if frame is empty
3263  if(!Cache->FrameList[frame].BlockCount) {
3264  WCacheRemoveFrame(Cache, Context, frame);
3265  }
3266  if(firstPos >= Cache->WriteCount) firstPos=0;
3267  }
3268  // write packet
3269 // status = Cache->WriteProcAsync(Context, tmp_buff, PS, Lba, &ReadBytes, FALSE);
3270  Cache->UpdateRelocProc(Context, NULL, reloc_tab, MaxReloc);
3271  status = Cache->WriteProc(Context, tmp_buff, PS, NULL, &ReadBytes, 0);
3272  if(!OS_SUCCESS(status)) {
3274  }
3275  } else {
3276 
3277  if((i = Cache->BlockCount - Cache->WriteCount) > MaxReloc) i = MaxReloc;
3278  // discard blocks
3279  for(; i; i--) {
3280  Lba = List[firstPos];
3281  frame = Lba >> Cache->BlocksPerFrameSh;
3282  firstLba = frame << Cache->BlocksPerFrameSh;
3283  block_array = Cache->FrameList[frame].Frame;
3284 
3285  if( (mod = WCacheGetModFlag(block_array, Lba - firstLba)) &&
3286  (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED) )
3287  continue;
3288  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3289  if(mod)
3290  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3291  // mark as non-cached & free pool
3292  WCacheFreeSector(frame, Lba-firstLba);
3293  // check if frame is empty
3294  if(!Cache->FrameList[frame].BlockCount) {
3295  WCacheRemoveFrame(Cache, Context, frame);
3296  }
3297  if(firstPos >= Cache->WriteCount) firstPos=0;
3298  }
3299  }
3300  }
3301  return STATUS_SUCCESS;
3302 } // end WCacheCheckLimitsR()
signed char * PCHAR
Definition: retypes.h:7
Definition: fatfs.h:173
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
OSSTATUS WCacheRaiseIoError(IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
Definition: wcache_lib.cpp:946
lba_t __fastcall WCacheFindLbaToRelease(IN PW_CACHE Cache)
Definition: wcache_lib.cpp:352
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
unsigned char BOOLEAN
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
VOID __fastcall WCacheRemoveItemFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:704
#define WCACHE_W_OP
Definition: wcache_lib.h:70
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgCopyMemory
Definition: env_spec_w32.h:331
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
#define WCACHE_INVALID_LBA
Definition: wcache_lib.h:189
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
static int mod
Definition: i386-dis.c:1281
Definition: ps.c:97

Referenced by WCacheCheckLimits().

◆ WCacheCheckLimitsRAM()

OSSTATUS __fastcall WCacheCheckLimitsRAM ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  ReqLba,
IN ULONG  BCount 
)

Definition at line 1631 of file wcache_lib.cpp.

1637 {
1638  ULONG frame;
1639  lba_t firstLba;
1640  lba_t* List = Cache->CachedBlocksList;
1641  lba_t lastLba;
1642  lba_t Lba;
1643 // PCHAR tmp_buff = Cache->tmp_buff;
1644  ULONG firstPos;
1645  ULONG lastPos;
1646 // ULONG BSh = Cache->BlockSizeSh;
1647 // ULONG BS = Cache->BlockSize;
1648 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
1649  ULONG PSs = Cache->PacketSize;
1650 // ULONG try_count = 0;
1651  PW_CACHE_ENTRY block_array;
1652 // OSSTATUS status;
1653  ULONG FreeFrameCount = 0;
1654 // PVOID addr;
1655 
1656  if(Cache->FrameCount >= Cache->MaxFrames) {
1657  FreeFrameCount = Cache->FramesToKeepFree;
1658  } else
1659  if((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
1660  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) {
1661  // we need free space to grow WCache without flushing data
1662  // for some period of time
1663  FreeFrameCount = Cache->FramesToKeepFree;
1664  goto Try_Another_Frame;
1665  }
1666  // remove(flush) some frames
1667  while((Cache->FrameCount >= Cache->MaxFrames) || FreeFrameCount) {
1668  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
1669 Try_Another_Frame:
1670  if(!Cache->FrameCount || !Cache->BlockCount) {
1671  ASSERT(!Cache->FrameCount);
1672  ASSERT(!Cache->BlockCount);
1673  if(!Cache->FrameCount)
1674  break;
1675  }
1676 
1678 #if 0
1679  if(Cache->FrameList[frame].WriteCount) {
1680  try_count++;
1681  if(try_count < MAX_TRIES_FOR_NA) goto Try_Another_Frame;
1682  } else {
1683  try_count = 0;
1684  }
1685 #else
1686 /*
1687  if(Cache->FrameList[frame].UpdateCount) {
1688  try_count = MAX_TRIES_FOR_NA;
1689  } else {
1690  try_count = 0;
1691  }
1692 */
1693 #endif
1694 
1695  if(FreeFrameCount)
1696  FreeFrameCount--;
1697 
1698  firstLba = frame << Cache->BlocksPerFrameSh;
1699  lastLba = firstLba + Cache->BlocksPerFrame;
1700  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1701  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1702  block_array = Cache->FrameList[frame].Frame;
1703 
1704  if(!block_array) {
1705  UDFPrint(("Hmm...\n"));
1706  BrutePoint();
1708  }
1709  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, TRUE);
1710 
1711  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), firstLba, Cache->BlocksPerFrame);
1712  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1713  WCacheRemoveFrame(Cache, Context, frame);
1714  }
1715 
1716  // check if we try to read too much data
1717  if(BCount > Cache->MaxBlocks) {
1718  return STATUS_INVALID_PARAMETER;
1719  }
1720 
1721  // remove(flush) packet
1722  while((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
1723  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) {
1724 // try_count = 0;
1725 //Try_Another_Block:
1726 
1727  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
1728  Lba = WCacheFindLbaToRelease(Cache) & ~(PSs-1);
1729  if(Lba == WCACHE_INVALID_LBA) {
1730  ASSERT(!Cache->FrameCount);
1731  ASSERT(!Cache->BlockCount);
1732  break;
1733  }
1734  frame = Lba >> Cache->BlocksPerFrameSh;
1735  firstLba = frame << Cache->BlocksPerFrameSh;
1736  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
1737  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba+PSs);
1738  block_array = Cache->FrameList[frame].Frame;
1739  if(!block_array) {
1740  ASSERT(FALSE);
1742  }
1743  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, TRUE);
1744  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), Lba, PSs);
1745  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, PSs);
1746  // check if frame is empty
1747  if(!(Cache->FrameList[frame].BlockCount)) {
1748  WCacheRemoveFrame(Cache, Context, frame);
1749  } else {
1750  ASSERT(Cache->FrameList[frame].Frame);
1751  }
1752  }
1753  return STATUS_SUCCESS;
1754 } // end WCacheCheckLimitsRAM()
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
lba_t __fastcall WCacheFindFrameToRelease(IN PW_CACHE Cache)
Definition: wcache_lib.cpp:386
lba_t __fastcall WCacheFindLbaToRelease(IN PW_CACHE Cache)
Definition: wcache_lib.cpp:352
#define FALSE
Definition: types.h:117
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define MAX_TRIES_FOR_NA
Definition: wcache_lib.h:116
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
OSSTATUS __fastcall WCacheFlushBlocksRAM(IN PW_CACHE Cache, IN PVOID Context, PW_CACHE_ENTRY block_array, lba_t *List, ULONG firstPos, ULONG lastPos, BOOLEAN Purge)
unsigned int ULONG
Definition: retypes.h:1
#define WCACHE_INVALID_LBA
Definition: wcache_lib.h:189
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WCacheCheckLimits().

◆ WCacheCheckLimitsRW()

OSSTATUS __fastcall WCacheCheckLimitsRW ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  ReqLba,
IN ULONG  BCount 
)

Definition at line 1361 of file wcache_lib.cpp.

1367 {
1368  ULONG frame;
1369  lba_t firstLba;
1370  lba_t* List = Cache->CachedBlocksList;
1371  lba_t lastLba;
1372  lba_t Lba;
1373 // PCHAR tmp_buff = Cache->tmp_buff;
1374  ULONG firstPos;
1375  ULONG lastPos;
1376  ULONG BSh = Cache->BlockSizeSh;
1377  ULONG BS = Cache->BlockSize;
1378  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
1379  ULONG PSs = Cache->PacketSize;
1380  ULONG try_count = 0;
1381  PW_CACHE_ENTRY block_array;
1382  OSSTATUS status;
1383  SIZE_T ReadBytes;
1384  ULONG FreeFrameCount = 0;
1385 // PVOID addr;
1386  PW_CACHE_ASYNC FirstWContext = NULL;
1387  PW_CACHE_ASYNC PrevWContext = NULL;
1388  ULONG chain_count = 0;
1389 
1390  if(Cache->FrameCount >= Cache->MaxFrames) {
1391  FreeFrameCount = Cache->FramesToKeepFree;
1392  } else
1393  if((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
1394  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) {
1395  // we need free space to grow WCache without flushing data
1396  // for some period of time
1397  FreeFrameCount = Cache->FramesToKeepFree;
1398  goto Try_Another_Frame;
1399  }
1400  // remove(flush) some frames
1401  while((Cache->FrameCount >= Cache->MaxFrames) || FreeFrameCount) {
1402 Try_Another_Frame:
1403  if(!Cache->FrameCount || !Cache->BlockCount) {
1404  //ASSERT(!Cache->FrameCount);
1405  if(Cache->FrameCount) {
1406  UDFPrint(("ASSERT: Cache->FrameCount = %d, when 0 is expected\n", Cache->FrameCount));
1407  }
1408  ASSERT(!Cache->BlockCount);
1409  if(!Cache->FrameCount)
1410  break;
1411  }
1412 
1414 #if 0
1415  if(Cache->FrameList[frame].WriteCount) {
1416  try_count++;
1417  if(try_count < MAX_TRIES_FOR_NA) goto Try_Another_Frame;
1418  } else {
1419  try_count = 0;
1420  }
1421 #else
1422  if(Cache->FrameList[frame].UpdateCount) {
1423  try_count = MAX_TRIES_FOR_NA;
1424  } else {
1425  try_count = 0;
1426  }
1427 #endif
1428 
1429  if(FreeFrameCount)
1430  FreeFrameCount--;
1431 
1432  firstLba = frame << Cache->BlocksPerFrameSh;
1433  lastLba = firstLba + Cache->BlocksPerFrame;
1434  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1435  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1436  block_array = Cache->FrameList[frame].Frame;
1437 
1438  if(!block_array) {
1439  UDFPrint(("Hmm...\n"));
1440  BrutePoint();
1442  }
1443 
1444  while(firstPos < lastPos) {
1445  // flush packet
1446  Lba = List[firstPos] & ~(PSs-1);
1447 
1448  // write packet out or prepare and add to chain (if chained mode enabled)
1449  status = WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
1450  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
1451 
1452  if(status != STATUS_PENDING) {
1453  // free memory
1454  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, PSs);
1455  }
1456 
1457  Lba += PSs;
1458  while((firstPos < lastPos) && (Lba > List[firstPos])) {
1459  firstPos++;
1460  }
1461  chain_count++;
1462  // write chained packets
1463  if(chain_count >= WCACHE_MAX_CHAIN) {
1464  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
1465  chain_count = 0;
1466  }
1467  }
1468  // remove flushed blocks from all lists
1469  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), firstLba, Cache->BlocksPerFrame);
1470  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1471 
1472  WCacheRemoveFrame(Cache, Context, frame);
1473  }
1474 
1475  // check if we try to read too much data
1476  if(BCount > Cache->MaxBlocks) {
1477  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext);
1478  return STATUS_INVALID_PARAMETER;
1479  }
1480 
1481  // remove(flush) packet
1482  while((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
1483  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) {
1484  try_count = 0;
1485 Try_Another_Block:
1486 
1487  Lba = WCacheFindLbaToRelease(Cache) & ~(PSs-1);
1488  if(Lba == WCACHE_INVALID_LBA) {
1489  ASSERT(!Cache->FrameCount);
1490  ASSERT(!Cache->BlockCount);
1491  break;
1492  }
1493  frame = Lba >> Cache->BlocksPerFrameSh;
1494  firstLba = frame << Cache->BlocksPerFrameSh;
1495  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
1496  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba+PSs);
1497  block_array = Cache->FrameList[frame].Frame;
1498  if(!block_array) {
1499  // write already prepared blocks to disk and return error
1500  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext);
1501  ASSERT(FALSE);
1503  }
1504 
1505  // write packet out or prepare and add to chain (if chained mode enabled)
1506  status = WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
1507  Lba, BSh, BS, PS, PSs, &ReadBytes, (try_count >= MAX_TRIES_FOR_NA), ASYNC_STATE_NONE);
1508 
1509  if(status == STATUS_RETRY) {
1510  try_count++;
1511  goto Try_Another_Block;
1512  }
1513 
1514  // free memory
1515  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, PSs);
1516 
1517  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), Lba, PSs);
1518  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, PSs);
1519  // check if frame is empty
1520  if(!(Cache->FrameList[frame].BlockCount)) {
1521  WCacheRemoveFrame(Cache, Context, frame);
1522  } else {
1523  ASSERT(Cache->FrameList[frame].Frame);
1524  }
1525  chain_count++;
1526  if(chain_count >= WCACHE_MAX_CHAIN) {
1527  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
1528  chain_count = 0;
1529  }
1530  }
1531  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext);
1532  return STATUS_SUCCESS;
1533 } // end WCacheCheckLimitsRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
lba_t __fastcall WCacheFindFrameToRelease(IN PW_CACHE Cache)
Definition: wcache_lib.cpp:386
lba_t __fastcall WCacheFindLbaToRelease(IN PW_CACHE Cache)
Definition: wcache_lib.cpp:352
OSSTATUS WCacheUpdatePacket(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN PW_CACHE_ENTRY block_array, IN lba_t firstLba, IN lba_t Lba, IN ULONG BSh, IN ULONG BS, IN ULONG PS, IN ULONG PSs, IN PSIZE_T ReadBytes, IN BOOLEAN PrefereWrite, IN ULONG State)
Definition: wcache_lib.cpp:986
#define FALSE
Definition: types.h:117
VOID WCacheFreePacket(IN PW_CACHE Cache, IN ULONG frame, IN PW_CACHE_ENTRY block_array, IN ULONG offs, IN ULONG PSs)
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
VOID WCacheUpdatePacketComplete(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN BOOLEAN FreePacket=TRUE)
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define MAX_TRIES_FOR_NA
Definition: wcache_lib.h:116
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define NULL
Definition: types.h:112
#define STATUS_RETRY
Definition: udferr_usr.h:182
unsigned int ULONG
Definition: retypes.h:1
#define WCACHE_INVALID_LBA
Definition: wcache_lib.h:189
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by WCacheCheckLimits().

◆ WCacheChFlags__()

ULONG WCacheChFlags__ ( IN PW_CACHE  Cache,
IN ULONG  SetFlags,
IN ULONG  ClrFlags 
)

Definition at line 3635 of file wcache_lib.cpp.

3640 {
3641  ULONG Flags;
3642 
3643  if(SetFlags || ClrFlags) {
3644  Flags = (Cache->Flags & ~ClrFlags) | SetFlags;
3645 
3647  return -1;
3648  }
3649  } else {
3650  return Cache->Flags;
3651  }
3652  return Flags;
3653 } // end WCacheSetMode__()
Definition: fatfs.h:173
OSSTATUS __fastcall WCacheDecodeFlags(IN PW_CACHE Cache, IN ULONG Flags)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
unsigned int ULONG
Definition: retypes.h:1

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ WCacheCompleteAsync__()

OSSTATUS WCacheCompleteAsync__ ( IN PVOID  WContext,
IN OSSTATUS  Status 
)

Definition at line 3586 of file wcache_lib.cpp.

3590 {
3591  PW_CACHE_ASYNC AsyncCtx = (PW_CACHE_ASYNC)WContext;
3592 // PW_CACHE Cache = AsyncCtx->Cache;
3593 
3594  AsyncCtx->PhContext.IosbToUse.Status = Status;
3595  KeSetEvent(&(AsyncCtx->PhContext.event), 0, FALSE);
3596 
3597  return STATUS_SUCCESS;
3598 } // end WCacheSetMode__()
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
struct _W_CACHE_ASYNC * PW_CACHE_ASYNC
IO_STATUS_BLOCK IosbToUse
Definition: Sys_spec_lib.h:24
UDF_PH_CALL_CONTEXT PhContext
Definition: wcache_lib.cpp:67
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WCacheUpdatePacket().

◆ WCacheDecodeFlags()

OSSTATUS __fastcall WCacheDecodeFlags ( IN PW_CACHE  Cache,
IN ULONG  Flags 
)

Definition at line 3606 of file wcache_lib.cpp.

3610 {
3611  //ULONG OldFlags;
3612  if(Flags & ~WCACHE_VALID_FLAGS) {
3613  UDFPrint(("Invalid flags: %x\n", Flags & ~WCACHE_VALID_FLAGS));
3614  return STATUS_INVALID_PARAMETER;
3615  }
3616  Cache->CacheWholePacket = (Flags & WCACHE_CACHE_WHOLE_PACKET) ? TRUE : FALSE;
3617  Cache->DoNotCompare = (Flags & WCACHE_DO_NOT_COMPARE) ? TRUE : FALSE;
3618  Cache->Chained = (Flags & WCACHE_CHAINED_IO) ? TRUE : FALSE;
3619  Cache->RememberBB = (Flags & WCACHE_MARK_BAD_BLOCKS) ? TRUE : FALSE;
3620  if(Cache->RememberBB) {
3621  Cache->NoWriteBB = (Flags & WCACHE_RO_BAD_BLOCKS) ? TRUE : FALSE;
3622  }
3623  Cache->NoWriteThrough = (Flags & WCACHE_NO_WRITE_THROUGH) ? TRUE : FALSE;
3624 
3625  Cache->Flags = Flags;
3626 
3627  return STATUS_SUCCESS;
3628 }
#define UDFPrint(Args)
Definition: udffs.h:225
#define WCACHE_CHAINED_IO
Definition: wcache_lib.h:193
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WCACHE_RO_BAD_BLOCKS
Definition: wcache_lib.h:195
#define WCACHE_MARK_BAD_BLOCKS
Definition: wcache_lib.h:194
#define WCACHE_CACHE_WHOLE_PACKET
Definition: wcache_lib.h:191
#define FALSE
Definition: types.h:117
#define WCACHE_VALID_FLAGS
Definition: wcache_lib.h:198
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define WCACHE_DO_NOT_COMPARE
Definition: wcache_lib.h:192
#define STATUS_SUCCESS
Definition: shellext.h:65
#define WCACHE_NO_WRITE_THROUGH
Definition: wcache_lib.h:196

Referenced by WCacheChFlags__(), and WCacheInit__().

◆ WCacheDirect__()

OSSTATUS WCacheDirect__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  Lba,
IN BOOLEAN  Modified,
OUT PCHAR CachedBlock,
IN BOOLEAN  CachedOnly 
)

Definition at line 2949 of file wcache_lib.cpp.

2957 {
2958  ULONG frame;
2959  ULONG i;
2961  PW_CACHE_ENTRY block_array;
2962  ULONG BS = Cache->BlockSize;
2963  PCHAR addr;
2964  SIZE_T _ReadBytes;
2965  ULONG block_type;
2966 
2967  WcPrint(("WC:%sD %x (1)\n", Modified ? "W" : "R", Lba));
2968 
2969  // lock cache if nececcary
2970  if(!CachedOnly) {
2971  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2972  }
2973  // check if we try to access beyond cached area
2974  if((Lba < Cache->FirstLba) ||
2975  (Lba > Cache->LastLba)) {
2976  UDFPrint(("LBA %#x is beyond cacheable area\n", Lba));
2977  BrutePoint();
2979  goto EO_WCache_D;
2980  }
2981 
2982  frame = Lba >> Cache->BlocksPerFrameSh;
2983  i = Lba - (frame << Cache->BlocksPerFrameSh);
2984  // check if we have enough space to store requested block
2985  if(!CachedOnly &&
2987  BrutePoint();
2988  goto EO_WCache_D;
2989  }
2990 
2991  // small updates are more important
2992  block_array = Cache->FrameList[frame].Frame;
2993  if(Modified) {
2994  Cache->FrameList[frame].UpdateCount+=8;
2995  } else {
2996  Cache->FrameList[frame].AccessCount+=8;
2997  }
2998  if(!block_array) {
2999  ASSERT(Cache->FrameCount < Cache->MaxFrames);
3000  block_array = WCacheInitFrame(Cache, Context, frame);
3001  if(!block_array) {
3003  goto EO_WCache_D;
3004  }
3005  }
3006  // check if requested block is already cached
3007  if( !(addr = (PCHAR)WCacheSectorAddr(block_array, i)) ) {
3008  // block is not cached
3009  // allocate memory and read block from media
3010  // do not set block_array[i].Sector here, because if media access fails and recursive access to cache
3011  // comes, this block should not be marked as 'cached'
3013  if(!addr) {
3015  goto EO_WCache_D;
3016  }
3017  block_type = Cache->CheckUsedProc(Context, Lba);
3018  if(block_type == WCACHE_BLOCK_USED) {
3019  status = Cache->ReadProc(Context, addr, BS, Lba, &_ReadBytes, PH_TMP_BUFFER);
3020  if(Cache->RememberBB) {
3021  if(!OS_SUCCESS(status)) {
3022  RtlZeroMemory(addr, BS);
3023  //WCacheSetBadFlag(block_array,i);
3024  }
3025  }
3026  } else {
3027  if(block_type & WCACHE_BLOCK_BAD) {
3028  DbgFreePool(addr);
3029  addr = NULL;
3031  goto EO_WCache_D;
3032  }
3033  if(!(block_type & WCACHE_BLOCK_ZERO)) {
3034  BrutePoint();
3035  }
3037  RtlZeroMemory(addr, BS);
3038  }
3039  // now add pointer to buffer to common storage
3040  block_array[i].Sector = addr;
3041  WCacheInsertItemToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba);
3042  if(Modified) {
3043  WCacheInsertItemToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3044  WCacheSetModFlag(block_array, i);
3045  }
3046  Cache->FrameList[frame].BlockCount ++;
3047  } else {
3048  // block is not cached
3049  // just return pointer
3050  block_type = Cache->CheckUsedProc(Context, Lba);
3051  if(block_type & WCACHE_BLOCK_BAD) {
3052  //if(WCacheGetBadFlag(block_array,i)) {
3053  // bad packet. no pre-read
3055  goto EO_WCache_D;
3056  }
3057 #ifndef UDF_CHECK_UTIL
3058  ASSERT(block_type & WCACHE_BLOCK_USED);
3059 #else
3060  if(!(block_type & WCACHE_BLOCK_USED)) {
3061  UDFPrint(("LBA %#x is not marked as used\n", Lba));
3062  }
3063 #endif
3064  if(Modified &&
3065  !WCacheGetModFlag(block_array, i)) {
3066  WCacheInsertItemToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3067  WCacheSetModFlag(block_array, i);
3068  }
3069  }
3070  (*CachedBlock) = addr;
3071 
3072 EO_WCache_D:
3073 
3074  return status;
3075 } // end WCacheDirect__()
signed char * PCHAR
Definition: retypes.h:7
#define UDFPrint(Args)
Definition: udffs.h:225
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
OSSTATUS __fastcall WCacheCheckLimits(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
#define WCacheSetModFlag(block_array, i)
Definition: wcache_lib.cpp:811
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
PCHAR Sector
Definition: wcache_lib.h:99
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
#define WCACHE_BLOCK_BAD
Definition: wcache_lib.h:56
#define DbgFreePool
Definition: env_spec_w32.h:334
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define MEM_WCBUF_TAG
Definition: wcache_lib.cpp:56
#define WCACHE_BLOCK_ZERO
Definition: wcache_lib.h:55
PW_CACHE_ENTRY __fastcall WCacheInitFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:731
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
VOID __fastcall WCacheInsertItemToList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:637
GLenum const GLvoid * addr
Definition: glext.h:9621
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
#define WcPrint
Definition: wcache_lib.cpp:61
#define CACHED_BLOCK_MEMORY_TYPE
Definition: wcache_lib.h:115
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
Definition: ps.c:97

Referenced by UDFWriteInSector().

◆ WCacheDiscardBlocks__()

VOID WCacheDiscardBlocks__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  ReqLba,
IN ULONG  BCount 
)

Definition at line 3520 of file wcache_lib.cpp.

3526 {
3527  ULONG frame;
3528  lba_t firstLba;
3529  lba_t* List;
3530  lba_t Lba;
3531  PW_CACHE_ENTRY block_array;
3532  BOOLEAN mod;
3533  ULONG i;
3534 
3535  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
3536 
3537  UDFPrint((" Discard req: %x@%x\n",BCount, ReqLba));
3538 
3539  List = Cache->CachedBlocksList;
3540  if(!List) {
3542  return;
3543  }
3544  i = WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba);
3545 
3546  // enumerate requested blocks
3547  while((List[i] < (ReqLba+BCount)) && (i < Cache->BlockCount)) {
3548 
3549  Lba = List[i];
3550  frame = Lba >> Cache->BlocksPerFrameSh;
3551  firstLba = frame << Cache->BlocksPerFrameSh;
3552  block_array = Cache->FrameList[frame].Frame;
3553  if(!block_array) {
3555  BrutePoint();
3556  return;
3557  }
3558  // check if modified
3559  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3560  // just discard
3561 
3562  // mark as non-cached & free pool
3563  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3564  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3565  if(mod)
3566  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3567  // mark as non-cached & free pool
3568  WCacheFreeSector(frame, Lba-firstLba);
3569  // check if frame is empty
3570  if(!Cache->FrameList[frame].BlockCount) {
3571  WCacheRemoveFrame(Cache, Context, frame);
3572  } else {
3573  ASSERT(Cache->FrameList[frame].Frame);
3574  }
3575  } else {
3576  // we should never get here !!!
3577  // getting this part of code means that we have
3578  // placed non-cached block in CachedBlocksList
3579  BrutePoint();
3580  }
3581  }
3583 } // end WCacheDiscardBlocks__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
unsigned char BOOLEAN
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
VOID __fastcall WCacheRemoveItemFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:704
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
uint32 lba_t
Definition: platform.h:20
static int mod
Definition: i386-dis.c:1281

Referenced by UDFMarkSpaceAsXXXNoProtect_().

◆ WCacheEODirect__()

OSSTATUS WCacheEODirect__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3083 of file wcache_lib.cpp.

3087 {
3089  return STATUS_SUCCESS;
3090 } // end WCacheEODirect__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: fatfs.h:173
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by UDFCommonRead(), UDFCommonWrite(), UDFIsExtentCached(), UDFVWorkItem(), and UDFWriteInSector().

◆ WCacheFindFrameToRelease()

lba_t __fastcall WCacheFindFrameToRelease ( IN PW_CACHE  Cache)

Definition at line 386 of file wcache_lib.cpp.

389 {
390  ULONG i, j;
391  ULONG frame = 0;
392  ULONG prev_uc = -1;
393  ULONG uc = -1;
394  lba_t lba;
395  BOOLEAN mod = FALSE;
396 
397  if(!(Cache->FrameCount))
398  return 0;
399  /*
400  return(Cache->CachedFramesList[((ULONG)WCacheRandom() % Cache->FrameCount)]);
401  */
402 
403  for(i=0; i<Cache->FrameCount; i++) {
404 
405  j = Cache->CachedFramesList[i];
406 
407  mod |= (Cache->FrameList[j].UpdateCount != 0);
408  uc = Cache->FrameList[j].UpdateCount*32 + Cache->FrameList[j].AccessCount;
409 
410  if(prev_uc > uc) {
411  prev_uc = uc;
412  frame = j;
413  }
414  }
415  if(!mod) {
416  frame = Cache->CachedFramesList[((ULONG)WCacheRandom() % Cache->FrameCount)];
417  lba = frame << Cache->BlocksPerFrameSh;
418  WcPrint(("WC:-frm %x\n", lba));
419  } else {
420  lba = frame << Cache->BlocksPerFrameSh;
421  WcPrint(("WC:-frm(mod) %x\n", lba));
422  for(i=0; i<Cache->FrameCount; i++) {
423 
424  j = Cache->CachedFramesList[i];
425  Cache->FrameList[j].UpdateCount = (Cache->FrameList[j].UpdateCount*2)/3;
426  Cache->FrameList[j].AccessCount = (Cache->FrameList[j].AccessCount*3)/4;
427  }
428  }
429  return frame;
430 } // end WCacheFindFrameToRelease()
Definition: fatfs.h:173
LONGLONG WCacheRandom(VOID)
Definition: wcache_lib.cpp:339
#define lba
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define WcPrint
Definition: wcache_lib.cpp:61
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
static int mod
Definition: i386-dis.c:1281

Referenced by WCacheCheckLimitsRAM(), and WCacheCheckLimitsRW().

◆ WCacheFindLbaToRelease()

lba_t __fastcall WCacheFindLbaToRelease ( IN PW_CACHE  Cache)

Definition at line 352 of file wcache_lib.cpp.

355 {
356  if(!(Cache->BlockCount))
357  return WCACHE_INVALID_LBA;
358  return(Cache->CachedBlocksList[((ULONG)WCacheRandom() % Cache->BlockCount)]);
359 } // end WCacheFindLbaToRelease()
Definition: fatfs.h:173
LONGLONG WCacheRandom(VOID)
Definition: wcache_lib.cpp:339
unsigned int ULONG
Definition: retypes.h:1
#define WCACHE_INVALID_LBA
Definition: wcache_lib.h:189

Referenced by WCacheCheckLimitsR(), WCacheCheckLimitsRAM(), and WCacheCheckLimitsRW().

◆ WCacheFindModifiedLbaToRelease()

lba_t __fastcall WCacheFindModifiedLbaToRelease ( IN PW_CACHE  Cache)

Definition at line 369 of file wcache_lib.cpp.

372 {
373  if(!(Cache->WriteCount))
374  return WCACHE_INVALID_LBA;
375  return(Cache->CachedModifiedBlocksList[((ULONG)WCacheRandom() % Cache->WriteCount)]);
376 } // end WCacheFindModifiedLbaToRelease()
Definition: fatfs.h:173
LONGLONG WCacheRandom(VOID)
Definition: wcache_lib.cpp:339
unsigned int ULONG
Definition: retypes.h:1
#define WCACHE_INVALID_LBA
Definition: wcache_lib.h:189

◆ WCacheFlushAll__()

VOID WCacheFlushAll__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2560 of file wcache_lib.cpp.

2563 {
2564  if(!(Cache->ReadProc)) return;
2565  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2566 
2567  switch(Cache->Mode) {
2568  case WCACHE_MODE_RAM:
2570  break;
2571  case WCACHE_MODE_ROM:
2572  case WCACHE_MODE_RW:
2574  break;
2575  case WCACHE_MODE_R:
2577  break;
2578  }
2579 
2581  return;
2582 } // end WCacheFlushAll__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
VOID __fastcall WCachePurgeAllR(IN PW_CACHE Cache, IN PVOID Context)
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
OSSTATUS __fastcall WCacheFlushAllRAM(IN PW_CACHE Cache, IN PVOID Context)
VOID __fastcall WCacheFlushAllRW(IN PW_CACHE Cache, IN PVOID Context)
#define WCACHE_MODE_RAM
Definition: wcache_lib.h:127
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
#define WCACHE_MODE_ROM
Definition: wcache_lib.h:124
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define WCACHE_MODE_RW
Definition: wcache_lib.h:125

Referenced by UDFEjectReqWaiter(), UDFFlushLogicalVolume(), UDFLoadPartDesc(), UDFRecordVAT(), UDFReleaseVCB(), UDFUmount__(), and UDFVerifyVolume().

◆ WCacheFlushAllRAM()

OSSTATUS __fastcall WCacheFlushAllRAM ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 1810 of file wcache_lib.cpp.

1814 {
1815  ULONG frame;
1816  lba_t firstLba;
1817  lba_t* List = Cache->CachedBlocksList;
1818  lba_t lastLba;
1819  ULONG firstPos;
1820  ULONG lastPos;
1821  PW_CACHE_ENTRY block_array;
1822 // OSSTATUS status;
1823 
1824  // flush frames
1825  while(Cache->WriteCount) {
1826 
1827  frame = Cache->CachedModifiedBlocksList[0] >> Cache->BlocksPerFrameSh;
1828 
1829  firstLba = frame << Cache->BlocksPerFrameSh;
1830  lastLba = firstLba + Cache->BlocksPerFrame;
1831  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1832  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1833  block_array = Cache->FrameList[frame].Frame;
1834 
1835  if(!block_array) {
1836  UDFPrint(("Hmm...\n"));
1837  BrutePoint();
1839  }
1840  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, FALSE);
1841 
1842  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1843  }
1844 
1845  return STATUS_SUCCESS;
1846 } // end WCacheFlushAllRAM()
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define FALSE
Definition: types.h:117
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
OSSTATUS __fastcall WCacheFlushBlocksRAM(IN PW_CACHE Cache, IN PVOID Context, PW_CACHE_ENTRY block_array, lba_t *List, ULONG firstPos, ULONG lastPos, BOOLEAN Purge)
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WCacheFlushAll__().

◆ WCacheFlushAllRW()

VOID __fastcall WCacheFlushAllRW ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2689 of file wcache_lib.cpp.

2692 {
2693  ULONG frame;
2694  lba_t firstLba;
2695  lba_t* List = Cache->CachedModifiedBlocksList;
2696  lba_t Lba;
2697 // ULONG firstPos;
2698 // ULONG lastPos;
2699  ULONG BSh = Cache->BlockSizeSh;
2700  ULONG BS = Cache->BlockSize;
2701  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2702  ULONG PSs = Cache->PacketSize;
2703  ULONG BFs = Cache->BlocksPerFrameSh;
2704  PW_CACHE_ENTRY block_array;
2705 // OSSTATUS status;
2706  SIZE_T ReadBytes;
2707  PW_CACHE_ASYNC FirstWContext = NULL;
2708  PW_CACHE_ASYNC PrevWContext = NULL;
2709  ULONG i;
2710  ULONG chain_count = 0;
2711 
2712  if(!(Cache->ReadProc)) return;
2713 
2714  // walk through modified blocks
2715  while(Cache->WriteCount) {
2716  Lba = List[0] & ~(PSs-1);
2717  frame = Lba >> BFs;
2718  firstLba = frame << BFs;
2719 // firstPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba);
2720 // lastPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba+PSs);
2721  block_array = Cache->FrameList[frame].Frame;
2722  if(!block_array) {
2723  BrutePoint();
2724  continue;;
2725  }
2726  // queue modify request
2727  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2728  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2729  // clear MODIFIED flag for queued blocks
2730  WCacheRemoveRangeFromList(List, &(Cache->WriteCount), Lba, PSs);
2731  Lba -= firstLba;
2732  for(i=0; i<PSs; i++) {
2733  WCacheClrModFlag(block_array, Lba+i);
2734  }
2735  chain_count++;
2736  // check queue size
2737  if(chain_count >= WCACHE_MAX_CHAIN) {
2738  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2739  chain_count = 0;
2740  }
2741  }
2742  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2743 #ifdef DBG
2744 #if 1
2745  // check consistency
2746  List = Cache->CachedBlocksList;
2747  for(i=0; i<Cache->BlockCount; i++) {
2748  Lba = List[i] /*& ~(PSs-1)*/;
2749  frame = Lba >> Cache->BlocksPerFrameSh;
2750  firstLba = frame << Cache->BlocksPerFrameSh;
2751  block_array = Cache->FrameList[frame].Frame;
2752  if(!block_array) {
2753  BrutePoint();
2754  }
2755  ASSERT(!WCacheGetModFlag(block_array, Lba-firstLba));
2756  }
2757 #endif // 1
2758 #endif // DBG
2759  return;
2760 } // end WCacheFlushAllRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
OSSTATUS WCacheUpdatePacket(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN PW_CACHE_ENTRY block_array, IN lba_t firstLba, IN lba_t Lba, IN ULONG BSh, IN ULONG BS, IN ULONG PS, IN ULONG PSs, IN PSIZE_T ReadBytes, IN BOOLEAN PrefereWrite, IN ULONG State)
Definition: wcache_lib.cpp:986
#define FALSE
Definition: types.h:117
struct _ACPI_EFI_BOOT_SERVICES * BS
VOID WCacheUpdatePacketComplete(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN BOOLEAN FreePacket=TRUE)
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define WCacheClrModFlag(block_array, i)
Definition: wcache_lib.cpp:819
#define ASSERT(a)
Definition: mode.c:44
#define BrutePoint()
Definition: env_spec_w32.h:504
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20

Referenced by WCacheFlushAll__().

◆ WCacheFlushBlocks__()

OSSTATUS WCacheFlushBlocks__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  Lba,
IN ULONG  BCount 
)

Definition at line 2899 of file wcache_lib.cpp.

2905 {
2906  OSSTATUS status;
2907 
2908  if(!(Cache->ReadProc)) return STATUS_INVALID_PARAMETER;
2909  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2910 
2911  // check if we try to access beyond cached area
2912  if((Lba < Cache->FirstLba) ||
2913  (Lba+BCount-1 > Cache->LastLba)) {
2914  UDFPrint(("LBA %#x (%x) is beyond cacheable area\n", Lba, BCount));
2915  BrutePoint();
2917  goto EO_WCache_F;
2918  }
2919 
2920  switch(Cache->Mode) {
2921  case WCACHE_MODE_RAM:
2922 // WCacheFlushBlocksRW(Cache, Context);
2923 // break;
2924  case WCACHE_MODE_ROM:
2925  case WCACHE_MODE_RW:
2926  status = WCacheFlushBlocksRW(Cache, Context, Lba, BCount);
2927  break;
2928  case WCACHE_MODE_R:
2930  break;
2931  }
2932 EO_WCache_F:
2934  return status;
2935 } // end WCacheFlushBlocks__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
OSSTATUS WCacheFlushBlocksRW(IN PW_CACHE Cache, IN PVOID Context, IN lba_t _Lba, IN ULONG BCount)
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define OSSTATUS
Definition: env_spec_w32.h:57
#define BrutePoint()
Definition: env_spec_w32.h:504
#define WCACHE_MODE_RAM
Definition: wcache_lib.h:127
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
#define WCACHE_MODE_ROM
Definition: wcache_lib.h:124
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define WCACHE_MODE_RW
Definition: wcache_lib.h:125
Definition: ps.c:97

Referenced by UDFCommonDeviceControl(), UDFEjectReqWaiter(), UDFFlushLogicalVolume(), UDFUmount__(), and UDFUpdateLogicalVolInt().

◆ WCacheFlushBlocksRAM()

OSSTATUS __fastcall WCacheFlushBlocksRAM ( IN PW_CACHE  Cache,
IN PVOID  Context,
PW_CACHE_ENTRY  block_array,
lba_t List,
ULONG  firstPos,
ULONG  lastPos,
BOOLEAN  Purge 
)

Definition at line 1537 of file wcache_lib.cpp.

1546 {
1547  ULONG frame;
1548  lba_t Lba;
1549  lba_t PrevLba;
1550  lba_t firstLba;
1551  PCHAR tmp_buff = NULL;
1552  ULONG n;
1553  ULONG BSh = Cache->BlockSizeSh;
1554  ULONG BS = Cache->BlockSize;
1555 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
1556  ULONG PSs = Cache->PacketSize;
1557  SIZE_T _WrittenBytes;
1559 
1560  frame = List[firstPos] >> Cache->BlocksPerFrameSh;
1561  firstLba = frame << Cache->BlocksPerFrameSh;
1562 
1563  while(firstPos < lastPos) {
1564  // flush blocks
1565  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
1566  Lba = List[firstPos];
1567  if(!WCacheGetModFlag(block_array, Lba - firstLba)) {
1568  // free memory
1569  if(Purge) {
1570  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, 1);
1571  }
1572  firstPos++;
1573  continue;
1574  }
1575  tmp_buff = Cache->tmp_buff;
1576  PrevLba = Lba;
1577  n=1;
1578  while((firstPos+n < lastPos) &&
1579  (List[firstPos+n] == PrevLba+1)) {
1580  PrevLba++;
1581  if(!WCacheGetModFlag(block_array, PrevLba - firstLba))
1582  break;
1583  DbgCopyMemory(tmp_buff + (n << BSh),
1584  (PVOID)WCacheSectorAddr(block_array, PrevLba - firstLba),
1585  BS);
1586  n++;
1587  if(n >= PSs)
1588  break;
1589  }
1590  if(n > 1) {
1591  DbgCopyMemory(tmp_buff,
1592  (PVOID)WCacheSectorAddr(block_array, Lba - firstLba),
1593  BS);
1594  } else {
1595  tmp_buff = (PCHAR)WCacheSectorAddr(block_array, Lba - firstLba);
1596  }
1597  // write sectors out
1598  status = Cache->WriteProc(Context, tmp_buff, n<<BSh, Lba, &_WrittenBytes, 0);
1599  if(!OS_SUCCESS(status)) {
1600  status = WCacheRaiseIoError(Cache, Context, status, Lba, n, tmp_buff, WCACHE_W_OP, NULL);
1601  if(!OS_SUCCESS(status)) {
1602  BrutePoint();
1603  }
1604  }
1605  firstPos += n;
1606  if(Purge) {
1607  // free memory
1608  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, n);
1609  } else {
1610  // clear Modified flag
1611  ULONG i;
1612  Lba -= firstLba;
1613  for(i=0; i<n; i++) {
1614  WCacheClrModFlag(block_array, Lba+i);
1615  }
1616  }
1617  }
1618 
1619  return status;
1620 } // end WCacheFlushBlocksRAM()
signed char * PCHAR
Definition: retypes.h:7
Definition: fatfs.h:173
GLdouble n
Definition: glext.h:7729
OSSTATUS WCacheRaiseIoError(IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
Definition: wcache_lib.cpp:946
VOID WCacheFreePacket(IN PW_CACHE Cache, IN ULONG frame, IN PW_CACHE_ENTRY block_array, IN ULONG offs, IN ULONG PSs)
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
#define WCACHE_W_OP
Definition: wcache_lib.h:70
#define PCHAR
Definition: match.c:90
#define WCacheClrModFlag(block_array, i)
Definition: wcache_lib.cpp:819
#define ASSERT(a)
Definition: mode.c:44
#define BrutePoint()
Definition: env_spec_w32.h:504
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgCopyMemory
Definition: env_spec_w32.h:331
#define NULL
Definition: types.h:112
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by WCacheCheckLimitsRAM(), WCacheFlushAllRAM(), WCachePurgeAllRAM(), and WCacheWriteBlocks__().

◆ WCacheFlushBlocksRW()

OSSTATUS WCacheFlushBlocksRW ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  _Lba,
IN ULONG  BCount 
)

Definition at line 2825 of file wcache_lib.cpp.

2831 {
2832  ULONG frame;
2833  lba_t firstLba;
2834  lba_t* List = Cache->CachedModifiedBlocksList;
2835  lba_t Lba;
2836 // ULONG firstPos;
2837 // ULONG lastPos;
2838  ULONG BSh = Cache->BlockSizeSh;
2839  ULONG BS = Cache->BlockSize;
2840  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2841  ULONG PSs = Cache->PacketSize;
2842  ULONG BFs = Cache->BlocksPerFrameSh;
2843  PW_CACHE_ENTRY block_array;
2844 // OSSTATUS status;
2845  SIZE_T ReadBytes;
2846  PW_CACHE_ASYNC FirstWContext = NULL;
2847  PW_CACHE_ASYNC PrevWContext = NULL;
2848  ULONG i;
2849  ULONG chain_count = 0;
2850  lba_t lim;
2851 
2852  if(!(Cache->ReadProc)) return STATUS_INVALID_PARAMETER;
2853 
2854  // walk through modified blocks
2855  lim = (_Lba+BCount+PSs-1) & ~(PSs-1);
2856  for(Lba = _Lba & ~(PSs-1);Lba < lim ; Lba += PSs) {
2857  frame = Lba >> BFs;
2858  firstLba = frame << BFs;
2859 // firstPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba);
2860 // lastPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba+PSs);
2861  block_array = Cache->FrameList[frame].Frame;
2862  if(!block_array) {
2863  // not cached block may be requested for flush
2864  Lba += (1 << BFs) - PSs;
2865  continue;
2866  }
2867  // queue modify request
2868  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2869  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2870  // clear MODIFIED flag for queued blocks
2871  WCacheRemoveRangeFromList(List, &(Cache->WriteCount), Lba, PSs);
2872  Lba -= firstLba;
2873  for(i=0; i<PSs; i++) {
2874  WCacheClrModFlag(block_array, Lba+i);
2875  }
2876  Lba += firstLba;
2877  chain_count++;
2878  // check queue size
2879  if(chain_count >= WCACHE_MAX_CHAIN) {
2880  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2881  chain_count = 0;
2882  }
2883  }
2884  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2885 /*
2886  if(Cache->Mode != WCACHE_MODE_RAM)
2887  return STATUS_SUCCESS;
2888 */
2889 
2890  return STATUS_SUCCESS;
2891 } // end WCacheFlushBlocksRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
OSSTATUS WCacheUpdatePacket(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN PW_CACHE_ENTRY block_array, IN lba_t firstLba, IN lba_t Lba, IN ULONG BSh, IN ULONG BS, IN ULONG PS, IN ULONG PSs, IN PSIZE_T ReadBytes, IN BOOLEAN PrefereWrite, IN ULONG State)
Definition: wcache_lib.cpp:986
#define FALSE
Definition: types.h:117
struct _ACPI_EFI_BOOT_SERVICES * BS
VOID WCacheUpdatePacketComplete(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN BOOLEAN FreePacket=TRUE)
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define WCacheClrModFlag(block_array, i)
Definition: wcache_lib.cpp:819
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WCacheFlushBlocks__().

◆ WCacheFreeAsyncEntry()

VOID WCacheFreeAsyncEntry ( IN PW_CACHE  Cache,
PW_CACHE_ASYNC  WContext 
)

Definition at line 934 of file wcache_lib.cpp.

938 {
939  DbgFreePool(WContext->Buffer);
940  MyFreePool__(WContext);
941 } // end WCacheFreeAsyncEntry()
#define DbgFreePool
Definition: env_spec_w32.h:334
#define MyFreePool__(addr)
Definition: mem_tools.h:152

Referenced by WCacheUpdatePacketComplete().

◆ WCacheFreePacket()

VOID WCacheFreePacket ( IN PW_CACHE  Cache,
IN ULONG  frame,
IN PW_CACHE_ENTRY  block_array,
IN ULONG  offs,
IN ULONG  PSs 
)

Definition at line 1186 of file wcache_lib.cpp.

1194 {
1195  ULONG i;
1196  // mark as non-cached & free pool
1197  for(i=0; i<PSs; i++, offs++) {
1198  if(WCacheSectorAddr(block_array,offs)) {
1199  WCacheFreeSector(frame, offs);
1200  }
1201  }
1202 } // end WCacheFreePacket()
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCacheCheckLimitsRW(), WCacheFlushBlocksRAM(), WCachePurgeAllRW(), and WCacheUpdatePacketComplete().

◆ WCacheGetMode__()

ULONG WCacheGetMode__ ( IN PW_CACHE  Cache)

Definition at line 3441 of file wcache_lib.cpp.

3444 {
3445  return Cache->Mode;
3446 } // end WCacheGetMode__()
Definition: fatfs.h:173

◆ WCacheGetSortedListIndex()

ULONG WCacheGetSortedListIndex ( IN ULONG  BlockCount,
IN lba_t List,
IN lba_t  Lba 
)

Definition at line 449 of file wcache_lib.cpp.

454 {
455  if(!BlockCount)
456  return 0;
457 
458 #if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
459 
460  __asm push ecx
461  __asm push ebx
462  __asm push edx
463  __asm push esi
464  __asm push edi
465 // left = 0;
466 // right = BlockCount - 1;
467 // pos = 0;
468  __asm xor edx,edx // left
469  __asm mov ebx,BlockCount
470  __asm dec ebx // right
471  __asm xor esi,esi // pos
472  __asm mov edi,List // List
473  __asm mov ecx,Lba // Lba
474 
475 While_1:
476 // while(left != right) {
477  __asm cmp edx,ebx
478  __asm jz EO_while_1
479 
480 // pos = (left + right) >> 1;
481  __asm lea esi,[ebx+edx]
482  __asm shr esi,1
483 // if(List[pos] == Lba)
484 // return pos;
485  __asm mov eax,[edi+esi*4]
486  __asm cmp eax,ecx
487  __asm jz EO_while_2
488 
489 // if(right - left == 1) {
490  __asm sub ebx,edx
491  __asm cmp ebx,1
492  __asm jne NO_r_sub_l_eq_1
493 // if(List[pos+1] < Lba) <=> if(List[pos+1] >= Lba)
494 // return (pos+2); <=> break;
495 // break; <=> return (pos+2);
496  __asm cmp [edi+esi*4+4],ecx
497  __asm jae EO_while_1
498  __asm add esi,2
499  __asm jmp EO_while_2
500 // }
501 NO_r_sub_l_eq_1:
502 // if(List[pos] < Lba) {
503  __asm cmp eax,ecx
504  __asm jae Update_r
505 // left = pos;
506  __asm add ebx,edx
507  __asm mov edx,esi
508  __asm jmp While_1
509 // } else {
510 Update_r:
511 // right = pos;
512  __asm mov ebx,esi
513  __asm jmp While_1
514 // }
515 // }
516 EO_while_1:
517 // if((List[pos] < Lba) && ((pos+1) <= BlockCount)) pos++;
518  __asm mov eax,[edi+esi*4]
519  __asm cmp eax,ecx
520  __asm jae EO_while_2
521  __asm inc esi
522  __asm cmp esi,BlockCount
523  __asm jbe EO_while_2
524  __asm dec esi
525 EO_while_2:
526 // return pos;
527  __asm mov eax,esi
528 
529  __asm pop edi
530  __asm pop esi
531  __asm pop edx
532  __asm pop ebx
533  __asm pop ecx
534 
535 #else // NO X86 optimization , use generic C/C++
536 
537  ULONG pos;
538  ULONG left;
539  ULONG right;
540 
541  if(!BlockCount)
542  return 0;
543 
544  left = 0;
545  right = BlockCount - 1;
546  pos = 0;
547  while(left != right) {
548  pos = (left + right) >> 1;
549  if(List[pos] == Lba)
550  return pos;
551  if(right - left == 1) {
552  if(List[pos+1] < Lba)
553  return (pos+2);
554  break;
555  }
556  if(List[pos] < Lba) {
557  left = pos;
558  } else {
559  right = pos;
560  }
561  }
562  if((List[pos] < Lba) && ((pos+1) <= BlockCount)) pos++;
563 
564  return pos;
565 
566 #endif // _X86_
567 
568 }
static void xor(unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count)
Definition: crypt_des.c:251
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esi
Definition: synth_sse3d.h:103
ios_base &_STLP_CALL dec(ios_base &__s)
Definition: _ios_base.h:321
#define cmp(status, error)
Definition: error.c:114
static calc_node_t * pop(void)
Definition: rpn_ieee.c:90
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm0 paddd mm4 mm0 mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm0 mm0 packssdw mm0 movd eax movw edi esi edx edi
Definition: synth_sse3d.h:185
GLint left
Definition: glext.h:7726
GLdouble GLdouble right
Definition: glext.h:10859
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl ebx
Definition: synth_sse3d.h:83
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
unsigned int ULONG
Definition: retypes.h:1
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx
Definition: synth_sse3d.h:85
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113

Referenced by WCacheCheckLimitsR(), WCacheCheckLimitsRAM(), WCacheCheckLimitsRW(), WCacheDiscardBlocks__(), WCacheFlushAllRAM(), WCacheInsertItemToList(), WCacheInsertRangeToList(), WCachePurgeAllRAM(), WCacheRemoveItemFromList(), WCacheRemoveRangeFromList(), and WCacheWriteBlocks__().

◆ WCacheGetWriteBlockCount__()

ULONG WCacheGetWriteBlockCount__ ( IN PW_CACHE  Cache)

Definition at line 3455 of file wcache_lib.cpp.

3458 {
3459  return Cache->WriteCount;
3460 } // end WCacheGetWriteBlockCount__()
Definition: fatfs.h:173

Referenced by UDFRecordVAT(), and UDFUmount__().

◆ WCacheInit__()

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 at line 116 of file wcache_lib.cpp.

171 {
172  ULONG l1, l2, l3;
173  ULONG PacketSize = (1) << PacketSizeSh;
174  ULONG BlockSize = (1) << BlockSizeSh;
175  ULONG BlocksPerFrame = (1) << BlocksPerFrameSh;
177  LARGE_INTEGER rseed;
178  ULONG res_init_flags = 0;
179 
180 #define WCLOCK_RES 1
181 
182  _SEH2_TRY {
183  // check input parameters
184  if(Mode == WCACHE_MODE_R) {
185  UDFPrint(("Disable Async-Write for WORM media\n"));
186  WriteProcAsync = NULL;
187  }
188  if((MaxBlocks % PacketSize) || !MaxBlocks) {
189  UDFPrint(("Total number of sectors must be packet-size-aligned\n"));
191  }
192  if(BlocksPerFrame % PacketSize) {
193  UDFPrint(("Number of sectors per Frame must be packet-size-aligned\n"));
195  }
196  if(!ReadProc) {
197  UDFPrint(("Read routine pointer must be valid\n"));
199  }
200  if(FirstLba >= LastLba) {
201  UDFPrint(("Invalid cached area parameters: (%x - %x)\n",FirstLba, LastLba));
203  }
204  if(!MaxFrames) {
205  UDFPrint(("Total frame number must be non-zero\n",FirstLba, LastLba));
207  }
208  if(Mode > WCACHE_MODE_MAX) {
209  UDFPrint(("Invalid media mode. Should be 0-%x\n",WCACHE_MODE_MAX));
211  }
212  if(FramesToKeepFree >= MaxFrames/2) {
213  UDFPrint(("Invalid FramesToKeepFree (%x). Should be Less or equal to MaxFrames/2 (%x)\n", FramesToKeepFree, MaxFrames/2));
215  }
216  // check 'features'
217  if(!WriteProc) {
218  UDFPrint(("Write routine not specified\n"));
219  UDFPrint(("Read-only mode enabled\n"));
220  }
221  MaxBlocks = max(MaxBlocks, BlocksPerFrame*3);
222  // initialize required structures
223  // we'll align structure size on system page size to
224  // avoid system crashes caused by pool fragmentation
225  if(!(Cache->FrameList =
226  (PW_CACHE_FRAME)MyAllocatePoolTag__(NonPagedPool, l1 = (((LastLba >> BlocksPerFrameSh)+1)*sizeof(W_CACHE_FRAME)), MEM_WCFRM_TAG) )) {
227  UDFPrint(("Cache init err 1\n"));
229  }
230  if(!(Cache->CachedBlocksList =
231  (PULONG)MyAllocatePoolTag__(NonPagedPool, l2 = ((MaxBlocks+2)*sizeof(lba_t)), MEM_WCFRM_TAG) )) {
232  UDFPrint(("Cache init err 2\n"));
234  }
235  if(!(Cache->CachedModifiedBlocksList =
237  UDFPrint(("Cache init err 3\n"));
239  }
240  if(!(Cache->CachedFramesList =
241  (PULONG)MyAllocatePoolTag__(NonPagedPool, l3 = ((MaxFrames+2)*sizeof(lba_t)), MEM_WCFRM_TAG) )) {
242  UDFPrint(("Cache init err 4\n"));
244  }
245  RtlZeroMemory(Cache->FrameList, l1);
246  RtlZeroMemory(Cache->CachedBlocksList, l2);
247  RtlZeroMemory(Cache->CachedModifiedBlocksList, l2);
248  RtlZeroMemory(Cache->CachedFramesList, l3);
249  // remember all useful parameters
250  Cache->BlocksPerFrame = BlocksPerFrame;
251  Cache->BlocksPerFrameSh = BlocksPerFrameSh;
252  Cache->BlockCount = 0;
253  Cache->MaxBlocks = MaxBlocks;
254  Cache->MaxBytesToRead = MaxBytesToRead;
255  Cache->FrameCount = 0;
256  Cache->MaxFrames = MaxFrames;
257  Cache->PacketSize = PacketSize;
258  Cache->PacketSizeSh = PacketSizeSh;
259  Cache->BlockSize = BlockSize;
260  Cache->BlockSizeSh = BlockSizeSh;
261  Cache->WriteCount = 0;
262  Cache->FirstLba = FirstLba;
263  Cache->LastLba = LastLba;
264  Cache->Mode = Mode;
265 
266  if(!OS_SUCCESS(RC = WCacheDecodeFlags(Cache, Flags))) {
267  return RC;
268  }
269 
270  Cache->FramesToKeepFree = FramesToKeepFree;
271  Cache->WriteProc = WriteProc;
272  Cache->ReadProc = ReadProc;
273  Cache->WriteProcAsync = WriteProcAsync;
274  Cache->ReadProcAsync = ReadProcAsync;
275  Cache->CheckUsedProc = CheckUsedProc;
276  Cache->UpdateRelocProc = UpdateRelocProc;
277  Cache->ErrorHandlerProc = ErrorHandlerProc;
278  // init permanent tmp buffers
279  if(!(Cache->tmp_buff =
281  UDFPrint(("Cache init err 5.W\n"));
283  }
284  if(!(Cache->tmp_buff_r =
286  UDFPrint(("Cache init err 5.R\n"));
288  }
289  if(!(Cache->reloc_tab =
290  (PULONG)MyAllocatePoolTag__(NonPagedPool, Cache->PacketSize*sizeof(ULONG), MEM_WCFRM_TAG))) {
291  UDFPrint(("Cache init err 6\n"));
293  }
294  if(!OS_SUCCESS(RC = ExInitializeResourceLite(&(Cache->WCacheLock)))) {
295  UDFPrint(("Cache init err (res)\n"));
296  try_return(RC);
297  }
298  res_init_flags |= WCLOCK_RES;
300  WCache_random = rseed.LowPart;
301 
302 try_exit: NOTHING;
303 
304  } _SEH2_FINALLY {
305 
306  if(!OS_SUCCESS(RC)) {
307  if(res_init_flags & WCLOCK_RES)
308  ExDeleteResourceLite(&(Cache->WCacheLock));
309  if(Cache->FrameList)
310  MyFreePool__(Cache->FrameList);
311  if(Cache->CachedBlocksList)
312  MyFreePool__(Cache->CachedBlocksList);
313  if(Cache->CachedModifiedBlocksList)
314  MyFreePool__(Cache->CachedModifiedBlocksList);
315  if(Cache->CachedFramesList)
316  MyFreePool__(Cache->CachedFramesList);
317  if(Cache->tmp_buff_r)
318  MyFreePool__(Cache->tmp_buff_r);
319  if(Cache->tmp_buff)
320  MyFreePool__(Cache->tmp_buff);
321  if(Cache->reloc_tab)
322  MyFreePool__(Cache->reloc_tab);
323  RtlZeroMemory(Cache, sizeof(W_CACHE));
324  } else {
325  Cache->Tag = 0xCAC11E00;
326  }
327 
328  } _SEH2_END;
329 
330  return RC;
331 } // end WCacheInit__()
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
signed char * PCHAR
Definition: retypes.h:7
#define max(a, b)
Definition: svc.c:63
#define UDFPrint(Args)
Definition: udffs.h:225
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG WCache_random
Definition: wcache_lib.cpp:90
_In_ ULONG Mode
Definition: hubbusif.h:303
Definition: fatfs.h:173
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
OSSTATUS __fastcall WCacheDecodeFlags(IN PW_CACHE Cache, IN ULONG Flags)
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
#define MEM_WCFRM_TAG
Definition: wcache_lib.cpp:55
_SEH2_TRY
Definition: create.c:4226
#define WCLOCK_RES
#define OSSTATUS
Definition: env_spec_w32.h:57
#define WCACHE_MODE_MAX
Definition: wcache_lib.h:129
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define try_return(S)
Definition: cdprocs.h:2179
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
ULONG LowPart
Definition: typedefs.h:106
#define NOTHING
Definition: env_spec_w32.h:461
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
_SEH2_END
Definition: create.c:4400
_In_ USHORT PacketSize
Definition: iofuncs.h:1058
_SEH2_FINALLY
Definition: create.c:4371
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ WCacheInitFrame()

PW_CACHE_ENTRY __fastcall WCacheInitFrame ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN ULONG  frame 
)

Definition at line 731 of file wcache_lib.cpp.

736 {
737  PW_CACHE_ENTRY block_array;
738  ULONG l;
739 #ifdef DBG
740  ULONG old_count = Cache->FrameCount;
741 #endif //DBG
742 
743  // We are about to add new cache frame.
744  // Thus check if we have enough free entries and
745  // flush unused ones if it is neccessary.
746  if(Cache->FrameCount >= Cache->MaxFrames) {
747  BrutePoint();
748  WCacheCheckLimits(Cache, Context, frame << Cache->BlocksPerFrameSh, Cache->PacketSize*2);
749  }
750  ASSERT(Cache->FrameCount < Cache->MaxFrames);
751  block_array = (PW_CACHE_ENTRY)MyAllocatePoolTag__(NonPagedPool, l = sizeof(W_CACHE_ENTRY) << Cache->BlocksPerFrameSh, MEM_WCFRM_TAG);
752  Cache->FrameList[frame].Frame = block_array;
753 
754  // Keep history !!!
755  //Cache->FrameList[frame].UpdateCount = 0;
756  //Cache->FrameList[frame].AccessCount = 0;
757 
758  if(block_array) {
759  ASSERT((ULONG_PTR)block_array > 0x1000);
760  WCacheInsertItemToList(Cache->CachedFramesList, &(Cache->FrameCount), frame);
761  RtlZeroMemory(block_array, l);
762  } else {
763  BrutePoint();
764  }
765  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
766 #ifdef DBG
767  ASSERT(old_count < Cache->FrameCount);
768 #endif //DBG
769  return block_array;
770 } // end WCacheInitFrame()
Definition: fatfs.h:173
struct _W_CACHE_ENTRY * PW_CACHE_ENTRY
#define MEM_WCFRM_TAG
Definition: wcache_lib.cpp:55
OSSTATUS __fastcall WCacheCheckLimits(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
uint32_t ULONG_PTR
Definition: typedefs.h:65
r l[0]
Definition: byte_order.h:167
#define ASSERT(a)
Definition: mode.c:44
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
VOID __fastcall WCacheInsertItemToList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:637
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by WCacheDirect__(), WCachePreReadPacket__(), WCacheReadBlocks__(), and WCacheWriteBlocks__().

◆ WCacheInsertItemToList()

VOID __fastcall WCacheInsertItemToList ( IN lba_t List,
IN PULONG  BlockCount,
IN lba_t  Lba 
)

Definition at line 637 of file wcache_lib.cpp.

642 {
643  ULONG firstPos = WCacheGetSortedListIndex(*BlockCount, List, Lba+1);
644  if(firstPos && (List[firstPos-1] == Lba))
645  return;
646 
647  // move list tail
648  if(*BlockCount) {
649 #ifdef WCACHE_BOUND_CHECKS
650  MyCheckArray(List, firstPos+1+(*BlockCount)-firstPos-1);
651 #endif //WCACHE_BOUND_CHECKS
652 // DbgMoveMemory(&(List[firstPos+1]), &(List[firstPos]), ((*BlockCount) - firstPos)*sizeof(ULONG));
653  DbgMoveMemory(&(List[firstPos+1]), &(List[firstPos]), ((*BlockCount) - firstPos) * sizeof(ULONG));
654  }
655 #ifdef WCACHE_BOUND_CHECKS
656  MyCheckArray(List, firstPos);
657 #endif //WCACHE_BOUND_CHECKS
658  List[firstPos] = Lba;
659  (*BlockCount) ++;
660 } // end WCacheInsertItemToList()
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define MyCheckArray(base, index)
Definition: mem_tools.h:310
#define DbgMoveMemory
Definition: env_spec_w32.h:329
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCacheDirect__(), and WCacheInitFrame().

◆ WCacheInsertRangeToList()

VOID __fastcall WCacheInsertRangeToList ( IN lba_t List,
IN PULONG  BlockCount,
IN lba_t  Lba,
IN ULONG  BCount 
)

Definition at line 588 of file wcache_lib.cpp.

594 {
595  if(!BCount)
596  return;
597 
598  ASSERT(!(BCount & 0x80000000));
599 
600  ULONG firstPos = WCacheGetSortedListIndex(*BlockCount, List, Lba);
601  ULONG lastPos = WCacheGetSortedListIndex(*BlockCount, List, Lba+BCount);
602  ULONG offs = firstPos + BCount - lastPos;
603 
604  if(offs) {
605  // move list tail
606 // ASSERT(lastPos+offs + ((*BlockCount) - lastPos) <= qq);
607  if(*BlockCount) {
608 #ifdef WCACHE_BOUND_CHECKS
609  MyCheckArray(List, lastPos+offs+(*BlockCount)-lastPos-1);
610 #endif //WCACHE_BOUND_CHECKS
611  DbgMoveMemory(&(List[lastPos+offs]), &(List[lastPos]), ((*BlockCount) - lastPos) * sizeof(ULONG));
612  }
613  lastPos += offs;
614  for(; firstPos<lastPos; firstPos++) {
615 #ifdef WCACHE_BOUND_CHECKS
616  MyCheckArray(List, firstPos);
617 #endif //WCACHE_BOUND_CHECKS
618  List[firstPos] = Lba;
619  Lba++;
620  }
621  (*BlockCount) += offs;
622  }
623 } // end WCacheInsertRangeToList()
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define MyCheckArray(base, index)
Definition: mem_tools.h:310
#define ASSERT(a)
Definition: mode.c:44
#define DbgMoveMemory
Definition: env_spec_w32.h:329
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCachePreReadPacket__(), WCacheReadBlocks__(), and WCacheWriteBlocks__().

◆ WCacheIsCached__()

BOOLEAN WCacheIsCached__ ( IN PW_CACHE  Cache,
IN lba_t  Lba,
IN ULONG  BCount 
)

WCacheGetBadFlag(block_array, i)

(Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_BAD)

Definition at line 3127 of file wcache_lib.cpp.

3132 {
3133  ULONG frame;
3134  ULONG i;
3135  PW_CACHE_ENTRY block_array;
3136 
3137  // check if we try to access beyond cached area
3138  if((Lba < Cache->FirstLba) ||
3139  (Lba + BCount - 1 > Cache->LastLba)) {
3140  return FALSE;
3141  }
3142 
3143  frame = Lba >> Cache->BlocksPerFrameSh;
3144  i = Lba - (frame << Cache->BlocksPerFrameSh);
3145 
3146  block_array = Cache->FrameList[frame].Frame;
3147  if(!block_array) {
3148  return FALSE;
3149  }
3150 
3151  while(BCount) {
3152  if(i >= Cache->BlocksPerFrame) {
3153  frame++;
3154  block_array = Cache->FrameList[frame].Frame;
3155  i -= Cache->BlocksPerFrame;
3156  }
3157  if(!block_array) {
3158  return FALSE;
3159  }
3160  // 'read' cached extent (if any)
3161  while(BCount &&
3162  (i < Cache->BlocksPerFrame) &&
3163  WCacheSectorAddr(block_array, i) &&
3166  TRUE ) {
3167  i++;
3168  BCount--;
3169  Lba++;
3170  }
3171  if(BCount &&
3172  (i < Cache->BlocksPerFrame) /*&&
3173  (!WCacheSectorAddr(block_array, i))*/ ) {
3174  return FALSE;
3175  }
3176  }
3177  return TRUE;
3178 } // end WCacheIsCached__()
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
Definition: wcache_lib.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int ULONG
Definition: retypes.h:1

◆ WCacheIsInitialized__()

BOOLEAN WCacheIsInitialized__ ( IN PW_CACHE  Cache)

Definition at line 2817 of file wcache_lib.cpp.

2820 {
2821  return (Cache->ReadProc != NULL);
2822 } // end WCacheIsInitialized__()
Definition: fatfs.h:173
#define NULL
Definition: types.h:112

Referenced by UDFVerifyVolume(), and UDFWriteInSector().

◆ WCachePreReadPacket__()

OSSTATUS WCachePreReadPacket__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN lba_t  Lba 
)

Definition at line 1856 of file wcache_lib.cpp.

1861 {
1862  ULONG frame;
1864  PW_CACHE_ENTRY block_array;
1865  ULONG BSh = Cache->BlockSizeSh;
1866  ULONG BS = Cache->BlockSize;
1867  PCHAR addr;
1868  SIZE_T _ReadBytes;
1869  ULONG PS = Cache->PacketSize; // (in blocks)
1870  ULONG BCount = PS;
1871  ULONG i, n, err_count;
1872  BOOLEAN sector_added = FALSE;
1873  ULONG block_type;
1874  BOOLEAN zero = FALSE;//TRUE;
1875 /*
1876  ULONG first_zero=0, last_zero=0;
1877  BOOLEAN count_first_zero = TRUE;
1878 */
1879 
1880  Lba &= ~(PS-1);
1881  frame = Lba >> Cache->BlocksPerFrameSh;
1882  i = Lba - (frame << Cache->BlocksPerFrameSh);
1883 
1884  // assume successful operation
1885  block_array = Cache->FrameList[frame].Frame;
1886  if(!block_array) {
1887  ASSERT(Cache->FrameCount < Cache->MaxFrames);
1888  block_array = WCacheInitFrame(Cache, Context, frame);
1889  if(!block_array)
1891  }
1892 
1893  // skip cached extent (if any)
1894  n=0;
1895  while((n < BCount) &&
1896  (n < Cache->BlocksPerFrame)) {
1897 
1898  addr = (PCHAR)WCacheSectorAddr(block_array, i+n);
1899  block_type = Cache->CheckUsedProc(Context, Lba+n);
1900  if(/*WCacheGetBadFlag(block_array,i+n)*/
1901  block_type & WCACHE_BLOCK_BAD) {
1902  // bad packet. no pre-read
1903  return STATUS_DEVICE_DATA_ERROR;
1904  }
1905  if(!(block_type & WCACHE_BLOCK_ZERO)) {
1906  zero = FALSE;
1907  //count_first_zero = FALSE;
1908  //last_zero = 0;
1909  if(!addr) {
1910  // sector is not cached, stop search
1911  break;
1912  }
1913  } else {
1914 /*
1915  if(count_first_zero) {
1916  first_zero++;
1917  }
1918  last_zero++;
1919 */
1920  }
1921  n++;
1922  }
1923  // do nothing if all sectors are already cached
1924  if(n < BCount) {
1925 
1926  // read whole packet
1927  if(!zero) {
1928  status = Cache->ReadProc(Context, Cache->tmp_buff_r, PS<<BSh, Lba, &_ReadBytes, PH_TMP_BUFFER);
1929  if(!OS_SUCCESS(status)) {
1930  status = WCacheRaiseIoError(Cache, Context, status, Lba, PS, Cache->tmp_buff_r, WCACHE_R_OP, NULL);
1931  }
1932  } else {
1934  //RtlZeroMemory(Cache->tmp_buff_r, PS<<BSh);
1935  _ReadBytes = PS<<BSh;
1936  }
1937  if(OS_SUCCESS(status)) {
1938  // and now we'll copy them to cache
1939  for(n=0; n<BCount; n++, i++) {
1940  if(WCacheSectorAddr(block_array,i)) {
1941  continue;
1942  }
1944  if(!addr) {
1945  BrutePoint();
1946  break;
1947  }
1948  sector_added = TRUE;
1949  if(!zero) {
1950  DbgCopyMemory(addr, Cache->tmp_buff_r+(n<<BSh), BS);
1951  } else {
1952  RtlZeroMemory(addr, BS);
1953  }
1954  Cache->FrameList[frame].BlockCount++;
1955  }
1956  } else {
1957  // read sectors one by one and copy them to cache
1958  // unreadable sectors will be treated as zero-filled
1959  err_count = 0;
1960  for(n=0; n<BCount; n++, i++) {
1961  if(WCacheSectorAddr(block_array,i)) {
1962  continue;
1963  }
1965  if(!addr) {
1966  BrutePoint();
1967  break;
1968  }
1969  sector_added = TRUE;
1970  status = Cache->ReadProc(Context, Cache->tmp_buff_r, BS, Lba+n, &_ReadBytes, PH_TMP_BUFFER);
1971  if(!OS_SUCCESS(status)) {
1972  status = WCacheRaiseIoError(Cache, Context, status, Lba+n, 1, Cache->tmp_buff_r, WCACHE_R_OP, NULL);
1973  if(!OS_SUCCESS(status)) {
1974  err_count++;
1975  }
1976  }
1977  if(!zero && OS_SUCCESS(status)) {
1978  DbgCopyMemory(addr, Cache->tmp_buff_r, BS);
1979  } else
1980  if(Cache->RememberBB) {
1981  RtlZeroMemory(addr, BS);
1982  /*
1983  if(!OS_SUCCESS(status)) {
1984  WCacheSetBadFlag(block_array,i);
1985  }
1986  */
1987  }
1988  Cache->FrameList[frame].BlockCount++;
1989  if(err_count >= 2) {
1990  break;
1991  }
1992  }
1993 // _ReadBytes = n<<BSh;
1994  }
1995  }
1996 
1997  // we know the number of unread sectors if an error occured
1998  // so we can need to update BlockCount
1999  // return number of read bytes
2000  if(sector_added)
2001  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, n);
2002 
2003  return status;
2004 } // end WCachePreReadPacket__()
signed char * PCHAR
Definition: retypes.h:7
VOID __fastcall WCacheInsertRangeToList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:588
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
#define WCACHE_R_OP
Definition: wcache_lib.h:71
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
GLdouble n
Definition: glext.h:7729
OSSTATUS WCacheRaiseIoError(IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
Definition: wcache_lib.cpp:946
#define FALSE
Definition: types.h:117
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
unsigned char BOOLEAN
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
int zero
Definition: sehframes.cpp:29
#define WCACHE_BLOCK_BAD
Definition: wcache_lib.h:56
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define MEM_WCBUF_TAG
Definition: wcache_lib.cpp:56
#define WCACHE_BLOCK_ZERO
Definition: wcache_lib.h:55
PW_CACHE_ENTRY __fastcall WCacheInitFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:731
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
GLenum const GLvoid * addr
Definition: glext.h:9621
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
#define CACHED_BLOCK_MEMORY_TYPE
Definition: wcache_lib.h:115
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgCopyMemory
Definition: env_spec_w32.h:331
#define NULL
Definition: types.h:112
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
Definition: ps.c:97

Referenced by WCacheReadBlocks__().

◆ WCachePurgeAll__()

VOID WCachePurgeAll__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2590 of file wcache_lib.cpp.

2593 {
2594  if(!(Cache->ReadProc)) return;
2595  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2596 
2597  switch(Cache->Mode) {
2598  case WCACHE_MODE_RAM:
2600  break;
2601  case WCACHE_MODE_ROM:
2602  case WCACHE_MODE_RW:
2604  break;
2605  case WCACHE_MODE_R:
2607  break;
2608  }
2609 
2611  return;
2612 } // end WCachePurgeAll__()
VOID __fastcall WCachePurgeAllRW(IN PW_CACHE Cache, IN PVOID Context)
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
VOID __fastcall WCachePurgeAllR(IN PW_CACHE Cache, IN PVOID Context)
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
OSSTATUS __fastcall WCachePurgeAllRAM(IN PW_CACHE Cache, IN PVOID Context)
#define WCACHE_MODE_RAM
Definition: wcache_lib.h:127
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
#define WCACHE_MODE_ROM
Definition: wcache_lib.h:124
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define WCACHE_MODE_RW
Definition: wcache_lib.h:125

Referenced by UDFFindAnchor().

◆ WCachePurgeAllR()

VOID __fastcall WCachePurgeAllR ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3312 of file wcache_lib.cpp.

3315 {
3316  ULONG frame;
3317  lba_t firstLba;
3318  lba_t* List = Cache->CachedBlocksList;
3319  lba_t Lba;
3320  PCHAR tmp_buff = Cache->tmp_buff;
3321  ULONG BSh = Cache->BlockSizeSh;
3322  ULONG BS = Cache->BlockSize;
3323 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3324 // ULONG PSs = Cache->PacketSize;
3325  PW_CACHE_ENTRY block_array;
3326  BOOLEAN mod;
3327  OSSTATUS status;
3328  SIZE_T ReadBytes;
3329  ULONG MaxReloc = Cache->PacketSize;
3330  PULONG reloc_tab = Cache->reloc_tab;
3331  ULONG RelocCount = 0;
3332  BOOLEAN IncompletePacket;
3333  ULONG i=0;
3334  ULONG PacketTail;
3335 
3336  while(Cache->WriteCount < Cache->BlockCount) {
3337 
3338  Lba = List[i];
3339  frame = Lba >> Cache->BlocksPerFrameSh;
3340  firstLba = frame << Cache->BlocksPerFrameSh;
3341  block_array = Cache->FrameList[frame].Frame;
3342  if(!block_array) {
3343  BrutePoint();
3344  return;
3345  }
3346  // check if modified
3347  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3348  // just discard
3349  if(!mod || !(Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3350  // mark as non-cached & free pool
3351  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3352  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3353  if(mod)
3354  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3355  // mark as non-cached & free pool
3356  WCacheFreeSector(frame, Lba-firstLba);
3357  // check if frame is empty
3358  if(!Cache->FrameList[frame].BlockCount) {
3359  WCacheRemoveFrame(Cache, Context, frame);
3360  }
3361  } else {
3362  BrutePoint();
3363  }
3364  } else {
3365  i++;
3366  }
3367  }
3368 
3369  PacketTail = Cache->WriteCount & (MaxReloc-1);
3370  IncompletePacket = (Cache->WriteCount >= MaxReloc) ? FALSE : TRUE;
3371 
3372  // remove(flush) packet
3373  while((Cache->WriteCount > PacketTail) || (Cache->WriteCount && IncompletePacket)) {
3374 
3375  Lba = List[0];
3376  frame = Lba >> Cache->BlocksPerFrameSh;
3377  firstLba = frame << Cache->BlocksPerFrameSh;
3378  block_array = Cache->FrameList[frame].Frame;
3379  if(!block_array) {
3380  BrutePoint();
3381  return;
3382  }
3383  // check if modified
3384  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3385  // pack/reloc/write
3386  if(mod) {
3387  DbgCopyMemory(tmp_buff + (RelocCount << BSh),
3388  (PVOID)WCacheSectorAddr(block_array, Lba-firstLba),
3389  BS);
3390  reloc_tab[RelocCount] = Lba;
3391  RelocCount++;
3392  // write packet
3393  if((RelocCount >= MaxReloc) || (Cache->BlockCount == 1)) {
3394 // status = Cache->WriteProcAsync(Context, tmp_buff, PS, Lba, &ReadBytes, FALSE);
3395  Cache->UpdateRelocProc(Context, NULL, reloc_tab, RelocCount);
3396  status = Cache->WriteProc(Context, tmp_buff, RelocCount<<BSh, NULL, &ReadBytes, 0);
3397  if(!OS_SUCCESS(status)) {
3398  status = WCacheRaiseIoError(Cache, Context, status, NULL, RelocCount, tmp_buff, WCACHE_W_OP, NULL);
3399  }
3400  RelocCount = 0;
3401  }
3402  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3403  } else {
3404  BrutePoint();
3405  }
3406  // mark as non-cached & free pool
3407  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3408  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3409  // mark as non-cached & free pool
3410  WCacheFreeSector(frame, Lba-firstLba);
3411  // check if frame is empty
3412  if(!Cache->FrameList[frame].BlockCount) {
3413  WCacheRemoveFrame(Cache, Context, frame);
3414  }
3415  } else {
3416  BrutePoint();
3417  }
3418  }
3419 } // end WCachePurgeAllR()
signed char * PCHAR
Definition: retypes.h:7
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
OSSTATUS WCacheRaiseIoError(IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
Definition: wcache_lib.cpp:946
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
#define FALSE
Definition: types.h:117
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
unsigned char BOOLEAN
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
VOID __fastcall WCacheRemoveItemFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:704
#define WCACHE_W_OP
Definition: wcache_lib.h:70
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgCopyMemory
Definition: env_spec_w32.h:331
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
static SERVICE_STATUS status
Definition: service.c:31
static int mod
Definition: i386-dis.c:1281
Definition: ps.c:97

Referenced by WCacheFlushAll__(), and WCachePurgeAll__().

◆ WCachePurgeAllRAM()

OSSTATUS __fastcall WCachePurgeAllRAM ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 1762 of file wcache_lib.cpp.

1766 {
1767  ULONG frame;
1768  lba_t firstLba;
1769  lba_t* List = Cache->CachedBlocksList;
1770  lba_t lastLba;
1771  ULONG firstPos;
1772  ULONG lastPos;
1773  PW_CACHE_ENTRY block_array;
1774 // OSSTATUS status;
1775 
1776  // remove(flush) some frames
1777  while(Cache->FrameCount) {
1778 
1779  frame = Cache->CachedFramesList[0];
1780 
1781  firstLba = frame << Cache->BlocksPerFrameSh;
1782  lastLba = firstLba + Cache->BlocksPerFrame;
1783  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1784  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1785  block_array = Cache->FrameList[frame].Frame;
1786 
1787  if(!block_array) {
1788  UDFPrint(("Hmm...\n"));
1789  BrutePoint();
1791  }
1792  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, TRUE);
1793 
1794  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), firstLba, Cache->BlocksPerFrame);
1795  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1796  WCacheRemoveFrame(Cache, Context, frame);
1797  }
1798 
1799  ASSERT(!Cache->FrameCount);
1800  ASSERT(!Cache->BlockCount);
1801  return STATUS_SUCCESS;
1802 } // end WCachePurgeAllRAM()
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
OSSTATUS __fastcall WCacheFlushBlocksRAM(IN PW_CACHE Cache, IN PVOID Context, PW_CACHE_ENTRY block_array, lba_t *List, ULONG firstPos, ULONG lastPos, BOOLEAN Purge)
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WCachePurgeAll__().

◆ WCachePurgeAllRW()

VOID __fastcall WCachePurgeAllRW ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2622 of file wcache_lib.cpp.

2625 {
2626  ULONG frame;
2627  lba_t firstLba;
2628  lba_t* List = Cache->CachedBlocksList;
2629  lba_t Lba;
2630 // ULONG firstPos;
2631 // ULONG lastPos;
2632  ULONG BSh = Cache->BlockSizeSh;
2633  ULONG BS = Cache->BlockSize;
2634  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2635  ULONG PSs = Cache->PacketSize;
2636  PW_CACHE_ENTRY block_array;
2637 // OSSTATUS status;
2638  SIZE_T ReadBytes;
2639  PW_CACHE_ASYNC FirstWContext = NULL;
2640  PW_CACHE_ASYNC PrevWContext = NULL;
2641  ULONG chain_count = 0;
2642 
2643  if(!(Cache->ReadProc)) return;
2644 
2645  while(Cache->BlockCount) {
2646  Lba = List[0] & ~(PSs-1);
2647  frame = Lba >> Cache->BlocksPerFrameSh;
2648  firstLba = frame << Cache->BlocksPerFrameSh;
2649 // firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
2650 // lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba+PSs);
2651  block_array = Cache->FrameList[frame].Frame;
2652  if(!block_array) {
2653  BrutePoint();
2654  return;
2655  }
2656 
2657  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2658  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2659 
2660  // free memory
2661  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, PSs);
2662 
2663  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), Lba, PSs);
2664  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, PSs);
2665  // check if frame is empty
2666  if(!(Cache->FrameList[frame].BlockCount)) {
2667  WCacheRemoveFrame(Cache, Context, frame);
2668  } else {
2669  ASSERT(Cache->FrameList[frame].Frame);
2670  }
2671  chain_count++;
2672  if(chain_count >= WCACHE_MAX_CHAIN) {
2673  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2674  chain_count = 0;
2675  }
2676  }
2677  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext);
2678  return;
2679 } // end WCachePurgeAllRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
OSSTATUS WCacheUpdatePacket(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN PW_CACHE_ENTRY block_array, IN lba_t firstLba, IN lba_t Lba, IN ULONG BSh, IN ULONG BS, IN ULONG PS, IN ULONG PSs, IN PSIZE_T ReadBytes, IN BOOLEAN PrefereWrite, IN ULONG State)
Definition: wcache_lib.cpp:986
#define FALSE
Definition: types.h:117
VOID WCacheFreePacket(IN PW_CACHE Cache, IN ULONG frame, IN PW_CACHE_ENTRY block_array, IN ULONG offs, IN ULONG PSs)
struct _ACPI_EFI_BOOT_SERVICES * BS
VOID WCacheUpdatePacketComplete(IN PW_CACHE Cache, IN PVOID Context, IN OUT PW_CACHE_ASYNC *FirstWContext, IN OUT PW_CACHE_ASYNC *PrevWContext, IN BOOLEAN FreePacket=TRUE)
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define ASSERT(a)
Definition: mode.c:44
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
#define BrutePoint()
Definition: env_spec_w32.h:504
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20

Referenced by WCachePurgeAll__().

◆ WCacheRaiseIoError()

OSSTATUS WCacheRaiseIoError ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN OSSTATUS  Status,
IN ULONG  Lba,
IN ULONG  BCount,
IN PVOID  Buffer,
IN BOOLEAN  ReadOp,
IN PBOOLEAN  Retry 
)

Definition at line 946 of file wcache_lib.cpp.

956 {
957  if(!Cache->ErrorHandlerProc)
958  return Status;
959 
961 
963  ec.Status = Status;
964  ec.ReadWrite.Lba = Lba;
965  ec.ReadWrite.BCount = BCount;
966  ec.ReadWrite.Buffer = Buffer;
967  Status = Cache->ErrorHandlerProc(Context, &ec);
968  if(Retry)
969  (*Retry) = ec.Retry;
970 
971  return Status;
972 
973 } // end WCacheRaiseIoError()
Definition: fatfs.h:173
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define WCACHE_ERROR_READ
Definition: wcache_lib.h:66
Status
Definition: gdiplustypes.h:24
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:310
#define WCACHE_ERROR_WRITE
Definition: wcache_lib.h:67
struct _WCACHE_ERROR_CONTEXT::@944::@946 ReadWrite

Referenced by WCacheCheckLimitsR(), WCacheFlushBlocksRAM(), WCachePreReadPacket__(), WCachePurgeAllR(), WCacheReadBlocks__(), WCacheUpdatePacket(), and WCacheWriteBlocks__().

◆ WCacheRandom()

LONGLONG WCacheRandom ( VOID  )

Definition at line 339 of file wcache_lib.cpp.

340 {
341  WCache_random = (WCache_random * 0x8088405 + 1);
342  return WCache_random;
343 } // end WCacheRandom()
ULONG WCache_random
Definition: wcache_lib.cpp:90

Referenced by WCacheFindFrameToRelease(), WCacheFindLbaToRelease(), and WCacheFindModifiedLbaToRelease().

◆ WCacheReadBlocks__()

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 
)

Definition at line 2012 of file wcache_lib.cpp.

2022 {
2023  ULONG frame;
2024  ULONG i, saved_i, saved_BC = BCount, n;
2026  PW_CACHE_ENTRY block_array;
2027  ULONG BSh = Cache->BlockSizeSh;
2028  SIZE_T BS = Cache->BlockSize;
2029  PCHAR addr;
2030  ULONG to_read, saved_to_read;
2031 // PCHAR saved_buff = Buffer;
2032  SIZE_T _ReadBytes;
2033  ULONG PS = Cache->PacketSize;
2034  ULONG MaxR = Cache->MaxBytesToRead;
2035  ULONG PacketMask = PS-1; // here we assume that Packet Size value is 2^n
2036  ULONG d;
2037  ULONG block_type;
2038 
2039  WcPrint(("WC:R %x (%x)\n", Lba, BCount));
2040 
2041  (*ReadBytes) = 0;
2042  // check if we try to read too much data
2043  if(BCount >= Cache->MaxBlocks) {
2044  i = 0;
2045  if(CachedOnly) {
2047  goto EO_WCache_R2;
2048  }
2049  while(TRUE) {
2050  status = WCacheReadBlocks__(Cache, Context, Buffer + (i<<BSh), Lba, PS, &_ReadBytes, FALSE);
2051  (*ReadBytes) += _ReadBytes;
2052  if(!OS_SUCCESS(status) || (BCount <= PS)) break;
2053  BCount -= PS;
2054  Lba += PS;
2055  i += PS;
2056  }
2057  return status;
2058  }
2059  // check if we try to access beyond cached area
2060  if((Lba < Cache->FirstLba) ||
2061  (Lba + BCount - 1 > Cache->LastLba)) {
2062  status = Cache->ReadProc(Context, Buffer, BCount, Lba, ReadBytes, 0);
2063  if(!OS_SUCCESS(status)) {
2065  }
2066  return status;
2067  }
2068  if(!CachedOnly) {
2069  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2070  }
2071 
2072  frame = Lba >> Cache->BlocksPerFrameSh;
2073  i = Lba - (frame << Cache->BlocksPerFrameSh);
2074 
2075  if(Cache->CacheWholePacket && (BCount < PS)) {
2076  if(!CachedOnly &&
2077  !OS_SUCCESS(status = WCacheCheckLimits(Cache, Context, Lba & ~(PS-1), PS*2)) ) {
2079  return status;
2080  }
2081  } else {
2082  if(!CachedOnly &&
2083  !OS_SUCCESS(status = WCacheCheckLimits(Cache, Context, Lba, BCount))) {
2085  return status;
2086  }
2087  }
2088  if(!CachedOnly) {
2089  // convert to shared
2090 // ExConvertExclusiveToSharedLite(&(Cache->WCacheLock));
2091  }
2092 
2093  // pre-read packet. It is very useful for
2094  // highly fragmented files
2095  if(Cache->CacheWholePacket && (BCount < PS)) {
2096 // status = WCacheReadBlocks__(Cache, Context, Cache->tmp_buff_r, Lba & (~PacketMask), PS, &_ReadBytes, TRUE);
2097  // we should not perform IO if user requested CachedOnly data
2098  if(!CachedOnly) {
2100  }
2102  }
2103 
2104  // assume successful operation
2105  block_array = Cache->FrameList[frame].Frame;
2106  if(!block_array) {
2107  ASSERT(!CachedOnly);
2108  ASSERT(Cache->FrameCount < Cache->MaxFrames);
2109  block_array = WCacheInitFrame(Cache, Context, frame);
2110  if(!block_array) {
2112  goto EO_WCache_R;
2113  }
2114  }
2115 
2116  Cache->FrameList[frame].AccessCount++;
2117  while(BCount) {
2118  if(i >= Cache->BlocksPerFrame) {
2119  frame++;
2120  block_array = Cache->FrameList[frame].Frame;
2121  i -= Cache->BlocksPerFrame;
2122  }
2123  if(!block_array) {
2124  ASSERT(Cache->FrameCount < Cache->MaxFrames);
2125  block_array = WCacheInitFrame(Cache, Context, frame);
2126  if(!block_array) {
2128  goto EO_WCache_R;
2129  }
2130  }
2131  // 'read' cached extent (if any)
2132  // it is just copying
2133  while(BCount &&
2134  (i < Cache->BlocksPerFrame) &&
2135  (addr = (PCHAR)WCacheSectorAddr(block_array, i)) ) {
2136  block_type = Cache->CheckUsedProc(Context, Lba+saved_BC-BCount);
2137  if(block_type & WCACHE_BLOCK_BAD) {
2138  //if(WCacheGetBadFlag(block_array,i)) {
2140  goto EO_WCache_R;
2141  }
2143  Buffer += BS;
2144  *ReadBytes += BS;
2145  i++;
2146  BCount--;
2147  }
2148  // read non-cached packet-size-aligned extent (if any)
2149  // now we'll calculate total length & decide if it has enough size
2150  if(!((d = Lba+saved_BC-BCount) & PacketMask) && d ) {
2151  n = 0;
2152  while(BCount &&
2153  (i < Cache->BlocksPerFrame) &&
2154  (!WCacheSectorAddr(block_array, i)) ) {
2155  n++;
2156  BCount--;
2157  }
2158  BCount += n;
2159  n &= ~PacketMask;
2160  if(n>PS) {
2161  if(!OS_SUCCESS(status = Cache->ReadProc(Context, Buffer, BS*n, Lba+saved_BC-BCount, &_ReadBytes, 0))) {
2162  status = WCacheRaiseIoError(Cache, Context, status, Lba+saved_BC-BCount, n, Buffer, WCACHE_R_OP, NULL);
2163  if(!OS_SUCCESS(status)) {
2164  goto EO_WCache_R;
2165  }
2166  }
2167 // WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2168  BCount -= n;
2169  Lba += saved_BC - BCount;
2170  saved_BC = BCount;
2171  i += n;
2172  Buffer += BS*n;
2173  *ReadBytes += BS*n;
2174  }
2175 // } else {
2176 // UDFPrint(("Unaligned\n"));
2177  }
2178  // read non-cached extent (if any)
2179  // firstable, we'll get total number of sectors to read
2180  to_read = 0;
2181  saved_i = i;
2182  d = BCount;
2183  while(d &&
2184  (i < Cache->BlocksPerFrame) &&
2185  (!WCacheSectorAddr(block_array, i)) ) {
2186  i++;
2187  to_read += BS;
2188  d--;
2189  }
2190  // read some not cached sectors
2191  if(to_read) {
2192  i = saved_i;
2193  saved_to_read = to_read;
2194  d = BCount - d;
2195  // split request if necessary
2196  if(saved_to_read > MaxR) {
2197  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2198  n = MaxR >> BSh;
2199  do {
2200  status = Cache->ReadProc(Context, Buffer, MaxR, i + (frame << Cache->BlocksPerFrameSh), &_ReadBytes, 0);
2201  *ReadBytes += _ReadBytes;
2202  if(!OS_SUCCESS(status)) {
2203  _ReadBytes &= ~(BS-1);
2204  BCount -= _ReadBytes >> BSh;
2205  saved_to_read -= _ReadBytes;
2206  Buffer += _ReadBytes;
2207  saved_BC = BCount;
2208  goto store_read_data_1;
2209  }
2210  Buffer += MaxR;
2211  saved_to_read -= MaxR;
2212  i += n;
2213  BCount -= n;
2214  d -= n;
2215  } while(saved_to_read > MaxR);
2216  saved_BC = BCount;
2217  }
2218  if(saved_to_read) {
2219  status = Cache->ReadProc(Context, Buffer, saved_to_read, i + (frame << Cache->BlocksPerFrameSh), &_ReadBytes, 0);
2220  *ReadBytes += _ReadBytes;
2221  if(!OS_SUCCESS(status)) {
2222  _ReadBytes &= ~(BS-1);
2223  BCount -= _ReadBytes >> BSh;
2224  saved_to_read -= _ReadBytes;
2225  Buffer += _ReadBytes;
2226  goto store_read_data_1;
2227  }
2228  Buffer += saved_to_read;
2229  saved_to_read = 0;
2230  BCount -= d;
2231  }
2232 
2233 store_read_data_1:
2234  // and now we'll copy them to cache
2235 
2236  //
2237  Buffer -= (to_read - saved_to_read);
2238  i = saved_i;
2239  while(to_read - saved_to_read) {
2241  if(!block_array[i].Sector) {
2242  BCount += to_read >> BSh;
2244  goto EO_WCache_R;
2245  }
2246  DbgCopyMemory(block_array[i].Sector, Buffer, BS);
2247  Cache->FrameList[frame].BlockCount++;
2248  i++;
2249  Buffer += BS;
2250  to_read -= BS;
2251  }
2252  if(!OS_SUCCESS(status))
2253  goto EO_WCache_R;
2254  to_read = 0;
2255  }
2256  }
2257 
2258 EO_WCache_R:
2259 
2260  // we know the number of unread sectors if an error occured
2261  // so we can need to update BlockCount
2262  // return number of read bytes
2263  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2264 // Cache->FrameList[frame].BlockCount -= BCount;
2265 EO_WCache_R2:
2266  if(!CachedOnly) {
2268  }
2269 
2270  return status;
2271 } // end WCacheReadBlocks__()
signed char * PCHAR
Definition: retypes.h:7
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
VOID __fastcall WCacheInsertRangeToList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:588
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
#define WCACHE_R_OP
Definition: wcache_lib.h:71
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLdouble n
Definition: glext.h:7729
OSSTATUS WCacheRaiseIoError(IN PW_CACHE Cache, IN PVOID Context, IN OSSTATUS Status, IN ULONG Lba, IN ULONG BCount, IN PVOID Buffer, IN BOOLEAN ReadOp, IN PBOOLEAN Retry)
Definition: wcache_lib.cpp:946
OSSTATUS __fastcall WCacheCheckLimits(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
#define OSSTATUS
Definition: env_spec_w32.h:57
struct _ACPI_EFI_BOOT_SERVICES * BS
PCHAR Sector
Definition: wcache_lib.h:99
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
Definition: bufpool.h:45
#define WCACHE_BLOCK_BAD
Definition: wcache_lib.h:56
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define MEM_WCBUF_TAG
Definition: wcache_lib.cpp:56
ULONG to_read
Definition: btrfs.c:4229
PW_CACHE_ENTRY __fastcall WCacheInitFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:731
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)
Definition: wcache_lib.h:97
OSSTATUS WCachePreReadPacket__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba)
GLenum const GLvoid * addr
Definition: glext.h:9621
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
#define WcPrint
Definition: wcache_lib.cpp:61
#define CACHED_BLOCK_MEMORY_TYPE
Definition: wcache_lib.h:115
ULONG_PTR SIZE_T
Definition: typedefs.h:80
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgCopyMemory
Definition: env_spec_w32.h:331
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define d
Definition: ke_i.h:81
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
Definition: ps.c:97

Referenced by WCacheReadBlocks__().

◆ WCacheRelease__()

VOID WCacheRelease__ ( IN PW_CACHE  Cache)

Definition at line 2768 of file wcache_lib.cpp.

2771 {
2772  ULONG i, j, k;
2773  PW_CACHE_ENTRY block_array;
2774 
2775  Cache->Tag = 0xDEADCACE;
2776  if(!(Cache->ReadProc)) return;
2777 // ASSERT(Cache->Tag == 0xCAC11E00);
2778  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2779  for(i=0; i<Cache->FrameCount; i++) {
2780  j = Cache->CachedFramesList[i];
2781  block_array = Cache->FrameList[j].Frame;
2782  if(block_array) {
2783  for(k=0; k<Cache->BlocksPerFrame; k++) {
2784  if(WCacheSectorAddr(block_array, k)) {
2785  WCacheFreeSector(j, k);
2786  }
2787  }
2788  MyFreePool__(block_array);
2789  }
2790  }
2791  if(Cache->FrameList)
2792  MyFreePool__(Cache->FrameList);
2793  if(Cache->CachedBlocksList)
2794  MyFreePool__(Cache->CachedBlocksList);
2795  if(Cache->CachedModifiedBlocksList)
2796  MyFreePool__(Cache->CachedModifiedBlocksList);
2797  if(Cache->CachedFramesList)
2798  MyFreePool__(Cache->CachedFramesList);
2799  if(Cache->tmp_buff_r)
2800  MyFreePool__(Cache->tmp_buff_r);
2801  if(Cache->CachedFramesList)
2802  MyFreePool__(Cache->tmp_buff);
2803  if(Cache->CachedFramesList)
2804  MyFreePool__(Cache->reloc_tab);
2806  ExDeleteResourceLite(&(Cache->WCacheLock));
2807  RtlZeroMemory(Cache, sizeof(W_CACHE));
2808  return;
2809 } // end WCacheRelease__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define MyFreePool__(addr)
Definition: mem_tools.h:152
Definition: wcache_lib.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
int k
Definition: mpi.c:3369

Referenced by UDFDoDismountSequence(), UDFReleaseVCB(), and UDFVerifyVolume().

◆ WCacheRemoveFrame()

VOID __fastcall WCacheRemoveFrame ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN ULONG  frame 
)

Definition at line 780 of file wcache_lib.cpp.

785 {
786  PW_CACHE_ENTRY block_array;
787 #ifdef DBG
788  ULONG old_count = Cache->FrameCount;
789 #endif //DBG
790 
791  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
792  block_array = Cache->FrameList[frame].Frame;
793 
794  WCacheRemoveItemFromList(Cache->CachedFramesList, &(Cache->FrameCount), frame);
795  MyFreePool__(block_array);
796 // ASSERT(!(Cache->FrameList[frame].WriteCount));
797 // ASSERT(!(Cache->FrameList[frame].WriteCount));
798  Cache->FrameList[frame].Frame = NULL;
799  ASSERT(Cache->FrameCount < Cache->MaxFrames);
800 #ifdef DBG
801  ASSERT(old_count > Cache->FrameCount);
802 #endif //DBG
803 
804 } // end WCacheRemoveFrame()
Definition: fatfs.h:173
VOID __fastcall WCacheRemoveItemFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:704
#define ASSERT(a)
Definition: mode.c:44
#define MyFreePool__(addr)
Definition: mem_tools.h:152
Definition: wcache_lib.h:97
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCacheCheckLimits(), WCacheCheckLimitsR(), WCacheCheckLimitsRAM(), WCacheCheckLimitsRW(), WCacheDiscardBlocks__(), WCachePurgeAllR(), WCachePurgeAllRAM(), and WCachePurgeAllRW().

◆ WCacheRemoveItemFromList()

VOID __fastcall WCacheRemoveItemFromList ( IN lba_t List,
IN PULONG  BlockCount,
IN lba_t  Lba 
)

Definition at line 704 of file wcache_lib.cpp.

709 {
710  if(!(*BlockCount)) return;
711  ULONG lastPos = WCacheGetSortedListIndex(*BlockCount, List, Lba+1);
712  if(!lastPos || (lastPos && (List[lastPos-1] != Lba)))
713  return;
714 
715  // move list tail
716  DbgMoveMemory(&(List[lastPos-1]), &(List[lastPos]), ((*BlockCount) - lastPos) * sizeof(ULONG));
717  (*BlockCount) --;
718 } // end WCacheRemoveItemFromList()
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define DbgMoveMemory
Definition: env_spec_w32.h:329
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCacheCheckLimitsR(), WCacheDiscardBlocks__(), WCachePurgeAllR(), and WCacheRemoveFrame().

◆ WCacheRemoveRangeFromList()

VOID __fastcall WCacheRemoveRangeFromList ( IN lba_t List,
IN PULONG  BlockCount,
IN lba_t  Lba,
IN ULONG  BCount 
)

Definition at line 675 of file wcache_lib.cpp.

681 {
682  ULONG firstPos = WCacheGetSortedListIndex(*BlockCount, List, Lba);
683  ULONG lastPos = WCacheGetSortedListIndex(*BlockCount, List, Lba+BCount);
684  ULONG offs = lastPos - firstPos;
685 
686  if(offs) {
687  // move list tail
688  DbgMoveMemory(&(List[lastPos-offs]), &(List[lastPos]), ((*BlockCount) - lastPos) * sizeof(ULONG));
689  (*BlockCount) -= offs;
690  }
691 } // end WCacheRemoveRangeFromList()
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
#define DbgMoveMemory
Definition: env_spec_w32.h:329
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
unsigned int ULONG
Definition: retypes.h:1

Referenced by WCacheCheckLimitsRAM(), WCacheCheckLimitsRW(), WCacheFlushAllRAM(), WCacheFlushAllRW(), WCacheFlushBlocksRW(), WCachePurgeAllRAM(), WCachePurgeAllRW(), and WCacheWriteBlocks__().

◆ WCacheSetMode__()

OSSTATUS WCacheSetMode__ ( IN PW_CACHE  Cache,
IN ULONG  Mode 
)

Definition at line 3426 of file wcache_lib.cpp.

3430 {
3432  Cache->Mode = Mode;
3433  return STATUS_SUCCESS;
3434 } // end WCacheSetMode__()
_In_ ULONG Mode
Definition: hubbusif.h:303
Definition: fatfs.h:173
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WCACHE_MODE_MAX
Definition: wcache_lib.h:129
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by UDFLoadPartDesc(), UDFMountVolume(), and UDFVerifyVolume().

◆ WCacheStartDirect__()

OSSTATUS WCacheStartDirect__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN BOOLEAN  Exclusive 
)

Definition at line 3101 of file wcache_lib.cpp.

3107 {
3108  if(Exclusive) {
3109  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
3110  } else {
3111  BrutePoint();
3112  ExAcquireResourceSharedLite(&(Cache->WCacheLock), TRUE);
3113  }
3114  return STATUS_SUCCESS;
3115 } // end WCacheStartDirect__()
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define BrutePoint()
Definition: env_spec_w32.h:504
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by UDFIsExtentCached(), and UDFVWorkItem().

◆ WCacheSyncReloc__()

VOID WCacheSyncReloc__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3470 of file wcache_lib.cpp.

3473 {
3474  ULONG frame;
3475  lba_t firstLba;
3476  lba_t* List = Cache->CachedBlocksList;
3477  lba_t Lba;
3478 // ULONG BSh = Cache->BlockSizeSh;
3479 // ULONG BS = Cache->BlockSize;
3480 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3481 // ULONG PSs = Cache->PacketSize;
3482  PW_CACHE_ENTRY block_array;
3483  BOOLEAN mod;
3484  ULONG MaxReloc = Cache->PacketSize;
3485  PULONG reloc_tab = Cache->reloc_tab;
3486  ULONG RelocCount = 0;
3487  BOOLEAN IncompletePacket;
3488 
3489  IncompletePacket = (Cache->WriteCount >= MaxReloc) ? FALSE : TRUE;
3490  // enumerate modified blocks
3491  for(ULONG i=0; IncompletePacket && (i<Cache->BlockCount); i++) {
3492 
3493  Lba = List[i];
3494  frame = Lba >> Cache->BlocksPerFrameSh;
3495  firstLba = frame << Cache->BlocksPerFrameSh;
3496  block_array = Cache->FrameList[frame].Frame;
3497  if(!block_array) {
3498  return;
3499  }
3500  // check if modified
3501  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3502  // update relocation table for modified sectors
3503  if(mod && (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3504  reloc_tab[RelocCount] = Lba;
3505  RelocCount++;
3506  if(RelocCount >= Cache->WriteCount) {
3507  Cache->UpdateRelocProc(Context, NULL, reloc_tab, RelocCount);
3508  break;
3509  }
3510  }
3511  }
3512 } // end WCacheSyncReloc__()
Definition: fatfs.h:173
#define TRUE
Definition: types.h:120
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Definition: wcache_lib.h:97
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
static int mod
Definition: i386-dis.c:1281

Referenced by UDFRecordVAT().

◆ WCacheUpdatePacket()

OSSTATUS WCacheUpdatePacket ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN OUT PW_CACHE_ASYNC FirstWContext,
IN OUT PW_CACHE_ASYNC PrevWContext,
IN PW_CACHE_ENTRY  block_array,
IN lba_t  firstLba,
IN lba_t  Lba,
IN ULONG  BSh,
IN ULONG  BS,
IN ULONG  PS,
IN ULONG  PSs,
IN PSIZE_T  ReadBytes,
IN BOOLEAN  PrefereWrite,
IN ULONG  State 
)

Definition at line 986 of file wcache_lib.cpp.

1003 {
1004  OSSTATUS status;
1005  PCHAR tmp_buff = Cache->tmp_buff;
1006  PCHAR tmp_buff2 = Cache->tmp_buff;
1007  BOOLEAN mod;
1008  BOOLEAN read;
1009  BOOLEAN zero;
1010  ULONG i;
1011  lba_t Lba0;
1012  PW_CACHE_ASYNC WContext;
1013  BOOLEAN Async = (Cache->ReadProcAsync && Cache->WriteProcAsync);
1014  ULONG block_type;
1015  BOOLEAN Chained = Cache->Chained;
1016 
1017  // Check if we are going to write down to disk
1018  // all prewiously prepared (chained) data
1019  if(State == ASYNC_STATE_WRITE) {
1020  WContext = (*PrevWContext);
1021  tmp_buff = (PCHAR)(WContext->Buffer);
1022  tmp_buff2 = (PCHAR)(WContext->Buffer2);
1023  if(!Chained)
1024  mod = (DbgCompareMemory(tmp_buff2, tmp_buff, PS) != PS);
1025  goto try_write;
1026  }
1027 
1028  // Check if packet contains modified blocks
1029  // If packet contains non-cached and unchanged, but used
1030  // blocks, it must be read from media before modification
1031  mod = read = zero = FALSE;
1032  Lba0 = Lba - firstLba;
1033  for(i=0; i<PSs; i++, Lba0++) {
1034  if(WCacheGetModFlag(block_array, Lba0)) {
1035  mod = TRUE;
1036  } else if(!WCacheSectorAddr(block_array,Lba0) &&
1037  ((block_type = Cache->CheckUsedProc(Context, Lba+i)) & WCACHE_BLOCK_USED) ) {
1038  //
1039  if(block_type & WCACHE_BLOCK_ZERO) {
1040  zero = TRUE;
1041  } else {
1042  read = TRUE;
1043  }
1044  }
1045  }
1046  // check if we are allowed to write to media
1047  if(mod && !PrefereWrite) {
1048  return STATUS_RETRY;
1049  }
1050  // return STATUS_SUCCESS if requested packet contains no modified blocks
1051  if(!mod) {
1052  (*ReadBytes) = PS;
1053  return STATUS_SUCCESS;
1054  }
1055 
1056  // pefrorm full update cycle: prepare(optional)/read/modify/write
1057 
1058  // do some preparations
1059  if(Chained || Async) {
1060  // For chained and async I/O we allocates context entry
1061  // and add it to list (chain)
1062  // We shall only read data to temporary buffer and
1063  // modify it. Write operations will be invoked later.
1064  // This is introduced in order to avoid frequent
1065  // read.write mode switching, because it significantly degrades
1066  // performance
1067  WContext = WCacheAllocAsyncEntry(Cache, FirstWContext, PrevWContext, PS);
1068  if(!WContext) {
1069  //return STATUS_INSUFFICIENT_RESOURCES;
1070  // try to recover
1071  Chained = FALSE;
1072  Async = FALSE;
1073  } else {
1074  tmp_buff = tmp_buff2 = (PCHAR)(WContext->Buffer);
1075  WContext->Lba = Lba;
1076  WContext->Cmd = ASYNC_CMD_UPDATE;
1077  WContext->State = ASYNC_STATE_NONE;
1078  }
1079  }
1080 
1081  // read packet (if it necessary)
1082  if(read) {
1083  if(Async) {
1084  WContext->State = ASYNC_STATE_READ;
1085  status = Cache->ReadProcAsync(Context, WContext, tmp_buff, PS, Lba,
1086  &(WContext->TransferredBytes));
1087 // tmp_buff2 = (PCHAR)(WContext->Buffer2);
1088  (*ReadBytes) = PS;
1089  return status;
1090  } else {
1091  status = Cache->ReadProc(Context, tmp_buff, PS, Lba, ReadBytes, PH_TMP_BUFFER);
1092  }
1093  if(!OS_SUCCESS(status)) {
1094  status = WCacheRaiseIoError(Cache, Context, status, Lba, PSs, tmp_buff, WCACHE_R_OP, NULL);
1095  if(!OS_SUCCESS(status)) {
1096  return status;
1097  }
1098  }
1099  } else
1100  if(zero) {
1101  RtlZeroMemory(tmp_buff, PS);
1102  }
1103 
1104  if(Chained) {
1105  // indicate that we prepared for writing block to disk
1106  WContext->State = ASYNC_STATE_WRITE_PRE;
1107  tmp_buff2 = tmp_buff;
1109  }
1110 
1111  // modify packet
1112 
1113  // If we didn't read packet from media, we can't
1114  // perform comparison to assure that packet was really modified.
1115  // Thus, assume that it is modified in this case.
1116  mod = !read || Cache->DoNotCompare;
1117  Lba0 = Lba - firstLba;
1118  for(i=0; i<PSs; i++, Lba0++) {
1119  if( WCacheGetModFlag(block_array, Lba0) ||
1120  (!read && WCacheSectorAddr(block_array,Lba0)) ) {
1121 
1122 #ifdef _NTDEF_
1123