ReactOS  0.4.14-dev-98-gb0d4763
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
smooth NULL
Definition: ftsmooth.c:416

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
#define MEM_WCCTX_TAG
Definition: wcache_lib.cpp:54
smooth NULL
Definition: ftsmooth.c:416
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
#define BufferSize
Definition: classpnp.h:419
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
struct _W_CACHE_ASYNC * NextWContext
Definition: wcache_lib.cpp:76

Referenced by WCacheUpdatePacket().

◆ WCacheCheckLimits()

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

Definition at line 1299 of file wcache_lib.cpp.

1305 {
1306 /* if(!Cache->FrameCount || !Cache->BlockCount) {
1307  ASSERT(!Cache->FrameCount);
1308  ASSERT(!Cache->BlockCount);
1309  if(!Cache->FrameCount)
1310  return STATUS_SUCCESS;
1311  }*/
1312 
1313  // check if we have reached Frame or Block limit
1314  if(!Cache->FrameCount && !Cache->BlockCount) {
1315  return STATUS_SUCCESS;
1316  }
1317 
1318  // check for empty frames
1319  if(Cache->FrameCount > (Cache->MaxFrames*3)/4) {
1320  ULONG frame;
1321  ULONG i;
1322  for(i=Cache->FrameCount; i>0; i--) {
1323  frame = Cache->CachedFramesList[i-1];
1324  // check if frame is empty
1325  if(!(Cache->FrameList[frame].BlockCount)) {
1326  WCacheRemoveFrame(Cache, Context, frame);
1327  } else {
1328  ASSERT(Cache->FrameList[frame].Frame);
1329  }
1330  }
1331  }
1332 
1333  if(!Cache->BlockCount) {
1334  return STATUS_SUCCESS;
1335  }
1336 
1337  // invoke media-specific limit-checker
1338  switch(Cache->Mode) {
1339  case WCACHE_MODE_RAM:
1340  return WCacheCheckLimitsRAM(Cache, Context, ReqLba, BCount);
1341  case WCACHE_MODE_ROM:
1342  case WCACHE_MODE_RW:
1343  return WCacheCheckLimitsRW(Cache, Context, ReqLba, BCount);
1344  case WCACHE_MODE_R:
1345  return WCacheCheckLimitsR(Cache, Context, ReqLba, BCount);
1346  }
1348 } // end WCacheCheckLimits()
OSSTATUS __fastcall WCacheCheckLimitsRW(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
Definition: fatfs.h:173
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
OSSTATUS __fastcall WCacheCheckLimitsRAM(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
#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
return STATUS_SUCCESS
Definition: btrfs.c:2966
#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 3188 of file wcache_lib.cpp.

3194 {
3195  ULONG frame;
3196  lba_t firstLba;
3197  lba_t* List = Cache->CachedBlocksList;
3198  lba_t Lba;
3199  PCHAR tmp_buff = Cache->tmp_buff;
3200  ULONG firstPos;
3201  ULONG BSh = Cache->BlockSizeSh;
3202  ULONG BS = Cache->BlockSize;
3203  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3204  ULONG PSs = Cache->PacketSize;
3205  ULONG i;
3206  PW_CACHE_ENTRY block_array;
3207  BOOLEAN mod;
3208  OSSTATUS status;
3209  SIZE_T ReadBytes;
3210  ULONG MaxReloc = Cache->PacketSize;
3211  PULONG reloc_tab = Cache->reloc_tab;
3212 
3213  // check if we try to read too much data
3214  if(BCount > Cache->MaxBlocks) {
3215  return STATUS_INVALID_PARAMETER;
3216  }
3217 
3218  // remove(flush) packets from entire frame(s)
3219  while( ((Cache->BlockCount + WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba) +
3220  BCount - WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba+BCount)) > Cache->MaxBlocks) ||
3221  (Cache->FrameCount >= Cache->MaxFrames) ) {
3222 
3223 WCCL_retry_1:
3224 
3226  if(Lba == WCACHE_INVALID_LBA) {
3227  ASSERT(!Cache->FrameCount);
3228  ASSERT(!Cache->BlockCount);
3229  break;
3230  }
3231  frame = Lba >> Cache->BlocksPerFrameSh;
3232  firstLba = frame << Cache->BlocksPerFrameSh;
3233  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
3234  block_array = Cache->FrameList[frame].Frame;
3235  if(!block_array) {
3237  }
3238  // check if modified
3239  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3240  // read/modify/write
3241  if(mod && (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3242  if(Cache->WriteCount < MaxReloc) goto WCCL_retry_1;
3243  firstPos = WCacheGetSortedListIndex(Cache->WriteCount, Cache->CachedModifiedBlocksList, Lba);
3244  if(!block_array) {
3246  }
3247  // prepare packet & reloc table
3248  for(i=0; i<MaxReloc; i++) {
3249  Lba = Cache->CachedModifiedBlocksList[firstPos];
3250  frame = Lba >> Cache->BlocksPerFrameSh;
3251  firstLba = frame << Cache->BlocksPerFrameSh;
3252  block_array = Cache->FrameList[frame].Frame;
3253  DbgCopyMemory(tmp_buff + (i << BSh),
3254  (PVOID)WCacheSectorAddr(block_array, Lba-firstLba),
3255  BS);
3256  reloc_tab[i] = Lba;
3257  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3258  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3259  // mark as non-cached & free pool
3260  WCacheFreeSector(frame, Lba-firstLba);
3261  // check if frame is empty
3262  if(!Cache->FrameList[frame].BlockCount) {
3263  WCacheRemoveFrame(Cache, Context, frame);
3264  }
3265  if(firstPos >= Cache->WriteCount) firstPos=0;
3266  }
3267  // write packet
3268 // status = Cache->WriteProcAsync(Context, tmp_buff, PS, Lba, &ReadBytes, FALSE);
3269  Cache->UpdateRelocProc(Context, NULL, reloc_tab, MaxReloc);
3270  status = Cache->WriteProc(Context, tmp_buff, PS, NULL, &ReadBytes, 0);
3271  if(!OS_SUCCESS(status)) {
3273  }
3274  } else {
3275 
3276  if((i = Cache->BlockCount - Cache->WriteCount) > MaxReloc) i = MaxReloc;
3277  // discard blocks
3278  for(; i; i--) {
3279  Lba = List[firstPos];
3280  frame = Lba >> Cache->BlocksPerFrameSh;
3281  firstLba = frame << Cache->BlocksPerFrameSh;
3282  block_array = Cache->FrameList[frame].Frame;
3283 
3284  if( (mod = WCacheGetModFlag(block_array, Lba - firstLba)) &&
3285  (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED) )
3286  continue;
3287  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3288  if(mod)
3289  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3290  // mark as non-cached & free pool
3291  WCacheFreeSector(frame, Lba-firstLba);
3292  // check if frame is empty
3293  if(!Cache->FrameList[frame].BlockCount) {
3294  WCacheRemoveFrame(Cache, Context, frame);
3295  }
3296  if(firstPos >= Cache->WriteCount) firstPos=0;
3297  }
3298  }
3299  }
3300  return STATUS_SUCCESS;
3301 } // 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
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
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
smooth NULL
Definition: ftsmooth.c:416
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
LIST_ENTRY List
Definition: psmgr.c:57
VOID __fastcall WCacheRemoveFrame(IN PW_CACHE Cache, IN PVOID Context, IN ULONG frame)
Definition: wcache_lib.cpp:780
Definition: wcache_lib.h:97
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define DbgCopyMemory
Definition: env_spec_w32.h:331
unsigned int * PULONG
Definition: retypes.h:1
#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
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
static int mod
Definition: i386-dis.c:1273
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 1630 of file wcache_lib.cpp.

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

Referenced by WCacheCheckLimits().

◆ WCacheCheckLimitsRW()

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

Definition at line 1360 of file wcache_lib.cpp.

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

3639 {
3640  ULONG Flags;
3641 
3642  if(SetFlags || ClrFlags) {
3643  Flags = (Cache->Flags & ~ClrFlags) | SetFlags;
3644 
3646  return -1;
3647  }
3648  } else {
3649  return Cache->Flags;
3650  }
3651  return Flags;
3652 } // 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 3585 of file wcache_lib.cpp.

