ReactOS 0.4.15-dev-8408-g466a198
wcache_lib.h File Reference
#include "platform.h"
Include dependency graph for wcache_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _WCACHE_ERROR_CONTEXT
 
struct  _W_CACHE_ENTRY
 
struct  _W_CACHE_FRAME
 
struct  _W_CACHE
 

Macros

#define WCACHE_BOUND_CHECKS
 
#define WCACHE_BLOCK_USED   0x01
 
#define WCACHE_BLOCK_ZERO   0x02
 
#define WCACHE_BLOCK_BAD   0x04
 
#define WCACHE_ERROR_READ   0x0001
 
#define WCACHE_ERROR_WRITE   0x0002
 
#define WCACHE_ERROR_INTERNAL   0x0003
 
#define WCACHE_W_OP   FALSE
 
#define WCACHE_R_OP   TRUE
 
#define CACHED_BLOCK_MEMORY_TYPE   PagedPool
 
#define MAX_TRIES_FOR_NA   3
 
#define WCACHE_ADDR_MASK   0xfffffff8
 
#define WCACHE_FLAG_MASK   0x00000007
 
#define WCACHE_FLAG_MODIFIED   0x00000001
 
#define WCACHE_FLAG_ZERO   0x00000002
 
#define WCACHE_FLAG_BAD   0x00000004
 
#define WCACHE_MODE_ROM   0x00000000
 
#define WCACHE_MODE_RW   0x00000001
 
#define WCACHE_MODE_R   0x00000002
 
#define WCACHE_MODE_RAM   0x00000003
 
#define WCACHE_MODE_EWR   0x00000004
 
#define WCACHE_MODE_MAX   WCACHE_MODE_RAM
 
#define PH_TMP_BUFFER   1
 
#define WCACHE_INVALID_LBA   ((lba_t)(-1))
 
#define WCACHE_CACHE_WHOLE_PACKET   0x01
 
#define WCACHE_DO_NOT_COMPARE   0x02
 
#define WCACHE_CHAINED_IO   0x04
 
#define WCACHE_MARK_BAD_BLOCKS   0x08
 
#define WCACHE_RO_BAD_BLOCKS   0x10
 
#define WCACHE_NO_WRITE_THROUGH   0x20
 
#define WCACHE_VALID_FLAGS
 
#define WCACHE_INVALID_FLAGS   (0xffffffff)
 

Typedefs

typedef OSSTATUS(* PWRITE_BLOCK) (IN PVOID Context, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN uint32 Flags)
 
typedef OSSTATUS(* PREAD_BLOCK) (IN PVOID Context, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T ReadBytes, IN uint32 Flags)
 
typedef OSSTATUS(* PWRITE_BLOCK_ASYNC) (IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN BOOLEAN FreeBuffer)
 
typedef OSSTATUS(* PREAD_BLOCK_ASYNC) (IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T ReadBytes)
 
typedef ULONG(* PCHECK_BLOCK) (IN PVOID Context, IN lba_t Lba)
 
typedef OSSTATUS(* PUPDATE_RELOC) (IN PVOID Context, IN lba_t Lba, IN PULONG RelocTab, IN ULONG BCount)
 
typedef struct _WCACHE_ERROR_CONTEXT WCACHE_ERROR_CONTEXT
 
typedef struct _WCACHE_ERROR_CONTEXTPWCACHE_ERROR_CONTEXT
 
typedef OSSTATUS(* PWC_ERROR_HANDLER) (IN PVOID Context, IN PWCACHE_ERROR_CONTEXT ErrorInfo)
 
typedef struct _W_CACHE_ENTRY W_CACHE_ENTRY
 
typedef struct _W_CACHE_ENTRYPW_CACHE_ENTRY
 
typedef struct _W_CACHE_FRAME W_CACHE_FRAME
 
typedef struct _W_CACHE_FRAMEPW_CACHE_FRAME
 
typedef struct _W_CACHE W_CACHE
 
typedef struct _W_CACHEPW_CACHE
 

Functions

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)
 
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)
 
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 WCacheFlushBlocks__ (IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
 
VOID WCacheDiscardBlocks__ (IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)
 
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 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)
 
ULONG WCacheChFlags__ (IN PW_CACHE Cache, IN ULONG SetFlags, IN ULONG ClrFlags)
 
OSSTATUS WCacheCompleteAsync__ (IN PVOID WContext, IN OSSTATUS Status)
 

Macro Definition Documentation

◆ CACHED_BLOCK_MEMORY_TYPE

