ReactOS 0.4.15-dev-6712-g46b4b55
remap.cpp File Reference
#include "udf.h"
Include dependency graph for remap.cpp:

Go to the source code of this file.

Classes

struct  _UDF_VERIFY_ITEM
 
struct  _UDF_VERIFY_REQ_RANGE
 
struct  _UDF_VERIFY_REQ
 

Macros

#define UDF_BUG_CHECK_ID   UDF_FILE_UDF_INFO_REMAP
 
#define MAX_VREQ_RANGES   128
 

Typedefs

typedef struct _UDF_VERIFY_ITEM UDF_VERIFY_ITEM
 
typedef struct _UDF_VERIFY_ITEMPUDF_VERIFY_ITEM
 
typedef struct _UDF_VERIFY_REQ_RANGE UDF_VERIFY_REQ_RANGE
 
typedef struct _UDF_VERIFY_REQ_RANGEPUDF_VERIFY_REQ_RANGE
 
typedef struct _UDF_VERIFY_REQ UDF_VERIFY_REQ
 
typedef struct _UDF_VERIFY_REQPUDF_VERIFY_REQ
 

Functions

VOID UDFVRemoveBlock (PUDF_VERIFY_CTX VerifyCtx, PUDF_VERIFY_ITEM vItem)
 
OSSTATUS UDFVInit (IN PVCB Vcb)
 
VOID UDFVWaitQueued (PUDF_VERIFY_CTX VerifyCtx)
 
VOID UDFVRelease (IN PVCB Vcb)
 
PUDF_VERIFY_ITEM UDFVStoreBlock (IN PVCB Vcb, IN uint32 LBA, IN PVOID Buffer, PLIST_ENTRY Link)
 
VOID UDFVUpdateBlock (IN PVCB Vcb, IN PVOID Buffer, PUDF_VERIFY_ITEM vItem)
 
