ReactOS 0.4.16-dev-197-g92996da
shutdown.c File Reference
#include "fatprocs.h"
Include dependency graph for shutdown.c:

Go to the source code of this file.

Macros

#define Dbg   (DEBUG_TRACE_SHUTDOWN)
 

Functions

 _Function_class_ (IRP_MJ_SHUTDOWN)
 
 _Requires_lock_held_ (_Global_critical_region_)
 

Macro Definition Documentation

◆ Dbg

#define Dbg   (DEBUG_TRACE_SHUTDOWN)

Definition at line 22 of file shutdown.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( IRP_MJ_SHUTDOWN  )

Definition at line 30 of file shutdown.c.

64{
66 PIRP_CONTEXT IrpContext = NULL;
67
69
70 PAGED_CODE();
71
72 DebugTrace(+1, Dbg, "FatFsdShutdown\n", 0);
73
74 //
75 // Call the common shutdown routine.
76 //
77
79
81
82 _SEH2_TRY {
83
84 IrpContext = FatCreateIrpContext( Irp, TRUE );
85
86 Status = FatCommonShutdown( IrpContext, Irp );
87
89
90 //
91 // We had some trouble trying to perform the requested
92 // operation, so we'll abort the I/O request with
93 // the error status that we get back from the
94 // execption code
95 //
96
97 Status = FatProcessException( IrpContext, Irp, _SEH2_GetExceptionCode() );
98 } _SEH2_END;
99
100 if (TopLevel) { IoSetTopLevelIrp( NULL ); }
101
103
104 //
105 // And return to our caller
106 //
107
108 DebugTrace(-1, Dbg, "FatFsdShutdown -> %08lx\n", Status);
109
110 UNREFERENCED_PARAMETER( VolumeDeviceObject );
111
112 return Status;
113}
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define Dbg
Definition: shutdown.c:22
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2418
PIRP_CONTEXT FatCreateIrpContext(IN PIRP Irp, IN BOOLEAN Wait)
Definition: strucsup.c:2301
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:25
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 116 of file shutdown.c.

