ReactOS 0.4.15-dev-7961-gdcf9eb0
close.c File Reference
#include "fatprocs.h"
Include dependency graph for close.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (FAT_BUG_CHECK_CLOSE)
 
#define Dbg   (DEBUG_TRACE_CLOSE)
 
#define FatAcquireCloseMutex()
 
#define FatReleaseCloseMutex()
 

Functions

 _Requires_lock_held_ (_Global_critical_region_)
 
VOID NTAPI FatCloseWorker (_In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PVOID Context)
 

Variables

ULONG FatMaxDelayedCloseCount
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (FAT_BUG_CHECK_CLOSE)

Definition at line 23 of file close.c.

◆ Dbg

#define Dbg   (DEBUG_TRACE_CLOSE)

Definition at line 29 of file close.c.

◆ FatAcquireCloseMutex

#define FatAcquireCloseMutex ( )
Value:
{ \
NT_ASSERT(KeAreApcsDisabled()); \
ExAcquireFastMutexUnsafe( &FatCloseQueueMutex ); \
}
FAST_MUTEX FatCloseQueueMutex
Definition: fatdata.c:112
BOOLEAN NTAPI KeAreApcsDisabled(VOID)
Definition: apc.c:958

Definition at line 34 of file close.c.

◆ FatReleaseCloseMutex

#define FatReleaseCloseMutex ( )
Value:
{ \
NT_ASSERT(KeAreApcsDisabled()); \
ExReleaseFastMutexUnsafe( &FatCloseQueueMutex ); \
}

Definition at line 39 of file close.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 48 of file close.c.