OSSTATUS UDFVWrite (IN PVCB Vcb, IN void *Buffer, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
OSSTATUS UDFVRead (IN PVCB Vcb, IN void *Buffer, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
OSSTATUS UDFVForget (IN PVCB Vcb, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
VOID NTAPI UDFVWorkItem (PVOID Context)
 
VOID UDFVVerify (IN PVCB Vcb, IN ULONG Flags)
 
VOID UDFVFlush (IN PVCB Vcb)
 
BOOLEAN __fastcall UDFCheckArea (IN PVCB Vcb, IN lba_t LBA, IN uint32 BCount)
 
OSSTATUS __fastcall UDFRemapPacket (IN PVCB Vcb, IN uint32 Lba, IN BOOLEAN RemapSpared)
 
OSSTATUS __fastcall UDFUnmapRange (IN PVCB Vcb, IN uint32 Lba, IN uint32 BCount)
 
uint32 __fastcall UDFRelocateSector (IN PVCB Vcb, IN uint32 Lba)
 
BOOLEAN __fastcall UDFAreSectorsRelocated (IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
 
PEXTENT_MAP __fastcall UDFRelocateSectors (IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
 

Macro Definition Documentation

◆ MAX_VREQ_RANGES

#define MAX_VREQ_RANGES   128

Definition at line 35 of file remap.cpp.

◆ UDF_BUG_CHECK_ID

#define UDF_BUG_CHECK_ID   UDF_FILE_UDF_INFO_REMAP

Definition at line 20 of file remap.cpp.

Typedef Documentation

◆ PUDF_VERIFY_ITEM

◆ PUDF_VERIFY_REQ

◆ PUDF_VERIFY_REQ_RANGE

◆ UDF_VERIFY_ITEM

◆ UDF_VERIFY_REQ

◆ UDF_VERIFY_REQ_RANGE

Function Documentation

◆ UDFAreSectorsRelocated()

BOOLEAN __fastcall UDFAreSectorsRelocated ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BlockCount 
)

Definition at line 982 of file remap.cpp.

987{
988
989 if(Vcb->SparingTable) {
990 // use sparing table for relocation
991 uint32 i, BS, orig;
992 BS = Vcb->SparingBlockSize;
993 PSPARING_MAP Map;
994
995 Map = Vcb->SparingTable;
996 for(i=0;i<Vcb->SparingCount;i++,Map++) {
997 if( ((Lba >= (orig = Map->origLocation)) && (Lba < orig + BS)) ||
998 ((Lba+BlockCount-1 >= orig) && (Lba+BlockCount-1 < orig + BS)) ||
999 ((orig >= Lba) && (orig < Lba+BlockCount)) ||
1000 ((orig+BS >= Lba) && (orig+BS < Lba+BlockCount)) ) {
1001 return TRUE;
1002 }
1003 }
1004 } else if(Vcb->Vat) {
1005 // use VAT for relocation
1006 uint32 i, root, j;
1007 uint32* Map;
1008 if(Lba < (root = Vcb->Partitions[Vcb->VatPartNdx].PartitionRoot))
1009 return FALSE;
1010 if(Lba+BlockCount >= Vcb->NWA)
1011 return TRUE;
1012 Map = &(Vcb->Vat[Lba-root/*+i*/]);
1013 for(i=0; i<BlockCount; i++, Map++) {
1014 if((j = (*Map)) &&
1015 (j != Lba-root+i) &&
1016 ((j != UDF_VAT_FREE_ENTRY) || ((Lba+i) < Vcb->LastLBA)))
1017 return TRUE;
1018 }
1019 }
1020 return FALSE;
1021} // end UDFAreSectorsRelocated()
unsigned int uint32
Definition: types.h:32
struct _root root
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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
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 UDF_VAT_FREE_ENTRY
Definition: osta_misc.h:71
#define Vcb
Definition: cdprocs.h:1415
uint32 origLocation
Definition: osta_misc.h:191
#define BS
Definition: telnetd.h:22

Referenced by UDFRelocateSectors().

◆ UDFCheckArea()

BOOLEAN __fastcall UDFCheckArea ( IN PVCB  Vcb,
IN lba_t  LBA,
IN uint32  BCount 
)

Definition at line 763 of file remap.cpp.

768{
769 uint8* buff;
770 OSSTATUS RC;
772 uint32 i, d;
773 BOOLEAN ext_ok = TRUE;
774 EXTENT_MAP Map[2];
775 uint32 PS = Vcb->WriteBlockSize >> Vcb->BlockSizeBits;
776
777 buff = (uint8*)DbgAllocatePoolWithTag(NonPagedPool, Vcb->WriteBlockSize, 'bNWD' );
778 if(buff) {
779 for(i=0; i<BCount; i+=d) {
780 if(!((LBA+i) & (PS-1)) &&
781 (i+PS <= BCount)) {
782 d = PS;
783 } else {
784 d = 1;
785 }
786 RC = UDFTRead(Vcb,
787 buff,
788 d << Vcb->BlockSizeBits,
789 LBA+i,
790 &ReadBytes,
792
793 if(RC != STATUS_SUCCESS) {
794 Map[0].extLocation = LBA+i;
795 Map[0].extLength = d << Vcb->BlockSizeBits;
796 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &(Map[0]), AS_DISCARDED | AS_BAD); // free
797 ext_ok = FALSE;
798 }
799 }
801 }
802 return ext_ok;
803} // end UDFCheckArea()
unsigned char BOOLEAN
unsigned char uint8
Definition: types.h:28
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
#define DbgFreePool
Definition: env_spec_w32.h:334
#define OSSTATUS
Definition: env_spec_w32.h:57
#define NonPagedPool
Definition: env_spec_w32.h:307
static unsigned char buff[32768]
Definition: fatten.c:17
@ PS
#define d
Definition: ke_i.h:81
OSSTATUS UDFTRead(IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T ReadBytes, IN uint32 Flags)
Definition: phys_lib.cpp:596
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32 extLength
Definition: ecma_167.h:128
uint32 extLocation
Definition: ecma_167.h:129
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define UDFMarkSpaceAsXXXNoProtect(Vcb, FileInfo, Map, asXXX)
Definition: udf_info.h:302
#define AS_BAD
Definition: udf_info.h:329
#define AS_DISCARDED
Definition: udf_info.h:328

Referenced by UDFAllocFreeExtent_(), and UDFRemapPacket().

◆ UDFRelocateSector()

uint32 __fastcall UDFRelocateSector ( IN PVCB  Vcb,
IN uint32  Lba 
)

Definition at line 934 of file remap.cpp.

938{
939 uint32 i, max, BS, orig;
940
941 if(Vcb->SparingTable) {
942 // use sparing table for relocation
943 uint32 _Lba;
944 PSPARING_MAP Map = Vcb->SparingTable;
945
946 max = Vcb->SparingCount;
947 BS = Vcb->SparingBlockSize;
948 _Lba = Lba & ~(BS-1);
949 for(i=0;i<max;i++,Map++) {
950 orig = Map->origLocation;
951 if(_Lba == (orig & ~(BS-1)) ) {
952 //if( (Lba >= (orig = Map->origLocation)) && (Lba < orig + BS) ) {
953 return Map->mappedLocation + Lba - orig;
954 }
955 }
956 } else if(Vcb->Vat) {
957 // use VAT for relocation
958 uint32* Map = Vcb->Vat;
959 uint32 root;
960 // check if given Lba lays in the partition covered by VAT
961 if(Lba >= Vcb->NWA)
962 return Vcb->NWA;
963 if(Lba < (root = Vcb->Partitions[Vcb->VatPartNdx].PartitionRoot))
964 return Lba;
965 Map = &(Vcb->Vat[(i = Lba - root)]);
966 if((i < Vcb->VatCount) && (i=(*Map)) ) {
967 if(i != UDF_VAT_FREE_ENTRY) {
968 return i + root;
969 } else {
970 return 0x7fffffff;
971 }
972 }
973 }
974 return Lba;
975} // end UDFRelocateSector()
uint32 mappedLocation
Definition: osta_misc.h:192
#define max(a, b)
Definition: svc.c:63

Referenced by UDFRelocateSectors().

◆ UDFRelocateSectors()

PEXTENT_MAP __fastcall UDFRelocateSectors ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BlockCount 
)

Definition at line 1029 of file remap.cpp.

1034{
1035 if(!UDFAreSectorsRelocated(Vcb, Lba, BlockCount)) return UDF_NO_EXTENT_MAP;
1036
1037 PEXTENT_MAP Extent=NULL, Extent2;
1038 uint32 NewLba, LastLba, j, i;
1039 EXTENT_AD locExt;
1040
1041 LastLba = UDFRelocateSector(Vcb, Lba);
1042 for(i=0, j=1; i<BlockCount; i++, j++) {
1043 // create new entry if the extent in not contigous
1044 if( ((NewLba = UDFRelocateSector(Vcb, Lba+i+1)) != (LastLba+1)) ||
1045 (i==(BlockCount-1)) ) {
1046 locExt.extLength = j << Vcb->BlockSizeBits;
1047 locExt.extLocation = LastLba-j+1;
1048 Extent2 = UDFExtentToMapping(&locExt);
1049 if(!Extent) {
1050 Extent = Extent2;
1051 } else {
1052 Extent = UDFMergeMappings(Extent, Extent2);
1053 MyFreePool__(Extent2);
1054 }
1055 if(!Extent) return NULL;
1056 j = 0;
1057 }
1058 LastLba = NewLba;
1059 }
1060 return Extent;
1061} // end UDFRelocateSectors()
#define NULL
Definition: types.h:112
PEXTENT_MAP __fastcall UDFMergeMappings(IN PEXTENT_MAP Extent, IN PEXTENT_MAP Extent2)
Definition: extent.cpp:266
#define MyFreePool__(addr)
Definition: mem_tools.h:152
BOOLEAN __fastcall UDFAreSectorsRelocated(IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
Definition: remap.cpp:982
uint32 __fastcall UDFRelocateSector(IN PVCB Vcb, IN uint32 Lba)
Definition: remap.cpp:934
#define UDFExtentToMapping(e)
Definition: udf_info.h:181
#define UDF_NO_EXTENT_MAP
Definition: udf_rel.h:519

Referenced by UDFTRead(), and UDFTWrite().

◆ UDFRemapPacket()

OSSTATUS __fastcall UDFRemapPacket ( IN PVCB  Vcb,
IN uint32  Lba,
IN BOOLEAN  RemapSpared 
)

Definition at line 810 of file remap.cpp.

815{
816 uint32 i, max, BS, orig;
817 PSPARING_MAP Map;
818 BOOLEAN verified = FALSE;
819
820 if(Vcb->SparingTable) {
821
822 max = Vcb->SparingCount;
823 BS = Vcb->SparingBlockSize;
824
825 // use sparing table for relocation
826 if(Vcb->SparingCountFree == (ULONG)-1) {
827 UDFPrint(("calculate free spare areas\n"));
828re_check:
829 UDFPrint(("verify spare area\n"));
830 Vcb->SparingCountFree = 0;
831 Map = Vcb->SparingTable;
832 for(i=0;i<max;i++,Map++) {
834 if(UDFCheckArea(Vcb, Map->mappedLocation, BS)) {
835 Vcb->SparingCountFree++;
836 } else {
837 UDFPrint(("initial check: bad spare block @ %x\n", Map->mappedLocation));
839 Vcb->SparingTableModified = TRUE;
840 }
841 }
842 }
843 }
844 if(!Vcb->SparingCountFree) {
845 UDFPrint(("sparing table full\n"));
846 return STATUS_DISK_FULL;
847 }
848
849 Map = Vcb->SparingTable;
850 Lba &= ~(BS-1);
851 for(i=0;i<max;i++,Map++) {
852 orig = Map->origLocation;
853 if(Lba == (orig & ~(BS-1)) ) {
854 // already remapped
855
856 UDFPrint(("remap remapped: bad spare block @ %x\n", Map->mappedLocation));
857 if(!verified) {
858 verified = TRUE;
859 goto re_check;
860 }
861
862 if(!RemapSpared) {
864 } else {
865 // look for another remap area
867 Vcb->SparingTableModified = TRUE;
868 Vcb->SparingCountFree--;
869 break;
870 }
871 }
872 }
873 Map = Vcb->SparingTable;
874 for(i=0;i<max;i++,Map++) {
876 UDFPrint(("remap %x -> %x\n", Lba, Map->mappedLocation));
877 Map->origLocation = Lba;
878 Vcb->SparingTableModified = TRUE;
879 Vcb->SparingCountFree--;
880 return STATUS_SUCCESS;
881 }
882 }
883 UDFPrint(("sparing table full\n"));
884 return STATUS_DISK_FULL;
885 }
886 return STATUS_UNSUCCESSFUL;
887} // end UDFRemapPacket()
#define SPARING_LOC_CORRUPTED
Definition: osta_misc.h:196
#define SPARING_LOC_AVAILABLE
Definition: osta_misc.h:195
BOOLEAN __fastcall UDFCheckArea(IN PVCB Vcb, IN lba_t LBA, IN uint32 BCount)
Definition: remap.cpp:763
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_SHARING_VIOLATION
Definition: udferr_usr.h:154
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
#define UDFPrint(Args)
Definition: udffs.h:225

◆ UDFUnmapRange()

OSSTATUS __fastcall UDFUnmapRange ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BCount 
)

Definition at line 894 of file remap.cpp.

899{
900 uint32 i, max, BS, orig;
901 PSPARING_MAP Map;
902
903 if(Vcb->SparingTable) {
904 // use sparing table for relocation
905
906 max = Vcb->SparingCount;
907 BS = Vcb->SparingBlockSize;
908 Map = Vcb->SparingTable;
909 for(i=0;i<max;i++,Map++) {
910 orig = Map->origLocation;
911 switch(orig) {
914 continue;
915 }
916 if(orig >= Lba &&
917 (orig+BS) <= (Lba+BCount)) {
918 // unmap
919 UDFPrint(("unmap %x -> %x\n", orig, Map->mappedLocation));
921 Vcb->SparingTableModified = TRUE;
922 Vcb->SparingCountFree++;
923 }
924 }
925 }
926 return STATUS_SUCCESS;
927} // end UDFUnmapRange()

Referenced by UDFMarkSpaceAsXXXNoProtect_().

◆ UDFVFlush()

VOID UDFVFlush ( IN PVCB  Vcb)

Definition at line 742 of file remap.cpp.

745{
746 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
747
748 if(!VerifyCtx->VInited) {
749 return;
750 }
751
752 UDFPrint(("UDFVFlush: wait for completion\n"));
753 UDFVWaitQueued(VerifyCtx);
754
756
757 UDFPrint(("UDFVFlush: wait for completion (2)\n"));
758 UDFVWaitQueued(VerifyCtx);
759} // end UDFVFlush()
VOID UDFVWaitQueued(PUDF_VERIFY_CTX VerifyCtx)
Definition: remap.cpp:109
VOID UDFVVerify(IN PVCB Vcb, IN ULONG Flags)
Definition: remap.cpp:601
BOOLEAN VInited
Definition: udf_rel.h:553
#define UFD_VERIFY_FLAG_FORCE
Definition: udf_info.h:1302

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

◆ UDFVForget()

OSSTATUS UDFVForget ( IN PVCB  Vcb,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 486 of file remap.cpp.

492{
494 PUDF_VERIFY_ITEM vItem;
495 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
496 ULONG i;
497 ULONG n;
499
500 if(!VerifyCtx->VInited) {
501 return STATUS_UNSUCCESSFUL;
502 }
503
505
506 for(i=0, n=0; i<BCount; i++) {
507 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
508 // some blocks are remembered
509 n++;
510 }
511 }
512
513 if(!n) {
514 // no blocks are remembered
515 UDFReleaseResource(&(VerifyCtx->VerifyLock));
516 return STATUS_SUCCESS;
517 }
518
519 Link = VerifyCtx->vrfList.Flink;
520 i = 0;
521 while(Link != &(VerifyCtx->vrfList)) {
522 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
523 Link = Link->Flink;
524 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
525 i++;
526 UDFVRemoveBlock(VerifyCtx, vItem);
527 if(i >= n) {
528 // no more blocks expected
529 break;
530 }
531 }
532 }
533
534 UDFReleaseResource(&(VerifyCtx->VerifyLock));
535 return status;
536
537} // end UDFVForget()
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
GLdouble n
Definition: glext.h:7729
VOID UDFVRemoveBlock(PUDF_VERIFY_CTX VerifyCtx, PUDF_VERIFY_ITEM vItem)
Definition: remap.cpp:211
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ERESOURCE VerifyLock
Definition: udf_rel.h:549
LIST_ENTRY vrfList
Definition: udf_rel.h:548
uint8 * StoredBitMap
Definition: udf_rel.h:546
Definition: ps.c:97
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define UDFGetBit(arr, bit)
Definition: udf_info.h:1180
static int Link(const char **args)
Definition: vfdcmd.c:2414