3589 {
3590  PW_CACHE_ASYNC AsyncCtx = (PW_CACHE_ASYNC)WContext;
3591 // PW_CACHE Cache = AsyncCtx->Cache;
3592 
3593  AsyncCtx->PhContext.IosbToUse.Status = Status;
3594  KeSetEvent(&(AsyncCtx->PhContext.event), 0, FALSE);
3595 
3596  return STATUS_SUCCESS;
3597 } // end WCacheSetMode__()
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by WCacheUpdatePacket().

◆ WCacheDecodeFlags()

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

Definition at line 3605 of file wcache_lib.cpp.

3609 {
3610  //ULONG OldFlags;
3611  if(Flags & ~WCACHE_VALID_FLAGS) {
3612  UDFPrint(("Invalid flags: %x\n", Flags & ~WCACHE_VALID_FLAGS));
3613  return STATUS_INVALID_PARAMETER;
3614  }
3615  Cache->CacheWholePacket = (Flags & WCACHE_CACHE_WHOLE_PACKET) ? TRUE : FALSE;
3616  Cache->DoNotCompare = (Flags & WCACHE_DO_NOT_COMPARE) ? TRUE : FALSE;
3617  Cache->Chained = (Flags & WCACHE_CHAINED_IO) ? TRUE : FALSE;
3618  Cache->RememberBB = (Flags & WCACHE_MARK_BAD_BLOCKS) ? TRUE : FALSE;
3619  if(Cache->RememberBB) {
3620  Cache->NoWriteBB = (Flags & WCACHE_RO_BAD_BLOCKS) ? TRUE : FALSE;
3621  }
3622  Cache->NoWriteThrough = (Flags & WCACHE_NO_WRITE_THROUGH) ? TRUE : FALSE;
3623 
3624  Cache->Flags = Flags;
3625 
3626  return STATUS_SUCCESS;
3627 }
#define UDFPrint(Args)
Definition: udffs.h:225
#define WCACHE_CHAINED_IO
Definition: wcache_lib.h:193
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define WCACHE_VALID_FLAGS
Definition: wcache_lib.h:198
#define WCACHE_DO_NOT_COMPARE
Definition: wcache_lib.h:192
return STATUS_SUCCESS
Definition: btrfs.c:2966
#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 2948 of file wcache_lib.cpp.

2956 {
2957  ULONG frame;
2958  ULONG i;
2960  PW_CACHE_ENTRY block_array;
2961  ULONG BS = Cache->BlockSize;
2962  PCHAR addr;
2963  SIZE_T _ReadBytes;
2964  ULONG block_type;
2965 
2966  WcPrint(("WC:%sD %x (1)\n", Modified ? "W" : "R", Lba));
2967 
2968  // lock cache if nececcary
2969  if(!CachedOnly) {
2970  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2971  }
2972  // check if we try to access beyond cached area
2973  if((Lba < Cache->FirstLba) ||
2974  (Lba > Cache->LastLba)) {
2975  UDFPrint(("LBA %#x is beyond cacheable area\n", Lba));
2976  BrutePoint();
2978  goto EO_WCache_D;
2979  }
2980 
2981  frame = Lba >> Cache->BlocksPerFrameSh;
2982  i = Lba - (frame << Cache->BlocksPerFrameSh);
2983  // check if we have enough space to store requested block
2984  if(!CachedOnly &&
2986  BrutePoint();
2987  goto EO_WCache_D;
2988  }
2989 
2990  // small updates are more important
2991  block_array = Cache->FrameList[frame].Frame;
2992  if(Modified) {
2993  Cache->FrameList[frame].UpdateCount+=8;
2994  } else {
2995  Cache->FrameList[frame].AccessCount+=8;
2996  }
2997  if(!block_array) {
2998  ASSERT(Cache->FrameCount < Cache->MaxFrames);
2999  block_array = WCacheInitFrame(Cache, Context, frame);
3000  if(!block_array) {
3002  goto EO_WCache_D;
3003  }
3004  }
3005  // check if requested block is already cached
3006  if( !(addr = (PCHAR)WCacheSectorAddr(block_array, i)) ) {
3007  // block is not cached
3008  // allocate memory and read block from media
3009  // do not set block_array[i].Sector here, because if media access fails and recursive access to cache
3010  // comes, this block should not be marked as 'cached'
3012  if(!addr) {
3014  goto EO_WCache_D;
3015  }
3016  block_type = Cache->CheckUsedProc(Context, Lba);
3017  if(block_type == WCACHE_BLOCK_USED) {
3018  status = Cache->ReadProc(Context, addr, BS, Lba, &_ReadBytes, PH_TMP_BUFFER);
3019  if(Cache->RememberBB) {
3020  if(!OS_SUCCESS(status)) {
3021  RtlZeroMemory(addr, BS);
3022  //WCacheSetBadFlag(block_array,i);
3023  }
3024  }
3025  } else {
3026  if(block_type & WCACHE_BLOCK_BAD) {
3027  DbgFreePool(addr);
3028  addr = NULL;
3030  goto EO_WCache_D;
3031  }
3032  if(!(block_type & WCACHE_BLOCK_ZERO)) {
3033  BrutePoint();
3034  }
3036  RtlZeroMemory(addr, BS);
3037  }
3038  // now add pointer to buffer to common storage
3039  block_array[i].Sector = addr;
3040  WCacheInsertItemToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba);
3041  if(Modified) {
3042  WCacheInsertItemToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3043  WCacheSetModFlag(block_array, i);
3044  }
3045  Cache->FrameList[frame].BlockCount ++;
3046  } else {
3047  // block is not cached
3048  // just return pointer
3049  block_type = Cache->CheckUsedProc(Context, Lba);
3050  if(block_type & WCACHE_BLOCK_BAD) {
3051  //if(WCacheGetBadFlag(block_array,i)) {
3052  // bad packet. no pre-read
3054  goto EO_WCache_D;
3055  }
3056 #ifndef UDF_CHECK_UTIL
3057  ASSERT(block_type & WCACHE_BLOCK_USED);
3058 #else
3059  if(!(block_type & WCACHE_BLOCK_USED)) {
3060  UDFPrint(("LBA %#x is not marked as used\n", Lba));
3061  }
3062 #endif
3063  if(Modified &&
3064  !WCacheGetModFlag(block_array, i)) {
3065  WCacheInsertItemToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3066  WCacheSetModFlag(block_array, i);
3067  }
3068  }
3069  (*CachedBlock) = addr;
3070 
3071 EO_WCache_D:
3072 
3073  return status;
3074 } // end WCacheDirect__()
signed char * PCHAR
Definition: retypes.h:7
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
#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 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
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 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
smooth NULL
Definition: ftsmooth.c:416
#define WCACHE_BLOCK_BAD
Definition: wcache_lib.h:56
#define DbgFreePool
Definition: env_spec_w32.h:334
#define PCHAR
Definition: match.c:90
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:78
#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:261
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 3519 of file wcache_lib.cpp.

