1 /* 2 * COPYRIGHT: See COPYRIGHT.TXT 3 * PROJECT: Ext2 File System Driver for WinNT/2K/XP 4 * FILE: cmcb.c 5 * PROGRAMMER: Matt Wu <mattwu@163.com> 6 * HOMEPAGE: http://www.ext2fsd.com 7 * UPDATE HISTORY: 8 */ 9 10 /* INCLUDES *****************************************************************/ 11 12 #include "ext2fs.h" 13 14 /* GLOBALS ***************************************************************/ 15 16 extern PEXT2_GLOBAL Ext2Global; 17 18 /* DEFINITIONS *************************************************************/ 19 20 #define CMCB_DEBUG_LEVEL DL_NVR 21 22 BOOLEAN NTAPI 23 Ext2AcquireForLazyWrite ( 24 IN PVOID Context, 25 IN BOOLEAN Wait) 26 { 27 // 28 // On a readonly filesystem this function still has to exist but it 29 // doesn't need to do anything. 30 31 PEXT2_FCB Fcb; 32 33 Fcb = (PEXT2_FCB) Context; 34 ASSERT(Fcb != NULL); 35 ASSERT((Fcb->Identifier.Type == EXT2FCB) && 36 (Fcb->Identifier.Size == sizeof(EXT2_FCB))); 37 #if EXT2_DEBUG 38 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2AcquireForLazyWrite: %s %s Fcb=%p\n", 39 Ext2GetCurrentProcessName(), "ACQUIRE_FOR_LAZY_WRITE", Fcb)); 40 #endif 41 if (!ExAcquireResourceExclusiveLite(Fcb->Header.Resource, Wait)) { 42 return FALSE; 43 } 44 45 ASSERT(Fcb->LazyWriterThread == NULL); 46 Fcb->LazyWriterThread = PsGetCurrentThread(); 47 48 ASSERT(IoGetTopLevelIrp() == NULL); 49 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 50 51 return TRUE; 52 } 53 54 VOID NTAPI 55 Ext2ReleaseFromLazyWrite (IN PVOID Context) 56 { 57 // 58 // On a readonly filesystem this function still has to exist but it 59 // doesn't need to do anything. 60 PEXT2_FCB Fcb = (PEXT2_FCB) Context; 61 62 ASSERT(Fcb != NULL); 63 64 ASSERT((Fcb->Identifier.Type == EXT2FCB) && 65 (Fcb->Identifier.Size == sizeof(EXT2_FCB))); 66 #if EXT2_DEBUG 67 DEBUG(CMCB_DEBUG_LEVEL, ( "Ext2ReleaseFromLazyWrite: %s %s Fcb=%p\n", 68 Ext2GetCurrentProcessName(), "RELEASE_FROM_LAZY_WRITE", Fcb)); 69 #endif 70 ASSERT(Fcb->LazyWriterThread == PsGetCurrentThread()); 71 Fcb->LazyWriterThread = NULL; 72 73 ExReleaseResourceLite(Fcb->Header.Resource); 74 75 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 76 IoSetTopLevelIrp( NULL ); 77 } 78 79 BOOLEAN NTAPI 80 Ext2AcquireForReadAhead (IN PVOID Context, 81 IN BOOLEAN Wait) 82 { 83 PEXT2_FCB Fcb = (PEXT2_FCB) Context; 84 85 ASSERT(Fcb != NULL); 86 ASSERT((Fcb->Identifier.Type == EXT2FCB) && 87 (Fcb->Identifier.Size == sizeof(EXT2_FCB))); 88 89 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2AcquireForReadAhead: i=%xh Fcb=%p\n", 90 Fcb->Mcb->Inode.i_ino, Fcb)); 91 92 if (!ExAcquireResourceSharedLite(Fcb->Header.Resource, Wait)) 93 return FALSE; 94 ASSERT(IoGetTopLevelIrp() == NULL); 95 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 96 97 return TRUE; 98 } 99 100 VOID NTAPI 101 Ext2ReleaseFromReadAhead (IN PVOID Context) 102 { 103 PEXT2_FCB Fcb = (PEXT2_FCB) Context; 104 105 ASSERT(Fcb != NULL); 106 107 ASSERT((Fcb->Identifier.Type == EXT2FCB) && 108 (Fcb->Identifier.Size == sizeof(EXT2_FCB))); 109 110 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2ReleaseFromReadAhead: i=%xh Fcb=%p\n", 111 Fcb->Mcb->Inode.i_ino, Fcb)); 112 113 IoSetTopLevelIrp(NULL); 114 ExReleaseResourceLite(Fcb->Header.Resource); 115 } 116 117 BOOLEAN NTAPI 118 Ext2NoOpAcquire ( 119 IN PVOID Fcb, 120 IN BOOLEAN Wait 121 ) 122 { 123 ASSERT(IoGetTopLevelIrp() == NULL); 124 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 125 return TRUE; 126 } 127 128 VOID NTAPI 129 Ext2NoOpRelease ( 130 IN PVOID Fcb 131 ) 132 { 133 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); 134 IoSetTopLevelIrp( NULL ); 135 136 return; 137 } 138 139