◆ UDFVInit()

OSSTATUS UDFVInit ( IN PVCB  Vcb)

Definition at line 54 of file remap.cpp.

57{
58 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
59 uint32 i;
61 BOOLEAN res_inited = FALSE;
62
63 if(VerifyCtx->VInited) {
64 UDFPrint(("Already inited\n"));
65 return STATUS_SUCCESS;
66 }
67
68 _SEH2_TRY {
69 RtlZeroMemory(VerifyCtx, sizeof(UDF_VERIFY_CTX));
70 if(!Vcb->VerifyOnWrite) {
71 UDFPrint(("Verify is disabled\n"));
72 return STATUS_SUCCESS;
73 }
74 if(Vcb->CDR_Mode) {
75 UDFPrint(("Verify is not intended for CD/DVD-R\n"));
76 return STATUS_SUCCESS;
77 }
80 }
81 res_inited = TRUE;
82 VerifyCtx->ItemCount = 0;
83 VerifyCtx->StoredBitMap = (uint8*)DbgAllocatePoolWithTag(PagedPool, (i = (Vcb->LastPossibleLBA+1+7)>>3), 'mNWD' );
84 if(VerifyCtx->StoredBitMap) {
85 RtlZeroMemory(VerifyCtx->StoredBitMap, i);
86 } else {
87 UDFPrint(("Can't alloc verify bitmap for %x blocks\n", Vcb->LastPossibleLBA));
89 }
90 InitializeListHead(&(VerifyCtx->vrfList));
92 VerifyCtx->WaiterCount = 0;
93 VerifyCtx->VInited = TRUE;
94
95try_exit: NOTHING;
96
98
99 if(!OS_SUCCESS(status)) {
100 if(res_inited) {
101 ExDeleteResourceLite(&(VerifyCtx->VerifyLock));
102 }
103 }
104 } _SEH2_END;
105 return status;
106} // end UDFVInit()
#define try_return(S)
Definition: cdprocs.h:2179
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define NOTHING
Definition: input_list.c:10
@ SynchronizationEvent
ULONG ItemCount
Definition: udf_rel.h:547
KEVENT vrfEvent
Definition: udf_rel.h:550
uint32 WaiterCount
Definition: udf_rel.h:551
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

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