3525 {
3526  ULONG frame;
3527  lba_t firstLba;
3528  lba_t* List;
3529  lba_t Lba;
3530  PW_CACHE_ENTRY block_array;
3531  BOOLEAN mod;
3532  ULONG i;
3533 
3534  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
3535 
3536  UDFPrint((" Discard req: %x@%x\n",BCount, ReqLba));
3537 
3538  List = Cache->CachedBlocksList;
3539  if(!List) {
3541  return;
3542  }
3543  i = WCacheGetSortedListIndex(Cache->BlockCount, List, ReqLba);
3544 
3545  // enumerate requested blocks
3546  while((List[i] < (ReqLba+BCount)) && (i < Cache->BlockCount)) {
3547 
3548  Lba = List[i];
3549  frame = Lba >> Cache->BlocksPerFrameSh;
3550  firstLba = frame << Cache->BlocksPerFrameSh;
3551  block_array = Cache->FrameList[frame].Frame;
3552  if(!block_array) {
3554  BrutePoint();
3555  return;
3556  }
3557  // check if modified
3558  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3559  // just discard
3560 
3561  // mark as non-cached & free pool
3562  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3563  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3564  if(mod)
3565  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3566  // mark as non-cached & free pool
3567  WCacheFreeSector(frame, Lba-firstLba);
3568  // check if frame is empty
3569  if(!Cache->FrameList[frame].BlockCount) {
3570  WCacheRemoveFrame(Cache, Context, frame);
3571  } else {
3572  ASSERT(Cache->FrameList[frame].Frame);
3573  }
3574  } else {
3575  // we should never get here !!!
3576  // getting this part of code means that we have
3577  // placed non-cached block in CachedBlocksList
3578  BrutePoint();
3579  }
3580  }
3582 } // end WCacheDiscardBlocks__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
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
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
LIST_ENTRY List
Definition: psmgr.c:57
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:1273

Referenced by UDFMarkSpaceAsXXXNoProtect_().

◆ WCacheEODirect__()

OSSTATUS WCacheEODirect__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3082 of file wcache_lib.cpp.

3086 {
3088  return STATUS_SUCCESS;
3089 } // 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
return STATUS_SUCCESS
Definition: btrfs.c:2966

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
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 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
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
static int mod
Definition: i386-dis.c:1273

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 2559 of file wcache_lib.cpp.

2562 {
2563  if(!(Cache->ReadProc)) return;
2564  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2565 
2566  switch(Cache->Mode) {
2567  case WCACHE_MODE_RAM:
2569  break;
2570  case WCACHE_MODE_ROM:
2571  case WCACHE_MODE_RW:
2573  break;
2574  case WCACHE_MODE_R:
2576  break;
2577  }
2578 
2580  return;
2581 } // end WCacheFlushAll__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
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 1809 of file wcache_lib.cpp.

1813 {
1814  ULONG frame;
1815  lba_t firstLba;
1816  lba_t* List = Cache->CachedBlocksList;
1817  lba_t lastLba;
1818  ULONG firstPos;
1819  ULONG lastPos;
1820  PW_CACHE_ENTRY block_array;
1821 // OSSTATUS status;
1822 
1823  // flush frames
1824  while(Cache->WriteCount) {
1825 
1826  frame = Cache->CachedModifiedBlocksList[0] >> Cache->BlocksPerFrameSh;
1827 
1828  firstLba = frame << Cache->BlocksPerFrameSh;
1829  lastLba = firstLba + Cache->BlocksPerFrame;
1830  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1831  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1832  block_array = Cache->FrameList[frame].Frame;
1833 
1834  if(!block_array) {
1835  UDFPrint(("Hmm...\n"));
1836  BrutePoint();
1838  }
1839  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, FALSE);
1840 
1841  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1842  }
1843 
1844  return STATUS_SUCCESS;
1845 } // end WCacheFlushAllRAM()
#define UDFPrint(Args)
Definition: udffs.h:225
Definition: fatfs.h:173
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
LIST_ENTRY List
Definition: psmgr.c:57
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
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
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by WCacheFlushAll__().

◆ WCacheFlushAllRW()

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

Definition at line 2688 of file wcache_lib.cpp.

2691 {
2692  ULONG frame;
2693  lba_t firstLba;
2694  lba_t* List = Cache->CachedModifiedBlocksList;
2695  lba_t Lba;
2696 // ULONG firstPos;
2697 // ULONG lastPos;
2698  ULONG BSh = Cache->BlockSizeSh;
2699  ULONG BS = Cache->BlockSize;
2700  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2701  ULONG PSs = Cache->PacketSize;
2702  ULONG BFs = Cache->BlocksPerFrameSh;
2703  PW_CACHE_ENTRY block_array;
2704 // OSSTATUS status;
2705  SIZE_T ReadBytes;
2706  PW_CACHE_ASYNC FirstWContext = NULL;
2707  PW_CACHE_ASYNC PrevWContext = NULL;
2708  ULONG i;
2709  ULONG chain_count = 0;
2710 
2711  if(!(Cache->ReadProc)) return;
2712 
2713  // walk through modified blocks
2714  while(Cache->WriteCount) {
2715  Lba = List[0] & ~(PSs-1);
2716  frame = Lba >> BFs;
2717  firstLba = frame << BFs;
2718 // firstPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba);
2719 // lastPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba+PSs);
2720  block_array = Cache->FrameList[frame].Frame;
2721  if(!block_array) {
2722  BrutePoint();
2723  continue;;
2724  }
2725  // queue modify request
2726  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2727  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2728  // clear MODIFIED flag for queued blocks
2729  WCacheRemoveRangeFromList(List, &(Cache->WriteCount), Lba, PSs);
2730  Lba -= firstLba;
2731  for(i=0; i<PSs; i++) {
2732  WCacheClrModFlag(block_array, Lba+i);
2733  }
2734  chain_count++;
2735  // check queue size
2736  if(chain_count >= WCACHE_MAX_CHAIN) {
2737  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2738  chain_count = 0;
2739  }
2740  }
2741  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2742 #ifdef DBG
2743 #if 1
2744  // check consistency
2745  List = Cache->CachedBlocksList;
2746  for(i=0; i<Cache->BlockCount; i++) {
2747  Lba = List[i] /*& ~(PSs-1)*/;
2748  frame = Lba >> Cache->BlocksPerFrameSh;
2749  firstLba = frame << Cache->BlocksPerFrameSh;
2750  block_array = Cache->FrameList[frame].Frame;
2751  if(!block_array) {
2752  BrutePoint();
2753  }
2754  ASSERT(!WCacheGetModFlag(block_array, Lba-firstLba));
2755  }
2756 #endif // 1
2757 #endif // DBG
2758  return;
2759 } // end WCacheFlushAllRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
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
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
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)
smooth NULL
Definition: ftsmooth.c:416
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
LIST_ENTRY List
Definition: psmgr.c:57
#define BrutePoint()
Definition: env_spec_w32.h:504
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:78
#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 2898 of file wcache_lib.cpp.

2904 {
2905  OSSTATUS status;
2906 
2907  if(!(Cache->ReadProc)) return STATUS_INVALID_PARAMETER;
2908  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2909 
2910  // check if we try to access beyond cached area
2911  if((Lba < Cache->FirstLba) ||
2912  (Lba+BCount-1 > Cache->LastLba)) {
2913  UDFPrint(("LBA %#x (%x) is beyond cacheable area\n", Lba, BCount));
2914  BrutePoint();
2916  goto EO_WCache_F;
2917  }
2918 
2919  switch(Cache->Mode) {
2920  case WCACHE_MODE_RAM:
2921 // WCacheFlushBlocksRW(Cache, Context);
2922 // break;
2923  case WCACHE_MODE_ROM:
2924  case WCACHE_MODE_RW:
2925  status = WCacheFlushBlocksRW(Cache, Context, Lba, BCount);
2926  break;
2927  case WCACHE_MODE_R:
2929  break;
2930  }
2931 EO_WCache_F:
2933  return status;
2934 } // end WCacheFlushBlocks__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#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
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 1536 of file wcache_lib.cpp.

