ReactOS  0.4.14-dev-991-g696cdc6
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 ); \
}
FAST_MUTEX FatCloseQueueMutex
Definition: fatdata.c:112
BOOLEAN NTAPI KeAreApcsDisabled(VOID)
Definition: apc.c:958

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) &&
188  !FlagOn( FileObject->Flags, FO_CLEANUP_COMPLETE ) &&
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) ||
282  (TypeOfOpen == DirectoryFile) ||
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 execption 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 }
#define IsFileObjectReadOnly(FO)
Definition: fatprocs.h:2854
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
PCLOSE_CONTEXT FatAllocateCloseContext(IN PVCB Vcb)
#define FsRtlExitFileSystem
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
enum _TYPE_OF_OPEN TypeOfOpen
Definition: fatstruc.h:207
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
Definition: cdstruc.h:1073
LONG NTSTATUS
Definition: precomp.h:26
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3083
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define FILE_OPENED
Definition: nt_native.h:769
#define Dbg
Definition: close.c:29
Definition: cdstruc.h:504
BOOLEAN ShutdownStarted
Definition: fatstruc.h:107
#define FatNull
Definition: fatdata.h:321
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2401
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:593
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1647
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
FAT_DATA FatData
Definition: fatdata.c:56
#define CCB_FLAG_READ_ONLY
Definition: fatstruc.h:1274
#define STATUS_PENDING
Definition: ntstatus.h:82
BOOLEAN Free
Definition: fatstruc.h:208
#define Vcb
Definition: cdprocs.h:1425
#define FCB_STATE_DELAY_CLOSE
Definition: fatstruc.h:1202
PEPROCESS OurProcess
Definition: fatstruc.h:74
#define FatIsFileOplockable(F)
Definition: fatprocs.h:2839
* PFILE_OBJECT
Definition: iotypes.h:1955
ULONG Flags
Definition: ntfs.h:532
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1747
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define CCB_FLAG_CLOSE_CONTEXT
Definition: fatstruc.h:1323
ULONG FcbState
Definition: cdstruc.h:977
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID FatDeallocateCcbStrings(IN PCCB Ccb)
Definition: strucsup.c:2208
IN BOOLEAN Wait
Definition: fatprocs.h:1529
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ 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 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define PAGED_CODE()
Definition: video.h:57
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Variable Documentation

◆ FatMaxDelayedCloseCount

ULONG FatMaxDelayedCloseCount

Definition at line 31 of file close.c.