◆ UDFVRead()

OSSTATUS UDFVRead ( IN PVCB  Vcb,
IN void Buffer,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 375 of file remap.cpp.

383{
385 PUDF_VERIFY_ITEM vItem;
386 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
387 ULONG crc;
388 ULONG i;
389 ULONG n;
391 uint32* bm;
392
393 if(!VerifyCtx->VInited) {
394 return STATUS_SUCCESS;
395 //return STATUS_UNSUCCESSFUL;
396 }
397
399
400 for(i=0, n=0; i<BCount; i++) {
401 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
402 // some blocks are remembered
403 n++;
404 }
405 }
406
407 if(!n) {
408 // no blocks are remembered
409 UDFReleaseResource(&(VerifyCtx->VerifyLock));
410 return STATUS_SUCCESS;
411 }
412
413 Link = VerifyCtx->vrfList.Flink;
414 i=0;
415 while(Link != &(VerifyCtx->vrfList)) {
416 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
417 Link = Link->Flink;
418 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
419 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, vItem->lba));
420 i++;
421 if(!(Flags & PH_READ_VERIFY_CACHE)) {
422 crc = crc32((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, Vcb->BlockSize);
423 if(vItem->crc != crc) {
424 UDFPrint(("UDFVRead: stored %x != %x\n", vItem->crc, crc));
425 RtlCopyMemory((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, vItem->Buffer, Vcb->BlockSize);
427
428 if(!(bm = (uint32*)(Vcb->BSBM_Bitmap))) {
429 crc = (Vcb->LastPossibleLBA+1+7) >> 3; // reuse 'crc' variable
430 bm = (uint32*)(Vcb->BSBM_Bitmap = (int8*)DbgAllocatePoolWithTag(NonPagedPool, crc, 'mNWD' ));
431 if(bm) {
432 RtlZeroMemory(bm, crc);
433 } else {
434 UDFPrint(("Can't alloc BSBM for %x blocks\n", Vcb->LastPossibleLBA));
435 }
436 }
437 if(bm) {
438 UDFSetBit(bm, vItem->lba);
439 UDFPrint(("Set BB @ %#x\n", vItem->lba));
440 }
441#ifdef _BROWSE_UDF_
442 bm = (uint32*)(Vcb->FSBM_Bitmap);
443 if(bm) {
444 UDFSetUsedBit(bm, vItem->lba);
445 UDFPrint(("Set BB @ %#x as used\n", vItem->lba));
446 }
447#endif //_BROWSE_UDF_
448 } else {
449 // ok
450 }
451 } else {
452 UDFPrint(("UDFVRead: get cached @ %x\n", vItem->lba));
453 RtlCopyMemory((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, vItem->Buffer, Vcb->BlockSize);
454 }
455 if(i >= n) {
456 // no more blocks expected
457 break;
458 }
459 }
460 }
461
463 // ok, forget this, no errors found
464 Link = VerifyCtx->vrfList.Flink;
465 i = 0;
466 while(Link != &(VerifyCtx->vrfList)) {
467 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
468 Link = Link->Flink;
469 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
470 i++;
471 UDFVRemoveBlock(VerifyCtx, vItem);
472 if(i >= n) {
473 // no more blocks expected
474 break;
475 }
476 }
477 }
478 }
479
480 UDFReleaseResource(&(VerifyCtx->VerifyLock));
481 return status;
482
483} // end UDFVRead()
Definition: bufpool.h:45
#define crc32(crc, buf, len)
Definition: inflate.c:1081
char int8
Definition: platform.h:10
#define ASSERT(a)
Definition: mode.c:44
PUCHAR Buffer
Definition: remap.cpp:25
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
#define PH_READ_VERIFY_CACHE
Definition: udf_info.h:1271
#define UDFSetBit(arr, bit)
Definition: udf_info.h:1181
#define UDFSetUsedBit(arr, bit)
Definition: udf_info.h:1200
#define PH_FORGET_VERIFIED
Definition: udf_info.h:1270
#define PH_KEEP_VERIFY_CACHE
Definition: udf_info.h:1272
#define STATUS_FT_WRITE_RECOVERY
Definition: udferr_usr.h:126
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by UDFPhReadSynchronous(), and UDFVWorkItem().