1545 {
1546  ULONG frame;
1547  lba_t Lba;
1548  lba_t PrevLba;
1549  lba_t firstLba;
1550  PCHAR tmp_buff = NULL;
1551  ULONG n;
1552  ULONG BSh = Cache->BlockSizeSh;
1553  ULONG BS = Cache->BlockSize;
1554 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
1555  ULONG PSs = Cache->PacketSize;
1556  SIZE_T _WrittenBytes;
1558 
1559  frame = List[firstPos] >> Cache->BlocksPerFrameSh;
1560  firstLba = frame << Cache->BlocksPerFrameSh;
1561 
1562  while(firstPos < lastPos) {
1563  // flush blocks
1564  ASSERT(Cache->FrameCount <= Cache->MaxFrames);
1565  Lba = List[firstPos];
1566  if(!WCacheGetModFlag(block_array, Lba - firstLba)) {
1567  // free memory
1568  if(Purge) {
1569  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, 1);
1570  }
1571  firstPos++;
1572  continue;
1573  }
1574  tmp_buff = Cache->tmp_buff;
1575  PrevLba = Lba;
1576  n=1;
1577  while((firstPos+n < lastPos) &&
1578  (List[firstPos+n] == PrevLba+1)) {
1579  PrevLba++;
1580  if(!WCacheGetModFlag(block_array, PrevLba - firstLba))
1581  break;
1582  DbgCopyMemory(tmp_buff + (n << BSh),
1583  (PVOID)WCacheSectorAddr(block_array, PrevLba - firstLba),
1584  BS);
1585  n++;
1586  if(n >= PSs)
1587  break;
1588  }
1589  if(n > 1) {
1590  DbgCopyMemory(tmp_buff,
1591  (PVOID)WCacheSectorAddr(block_array, Lba - firstLba),
1592  BS);
1593  } else {
1594  tmp_buff = (PCHAR)WCacheSectorAddr(block_array, Lba - firstLba);
1595  }
1596  // write sectors out
1597  status = Cache->WriteProc(Context, tmp_buff, n<<BSh, Lba, &_WrittenBytes, 0);
1598  if(!OS_SUCCESS(status)) {
1599  status = WCacheRaiseIoError(Cache, Context, status, Lba, n, tmp_buff, WCACHE_W_OP, NULL);
1600  if(!OS_SUCCESS(status)) {
1601  BrutePoint();
1602  }
1603  }
1604  firstPos += n;
1605  if(Purge) {
1606  // free memory
1607  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, n);
1608  } else {
1609  // clear Modified flag
1610  ULONG i;
1611  Lba -= firstLba;
1612  for(i=0; i<n; i++) {
1613  WCacheClrModFlag(block_array, Lba+i);
1614  }
1615  }
1616  }
1617 
1618  return status;
1619 } // 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
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
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
smooth NULL
Definition: ftsmooth.c:416
#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
LIST_ENTRY List
Definition: psmgr.c:57
#define BrutePoint()
Definition: env_spec_w32.h:504
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define DbgCopyMemory
Definition: env_spec_w32.h:331
#define WCacheGetModFlag(block_array, i)
Definition: wcache_lib.cpp:828
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 2824 of file wcache_lib.cpp.

2830 {
2831  ULONG frame;
2832  lba_t firstLba;
2833  lba_t* List = Cache->CachedModifiedBlocksList;
2834  lba_t Lba;
2835 // ULONG firstPos;
2836 // ULONG lastPos;
2837  ULONG BSh = Cache->BlockSizeSh;
2838  ULONG BS = Cache->BlockSize;
2839  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2840  ULONG PSs = Cache->PacketSize;
2841  ULONG BFs = Cache->BlocksPerFrameSh;
2842  PW_CACHE_ENTRY block_array;
2843 // OSSTATUS status;
2844  SIZE_T ReadBytes;
2845  PW_CACHE_ASYNC FirstWContext = NULL;
2846  PW_CACHE_ASYNC PrevWContext = NULL;
2847  ULONG i;
2848  ULONG chain_count = 0;
2849  lba_t lim;
2850 
2851  if(!(Cache->ReadProc)) return STATUS_INVALID_PARAMETER;
2852 
2853  // walk through modified blocks
2854  lim = (_Lba+BCount+PSs-1) & ~(PSs-1);
2855  for(Lba = _Lba & ~(PSs-1);Lba < lim ; Lba += PSs) {
2856  frame = Lba >> BFs;
2857  firstLba = frame << BFs;
2858 // firstPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba);
2859 // lastPos = WCacheGetSortedListIndex(Cache->WriteCount, List, Lba+PSs);
2860  block_array = Cache->FrameList[frame].Frame;
2861  if(!block_array) {
2862  // not cached block may be requested for flush
2863  Lba += (1 << BFs) - PSs;
2864  continue;
2865  }
2866  // queue modify request
2867  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2868  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2869  // clear MODIFIED flag for queued blocks
2870  WCacheRemoveRangeFromList(List, &(Cache->WriteCount), Lba, PSs);
2871  Lba -= firstLba;
2872  for(i=0; i<PSs; i++) {
2873  WCacheClrModFlag(block_array, Lba+i);
2874  }
2875  Lba += firstLba;
2876  chain_count++;
2877  // check queue size
2878  if(chain_count >= WCACHE_MAX_CHAIN) {
2879  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2880  chain_count = 0;
2881  }
2882  }
2883  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2884 /*
2885  if(Cache->Mode != WCACHE_MODE_RAM)
2886  return STATUS_SUCCESS;
2887 */
2888 
2889  return STATUS_SUCCESS;
2890 } // end WCacheFlushBlocksRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#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
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
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)
smooth NULL
Definition: ftsmooth.c:416
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
LIST_ENTRY List
Definition: psmgr.c:57
#define ASYNC_STATE_NONE
Definition: wcache_lib.cpp:41
Definition: wcache_lib.h:97
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:78
unsigned int ULONG
Definition: retypes.h:1
uint32 lba_t
Definition: platform.h:20
return STATUS_SUCCESS
Definition: btrfs.c:2966

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 1185 of file wcache_lib.cpp.

1193 {
1194  ULONG i;
1195  // mark as non-cached & free pool
1196  for(i=0; i<PSs; i++, offs++) {
1197  if(WCacheSectorAddr(block_array,offs)) {
1198  WCacheFreeSector(frame, offs);
1199  }
1200  }
1201 } // end WCacheFreePacket()
#define WCacheFreeSector(frame, offs)
Definition: wcache_lib.cpp:873
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 WCacheSectorAddr(block_array, i)
Definition: wcache_lib.cpp:864
unsigned int ULONG
Definition: retypes.h:1

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

◆ WCacheGetMode__()

ULONG WCacheGetMode__ ( IN PW_CACHE  Cache)

Definition at line 3440 of file wcache_lib.cpp.

3443 {
3444  return Cache->Mode;
3445 } // 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 }
int add
Definition: i386-dis.c:3122
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
LIST_ENTRY List
Definition: psmgr.c:57
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
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
jmp_buf jmp
Definition: mach.c:35

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

◆ WCacheGetWriteBlockCount__()

ULONG WCacheGetWriteBlockCount__ ( IN PW_CACHE  Cache)

Definition at line 3454 of file wcache_lib.cpp.

3457 {
3458  return Cache->WriteCount;
3459 } // 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:4250
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define WCLOCK_RES
#define OSSTATUS
Definition: env_spec_w32.h:57
#define WCACHE_MODE_MAX
Definition: wcache_lib.h:129
smooth NULL
Definition: ftsmooth.c:416
#define try_return(S)
Definition: cdprocs.h:2189
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
ULONG LowPart
Definition: typedefs.h:104
#define NOTHING
Definition: env_spec_w32.h:461
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
_SEH2_END
Definition: create.c:4424
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
_SEH2_FINALLY
Definition: create.c:4395
unsigned int * PULONG
Definition: retypes.h:1
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
uint32 lba_t
Definition: platform.h:20
return STATUS_SUCCESS
Definition: btrfs.c:2966

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:63
r l[0]
Definition: byte_order.h:167
#define BrutePoint()
Definition: env_spec_w32.h:504
Definition: wcache_lib.h:97
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:261

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:301
LIST_ENTRY List
Definition: psmgr.c:57
#define DbgMoveMemory
Definition: env_spec_w32.h:329
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:301
LIST_ENTRY List
Definition: psmgr.c:57
#define DbgMoveMemory
Definition: env_spec_w32.h:329
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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 3126 of file wcache_lib.cpp.

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