#define CACHED_BLOCK_MEMORY_TYPE   PagedPool

Definition at line 115 of file wcache_lib.h.

◆ MAX_TRIES_FOR_NA

#define MAX_TRIES_FOR_NA   3

Definition at line 116 of file wcache_lib.h.

◆ PH_TMP_BUFFER

#define PH_TMP_BUFFER   1

Definition at line 131 of file wcache_lib.h.

◆ WCACHE_ADDR_MASK

#define WCACHE_ADDR_MASK   0xfffffff8

Definition at line 118 of file wcache_lib.h.

◆ WCACHE_BLOCK_BAD

#define WCACHE_BLOCK_BAD   0x04

Definition at line 56 of file wcache_lib.h.

◆ WCACHE_BLOCK_USED

#define WCACHE_BLOCK_USED   0x01

Definition at line 54 of file wcache_lib.h.

◆ WCACHE_BLOCK_ZERO

#define WCACHE_BLOCK_ZERO   0x02

Definition at line 55 of file wcache_lib.h.

◆ WCACHE_BOUND_CHECKS

#define WCACHE_BOUND_CHECKS

Definition at line 20 of file wcache_lib.h.

◆ WCACHE_CACHE_WHOLE_PACKET

#define WCACHE_CACHE_WHOLE_PACKET   0x01

Definition at line 191 of file wcache_lib.h.

◆ WCACHE_CHAINED_IO

#define WCACHE_CHAINED_IO   0x04

Definition at line 193 of file wcache_lib.h.

◆ WCACHE_DO_NOT_COMPARE

#define WCACHE_DO_NOT_COMPARE   0x02

Definition at line 192 of file wcache_lib.h.

◆ WCACHE_ERROR_INTERNAL

#define WCACHE_ERROR_INTERNAL   0x0003

Definition at line 68 of file wcache_lib.h.

◆ WCACHE_ERROR_READ

#define WCACHE_ERROR_READ   0x0001

Definition at line 66 of file wcache_lib.h.

◆ WCACHE_ERROR_WRITE

#define WCACHE_ERROR_WRITE   0x0002

Definition at line 67 of file wcache_lib.h.

◆ WCACHE_FLAG_BAD

#define WCACHE_FLAG_BAD   0x00000004

Definition at line 122 of file wcache_lib.h.

◆ WCACHE_FLAG_MASK

#define WCACHE_FLAG_MASK   0x00000007

Definition at line 119 of file wcache_lib.h.

◆ WCACHE_FLAG_MODIFIED

#define WCACHE_FLAG_MODIFIED   0x00000001

Definition at line 120 of file wcache_lib.h.

◆ WCACHE_FLAG_ZERO

#define WCACHE_FLAG_ZERO   0x00000002

Definition at line 121 of file wcache_lib.h.

◆ WCACHE_INVALID_FLAGS

#define WCACHE_INVALID_FLAGS   (0xffffffff)

Definition at line 205 of file wcache_lib.h.

◆ WCACHE_INVALID_LBA

#define WCACHE_INVALID_LBA   ((lba_t)(-1))

Definition at line 189 of file wcache_lib.h.

◆ WCACHE_MARK_BAD_BLOCKS

#define WCACHE_MARK_BAD_BLOCKS   0x08

Definition at line 194 of file wcache_lib.h.

◆ WCACHE_MODE_EWR

#define WCACHE_MODE_EWR   0x00000004

Definition at line 128 of file wcache_lib.h.

◆ WCACHE_MODE_MAX

#define WCACHE_MODE_MAX   WCACHE_MODE_RAM

Definition at line 129 of file wcache_lib.h.

◆ WCACHE_MODE_R

#define WCACHE_MODE_R   0x00000002

Definition at line 126 of file wcache_lib.h.

◆ WCACHE_MODE_RAM

#define WCACHE_MODE_RAM   0x00000003

Definition at line 127 of file wcache_lib.h.

◆ WCACHE_MODE_ROM

#define WCACHE_MODE_ROM   0x00000000

Definition at line 124 of file wcache_lib.h.

◆ WCACHE_MODE_RW

#define WCACHE_MODE_RW   0x00000001

Definition at line 125 of file wcache_lib.h.

◆ WCACHE_NO_WRITE_THROUGH

#define WCACHE_NO_WRITE_THROUGH   0x20

Definition at line 196 of file wcache_lib.h.

◆ WCACHE_R_OP

#define WCACHE_R_OP   TRUE

Definition at line 71 of file wcache_lib.h.

