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 #ifdef __REACTOS__
23 BOOLEAN NTAPI
24 #else
25 BOOLEAN
26 #endif
Ext2AcquireForLazyWrite(IN PVOID Context,IN BOOLEAN Wait)27 Ext2AcquireForLazyWrite (
28 IN PVOID Context,
29 IN BOOLEAN Wait)
30 {
31 //
32 // On a readonly filesystem this function still has to exist but it
33 // doesn't need to do anything.
34
35 PEXT2_FCB Fcb;
36
37 Fcb = (PEXT2_FCB) Context;
38 ASSERT(Fcb != NULL);
39 ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
40 (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
41 #if EXT2_DEBUG
42 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2AcquireForLazyWrite: %s %s Fcb=%p\n",
43 Ext2GetCurrentProcessName(), "ACQUIRE_FOR_LAZY_WRITE", Fcb));
44 #endif
45 if (!ExAcquireResourceExclusiveLite(Fcb->Header.Resource, Wait)) {
46 return FALSE;
47 }
48
49 ASSERT(Fcb->LazyWriterThread == NULL);
50 Fcb->LazyWriterThread = PsGetCurrentThread();
51
52 ASSERT(IoGetTopLevelIrp() == NULL);
53 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
54
55 return TRUE;
56 }
57
58 #ifdef __REACTOS__
59 VOID NTAPI
60 #else
61 VOID
62 #endif
Ext2ReleaseFromLazyWrite(IN PVOID Context)63 Ext2ReleaseFromLazyWrite (IN PVOID Context)
64 {
65 //
66 // On a readonly filesystem this function still has to exist but it
67 // doesn't need to do anything.
68 PEXT2_FCB Fcb = (PEXT2_FCB) Context;
69
70 ASSERT(Fcb != NULL);
71
72 ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
73 (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
74 #if EXT2_DEBUG
75 DEBUG(CMCB_DEBUG_LEVEL, ( "Ext2ReleaseFromLazyWrite: %s %s Fcb=%p\n",
76 Ext2GetCurrentProcessName(), "RELEASE_FROM_LAZY_WRITE", Fcb));
77 #endif
78 ASSERT(Fcb->LazyWriterThread == PsGetCurrentThread());
79 Fcb->LazyWriterThread = NULL;
80
81 ExReleaseResourceLite(Fcb->Header.Resource);
82
83 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
84 IoSetTopLevelIrp( NULL );
85 }
86
87 #ifdef __REACTOS__
88 BOOLEAN NTAPI
89 #else
90 BOOLEAN
91 #endif
Ext2AcquireForReadAhead(IN PVOID Context,IN BOOLEAN Wait)92 Ext2AcquireForReadAhead (IN PVOID Context,
93 IN BOOLEAN Wait)
94 {
95 PEXT2_FCB Fcb = (PEXT2_FCB) Context;
96
97 ASSERT(Fcb != NULL);
98 ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
99 (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
100
101 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2AcquireForReadAhead: i=%xh Fcb=%p\n",
102 Fcb->Mcb->Inode.i_ino, Fcb));
103
104 if (!ExAcquireResourceSharedLite(Fcb->Header.Resource, Wait))
105 return FALSE;
106 ASSERT(IoGetTopLevelIrp() == NULL);
107 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
108
109 return TRUE;
110 }
111
112 #ifdef __REACTOS__
113 VOID NTAPI
114 #else
115 VOID
116 #endif
Ext2ReleaseFromReadAhead(IN PVOID Context)117 Ext2ReleaseFromReadAhead (IN PVOID Context)
118 {
119 PEXT2_FCB Fcb = (PEXT2_FCB) Context;
120
121 ASSERT(Fcb != NULL);
122
123 ASSERT((Fcb->Identifier.Type == EXT2FCB) &&
124 (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
125
126 DEBUG(CMCB_DEBUG_LEVEL, ("Ext2ReleaseFromReadAhead: i=%xh Fcb=%p\n",
127 Fcb->Mcb->Inode.i_ino, Fcb));
128
129 IoSetTopLevelIrp(NULL);
130 ExReleaseResourceLite(Fcb->Header.Resource);
131 }
132
133 #ifdef __REACTOS__
134 BOOLEAN NTAPI
135 #else
136 BOOLEAN
137 #endif
Ext2NoOpAcquire(IN PVOID Fcb,IN BOOLEAN Wait)138 Ext2NoOpAcquire (
139 IN PVOID Fcb,
140 IN BOOLEAN Wait
141 )
142 {
143 ASSERT(IoGetTopLevelIrp() == NULL);
144 IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
145 return TRUE;
146 }
147
148 #ifdef __REACTOS__
149 VOID NTAPI
150 #else
151 VOID
152 #endif
Ext2NoOpRelease(IN PVOID Fcb)153 Ext2NoOpRelease (
154 IN PVOID Fcb
155 )
156 {
157 ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
158 IoSetTopLevelIrp( NULL );
159
160 return;
161 }
162
163