◆ WCacheIsInitialized__()

BOOLEAN WCacheIsInitialized__ ( IN PW_CACHE  Cache)

Definition at line 2816 of file wcache_lib.cpp.

2819 {
2820  return (Cache->ReadProc != NULL);
2821 } // end WCacheIsInitialized__()
Definition: fatfs.h:173
smooth NULL
Definition: ftsmooth.c:416

Referenced by UDFVerifyVolume(), and UDFWriteInSector().

◆ WCachePreReadPacket__()

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

Definition at line 1855 of file wcache_lib.cpp.

1860 {
1861  ULONG frame;
1863  PW_CACHE_ENTRY block_array;
1864  ULONG BSh = Cache->BlockSizeSh;
1865  ULONG BS = Cache->BlockSize;
1866  PCHAR addr;
1867  SIZE_T _ReadBytes;
1868  ULONG PS = Cache->PacketSize; // (in blocks)
1869  ULONG BCount = PS;
1870  ULONG i, n, err_count;
1871  BOOLEAN sector_added = FALSE;
1872  ULONG block_type;
1873  BOOLEAN zero = FALSE;//TRUE;
1874 /*
1875  ULONG first_zero=0, last_zero=0;
1876  BOOLEAN count_first_zero = TRUE;
1877 */
1878 
1879  Lba &= ~(PS-1);
1880  frame = Lba >> Cache->BlocksPerFrameSh;
1881  i = Lba - (frame << Cache->BlocksPerFrameSh);
1882 
1883  // assume successful operation
1884  block_array = Cache->FrameList[frame].Frame;
1885  if(!block_array) {
1886  ASSERT(Cache->FrameCount < Cache->MaxFrames);
1887  block_array = WCacheInitFrame(Cache, Context, frame);
1888  if(!block_array)
1890  }
1891 
1892  // skip cached extent (if any)
1893  n=0;
1894  while((n < BCount) &&
1895  (n < Cache->BlocksPerFrame)) {
1896 
1897  addr = (PCHAR)WCacheSectorAddr(block_array, i+n);
1898  block_type = Cache->CheckUsedProc(Context, Lba+n);
1899  if(/*WCacheGetBadFlag(block_array,i+n)*/
1900  block_type & WCACHE_BLOCK_BAD) {
1901  // bad packet. no pre-read
1902  return STATUS_DEVICE_DATA_ERROR;
1903  }
1904  if(!(block_type & WCACHE_BLOCK_ZERO)) {
1905  zero = FALSE;
1906  //count_first_zero = FALSE;
1907  //last_zero = 0;
1908  if(!addr) {
1909  // sector is not cached, stop search
1910  break;
1911  }
1912  } else {
1913 /*
1914  if(count_first_zero) {
1915  first_zero++;
1916  }
1917  last_zero++;
1918 */
1919  }
1920  n++;
1921  }
1922  // do nothing if all sectors are already cached
1923  if(n < BCount) {
1924 
1925  // read whole packet
1926  if(!zero) {
1927  status = Cache->ReadProc(Context, Cache->tmp_buff_r, PS<<BSh, Lba, &_ReadBytes, PH_TMP_BUFFER);
1928  if(!OS_SUCCESS(status)) {
1929  status = WCacheRaiseIoError(Cache, Context, status, Lba, PS, Cache->tmp_buff_r, WCACHE_R_OP, NULL);
1930  }
1931  } else {
1933  //RtlZeroMemory(Cache->tmp_buff_r, PS<<BSh);
1934  _ReadBytes = PS<<BSh;
1935  }
1936  if(OS_SUCCESS(status)) {
1937  // and now we'll copy them to cache
1938  for(n=0; n<BCount; n++, i++) {
1939  if(WCacheSectorAddr(block_array,i)) {
1940  continue;
1941  }
1943  if(!addr) {
1944  BrutePoint();
1945  break;
1946  }
1947  sector_added = TRUE;
1948  if(!zero) {
1949  DbgCopyMemory(addr, Cache->tmp_buff_r+(n<<BSh), BS);
1950  } else {
1951  RtlZeroMemory(addr, BS);
1952  }
1953  Cache->FrameList[frame].BlockCount++;
1954  }
1955  } else {
1956  // read sectors one by one and copy them to cache
1957  // unreadable sectors will be treated as zero-filled
1958  err_count = 0;
1959  for(n=0; n<BCount; n++, i++) {
1960  if(WCacheSectorAddr(block_array,i)) {
1961  continue;
1962  }
1964  if(!addr) {
1965  BrutePoint();
1966  break;
1967  }
1968  sector_added = TRUE;
1969  status = Cache->ReadProc(Context, Cache->tmp_buff_r, BS, Lba+n, &_ReadBytes, PH_TMP_BUFFER);
1970  if(!OS_SUCCESS(status)) {
1971  status = WCacheRaiseIoError(Cache, Context, status, Lba+n, 1, Cache->tmp_buff_r, WCACHE_R_OP, NULL);
1972  if(!OS_SUCCESS(status)) {
1973  err_count++;
1974  }
1975  }
1976  if(!zero && OS_SUCCESS(status)) {
1977  DbgCopyMemory(addr, Cache->tmp_buff_r, BS);
1978  } else
1979  if(Cache->RememberBB) {
1980  RtlZeroMemory(addr, BS);
1981  /*
1982  if(!OS_SUCCESS(status)) {
1983  WCacheSetBadFlag(block_array,i);
1984  }
1985  */
1986  }
1987  Cache->FrameList[frame].BlockCount++;
1988  if(err_count >= 2) {
1989  break;
1990  }
1991  }
1992 // _ReadBytes = n<<BSh;
1993  }
1994  }
1995 
1996  // we know the number of unread sectors if an error occured
1997  // so we can need to update BlockCount
1998  // return number of read bytes
1999  if(sector_added)
2000  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, n);
2001 
2002  return status;
2003 } // 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 TRUE
Definition: types.h:120
#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
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
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 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
smooth NULL
Definition: ftsmooth.c:416
#define WCACHE_BLOCK_BAD
Definition: wcache_lib.h:56
#define PCHAR
Definition: match.c:90
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static double zero
Definition: j0_y0.c:96
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:78
#define DbgCopyMemory
Definition: env_spec_w32.h:331
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 2589 of file wcache_lib.cpp.

2592 {
2593  if(!(Cache->ReadProc)) return;
2594  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2595 
2596  switch(Cache->Mode) {
2597  case WCACHE_MODE_RAM:
2599  break;
2600  case WCACHE_MODE_ROM:
2601  case WCACHE_MODE_RW:
2603  break;
2604  case WCACHE_MODE_R:
2606  break;
2607  }
2608 
2610  return;
2611 } // end WCachePurgeAll__()
VOID __fastcall WCachePurgeAllRW(IN PW_CACHE Cache, IN PVOID Context)
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
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 3311 of file wcache_lib.cpp.