◆ UDFVRelease()

VOID UDFVRelease ( IN PVCB  Vcb)

Definition at line 132 of file remap.cpp.

135{
136 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
138 PUDF_VERIFY_ITEM vItem;
139
140 if(!VerifyCtx->VInited) {
141 return;
142 }
143
144 UDFPrint(("UDFVRelease: wait for completion\n"));
145 UDFVWaitQueued(VerifyCtx);
146
148
149 Link = VerifyCtx->vrfList.Flink;
150
151 while(Link != &(VerifyCtx->vrfList)) {
152 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
153 Link = Link->Flink;
154 //DbgFreePool(vItem);
155 UDFVRemoveBlock(VerifyCtx, vItem);
156 }
157 VerifyCtx->VInited = FALSE;
158
159 UDFReleaseResource(&(VerifyCtx->VerifyLock));
160
161 ExDeleteResourceLite(&(VerifyCtx->VerifyLock));
162 DbgFreePool(VerifyCtx->StoredBitMap);
163
164 RtlZeroMemory(VerifyCtx, sizeof(UDF_VERIFY_CTX));
165
166 return;
167} // end UDFVRelease()

Referenced by UDFCommonDeviceControl(), and UDFReleaseVCB().

◆ UDFVRemoveBlock()

VOID UDFVRemoveBlock ( PUDF_VERIFY_CTX  VerifyCtx,
PUDF_VERIFY_ITEM  vItem 
)

Definition at line 211 of file remap.cpp.

215{
216 UDFPrint(("v-del %x\n", vItem->lba));
217 UDFClrBit(VerifyCtx->StoredBitMap, vItem->lba);
218 RemoveEntryList(&(vItem->vrfList));
219 VerifyCtx->ItemCount--;
220 DbgFreePool(vItem);
221 return;
222} // end UDFVUpdateBlock()
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
LIST_ENTRY vrfList
Definition: remap.cpp:26
#define UDFClrBit(arr, bit)
Definition: udf_info.h:1182

Referenced by UDFVForget(), UDFVRead(), UDFVRelease(), and UDFVWrite().

◆ UDFVStoreBlock()

PUDF_VERIFY_ITEM UDFVStoreBlock ( IN PVCB  Vcb,
IN uint32  LBA,
IN PVOID  Buffer,
PLIST_ENTRY  Link 
)

Definition at line 170 of file remap.cpp.