108{
112
113 PVCB Vcb;
114 PFCB Fcb;
115 PCCB Ccb;
117
119 BOOLEAN VcbDeleted = FALSE;
120
121 PAGED_CODE();
122
123 //
124 // If we were called with our file system device object instead of a
125 // volume device object, just complete this request with STATUS_SUCCESS
126 //
127
128 if (FatDeviceIsFatFsdo( VolumeDeviceObject)) {
129
130 Irp->IoStatus.Status = STATUS_SUCCESS;
131 Irp->IoStatus.Information = FILE_OPENED;
132
134
135 return STATUS_SUCCESS;
136 }
137
138 DebugTrace(+1, Dbg, "FatFsdClose\n", 0);
139
140 //
141 // Call the common Close routine
142 //
143
145
147
148 //
149 // Get a pointer to the current stack location and the file object
150 //
151
153
155
156 //
157 // Decode the file object and set the read-only bit in the Ccb.
158 //
159
161
163
165 }
166
167 _SEH2_TRY {
168
169 PCLOSE_CONTEXT CloseContext = NULL;
170
171 //
172 // If we are top level, WAIT can be TRUE, otherwise make it FALSE
173 // to avoid deadlocks, unless this is a top
174 // level request not originating from the system process.
175 //
176
178
179#if (NTDDI_VERSION >= NTDDI_WIN8)
180
181 //
182 // To catch the odd case where a close comes in without a preceding cleanup,
183 // call the oplock package to get rid of any oplock state. This can only
184 // be safely done in the FSD path.
185 //
186
187 if ((Fcb != NULL) &&
190
191 //
192 // This is equivalent to handling cleanup, and it always cleans up any
193 // oplock immediately. Also, we don't need any locking of the FCB here;
194 // the oplock's own lock will be sufficient for this purpose.
195 //
196
197 FsRtlCheckOplockEx( FatGetFcbOplock(Fcb),
198 Irp,
199 0,
200 NULL,
201 NULL,
202 NULL );
203 }
204#endif
205
206 //
207 // Metadata streams have had close contexts preallocated. Pull one out now, while we're
208 // guaranteed the VCB exists.
209 //
210
212 ) {
213
214 CloseContext = FatAllocateCloseContext( Vcb );
215 NT_ASSERT( CloseContext != NULL );
216 CloseContext->Free = TRUE;
217
218 }
219
220 //
221 // Call the common Close routine if we are not delaying this close.
222 //
223
224 if ((((TypeOfOpen == UserFileOpen) ||
228 (FatCommonClose( Vcb, Fcb, Ccb, TypeOfOpen, Wait, TopLevel, &VcbDeleted ) == STATUS_PENDING)) {
229
230 //
231 // Ship it off to the delayed close queue if we tried to close, and got STATUS_PENDING, or
232 // if the user open told us to delay the close.
233 //
234
235 //
236 // Metadata streams have had close contexts preallocated. If we have a user open,
237 // pull the close context out of the Ccb.
238 //
239
240 if( CloseContext == NULL ) {
241
242 //
243 // Free up any query template strings before using the close context fields,
244 // which overlap (union)
245 //
246
248
249 CloseContext = &Ccb->CloseContext;
250 CloseContext->Free = FALSE;
251
253 }
254
255 //
256 // If the status is pending, then let's get the information we
257 // need into the close context we already have bagged, complete
258 // the request, and post it. It is important we allocate nothing
259 // in the close path.
260 //
261
262 CloseContext->Vcb = Vcb;
263 CloseContext->Fcb = Fcb;
264 CloseContext->TypeOfOpen = TypeOfOpen;
265
266 //
267 // Send it off, either to an ExWorkerThread or to the async
268 // close list.
269 //
270
271 FatQueueClose( CloseContext,
273
274 } else {
275
276 //
277 // The close proceeded synchronously, so for the metadata objects we
278 // can now drop the close context we preallocated.
279 //
280
281 if ((TypeOfOpen == VirtualVolumeFile) ||
283 (TypeOfOpen == EaFile)
284 ) {
285
286 if (CloseContext != NULL) {
287
288 ExFreePool( CloseContext );
289
290 }
291 }
292 }
293
295
296 }
298
299 //
300 // We had some trouble trying to perform the requested
301 // operation, so we'll abort the I/O request with the
302 // error status that we get back from the exception code.
303 //
304
305 Status = FatProcessException( NULL, Irp, _SEH2_GetExceptionCode() );
306 } _SEH2_END;
307
308 if (TopLevel) { IoSetTopLevelIrp( NULL ); }
309
311
312 //
313 // And return to our caller
314 //
315
316 DebugTrace(-1, Dbg, "FatFsdClose -> %08lx\n", Status);
317
318 UNREFERENCED_PARAMETER( VolumeDeviceObject );
319
320 return Status;
321}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:589
@ UserDirectoryOpen
Definition: cdprocs.h:576
@ UserFileOpen
Definition: cdprocs.h:577
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define Dbg
Definition: close.c:29
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
FAT_DATA FatData
Definition: fatdata.c:56
#define FatNull
Definition: fatdata.h:321
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define IsFileObjectReadOnly(FO)
Definition: fatprocs.h:2866
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2417
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2633
@ DirectoryFile
Definition: fatprocs.h:1046
@ VirtualVolumeFile
Definition: fatprocs.h:1045
@ EaFile
Definition: fatprocs.h:1047
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3095
VOID FatDeallocateCcbStrings(IN PCCB Ccb)
Definition: strucsup.c:2209
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1656
#define FatIsFileOplockable(F)
Definition: fatprocs.h:2851
PCLOSE_CONTEXT FatAllocateCloseContext(IN PVCB Vcb)
#define CCB_FLAG_READ_ONLY
Definition: fatstruc.h:1275
#define CCB_FLAG_CLOSE_CONTEXT
Definition: fatstruc.h:1324
#define FCB_STATE_DELAY_CLOSE
Definition: fatstruc.h:1203
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:25
#define FILE_OPENED
Definition: nt_native.h:769
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1415
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:158
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN Free
Definition: fatstruc.h:209
enum _TYPE_OF_OPEN TypeOfOpen
Definition: fatstruc.h:208
Definition: cdstruc.h:1067
BOOLEAN ShutdownStarted
Definition: fatstruc.h:108
PEPROCESS OurProcess
Definition: fatstruc.h:75
Definition: cdstruc.h:902
ULONG Flags
Definition: ntfs.h:536
ULONG FcbState
Definition: cdstruc.h:971
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
Definition: cdstruc.h:498
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1790
* PFILE_OBJECT
Definition: iotypes.h:1998
#define IO_DISK_INCREMENT
Definition: iotypes.h:600
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define NT_ASSERT
Definition: rtlfuncs.h:3310

◆ FatCloseWorker()

VOID NTAPI FatCloseWorker ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_opt_ PVOID  Context 
)

Definition at line 325 of file close.c.

345{
346 PAGED_CODE();
347
349
351
352 FatFspClose (Context);
353
355}
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Variable Documentation

◆ FatMaxDelayedCloseCount

ULONG FatMaxDelayedCloseCount

Definition at line 31 of file close.c.