ReactOS 0.4.16-dev-197-g92996da
shutdown.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1997-2006 Microsoft Corporation
4
5Module Name:
6
7 Shutdown.c
8
9Abstract:
10
11 This module implements the shutdown routine for CDFS called by
12 the dispatch driver.
13
14
15--*/
16
17#include "cdprocs.h"
18
19//
20// The Bug check file id for this module
21//
22
23#define BugCheckFileId (CDFS_BUG_CHECK_SHUTDOWN)
24
25#ifdef ALLOC_PRAGMA
26#pragma alloc_text(PAGE, CdCommonShutdown)
27#endif
28
29_Requires_lock_held_(_Global_critical_region_)
31CdCommonShutdown (
32 _Inout_ PIRP_CONTEXT IrpContext,
34 )
35
36/*++
37
38Routine Description:
39
40 This is the common routine for handling shutdown operation called
41 by both the fsd and fsp threads
42
43Arguments:
44
45 Irp - Supplies the Irp to process
46
47Return Value:
48
49 NTSTATUS - The return status for the operation
50
51--*/
52
53{
55 PLIST_ENTRY Links;
56 PVCB Vcb;
57 PIRP NewIrp;
59 BOOLEAN VcbPresent;
61
62 PAGED_CODE();
63
64 //
65 // Make sure we don't get any pop-ups.
66 //
67
68 SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS );
69
70 //
71 // Initialize an event for doing calls down to
72 // our target device objects.
73 //
74
76
77 //
78 // Indicate that shutdown has started.
79 //
80
82
83 //
84 // Get everyone else out of the way
85 //
86
87 CdAcquireCdData( IrpContext );
88
89 //
90 // Now walk through all the mounted Vcb's and shutdown the target
91 // device objects.
92 //
93
94 Links = CdData.VcbQueue.Flink;
95
96 while (Links != &CdData.VcbQueue) {
97
98 Vcb = CONTAINING_RECORD( Links, VCB, VcbLinks );
99
100 //
101 // Move to the next link now since the current Vcb may be deleted.
102 //
103
104 Links = Links->Flink;
105
106 //
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.
110 //
111
112 if (FlagOn( Vcb->VcbState, VCB_STATE_SHUTDOWN ) ||
113 (Vcb->VcbCondition != VcbMounted)) {
114
115 continue;
116 }
117
118 CdAcquireVcbExclusive( IrpContext, Vcb, FALSE );
119
120 CdPurgeVolume( IrpContext, Vcb, FALSE );
121
122 //
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.
125 //
126
128 Vcb->TargetDeviceObject,
129 NULL,
130 0,
131 NULL,
132 &Event,
133 &Iosb );
134
135 if (NewIrp != NULL) {
136
137 Status = IoCallDriver( Vcb->TargetDeviceObject, NewIrp );
138
139 if (Status == STATUS_PENDING) {
140
142 Executive,
144 FALSE,
145 NULL );
146 }
147
149 }
150
151 SetFlag( Vcb->VcbState, VCB_STATE_SHUTDOWN );
152
153 //
154 // Attempt to punch the volume down.
155 //
156
157 VcbPresent = CdCheckForDismount( IrpContext, Vcb, FALSE );
158
159 if (VcbPresent) {
160
161 CdReleaseVcb( IrpContext, Vcb );
162 }
163 }
164
165
166 CdReleaseCdData( IrpContext );
167
170#ifdef __REACTOS__
171 IoUnregisterFileSystem( CdData.HddFileSystemDeviceObject );
172 IoDeleteDevice( CdData.HddFileSystemDeviceObject );
173#endif
174
175 CdCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
176 return STATUS_SUCCESS;
177}
178
179
#define PAGED_CODE()
unsigned char BOOLEAN
#define VOID
Definition: acefi.h:82
LONG NTSTATUS
Definition: precomp.h:26
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
Definition: cddata.c:914
CD_DATA CdData
Definition: cddata.c:42
#define CdAcquireCdData(IC)
Definition: cdprocs.h:973
#define CdReleaseVcb(IC, V)
Definition: cdprocs.h:985
#define CdReleaseCdData(IC)
Definition: cdprocs.h:976
#define CdAcquireVcbExclusive(IC, V, I)
Definition: cdprocs.h:979
#define VCB_STATE_SHUTDOWN
Definition: cdstruc.h:715
#define CD_FLAGS_SHUTDOWN
Definition: cdstruc.h:422
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
Definition: cdstruc.h:1222
@ VcbMounted
Definition: cdstruc.h:492
#define _Requires_lock_held_(lock)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
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
Status
Definition: gdiplustypes.h:25
#define _Inout_
Definition: ms_sal.h:378
#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
USHORT Flags
Definition: cdstruc.h:380
LIST_ENTRY VcbQueue
Definition: cdstruc.h:334
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:350
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