176{
177 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
178 PUDF_VERIFY_ITEM vItem;
179
180 UDFPrint(("v-add %x\n", LBA));
181
182 vItem = (PUDF_VERIFY_ITEM)DbgAllocatePoolWithTag(PagedPool, sizeof(UDF_VERIFY_ITEM)+Vcb->BlockSize, 'bvWD');
183 if(!vItem)
184 return NULL;
185 RtlCopyMemory(vItem+1, Buffer, Vcb->BlockSize);
186 vItem->lba = LBA;
187 vItem->crc = crc32((PUCHAR)Buffer, Vcb->BlockSize);
188 vItem->Buffer = (PUCHAR)(vItem+1);
189 vItem->queued = FALSE;
190 InitializeListHead(&(vItem->vrfList));
191 InsertTailList(Link, &(vItem->vrfList));
192 UDFSetBit(VerifyCtx->StoredBitMap, LBA);
193 VerifyCtx->ItemCount++;
194 return vItem;
195} // end UDFVStoreBlock()
#define InsertTailList(ListHead, Entry)
struct _UDF_VERIFY_ITEM * PUDF_VERIFY_ITEM
BOOLEAN queued
Definition: remap.cpp:27

Referenced by UDFVWrite().

◆ UDFVUpdateBlock()

VOID UDFVUpdateBlock ( IN PVCB  Vcb,
IN PVOID  Buffer,
PUDF_VERIFY_ITEM  vItem 
)

Definition at line 198 of file remap.cpp.

203{
204 UDFPrint(("v-upd %x\n", vItem->lba));
205 RtlCopyMemory(vItem+1, Buffer, Vcb->BlockSize);
206 vItem->crc = crc32((PUCHAR)Buffer, Vcb->BlockSize);
207 return;
208} // end UDFVUpdateBlock()

Referenced by UDFVWrite().

◆ UDFVVerify()

VOID UDFVVerify ( IN PVCB  Vcb,
IN ULONG  Flags 
)

Definition at line 601 of file remap.cpp.

605{
606 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
608 PUDF_VERIFY_ITEM vItem;
609 PUDF_VERIFY_REQ VerifyReq = NULL;
610 ULONG len, max_len=0;
611 lba_t prev_lba;
612 //PUCHAR tmp_buff;
613 ULONG i;
614 BOOLEAN do_vrf = FALSE;
615
616 if(!VerifyCtx->VInited) {
617 return;
618 }
619 if(VerifyCtx->QueuedCount) {
621 UDFPrint((" wait for verify flush\n"));
622 goto wait;
623 }
624 UDFPrint((" verify flush already queued\n"));
625 return;
626 }
627
629 if(VerifyCtx->ItemCount < UDF_MAX_VERIFY_CACHE) {
630 return;
631 }
632
633 }
636 }
637
639 i = VerifyCtx->ItemCount;
640 } else {
641 if(VerifyCtx->ItemCount >= UDF_MAX_VERIFY_CACHE) {
642 i = VerifyCtx->ItemCount - UDF_VERIFY_CACHE_LOW;
643 } else {
644 i = min(UDF_VERIFY_CACHE_GRAN, VerifyCtx->ItemCount);
645 }
646 }
647
648 Link = VerifyCtx->vrfList.Flink;
649 prev_lba = -2;
650 len = 0;
651
652 while(i) {
653 ASSERT(Link != &(VerifyCtx->vrfList));
654/*
655 if(Link == &(VerifyCtx->vrfList)) {
656 if(!len)
657 break;
658 i=1;
659 goto queue_req;
660 }
661*/
662 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
663 Link = Link->Flink;
664
665 //
666 if(!vItem->queued && (prev_lba+len == vItem->lba)) {
667 vItem->queued = TRUE;
668 len++;
669 } else {
670 if(len) {
671 do_vrf = TRUE;
672 } else {
673 len = 1;
674 prev_lba = vItem->lba;
675 }
676 }
677 if((i == 1) && len) {
678 do_vrf = TRUE;
679 }
680 if(len >= 0x100) {
681 do_vrf = TRUE;
682 }
683 if(do_vrf) {
684//queue_req:
685 if(!VerifyReq) {
687 if(VerifyReq) {
688 RtlZeroMemory(VerifyReq, sizeof(UDF_VERIFY_REQ));
689 VerifyReq->Vcb = Vcb;
690 }
691 }
692 if(VerifyReq) {
693
694 VerifyReq->vr[VerifyReq->nReq].lba = prev_lba;
695 VerifyReq->vr[VerifyReq->nReq].BCount = len;
696 VerifyReq->nReq++;
697 if(max_len < len) {
698 max_len = len;
699 }
700
701 if((VerifyReq->nReq >= MAX_VREQ_RANGES) || (i == 1)) {
702
703 VerifyReq->Buffer = (PUCHAR)DbgAllocatePoolWithTag(NonPagedPool, max_len * Vcb->BlockSize, 'bNWD');
704 if(VerifyReq->Buffer) {
705 InterlockedIncrement((PLONG)&(VerifyCtx->QueuedCount));
706#ifndef _CONSOLE
707 ExInitializeWorkItem( &(VerifyReq->VerifyItem),
709 VerifyReq );
711#else
712 UDFVWorkItem(VerifyReq);
713#endif
714 } else {
715 DbgFreePool(VerifyReq);
716 }
717 VerifyReq = NULL;
718 max_len = 0;
719 } else {
720 }
721 }
722 len = 1;
723 prev_lba = vItem->lba;
724 do_vrf = FALSE;
725 }
726 i--;
727 }
728
730 UDFReleaseResource(&(VerifyCtx->VerifyLock));
731 }
733wait:
734 UDFPrint(("UDFVVerify: wait for completion\n"));
735 UDFVWaitQueued(VerifyCtx);
736 }
737
738 return;
739} // end UDFVVerify()
#define InterlockedIncrement
Definition: armddk.h:53
uint32 lba_t
Definition: platform.h:20
GLenum GLsizei len
Definition: glext.h:6722
#define min(a, b)
Definition: monoChain.cc:55
#define MAX_VREQ_RANGES
Definition: remap.cpp:35
struct _UDF_VERIFY_REQ * PUDF_VERIFY_REQ
VOID NTAPI UDFVWorkItem(PVOID Context)
Definition: remap.cpp:541
uint32 QueuedCount
Definition: udf_rel.h:552
PUCHAR Buffer
Definition: remap.cpp:39
ULONG nReq
Definition: remap.cpp:40
WORK_QUEUE_ITEM VerifyItem
Definition: remap.cpp:43
UDF_VERIFY_REQ_RANGE vr[MAX_VREQ_RANGES]
Definition: remap.cpp:41
int32_t * PLONG
Definition: typedefs.h:58
#define UDF_MAX_VERIFY_CACHE
Definition: udf_info.h:1255
#define UFD_VERIFY_FLAG_WAIT
Definition: udf_info.h:1303
#define UDF_VERIFY_CACHE_GRAN
Definition: udf_info.h:1257
#define UFD_VERIFY_FLAG_BG
Definition: udf_info.h:1304
#define UFD_VERIFY_FLAG_LOCKED
Definition: udf_info.h:1305
#define UDF_VERIFY_CACHE_LOW
Definition: udf_info.h:1256
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ CriticalWorkQueue
Definition: extypes.h:189