3314 {
3315  ULONG frame;
3316  lba_t firstLba;
3317  lba_t* List = Cache->CachedBlocksList;
3318  lba_t Lba;
3319  PCHAR tmp_buff = Cache->tmp_buff;
3320  ULONG BSh = Cache->BlockSizeSh;
3321  ULONG BS = Cache->BlockSize;
3322 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3323 // ULONG PSs = Cache->PacketSize;
3324  PW_CACHE_ENTRY block_array;
3325  BOOLEAN mod;
3326  OSSTATUS status;
3327  SIZE_T ReadBytes;
3328  ULONG MaxReloc = Cache->PacketSize;
3329  PULONG reloc_tab = Cache->reloc_tab;
3330  ULONG RelocCount = 0;
3331  BOOLEAN IncompletePacket;
3332  ULONG i=0;
3333  ULONG PacketTail;
3334 
3335  while(Cache->WriteCount < Cache->BlockCount) {
3336 
3337  Lba = List[i];
3338  frame = Lba >> Cache->BlocksPerFrameSh;
3339  firstLba = frame << Cache->BlocksPerFrameSh;
3340  block_array = Cache->FrameList[frame].Frame;
3341  if(!block_array) {
3342  BrutePoint();
3343  return;
3344  }
3345  // check if modified
3346  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3347  // just discard
3348  if(!mod || !(Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3349  // mark as non-cached & free pool
3350  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3351  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3352  if(mod)
3353  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3354  // mark as non-cached & free pool
3355  WCacheFreeSector(frame, Lba-firstLba);
3356  // check if frame is empty
3357  if(!Cache->FrameList[frame].BlockCount) {
3358  WCacheRemoveFrame(Cache, Context, frame);
3359  }
3360  } else {
3361  BrutePoint();
3362  }
3363  } else {
3364  i++;
3365  }
3366  }
3367 
3368  PacketTail = Cache->WriteCount & (MaxReloc-1);
3369  IncompletePacket = (Cache->WriteCount >= MaxReloc) ? FALSE : TRUE;
3370 
3371  // remove(flush) packet
3372  while((Cache->WriteCount > PacketTail) || (Cache->WriteCount && IncompletePacket)) {
3373 
3374  Lba = List[0];
3375  frame = Lba >> Cache->BlocksPerFrameSh;
3376  firstLba = frame << Cache->BlocksPerFrameSh;
3377  block_array = Cache->FrameList[frame].Frame;
3378  if(!block_array) {
3379  BrutePoint();
3380  return;
3381  }
3382  // check if modified
3383  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3384  // pack/reloc/write
3385  if(mod) {
3386  DbgCopyMemory(tmp_buff + (RelocCount << BSh),
3387  (PVOID)WCacheSectorAddr(block_array, Lba-firstLba),
3388  BS);
3389  reloc_tab[RelocCount] = Lba;
3390  RelocCount++;
3391  // write packet
3392  if((RelocCount >= MaxReloc) || (Cache->BlockCount == 1)) {
3393 // status = Cache->WriteProcAsync(Context, tmp_buff, PS, Lba, &ReadBytes, FALSE);
3394  Cache->UpdateRelocProc(Context, NULL, reloc_tab, RelocCount);
3395  status = Cache->WriteProc(Context, tmp_buff, RelocCount<<BSh, NULL, &ReadBytes, 0);
3396  if(!OS_SUCCESS(status)) {
3397  status = WCacheRaiseIoError(Cache, Context, status, NULL, RelocCount, tmp_buff, WCACHE_W_OP, NULL);
3398  }
3399  RelocCount = 0;
3400  }
3401  WCacheRemoveItemFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba);
3402  } else {
3403  BrutePoint();
3404  }
3405  // mark as non-cached & free pool
3406  if(WCacheSectorAddr(block_array,Lba-firstLba)) {
3407  WCacheRemoveItemFromList(List, &(Cache->BlockCount), Lba);
3408  // mark as non-cached & free pool
3409  WCacheFreeSector(frame, Lba-firstLba);
3410  // check if frame is empty
3411  if(!Cache->FrameList[frame].BlockCount) {
3412  WCacheRemoveFrame(Cache, Context, frame);
3413  }
3414  } else {
3415  BrutePoint();
3416  }
3417  }
3418 } // end WCachePurgeAllR()
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#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
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 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
smooth NULL
Definition: ftsmooth.c:416
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
LIST_ENTRY List
Definition: psmgr.c:57
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
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define DbgCopyMemory
Definition: env_spec_w32.h:331
unsigned int * PULONG
Definition: retypes.h:1
#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:1273
Definition: ps.c:97

Referenced by WCacheFlushAll__(), and WCachePurgeAll__().

◆ WCachePurgeAllRAM()

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

Definition at line 1761 of file wcache_lib.cpp.

1765 {
1766  ULONG frame;
1767  lba_t firstLba;
1768  lba_t* List = Cache->CachedBlocksList;
1769  lba_t lastLba;
1770  ULONG firstPos;
1771  ULONG lastPos;
1772  PW_CACHE_ENTRY block_array;
1773 // OSSTATUS status;
1774 
1775  // remove(flush) some frames
1776  while(Cache->FrameCount) {
1777 
1778  frame = Cache->CachedFramesList[0];
1779 
1780  firstLba = frame << Cache->BlocksPerFrameSh;
1781  lastLba = firstLba + Cache->BlocksPerFrame;
1782  firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, firstLba);
1783  lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, lastLba);
1784  block_array = Cache->FrameList[frame].Frame;
1785 
1786  if(!block_array) {
1787  UDFPrint(("Hmm...\n"));
1788  BrutePoint();
1790  }
1791  WCacheFlushBlocksRAM(Cache, Context, block_array, List, firstPos, lastPos, TRUE);
1792 
1793  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), firstLba, Cache->BlocksPerFrame);
1794  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), firstLba, Cache->BlocksPerFrame);
1795  WCacheRemoveFrame(Cache, Context, frame);
1796  }
1797 
1798  ASSERT(!Cache->FrameCount);
1799  ASSERT(!Cache->BlockCount);
1800  return STATUS_SUCCESS;
1801 } // end WCachePurgeAllRAM()
#define UDFPrint(Args)
Definition: udffs.h:225
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
ULONG WCacheGetSortedListIndex(IN ULONG BlockCount, IN lba_t *List, IN lba_t Lba)
Definition: wcache_lib.cpp:449
LIST_ENTRY List
Definition: psmgr.c:57
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
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
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by WCachePurgeAll__().

◆ WCachePurgeAllRW()

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

Definition at line 2621 of file wcache_lib.cpp.

2624 {
2625  ULONG frame;
2626  lba_t firstLba;
2627  lba_t* List = Cache->CachedBlocksList;
2628  lba_t Lba;
2629 // ULONG firstPos;
2630 // ULONG lastPos;
2631  ULONG BSh = Cache->BlockSizeSh;
2632  ULONG BS = Cache->BlockSize;
2633  ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
2634  ULONG PSs = Cache->PacketSize;
2635  PW_CACHE_ENTRY block_array;
2636 // OSSTATUS status;
2637  SIZE_T ReadBytes;
2638  PW_CACHE_ASYNC FirstWContext = NULL;
2639  PW_CACHE_ASYNC PrevWContext = NULL;
2640  ULONG chain_count = 0;
2641 
2642  if(!(Cache->ReadProc)) return;
2643 
2644  while(Cache->BlockCount) {
2645  Lba = List[0] & ~(PSs-1);
2646  frame = Lba >> Cache->BlocksPerFrameSh;
2647  firstLba = frame << Cache->BlocksPerFrameSh;
2648 // firstPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba);
2649 // lastPos = WCacheGetSortedListIndex(Cache->BlockCount, List, Lba+PSs);
2650  block_array = Cache->FrameList[frame].Frame;
2651  if(!block_array) {
2652  BrutePoint();
2653  return;
2654  }
2655 
2656  WCacheUpdatePacket(Cache, Context, &FirstWContext, &PrevWContext, block_array, firstLba,
2657  Lba, BSh, BS, PS, PSs, &ReadBytes, TRUE, ASYNC_STATE_NONE);
2658 
2659  // free memory
2660  WCacheFreePacket(Cache, frame, block_array, Lba-firstLba, PSs);
2661 
2662  WCacheRemoveRangeFromList(List, &(Cache->BlockCount), Lba, PSs);
2663  WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, PSs);
2664  // check if frame is empty
2665  if(!(Cache->FrameList[frame].BlockCount)) {
2666  WCacheRemoveFrame(Cache, Context, frame);
2667  } else {
2668  ASSERT(Cache->FrameList[frame].Frame);
2669  }
2670  chain_count++;
2671  if(chain_count >= WCACHE_MAX_CHAIN) {
2672  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext, FALSE);
2673  chain_count = 0;
2674  }
2675  }
2676  WCacheUpdatePacketComplete(Cache, Context, &FirstWContext, &PrevWContext);
2677  return;
2678 } // end WCachePurgeAllRW()
#define WCACHE_MAX_CHAIN
Definition: wcache_lib.cpp:52
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
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
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)
smooth NULL
Definition: ftsmooth.c:416
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
LIST_ENTRY List
Definition: psmgr.c:57
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:78
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 PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
#define WCACHE_ERROR_READ
Definition: wcache_lib.h:66
#define WCACHE_ERROR_WRITE
Definition: wcache_lib.h:67
Status
Definition: gdiplustypes.h:24
struct _WCACHE_ERROR_CONTEXT::@954::@956 ReadWrite
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

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 2011 of file wcache_lib.cpp.

