3 Copyright (c) 1997-2006 Microsoft Corporation
11 This module implements the shutdown routine for CDFS called by
20 // The Bug check file id for this module
23 #define BugCheckFileId (CDFS_BUG_CHECK_SHUTDOWN)
26 #pragma alloc_text(PAGE, CdCommonShutdown)
29 _Requires_lock_held_(_Global_critical_region_
)
32 _Inout_ PIRP_CONTEXT IrpContext
,
40 This is the common routine for handling shutdown operation called
41 by both the fsd and fsp threads
45 Irp - Supplies the Irp to process
49 NTSTATUS - The return status for the operation
65 // Make sure we don't get any pop-ups.
68 SetFlag( IrpContext
->Flags
, IRP_CONTEXT_FLAG_DISABLE_POPUPS
);
71 // Initialize an event for doing calls down to
72 // our target device objects.
75 KeInitializeEvent( &Event
, NotificationEvent
, FALSE
);
78 // Indicate that shutdown has started.
81 SetFlag( CdData
.Flags
, CD_FLAGS_SHUTDOWN
);
84 // Get everyone else out of the way
87 CdAcquireCdData( IrpContext
);
90 // Now walk through all the mounted Vcb's and shutdown the target
94 Links
= CdData
.VcbQueue
.Flink
;
96 while (Links
!= &CdData
.VcbQueue
) {
98 Vcb
= CONTAINING_RECORD( Links
, VCB
, VcbLinks
);
101 // Move to the next link now since the current Vcb may be deleted.
104 Links
= Links
->Flink
;
107 // If we have already been called before for this volume
108 // (and yes this does happen), skip this volume as no writes
109 // have been allowed since the first shutdown.
112 if (FlagOn( Vcb
->VcbState
, VCB_STATE_SHUTDOWN
) ||
113 (Vcb
->VcbCondition
!= VcbMounted
)) {
118 CdAcquireVcbExclusive( IrpContext
, Vcb
, FALSE
);
120 CdPurgeVolume( IrpContext
, Vcb
, FALSE
);
123 // Build an irp for this volume stack - our own irp is probably too small and
124 // each stack may have a different stack size.
127 NewIrp
= IoBuildSynchronousFsdRequest( IRP_MJ_SHUTDOWN
,
128 Vcb
->TargetDeviceObject
,
135 if (NewIrp
!= NULL
) {
137 Status
= IoCallDriver( Vcb
->TargetDeviceObject
, NewIrp
);
139 if (Status
== STATUS_PENDING
) {
141 (VOID
)KeWaitForSingleObject( &Event
,
148 KeClearEvent( &Event
);
151 SetFlag( Vcb
->VcbState
, VCB_STATE_SHUTDOWN
);
154 // Attempt to punch the volume down.
157 VcbPresent
= CdCheckForDismount( IrpContext
, Vcb
, FALSE
);
161 CdReleaseVcb( IrpContext
, Vcb
);
166 CdReleaseCdData( IrpContext
);
168 IoUnregisterFileSystem( CdData
.FileSystemDeviceObject
);
169 IoDeleteDevice( CdData
.FileSystemDeviceObject
);
171 CdCompleteRequest( IrpContext
, Irp
, STATUS_SUCCESS
);
172 return STATUS_SUCCESS
;