◆ WCACHE_RO_BAD_BLOCKS

#define WCACHE_RO_BAD_BLOCKS   0x10

Definition at line 195 of file wcache_lib.h.

◆ WCACHE_VALID_FLAGS

#define WCACHE_VALID_FLAGS
Value:
#define WCACHE_RO_BAD_BLOCKS
Definition: wcache_lib.h:195
#define WCACHE_NO_WRITE_THROUGH
Definition: wcache_lib.h:196
#define WCACHE_CACHE_WHOLE_PACKET
Definition: wcache_lib.h:191
#define WCACHE_MARK_BAD_BLOCKS
Definition: wcache_lib.h:194
#define WCACHE_DO_NOT_COMPARE
Definition: wcache_lib.h:192
#define WCACHE_CHAINED_IO
Definition: wcache_lib.h:193

Definition at line 198 of file wcache_lib.h.

◆ WCACHE_W_OP

#define WCACHE_W_OP   FALSE

Definition at line 70 of file wcache_lib.h.

Typedef Documentation

◆ PCHECK_BLOCK

typedef ULONG(* PCHECK_BLOCK) (IN PVOID Context, IN lba_t Lba)

Definition at line 58 of file wcache_lib.h.

◆ PREAD_BLOCK

Definition at line 29 of file wcache_lib.h.

◆ PREAD_BLOCK_ASYNC

typedef OSSTATUS(* PREAD_BLOCK_ASYNC) (IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T ReadBytes)

Definition at line 44 of file wcache_lib.h.

◆ PUPDATE_RELOC

typedef OSSTATUS(* PUPDATE_RELOC) (IN PVOID Context, IN lba_t Lba, IN PULONG RelocTab, IN ULONG BCount)

Definition at line 61 of file wcache_lib.h.

◆ PW_CACHE

◆ PW_CACHE_ENTRY

◆ PW_CACHE_FRAME

◆ PWC_ERROR_HANDLER

typedef OSSTATUS(* PWC_ERROR_HANDLER) (IN PVOID Context, IN PWCACHE_ERROR_CONTEXT ErrorInfo)

Definition at line 93 of file wcache_lib.h.

◆ PWCACHE_ERROR_CONTEXT

◆ PWRITE_BLOCK

typedef OSSTATUS(* PWRITE_BLOCK) (IN PVOID Context, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN uint32 Flags)

Definition at line 22 of file wcache_lib.h.

◆ PWRITE_BLOCK_ASYNC

typedef OSSTATUS(* PWRITE_BLOCK_ASYNC) (IN PVOID Context, IN PVOID WContext, IN PVOID Buffer, IN SIZE_T Length, IN lba_t Lba, OUT PSIZE_T WrittenBytes, IN BOOLEAN FreeBuffer)

Definition at line 36 of file wcache_lib.h.

◆ W_CACHE

◆ W_CACHE_ENTRY

◆ W_CACHE_FRAME

◆ WCACHE_ERROR_CONTEXT

Function Documentation

◆ WCacheChFlags__()

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

Definition at line 3635 of file wcache_lib.cpp.

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

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ WCacheCompleteAsync__()

OSSTATUS WCacheCompleteAsync__ ( IN PVOID  WContext,
IN OSSTATUS  Status 
)

Definition at line 3586 of file wcache_lib.cpp.

3590{
3591 PW_CACHE_ASYNC AsyncCtx = (PW_CACHE_ASYNC)WContext;
3592// PW_CACHE Cache = AsyncCtx->Cache;
3593
3594 AsyncCtx->PhContext.IosbToUse.Status = Status;
3595 KeSetEvent(&(AsyncCtx->PhContext.event), 0, FALSE);
3596
3597 return STATUS_SUCCESS;
3598} // end WCacheSetMode__()
#define FALSE
Definition: types.h:117
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
Status
Definition: gdiplustypes.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
IO_STATUS_BLOCK IosbToUse
Definition: Sys_spec_lib.h:24
UDF_PH_CALL_CONTEXT PhContext
Definition: wcache_lib.cpp:67
struct _W_CACHE_ASYNC * PW_CACHE_ASYNC

Referenced by WCacheUpdatePacket().

◆ WCacheDirect__()

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

Definition at line 2949 of file wcache_lib.cpp.

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

Referenced by UDFWriteInSector().

◆ WCacheDiscardBlocks__()

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

Definition at line 3520 of file wcache_lib.cpp.

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

Referenced by UDFMarkSpaceAsXXXNoProtect_().