2021 {
2022  ULONG frame;
2023  ULONG i, saved_i, saved_BC = BCount, n;
2025  PW_CACHE_ENTRY block_array;
2026  ULONG BSh = Cache->BlockSizeSh;
2027  SIZE_T BS = Cache->BlockSize;
2028  PCHAR addr;
2029  ULONG to_read, saved_to_read;
2030 // PCHAR saved_buff = Buffer;
2031  SIZE_T _ReadBytes;
2032  ULONG PS = Cache->PacketSize;
2033  ULONG MaxR = Cache->MaxBytesToRead;
2034  ULONG PacketMask = PS-1; // here we assume that Packet Size value is 2^n
2035  ULONG d;
2036  ULONG block_type;
2037 
2038  WcPrint(("WC:R %x (%x)\n", Lba, BCount));
2039 
2040  (*ReadBytes) = 0;
2041  // check if we try to read too much data
2042  if(BCount >= Cache->MaxBlocks) {
2043  i = 0;
2044  if(CachedOnly) {
2046  goto EO_WCache_R2;
2047  }
2048  while(TRUE) {
2049  status = WCacheReadBlocks__(Cache, Context, Buffer + (i<<BSh), Lba, PS, &_ReadBytes, FALSE);
2050  (*ReadBytes) += _ReadBytes;
2051  if(!OS_SUCCESS(status) || (BCount <= PS)) break;
2052  BCount -= PS;
2053  Lba += PS;
2054  i += PS;
2055  }
2056  return status;
2057  }
2058  // check if we try to access beyond cached area
2059  if((Lba < Cache->FirstLba) ||
2060  (Lba + BCount - 1 > Cache->LastLba)) {
2061  status = Cache->ReadProc(Context, Buffer, BCount, Lba, ReadBytes, 0);
2062  if(!OS_SUCCESS(status)) {
2064  }
2065  return status;
2066  }
2067  if(!CachedOnly) {
2068  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2069  }
2070 
2071  frame = Lba >> Cache->BlocksPerFrameSh;
2072  i = Lba - (frame << Cache->BlocksPerFrameSh);
2073 
2074  if(Cache->CacheWholePacket && (BCount < PS)) {
2075  if(!CachedOnly &&
2076  !OS_SUCCESS(status = WCacheCheckLimits(Cache, Context, Lba & ~(PS-1), PS*2)) ) {
2078  return status;
2079  }
2080  } else {
2081  if(!CachedOnly &&
2082  !OS_SUCCESS(status = WCacheCheckLimits(Cache, Context, Lba, BCount))) {
2084  return status;
2085  }
2086  }
2087  if(!CachedOnly) {
2088  // convert to shared
2089 // ExConvertExclusiveToSharedLite(&(Cache->WCacheLock));
2090  }
2091 
2092  // pre-read packet. It is very useful for
2093  // highly fragmented files
2094  if(Cache->CacheWholePacket && (BCount < PS)) {
2095 // status = WCacheReadBlocks__(Cache, Context, Cache->tmp_buff_r, Lba & (~PacketMask), PS, &_ReadBytes, TRUE);
2096  // we should not perform IO if user requested CachedOnly data
2097  if(!CachedOnly) {
2099  }
2101  }
2102 
2103  // assume successful operation
2104  block_array = Cache->FrameList[frame].Frame;
2105  if(!block_array) {
2106  ASSERT(!CachedOnly);
2107  ASSERT(Cache->FrameCount < Cache->MaxFrames);
2108  block_array = WCacheInitFrame(Cache, Context, frame);
2109  if(!block_array) {
2111  goto EO_WCache_R;
2112  }
2113  }
2114 
2115  Cache->FrameList[frame].AccessCount++;
2116  while(BCount) {
2117  if(i >= Cache->BlocksPerFrame) {
2118  frame++;
2119  block_array = Cache->FrameList[frame].Frame;
2120  i -= Cache->BlocksPerFrame;
2121  }
2122  if(!block_array) {
2123  ASSERT(Cache->FrameCount < Cache->MaxFrames);
2124  block_array = WCacheInitFrame(Cache, Context, frame);
2125  if(!block_array) {
2127  goto EO_WCache_R;
2128  }
2129  }
2130  // 'read' cached extent (if any)
2131  // it is just copying
2132  while(BCount &&
2133  (i < Cache->BlocksPerFrame) &&
2134  (addr = (PCHAR)WCacheSectorAddr(block_array, i)) ) {
2135  block_type = Cache->CheckUsedProc(Context, Lba+saved_BC-BCount);
2136  if(block_type & WCACHE_BLOCK_BAD) {
2137  //if(WCacheGetBadFlag(block_array,i)) {
2139  goto EO_WCache_R;
2140  }
2142  Buffer += BS;
2143  *ReadBytes += BS;
2144  i++;
2145  BCount--;
2146  }
2147  // read non-cached packet-size-aligned extent (if any)
2148  // now we'll calculate total length & decide if it has enough size
2149  if(!((d = Lba+saved_BC-BCount) & PacketMask) && d ) {
2150  n = 0;
2151  while(BCount &&
2152  (i < Cache->BlocksPerFrame) &&
2153  (!WCacheSectorAddr(block_array, i)) ) {
2154  n++;
2155  BCount--;
2156  }
2157  BCount += n;
2158  n &= ~PacketMask;
2159  if(n>PS) {
2160  if(!OS_SUCCESS(status = Cache->ReadProc(Context, Buffer, BS*n, Lba+saved_BC-BCount, &_ReadBytes, 0))) {
2161  status = WCacheRaiseIoError(Cache, Context, status, Lba+saved_BC-BCount, n, Buffer, WCACHE_R_OP, NULL);
2162  if(!OS_SUCCESS(status)) {
2163  goto EO_WCache_R;
2164  }
2165  }
2166 // WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2167  BCount -= n;
2168  Lba += saved_BC - BCount;
2169  saved_BC = BCount;
2170  i += n;
2171  Buffer += BS*n;
2172  *ReadBytes += BS*n;
2173  }
2174 // } else {
2175 // UDFPrint(("Unaligned\n"));
2176  }
2177  // read non-cached extent (if any)
2178  // firstable, we'll get total number of sectors to read
2179  to_read = 0;
2180  saved_i = i;
2181  d = BCount;
2182  while(d &&
2183  (i < Cache->BlocksPerFrame) &&
2184  (!WCacheSectorAddr(block_array, i)) ) {
2185  i++;
2186  to_read += BS;
2187  d--;
2188  }
2189  // read some not cached sectors
2190  if(to_read) {
2191  i = saved_i;
2192  saved_to_read = to_read;
2193  d = BCount - d;
2194  // split request if necessary
2195  if(saved_to_read > MaxR) {
2196  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2197  n = MaxR >> BSh;
2198  do {
2199  status = Cache->ReadProc(Context, Buffer, MaxR, i + (frame << Cache->BlocksPerFrameSh), &_ReadBytes, 0);
2200  *ReadBytes += _ReadBytes;
2201  if(!OS_SUCCESS(status)) {
2202  _ReadBytes &= ~(BS-1);
2203  BCount -= _ReadBytes >> BSh;
2204  saved_to_read -= _ReadBytes;
2205  Buffer += _ReadBytes;
2206  saved_BC = BCount;
2207  goto store_read_data_1;
2208  }
2209  Buffer += MaxR;
2210  saved_to_read -= MaxR;
2211  i += n;
2212  BCount -= n;
2213  d -= n;
2214  } while(saved_to_read > MaxR);
2215  saved_BC = BCount;
2216  }
2217  if(saved_to_read) {
2218  status = Cache->ReadProc(Context, Buffer, saved_to_read, i + (frame << Cache->BlocksPerFrameSh), &_ReadBytes, 0);
2219  *ReadBytes += _ReadBytes;
2220  if(!OS_SUCCESS(status)) {
2221  _ReadBytes &= ~(BS-1);
2222  BCount -= _ReadBytes >> BSh;
2223  saved_to_read -= _ReadBytes;
2224  Buffer += _ReadBytes;
2225  goto store_read_data_1;
2226  }
2227  Buffer += saved_to_read;
2228  saved_to_read = 0;
2229  BCount -= d;
2230  }
2231 
2232 store_read_data_1:
2233  // and now we'll copy them to cache
2234 
2235  //
2236  Buffer -= (to_read - saved_to_read);
2237  i = saved_i;
2238  while(to_read - saved_to_read) {
2240  if(!block_array[i].Sector) {
2241  BCount += to_read >> BSh;
2243  goto EO_WCache_R;
2244  }
2245  DbgCopyMemory(block_array[i].Sector, Buffer, BS);
2246  Cache->FrameList[frame].BlockCount++;
2247  i++;
2248  Buffer += BS;
2249  to_read -= BS;
2250  }
2251  if(!OS_SUCCESS(status))
2252  goto EO_WCache_R;
2253  to_read = 0;
2254  }
2255  }
2256 
2257 EO_WCache_R:
2258 
2259  // we know the number of unread sectors if an error occured
2260  // so we can need to update BlockCount
2261  // return number of read bytes
2262  WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2263 // Cache->FrameList[frame].BlockCount -= BCount;
2264 EO_WCache_R2:
2265  if(!CachedOnly) {
2267  }
2268 
2269  return status;
2270 } // 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 TRUE
Definition: types.h:120
#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 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
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 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
smooth NULL
Definition: ftsmooth.c:416
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 d
Definition: ke_i.h:81
#define MEM_WCBUF_TAG
Definition: wcache_lib.cpp:56
ULONG to_read
Definition: btrfs.c:4161
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:78
#define DbgCopyMemory
Definition: env_spec_w32.h:331
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
return STATUS_SUCCESS
Definition: btrfs.c:2966
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__().

