ReactOS  0.4.13-dev-73-gcfe54aa
shutdown.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1997-2006 Microsoft Corporation
4 
5 Module Name:
6 
7  Shutdown.c
8 
9 Abstract:
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_)
31 CdCommonShutdown (
32  _Inout_ PIRP_CONTEXT IrpContext,
34  )
35 
36 /*++
37 
38 Routine Description:
39 
40  This is the common routine for handling shutdown operation called
41  by both the fsd and fsp threads
42 
43 Arguments:
44 
45  Irp - Supplies the Irp to process
46 
47 Return Value:
48 
49  NTSTATUS - The return status for the operation
50 
51 --*/
52 
53 {
54  KEVENT Event;
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,
143  KernelMode,
144  FALSE,
145  NULL );
146  }
147 
148  KeClearEvent( &Event );
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 
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:356
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 IRP_MJ_SHUTDOWN
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1053
LONG NTSTATUS
Definition: precomp.h:26
Definition: cdstruc.h:504
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
Definition: cdstruc.h:1228
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
Definition: cddata.c:914
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define VCB_STATE_SHUTDOWN
Definition: cdstruc.h:721
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define CdAcquireVcbExclusive(IC, V, I)
Definition: cdprocs.h:984
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
USHORT Flags
Definition: cdstruc.h:386
CD_DATA CdData
Definition: cddata.c:42
return Iosb
Definition: create.c:4426
#define CdReleaseVcb(IC, V)
Definition: cdprocs.h:990
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
#define _Inout_
Definition: no_sal2.h:244
#define VOID
Definition: acefi.h:82
Definition: typedefs.h:117
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define CdAcquireCdData(IC)
Definition: cdprocs.h:978
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define CdReleaseCdData(IC)
Definition: cdprocs.h:981
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_Requires_lock_held_(_Global_critical_region_)
Definition: shutdown.c:29
LIST_ENTRY VcbQueue
Definition: cdstruc.h:340
#define CD_FLAGS_SHUTDOWN
Definition: cdstruc.h:428
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2725