◆ WCacheEODirect__()

OSSTATUS WCacheEODirect__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3083 of file wcache_lib.cpp.

3087{
3089 return STATUS_SUCCESS;
3090} // end WCacheEODirect__()

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

◆ WCacheFlushAll__()

VOID WCacheFlushAll__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2560 of file wcache_lib.cpp.

2563{
2564 if(!(Cache->ReadProc)) return;
2565 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2566
2567 switch(Cache->Mode) {
2568 case WCACHE_MODE_RAM:
2570 break;
2571 case WCACHE_MODE_ROM:
2572 case WCACHE_MODE_RW:
2574 break;
2575 case WCACHE_MODE_R:
2577 break;
2578 }
2579
2581 return;
2582} // end WCacheFlushAll__()
OSSTATUS __fastcall WCacheFlushAllRAM(IN PW_CACHE Cache, IN PVOID Context)
VOID __fastcall WCachePurgeAllR(IN PW_CACHE Cache, IN PVOID Context)
VOID __fastcall WCacheFlushAllRW(IN PW_CACHE Cache, IN PVOID Context)
#define WCACHE_MODE_R
Definition: wcache_lib.h:126
#define WCACHE_MODE_RW
Definition: wcache_lib.h:125
#define WCACHE_MODE_ROM
Definition: wcache_lib.h:124
#define WCACHE_MODE_RAM
Definition: wcache_lib.h:127

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

◆ WCacheFlushBlocks__()

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

Definition at line 2899 of file wcache_lib.cpp.

2905{
2907
2908 if(!(Cache->ReadProc)) return STATUS_INVALID_PARAMETER;
2909 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2910
2911 // check if we try to access beyond cached area
2912 if((Lba < Cache->FirstLba) ||
2913 (Lba+BCount-1 > Cache->LastLba)) {
2914 UDFPrint(("LBA %#x (%x) is beyond cacheable area\n", Lba, BCount));
2915 BrutePoint();
2917 goto EO_WCache_F;
2918 }
2919
2920 switch(Cache->Mode) {
2921 case WCACHE_MODE_RAM:
2922// WCacheFlushBlocksRW(Cache, Context);
2923// break;
2924 case WCACHE_MODE_ROM:
2925 case WCACHE_MODE_RW:
2926 status = WCacheFlushBlocksRW(Cache, Context, Lba, BCount);
2927 break;
2928 case WCACHE_MODE_R:
2930 break;
2931 }
2932EO_WCache_F:
2934 return status;
2935} // end WCacheFlushBlocks__()
OSSTATUS WCacheFlushBlocksRW(IN PW_CACHE Cache, IN PVOID Context, IN lba_t _Lba, IN ULONG BCount)

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

◆ WCacheGetMode__()

ULONG WCacheGetMode__ ( IN PW_CACHE  Cache)

Definition at line 3441 of file wcache_lib.cpp.

3444{
3445 return Cache->Mode;
3446} // end WCacheGetMode__()

◆ WCacheGetWriteBlockCount__()

ULONG WCacheGetWriteBlockCount__ ( IN PW_CACHE  Cache)

Definition at line 3455 of file wcache_lib.cpp.

3458{
3459 return Cache->WriteCount;
3460} // end WCacheGetWriteBlockCount__()

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
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 =
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
302try_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 try_return(S)
Definition: cdprocs.h:2179
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define NonPagedPool
Definition: env_spec_w32.h:307
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
_In_ ULONG Mode
Definition: hubbusif.h:303
#define NOTHING
Definition: input_list.c:10
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
#define max(a, b)
Definition: svc.c:63
uint32_t * PULONG
Definition: typedefs.h:59
ULONG LowPart
Definition: typedefs.h:106
ULONG WCache_random
Definition: wcache_lib.cpp:90
#define MEM_WCFRM_TAG
Definition: wcache_lib.cpp:55
#define WCLOCK_RES
#define WCACHE_MODE_MAX
Definition: wcache_lib.h:129
_In_ USHORT PacketSize
Definition: iofuncs.h:1058

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ WCacheIsCached__()

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

WCacheGetBadFlag(block_array, i)

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

Definition at line 3127 of file wcache_lib.cpp.

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

◆ WCacheIsInitialized__()

BOOLEAN WCacheIsInitialized__ ( IN PW_CACHE  Cache)

Definition at line 2817 of file wcache_lib.cpp.

2820{
2821 return (Cache->ReadProc != NULL);
2822} // end WCacheIsInitialized__()