Referenced by UDFCommonWrite(), UDFEjectReqWaiter(), UDFVFlush(), and UDFVWrite().

◆ UDFVWaitQueued()

VOID UDFVWaitQueued ( PUDF_VERIFY_CTX  VerifyCtx)

Definition at line 109 of file remap.cpp.

112{
113 ULONG w;
114
115 while(VerifyCtx->QueuedCount) {
116 UDFPrint(("UDFVWaitQueued: wait for completion (%d)\n", VerifyCtx->QueuedCount));
117 w = InterlockedIncrement((PLONG)&(VerifyCtx->WaiterCount));
118 UDFPrint((" %d waiters\n", w));
119 DbgWaitForSingleObject(&(VerifyCtx->vrfEvent), NULL);
120 if((w = InterlockedDecrement((PLONG)&(VerifyCtx->WaiterCount)))) {
121 UDFPrint((" still %d waiters, q %d\n", w, VerifyCtx->QueuedCount));
122 if(!VerifyCtx->QueuedCount) {
123 UDFPrint((" pulse event\n", w));
124 KeSetEvent(&(VerifyCtx->vrfEvent), 0, FALSE);
125 }
126 }
127 }
128 return;
129} // end UDFVWaitQueued()
#define InterlockedDecrement
Definition: armddk.h:52
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DbgWaitForSingleObject(o, to)
Definition: env_spec_w32.h:479
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102

Referenced by UDFVFlush(), UDFVRelease(), and UDFVVerify().

◆ UDFVWorkItem()

VOID NTAPI UDFVWorkItem ( PVOID  Context)

Definition at line 541 of file remap.cpp.