140{
142 PLIST_ENTRY Links;
143 PVCB Vcb;
144 PIRP NewIrp;
146 BOOLEAN VcbDeleted;
147
148 PAGED_CODE();
149
150 //
151 // Make sure we don't get any pop-ups, and write everything through.
152 //
153
154 SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS |
156
157 //
158 // Initialize an event for doing calls down to
159 // our target device objects.
160 //
161
163
164 //
165 // Indicate that shutdown has started. This is used in FatFspClose.
166 //
167
169
170 //
171 // Get everyone else out of the way
172 //
173
174 NT_ASSERT( FlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) );
175
176#ifdef _MSC_VER
177#pragma prefast( push )
178#pragma prefast( disable: 28137, "prefast wants the wait to be a constant, but that isn't possible for the way fastfat is designed" )
179#pragma prefast( disable: 28193, "this will always wait" )
180#endif
181
182 (VOID) FatAcquireExclusiveGlobal( IrpContext );
183
184#ifdef _MSC_VER
185#pragma prefast( pop )
186#endif
187
188 _SEH2_TRY {
189
190 //
191 // For every volume that is mounted we will flush the
192 // volume and then shutdown the target device objects.
193 //
194
195 Links = FatData.VcbQueue.Flink;
196 while (Links != &FatData.VcbQueue) {
197
198 Vcb = CONTAINING_RECORD(Links, VCB, VcbLinks);
199
200 Links = Links->Flink;
201
202 //
203 // If we have already been called before for this volume
204 // (and yes this does happen), skip this volume as no writes
205 // have been allowed since the first shutdown.
206 //
207
208 if ( FlagOn( Vcb->VcbState, VCB_STATE_FLAG_SHUTDOWN) ||
209 (Vcb->VcbCondition != VcbGood) ) {
210
211 continue;
212 }
213
214 FatAcquireExclusiveVolume( IrpContext, Vcb );
215
216 _SEH2_TRY {
217
218 (VOID)FatFlushVolume( IrpContext, Vcb, Flush );
219
220 //
221 // The volume is now clean, note it. We purge the
222 // volume file cache map before marking the volume
223 // clean incase there is a stale Bpb in the cache.
224 //
225
226 if (!FlagOn(Vcb->VcbState, VCB_STATE_FLAG_MOUNTED_DIRTY)) {
227
228 CcPurgeCacheSection( &Vcb->SectionObjectPointers,
229 NULL,
230 0,
231 FALSE );
232
233 FatMarkVolume( IrpContext, Vcb, VolumeClean );
234 }
235
237
238 FatResetExceptionState( IrpContext );
239 } _SEH2_END;
240
241 //
242 // Sometimes we take an excepion while flushing the volume, such
243 // as when autoconv has converted the volume and is rebooting.
244 // Even in that case we want to send the shutdown irp to the
245 // target device so it can know to flush its cache, if it has one.
246 //
247
248 _SEH2_TRY {
249
251 Vcb->TargetDeviceObject,
252 NULL,
253 0,
254 NULL,
255 &Event,
256 &Iosb );
257
258 if (NewIrp != NULL) {
259
260 if (NT_SUCCESS(IoCallDriver( Vcb->TargetDeviceObject, NewIrp ))) {
261
263 Executive,
265 FALSE,
266 NULL );
267
269 }
270 }
271
273
274 FatResetExceptionState( IrpContext );
275 } _SEH2_END;
276
277 SetFlag( Vcb->VcbState, VCB_STATE_FLAG_SHUTDOWN );
278
279 //
280 // Attempt to punch the volume down.
281 //
282
283 VcbDeleted = FatCheckForDismount( IrpContext,
284 Vcb,
285 FALSE );
286
287 if (!VcbDeleted) {
288
289 FatReleaseVolume( IrpContext, Vcb );
290 }
291 }
292
293 } _SEH2_FINALLY {
294
295
296 FatReleaseGlobal( IrpContext );
297
298 //
299 // Unregister the file system.
300 //
301
306
307 FatCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
308 } _SEH2_END;
309
310 //
311 // And return to our caller
312 //
313
314 DebugTrace(-1, Dbg, "FatFsdShutdown -> STATUS_SUCCESS\n", 0);
315
316 return STATUS_SUCCESS;
317}
#define VOID
Definition: acefi.h:82
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
Definition: cdstruc.h:1222
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
return Iosb
Definition: create.c:4402
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define IRP_CONTEXT_FLAG_WRITE_THROUGH
Definition: ext2fs.h:1088
PDEVICE_OBJECT FatDiskFileSystemDeviceObject
Definition: fatdata.c:58
FAT_DATA FatData
Definition: fatdata.c:56
PDEVICE_OBJECT FatCdromFileSystemDeviceObject
Definition: fatdata.c:59
@ VolumeClean
Definition: fatprocs.h:1955
#define FatAcquireExclusiveGlobal(IRPCONTEXT)
Definition: fatprocs.h:1388
#define FatAcquireExclusiveVolume(IRPCONTEXT, VCB)
Definition: fatprocs.h:1410
#define FatReleaseVolume(IRPCONTEXT, VCB)
Definition: fatprocs.h:1419
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2634
#define FatReleaseGlobal(IRPCONTEXT)
Definition: fatprocs.h:1637
#define FatResetExceptionState(IRPCONTEXT)
Definition: fatprocs.h:2984
@ Flush
Definition: fatprocs.h:1055
#define VCB_STATE_FLAG_SHUTDOWN
Definition: fatstruc.h:563
#define VCB_STATE_FLAG_MOUNTED_DIRTY
Definition: fatstruc.h:562
@ VcbGood
Definition: fatstruc.h:223
#define _SEH2_FINALLY
Definition: filesup.c:21
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1056
#define Vcb
Definition: cdprocs.h:1415
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOLEAN ShutdownStarted
Definition: fatstruc.h:108
LIST_ENTRY VcbQueue
Definition: fatstruc.h:49
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: cdstruc.h:498
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define IRP_MJ_SHUTDOWN
@ Executive
Definition: ketypes.h:415
#define NT_ASSERT
Definition: rtlfuncs.h:3324