Referenced by UDFVerifyVolume(), and UDFWriteInSector().

◆ WCachePurgeAll__()

VOID WCachePurgeAll__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 2590 of file wcache_lib.cpp.

2593{
2594 if(!(Cache->ReadProc)) return;
2595 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2596
2597 switch(Cache->Mode) {
2598 case WCACHE_MODE_RAM:
2600 break;
2601 case WCACHE_MODE_ROM:
2602 case WCACHE_MODE_RW:
2604 break;
2605 case WCACHE_MODE_R:
2607 break;
2608 }
2609
2611 return;
2612} // end WCachePurgeAll__()
OSSTATUS __fastcall WCachePurgeAllRAM(IN PW_CACHE Cache, IN PVOID Context)
VOID __fastcall WCachePurgeAllRW(IN PW_CACHE Cache, IN PVOID Context)

Referenced by UDFFindAnchor().

◆ WCacheReadBlocks__()

OSSTATUS WCacheReadBlocks__ ( IN PW_CACHE  Cache,
IN PVOID  Context,
IN PCHAR  Buffer,
IN lba_t  Lba,
IN ULONG  BCount,
OUT PSIZE_T  ReadBytes,
IN BOOLEAN  CachedOnly 
)

Definition at line 2012 of file wcache_lib.cpp.

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

Referenced by WCacheReadBlocks__().

◆ WCacheRelease__()

VOID WCacheRelease__ ( IN PW_CACHE  Cache)

Definition at line 2768 of file wcache_lib.cpp.

2771{
2772 ULONG i, j, k;
2773 PW_CACHE_ENTRY block_array;
2774
2775 Cache->Tag = 0xDEADCACE;
2776 if(!(Cache->ReadProc)) return;
2777// ASSERT(Cache->Tag == 0xCAC11E00);
2778 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2779 for(i=0; i<Cache->FrameCount; i++) {
2780 j = Cache->CachedFramesList[i];
2781 block_array = Cache->FrameList[j].Frame;
2782 if(block_array) {
2783 for(k=0; k<Cache->BlocksPerFrame; k++) {
2784 if(WCacheSectorAddr(block_array, k)) {
2786 }
2787 }
2788 MyFreePool__(block_array);
2789 }
2790 }
2791 if(Cache->FrameList)
2792 MyFreePool__(Cache->FrameList);
2793 if(Cache->CachedBlocksList)
2794 MyFreePool__(Cache->CachedBlocksList);
2795 if(Cache->CachedModifiedBlocksList)
2796 MyFreePool__(Cache->CachedModifiedBlocksList);
2797 if(Cache->CachedFramesList)
2798 MyFreePool__(Cache->CachedFramesList);
2799 if(Cache->tmp_buff_r)
2800 MyFreePool__(Cache->tmp_buff_r);
2801 if(Cache->CachedFramesList)
2802 MyFreePool__(Cache->tmp_buff);
2803 if(Cache->CachedFramesList)
2804 MyFreePool__(Cache->reloc_tab);
2806 ExDeleteResourceLite(&(Cache->WCacheLock));
2807 RtlZeroMemory(Cache, sizeof(W_CACHE));
2808 return;
2809} // end WCacheRelease__()
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
int k
Definition: mpi.c:3369

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

◆ WCacheSetMode__()

OSSTATUS WCacheSetMode__ ( IN PW_CACHE  Cache,
IN ULONG  Mode 
)

Definition at line 3426 of file wcache_lib.cpp.

3430{
3432 Cache->Mode = Mode;
3433 return STATUS_SUCCESS;
3434} // end WCacheSetMode__()

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

◆ WCacheStartDirect__()

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

Definition at line 3101 of file wcache_lib.cpp.

3107{
3108 if(Exclusive) {
3109 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
3110 } else {
3111 BrutePoint();
3112 ExAcquireResourceSharedLite(&(Cache->WCacheLock), TRUE);
3113 }
3114 return STATUS_SUCCESS;
3115} // end WCacheStartDirect__()
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive

Referenced by UDFIsExtentCached(), and UDFVWorkItem().

◆ WCacheSyncReloc__()

VOID WCacheSyncReloc__ ( IN PW_CACHE  Cache,
IN PVOID  Context 
)

Definition at line 3470 of file wcache_lib.cpp.