◆ WCacheRelease__()

VOID WCacheRelease__ ( IN PW_CACHE  Cache)

Definition at line 2767 of file wcache_lib.cpp.

2770 {
2771  ULONG i, j, k;
2772  PW_CACHE_ENTRY block_array;
2773 
2774  Cache->Tag = 0xDEADCACE;
2775  if(!(Cache->ReadProc)) return;
2776 // ASSERT(Cache->Tag == 0xCAC11E00);
2777  ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2778  for(i=0; i<Cache->FrameCount; i++) {
2779  j = Cache->CachedFramesList[i];
2780  block_array = Cache->FrameList[j].Frame;
2781  if(block_array) {
2782  for(k=0; k<Cache->BlocksPerFrame; k++) {
2783  if(WCacheSectorAddr(block_array, k)) {
2784  WCacheFreeSector(j, k);
2785  }
2786  }
2787  MyFreePool__(block_array);
2788  }
2789  }
2790  if(Cache->FrameList)
2791  MyFreePool__(Cache->FrameList);
2792  if(Cache->CachedBlocksList)
2793  MyFreePool__(Cache->CachedBlocksList);
2794  if(Cache->CachedBlocksList)
2795  MyFreePool__(Cache->CachedModifiedBlocksList);
2796  if(Cache->CachedFramesList)
2797  MyFreePool__(Cache->CachedFramesList);
2798  if(Cache->tmp_buff_r)
2799  MyFreePool__(Cache->tmp_buff_r);
2800  if(Cache->CachedFramesList)
2801  MyFreePool__(Cache->tmp_buff);
2802  if(Cache->CachedFramesList)
2803  MyFreePool__(Cache->reloc_tab);
2805  ExDeleteResourceLite(&(Cache->WCacheLock));
2806  RtlZeroMemory(Cache, sizeof(W_CACHE));
2807  return;
2808 } // end WCacheRelease__()
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
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
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 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
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
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
smooth NULL
Definition: ftsmooth.c:416
VOID __fastcall WCacheRemoveItemFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba)
Definition: wcache_lib.cpp:704
#define MyFreePool__(addr)
Definition: mem_tools.h:152
Definition: wcache_lib.h:97
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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
LIST_ENTRY List
Definition: psmgr.c:57
#define DbgMoveMemory
Definition: env_spec_w32.h:329
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
LIST_ENTRY List
Definition: psmgr.c:57
#define DbgMoveMemory
Definition: env_spec_w32.h:329
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 3425 of file wcache_lib.cpp.

3429 {
3431  Cache->Mode = Mode;
3432  return STATUS_SUCCESS;
3433 } // 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
return STATUS_SUCCESS
Definition: btrfs.c:2966

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

◆ WCacheStartDirect__()

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

Definition at line 3100 of file wcache_lib.cpp.

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

Referenced by UDFIsExtentCached(), and UDFVWorkItem().

◆ WCacheSyncReloc__()

VOID WCacheSyncReloc__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3469 of file wcache_lib.cpp.

3472 {
3473  ULONG frame;
3474  lba_t firstLba;
3475  lba_t* List = Cache->CachedBlocksList;
3476  lba_t Lba;
3477 // ULONG BSh = Cache->BlockSizeSh;
3478 // ULONG BS = Cache->BlockSize;
3479 // ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3480 // ULONG PSs = Cache->PacketSize;
3481  PW_CACHE_ENTRY block_array;
3482  BOOLEAN mod;
3483  ULONG MaxReloc = Cache->PacketSize;
3484  PULONG reloc_tab = Cache->reloc_tab;
3485  ULONG RelocCount = 0;
3486  BOOLEAN IncompletePacket;
3487 
3488  IncompletePacket = (Cache->WriteCount >= MaxReloc) ? FALSE : TRUE;
3489  // enumerate modified blocks
3490  for(ULONG i=0; IncompletePacket && (i<Cache->BlockCount); i++) {
3491 
3492  Lba = List[i];
3493  frame = Lba >> Cache->BlocksPerFrameSh;
3494  firstLba = frame << Cache->BlocksPerFrameSh;
3495  block_array = Cache->FrameList[frame].Frame;
3496  if(!block_array) {
3497  return;
3498  }
3499  // check if modified
3500  mod = WCacheGetModFlag(block_array, Lba - firstLba);
3501  // update relocation table for modified sectors
3502  if(mod && (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3503  reloc_tab[RelocCount] = Lba;
3504  RelocCount++;
3505  if(RelocCount >= Cache->WriteCount) {
3506  Cache->UpdateRelocProc(Context, NULL, reloc_tab, RelocCount);
3507  break;
3508  }
3509  }
3510  }
3511 } // end WCacheSyncReloc__()
#define TRUE
Definition: types.h:120
Definition: fatfs.h:173
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
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 char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY List
Definition: psmgr.c:57
Definition: wcache_lib.h:97
unsigned int * PULONG
Definition: retypes.h:1
#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:1273

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  ASSERT((ULONG)WCacheSectorAddr(block_array,Lba0) & 0x80000000);
1124 #endif //_NTDEF_
1125  if(!mod) {
1126  ASSERT(read);
1127  mod = (DbgCompareMemory(tmp_buff2 + (i << BSh),
1128  (PVOID)WCacheSectorAddr(block_array, Lba0),
1129  BS) != BS);
1130  }
1131  if(mod)
1132  DbgCopyMemory(tmp_buff2 + (i << BSh),
1133  (PVOID)WCacheSectorAddr(block_array, Lba0),
1134  BS);