544{
546 PVCB Vcb = VerifyReq->Vcb;
548// OSSTATUS RC;
549 ULONG i;
550
552#if 1
553 if(Vcb->SparingCountFree) {
554 WCacheStartDirect__(&(Vcb->FastCache), Vcb, TRUE);
555 for(i=0; i<VerifyReq->nReq; i++) {
557 VerifyReq->Buffer, // Target buffer
558 VerifyReq->vr[i].BCount << Vcb->BlockSizeBits,
559 VerifyReq->vr[i].lba,
560 &ReadBytes,
561 PH_TMP_BUFFER | PH_VCB_IN_RETLEN /*| PH_LOCK_CACHE*/);
562 }
563 WCacheEODirect__(&(Vcb->FastCache), Vcb);
564 } else {
565 for(i=0; i<VerifyReq->nReq; i++) {
566 UDFPrint(("!!! No more space for remap !!!\n"));
567 UDFPrint((" try del from verify cache @ %x\n", VerifyReq->vr[i].lba));
568 UDFVRead(Vcb, VerifyReq->Buffer, VerifyReq->vr[i].BCount, VerifyReq->vr[i].lba,
570 }
571 }
572#else
573 for(i=0; i<VerifyReq->nReq; i++) {
574 if(Vcb->SparingCountFree) {
575 WCacheStartDirect__(&(Vcb->FastCache), Vcb, TRUE);
576 RC = UDFTIOVerify(Vcb,
577 VerifyReq->Buffer, // Target buffer
578 VerifyReq->vr[i].BCount << Vcb->BlockSizeBits,
579 VerifyReq->vr[i].lba,
580 &ReadBytes,
581 PH_TMP_BUFFER | PH_VCB_IN_RETLEN /*| PH_LOCK_CACHE*/);
582 WCacheEODirect__(&(Vcb->FastCache), Vcb);
583 } else {
584 UDFPrint(("!!! No more space for remap !!!\n"));
585 UDFPrint((" try del from verify cache @ %x\n", VerifyReq->vr[i].lba));
586 RC = UDFVRead(Vcb, VerifyReq->Buffer, VerifyReq->vr[i].BCount, VerifyReq->vr[i].lba,
588 }
589 }
590#endif
591 DbgFreePool(VerifyReq->Buffer);
592 DbgFreePool(VerifyReq);
593 InterlockedDecrement((PLONG)&(Vcb->VerifyCtx.QueuedCount));
594 UDFPrint((" QueuedCount = %d\n", Vcb->VerifyCtx.QueuedCount));
595 UDFPrint((" Setting event...\n"));
596 KeSetEvent(&(Vcb->VerifyCtx.vrfEvent), 0, FALSE);
597 return;
598} // end UDFVWorkItem()
#define PH_VCB_IN_RETLEN
Definition: phys_lib.h:66
OSSTATUS __fastcall UDFTIOVerify(IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T IOBytes, IN uint32 Flags)
OSSTATUS UDFVRead(IN PVCB Vcb, IN void *Buffer, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
Definition: remap.cpp:375
Definition: cdstruc.h:498
OSSTATUS WCacheStartDirect__(IN PW_CACHE Cache, IN PVOID Context, IN BOOLEAN Exclusive)
OSSTATUS WCacheEODirect__(IN PW_CACHE Cache, IN PVOID Context)

Referenced by UDFVVerify().

◆ UDFVWrite()

OSSTATUS UDFVWrite ( IN PVCB  Vcb,
IN void Buffer,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 225 of file remap.cpp.

233{
235 PUDF_VERIFY_ITEM vItem;
236 //PUDF_VERIFY_ITEM vItem1;
237 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
238 ULONG i;
239 ULONG n;
240 //uint32 prev_lba;
241
242 if(!VerifyCtx->VInited) {
243 return STATUS_SUCCESS;
244 }
245
247
248 for(i=0, n=0; i<BCount; i++) {
249 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
250 // some blocks are remembered
251 n++;
252 }
253 }
254
255 if(n == BCount) {
256 // update all blocks
257 n = 0;
258 Link = VerifyCtx->vrfList.Blink;
259 while(Link != &(VerifyCtx->vrfList)) {
260 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
261 Link = Link->Blink;
262 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
263 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, vItem->lba));
264 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+(vItem->lba-LBA)*Vcb->BlockSize, vItem);
265 n++;
266 if(n == BCount) {
267 // all updated
268 break;
269 }
270 }
271 }
272 } else
273 if(n) {
274#if 0
275 // find remembered blocks (the 1st one)
276 Link = VerifyCtx->vrfList.Blink;
277 while(Link != &(VerifyCtx->vrfList)) {
278 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
279 Link = Link->Blink;
280 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
281 //UDFVRemoveBlock(VerifyCtx, vItem);
282 break;
283 }
284 }
285
286 // check if contiguous
287 i=1;
288 prev_lba = vItem->lba;
289 vItem1 = vItem;
290 Link = Link->Blink;
291 while((i < n) && (Link != &(VerifyCtx->vrfList))) {
292 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
293 Link = Link->Blink;
294 if(vItem->lba > LBA || vItem->lba >= LBA+BCount) {
295 // end
296 break;
297 }
298 if(vItem->lba < prev_lba) {
299 // not sorted
300 break;
301 }
302 prev_lba = vItem->lba;
303 i++;
304 }
305
306 if(i == n) {
307 // cont
308 } else {
309 // drop all and add again
310 }
311
312 vItem1 = vItem;
313 for(i=0; i<BCount; i++) {
314 if(vItem->lba == LBA+i) {
315 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
316 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+i*Vcb->BlockSize, vItem);
317 continue;
318 }
319 if(vItem1->lba == LBA+i) {
320 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
321 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+i*Vcb->BlockSize, vItem1);
322 continue;
323 }
324 if(vItem1->lba > LBA+i) {
325 // just insert this block
326 ASSERT(!UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
327 UDFVStoreBlock(Vcb, LBA+i, ((PUCHAR)Buffer)+i*Vcb->BlockSize, &(vItem1->vrfList));
328 } else {
329 vItem = CONTAINING_RECORD( vItem->vrfList.Blink, UDF_VERIFY_ITEM, vrfList );
330 }
331 }
332#else
333 Link = VerifyCtx->vrfList.Blink;
334 i=0;
335 while(Link != &(VerifyCtx->vrfList)) {
336 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
337 Link = Link->Blink;
338 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
339 UDFVRemoveBlock(VerifyCtx, vItem);
340 i++;
341 if(i == n) {
342 // all killed
343 break;
344 }
345 }
346 }
347 goto remember_all;
348#endif
349
350 } else {
351remember_all:
352 // remember all blocks
353 for(i=0; i<BCount; i++) {
354 ASSERT(!UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
355 UDFVStoreBlock(Vcb, LBA+i, ((PUCHAR)Buffer)+i*Vcb->BlockSize, &(VerifyCtx->vrfList));
356 }
357 }
358
359 if(VerifyCtx->ItemCount > UDF_MAX_VERIFY_CACHE) {
361 }
362
363 UDFReleaseResource(&(VerifyCtx->VerifyLock));
364
365 if(VerifyCtx->ItemCount > UDF_MAX_VERIFY_CACHE*2) {
366 //UDFVVerify(Vcb, UFD_VERIFY_FLAG_LOCKED);
367 // TODO: make some delay
368 }
369
370 return STATUS_SUCCESS;
371
372} // end UDFVWrite()
PUDF_VERIFY_ITEM UDFVStoreBlock(IN PVCB Vcb, IN uint32 LBA, IN PVOID Buffer, PLIST_ENTRY Link)
Definition: remap.cpp:170
VOID UDFVUpdateBlock(IN PVCB Vcb, IN PVOID Buffer, PUDF_VERIFY_ITEM vItem)
Definition: remap.cpp:198
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122

Referenced by UDFPhWriteSynchronous().