3473{
3474 ULONG frame;
3475 lba_t firstLba;
3476 lba_t* List = Cache->CachedBlocksList;
3477 lba_t Lba;
3478// ULONG BSh = Cache->BlockSizeSh;
3479// ULONG BS = Cache->BlockSize;
3480// ULONG PS = BS << Cache->PacketSizeSh; // packet size (bytes)
3481// ULONG PSs = Cache->PacketSize;
3482 PW_CACHE_ENTRY block_array;
3483 BOOLEAN mod;
3484 ULONG MaxReloc = Cache->PacketSize;
3485 PULONG reloc_tab = Cache->reloc_tab;
3486 ULONG RelocCount = 0;
3487 BOOLEAN IncompletePacket;
3488
3489 IncompletePacket = (Cache->WriteCount >= MaxReloc) ? FALSE : TRUE;
3490 // enumerate modified blocks
3491 for(ULONG i=0; IncompletePacket && (i<Cache->BlockCount); i++) {
3492
3493 Lba = List[i];
3494 frame = Lba >> Cache->BlocksPerFrameSh;
3495 firstLba = frame << Cache->BlocksPerFrameSh;
3496 block_array = Cache->FrameList[frame].Frame;
3497 if(!block_array) {
3498 return;
3499 }
3500 // check if modified
3501 mod = WCacheGetModFlag(block_array, Lba - firstLba);
3502 // update relocation table for modified sectors
3503 if(mod && (Cache->CheckUsedProc(Context, Lba) & WCACHE_BLOCK_USED)) {
3504 reloc_tab[RelocCount] = Lba;
3505 RelocCount++;
3506 if(RelocCount >= Cache->WriteCount) {
3507 Cache->UpdateRelocProc(Context, NULL, reloc_tab, RelocCount);
3508 break;
3509 }
3510 }
3511 }
3512} // end WCacheSyncReloc__()

Referenced by UDFRecordVAT().

◆ WCacheWriteBlocks__()

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 
)

Definition at line 2281 of file wcache_lib.cpp.

2291{
2292 ULONG frame;
2293 ULONG i, saved_BC = BCount, n, d;
2295 PW_CACHE_ENTRY block_array;
2296 ULONG BSh = Cache->BlockSizeSh;
2297 ULONG BS = Cache->BlockSize;
2298 PCHAR addr;
2299// PCHAR saved_buff = Buffer;
2300 SIZE_T _WrittenBytes;
2301 ULONG PS = Cache->PacketSize;
2302 ULONG PacketMask = PS-1; // here we assume that Packet Size value is 2^n
2303 ULONG block_type;
2304// BOOLEAN Aligned = FALSE;
2305
2306 BOOLEAN WriteThrough = FALSE;
2307 lba_t WTh_Lba;
2308 ULONG WTh_BCount;
2309
2310 WcPrint(("WC:W %x (%x)\n", Lba, BCount));
2311
2312 *WrittenBytes = 0;
2313// UDFPrint(("BCount:%x\n",BCount));
2314 // check if we try to read too much data
2315 if(BCount >= Cache->MaxBlocks) {
2316 i = 0;
2317 if(CachedOnly) {
2319 goto EO_WCache_W2;
2320 }
2321 while(TRUE) {
2322// UDFPrint((" BCount:%x\n",BCount));
2323 status = WCacheWriteBlocks__(Cache, Context, Buffer + (i<<BSh), Lba, min(PS,BCount), &_WrittenBytes, FALSE);
2324 (*WrittenBytes) += _WrittenBytes;
2325 BCount -= PS;
2326 Lba += PS;
2327 i += PS;
2328 if(!OS_SUCCESS(status) || (BCount < PS))
2329 return status;
2330 }
2331 }
2332 // check if we try to access beyond cached area
2333 if((Lba < Cache->FirstLba) ||
2334 (Lba + BCount - 1 > Cache->LastLba)) {
2336 }
2337 if(!CachedOnly) {
2338 ExAcquireResourceExclusiveLite(&(Cache->WCacheLock), TRUE);
2339 }
2340
2341 frame = Lba >> Cache->BlocksPerFrameSh;
2342 i = Lba - (frame << Cache->BlocksPerFrameSh);
2343
2344 if(!CachedOnly &&
2345 !OS_SUCCESS(status = WCacheCheckLimits(Cache, Context, Lba, BCount))) {
2347 return status;
2348 }
2349
2350 // assume successful operation
2351 block_array = Cache->FrameList[frame].Frame;
2352 if(!block_array) {
2353
2354 if(BCount && !(BCount & (PS-1)) && !(Lba & (PS-1)) &&
2355 (Cache->Mode != WCACHE_MODE_R) &&
2356 (i+BCount <= Cache->BlocksPerFrame) &&
2357 !Cache->NoWriteThrough) {
2358 status = Cache->WriteProc(Context, Buffer, BCount<<BSh, Lba, WrittenBytes, 0);
2359 if(!OS_SUCCESS(status)) {
2361 }
2362 goto EO_WCache_W2;
2363 }
2364
2365 ASSERT(!CachedOnly);
2366 ASSERT(Cache->FrameCount < Cache->MaxFrames);
2367 block_array = WCacheInitFrame(Cache, Context, frame);
2368 if(!block_array) {
2370 goto EO_WCache_W;
2371 }
2372 }
2373
2374 if(Cache->Mode == WCACHE_MODE_RAM &&
2375 BCount &&
2376// !(Lba & (PS-1)) &&
2377 (!(BCount & (PS-1)) || (BCount > PS)) ) {
2378 WriteThrough = TRUE;
2379 WTh_Lba = Lba;
2380 WTh_BCount = BCount;
2381 } else
2382 if(Cache->Mode == WCACHE_MODE_RAM &&
2383 ((Lba & ~PacketMask) != ((Lba+BCount-1) & ~PacketMask))
2384 ) {
2385 WriteThrough = TRUE;
2386 WTh_Lba = Lba & ~PacketMask;
2387 WTh_BCount = PS;
2388 }
2389
2390 Cache->FrameList[frame].UpdateCount++;
2391// UDFPrint((" BCount:%x\n",BCount));
2392 while(BCount) {
2393 if(i >= Cache->BlocksPerFrame) {
2394 frame++;
2395 block_array = Cache->FrameList[frame].Frame;
2396 i -= Cache->BlocksPerFrame;
2397 }
2398 if(!block_array) {
2399 ASSERT(Cache->FrameCount < Cache->MaxFrames);
2400 block_array = WCacheInitFrame(Cache, Context, frame);
2401 if(!block_array) {
2403 goto EO_WCache_W;
2404 }
2405 }
2406 // 'write' cached extent (if any)
2407 // it is just copying
2408 while(BCount &&
2409 (i < Cache->BlocksPerFrame) &&
2410 (addr = (PCHAR)WCacheSectorAddr(block_array, i)) ) {
2411// UDFPrint(("addr:%x:Buffer:%x:BS:%x:BCount:%x\n",addr, Buffer, BS, BCount));
2412 block_type = Cache->CheckUsedProc(Context, Lba+saved_BC-BCount);
2413 if(Cache->NoWriteBB &&
2414 /*WCacheGetBadFlag(block_array,i)*/
2415 (block_type & WCACHE_BLOCK_BAD)) {
2416 // bad packet. no cached write
2418 goto EO_WCache_W;
2419 }
2421 WCacheSetModFlag(block_array, i);
2422 Buffer += BS;
2423 *WrittenBytes += BS;
2424 i++;
2425 BCount--;
2426 }
2427 // write non-cached not-aligned extent (if any) till aligned one
2428 while(BCount &&
2429 (i & PacketMask) &&
2430 (Cache->Mode != WCACHE_MODE_R) &&
2431 (i < Cache->BlocksPerFrame) &&
2432 (!WCacheSectorAddr(block_array, i)) ) {
2434 if(!block_array[i].Sector) {
2436 goto EO_WCache_W;
2437 }
2438// UDFPrint(("addr:%x:Buffer:%x:BS:%x:BCount:%x\n",block_array[i].Sector, Buffer, BS, BCount));
2439 DbgCopyMemory(block_array[i].Sector, Buffer, BS);
2440 WCacheSetModFlag(block_array, i);
2441 i++;
2442 Buffer += BS;
2443 *WrittenBytes += BS;
2444 BCount--;
2445 Cache->FrameList[frame].BlockCount ++;
2446 }
2447 // write non-cached packet-size-aligned extent (if any)
2448 // now we'll calculate total length & decide if has enough size
2449 if(!Cache->NoWriteThrough
2450 &&
2451 ( !(i & PacketMask) ||
2452 ((Cache->Mode == WCACHE_MODE_R) && (BCount >= PS)) )) {
2453 n = 0;
2454 while(BCount &&
2455 (i < Cache->BlocksPerFrame) &&
2456 (!WCacheSectorAddr(block_array, i)) ) {
2457 n++;
2458 BCount--;
2459 }
2460 BCount += n;
2461 n &= ~PacketMask;
2462// if(!OS_SUCCESS(status = Cache->WriteProcAsync(Context, Buffer, BS*n, Lba+saved_BC-BCount, &_WrittenBytes, FALSE)))
2463 if(n) {
2464 // add previously written data to list
2465 d = saved_BC - BCount;
2466 WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, d);
2467 WCacheInsertRangeToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, d);
2468 Lba += d;
2469 saved_BC = BCount;
2470
2471 while(n) {
2472 if(Cache->Mode == WCACHE_MODE_R)
2473 Cache->UpdateRelocProc(Context, Lba, NULL, PS);
2474 if(!OS_SUCCESS(status = Cache->WriteProc(Context, Buffer, PS<<BSh, Lba, &_WrittenBytes, 0))) {
2476 if(!OS_SUCCESS(status)) {
2477 goto EO_WCache_W;
2478 }
2479 }
2480 BCount -= PS;
2481 Lba += PS;
2482 saved_BC = BCount;
2483 i += PS;
2484 Buffer += PS<<BSh;
2485 *WrittenBytes += PS<<BSh;
2486 n-=PS;
2487 }
2488 }
2489 }
2490 // write non-cached not-aligned extent (if any)
2491 while(BCount &&
2492 (i < Cache->BlocksPerFrame) &&
2493 (!WCacheSectorAddr(block_array, i)) ) {
2495 if(!block_array[i].Sector) {
2497 goto EO_WCache_W;
2498 }
2499// UDFPrint(("addr:%x:Buffer:%x:BS:%x:BCount:%x\n",block_array[i].Sector, Buffer, BS, BCount));
2500 DbgCopyMemory(block_array[i].Sector, Buffer, BS);
2501 WCacheSetModFlag(block_array, i);
2502 i++;
2503 Buffer += BS;
2504 *WrittenBytes += BS;
2505 BCount--;
2506 Cache->FrameList[frame].BlockCount ++;
2507 }
2508 }
2509
2510EO_WCache_W:
2511
2512 // we know the number of unread sectors if an error occured
2513 // so we can need to update BlockCount
2514 // return number of read bytes
2515 WCacheInsertRangeToList(Cache->CachedBlocksList, &(Cache->BlockCount), Lba, saved_BC - BCount);
2516 WCacheInsertRangeToList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, saved_BC - BCount);
2517
2518 if(WriteThrough && !BCount) {
2519 ULONG d;
2520// lba_t lastLba;
2521 ULONG firstPos;
2522 ULONG lastPos;
2523
2524 BCount = WTh_BCount;
2525 Lba = WTh_Lba;
2526 while(BCount) {
2527 frame = Lba >> Cache->BlocksPerFrameSh;
2528// firstLba = frame << Cache->BlocksPerFrameSh;
2529 firstPos = WCacheGetSortedListIndex(Cache->BlockCount, Cache->CachedBlocksList, Lba);
2530 d = min(Lba+BCount, (frame+1) << Cache->BlocksPerFrameSh) - Lba;
2531 lastPos = WCacheGetSortedListIndex(Cache->BlockCount, Cache->CachedBlocksList, Lba+d);
2532 block_array = Cache->FrameList[frame].Frame;
2533 if(!block_array) {
2534 ASSERT(FALSE);
2535 BCount -= d;
2536 Lba += d;
2537 continue;
2538 }
2539 status = WCacheFlushBlocksRAM(Cache, Context, block_array, Cache->CachedBlocksList, firstPos, lastPos, FALSE);
2540 WCacheRemoveRangeFromList(Cache->CachedModifiedBlocksList, &(Cache->WriteCount), Lba, d);
2541 BCount -= d;
2542 Lba += d;
2543 }
2544 }
2545
2546EO_WCache_W2:
2547
2548 if(!CachedOnly) {
2550 }
2551 return status;
2552} // end WCacheWriteBlocks__()
#define min(a, b)
Definition: monoChain.cc:55
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)
OSSTATUS __fastcall WCacheFlushBlocksRAM(IN PW_CACHE Cache, IN PVOID Context, PW_CACHE_ENTRY block_array, lba_t *List, ULONG firstPos, ULONG lastPos, BOOLEAN Purge)
VOID __fastcall WCacheRemoveRangeFromList(IN lba_t *List, IN PULONG BlockCount, IN lba_t Lba, IN ULONG BCount)
Definition: wcache_lib.cpp:675
#define WCACHE_W_OP
Definition: wcache_lib.h:70

Referenced by UDFWriteSectors(), and WCacheWriteBlocks__().