Sample Code
windows driver samples/ cdfs file system driver/ C++/ shutdown.c/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /*++ Copyright (c) 1997-2006 Microsoft Corporation Module Name: Shutdown.c Abstract: This module implements the shutdown routine for CDFS called by the dispatch driver. --*/ #include "CdProcs.h" // // The Bug check file id for this module // #define BugCheckFileId (CDFS_BUG_CHECK_SHUTDOWN) #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, CdCommonShutdown) #endif _Requires_lock_held_(_Global_critical_region_) NTSTATUS CdCommonShutdown ( _Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp ) /*++ Routine Description: This is the common routine for handling shutdown operation called by both the fsd and fsp threads Arguments: Irp - Supplies the Irp to process Return Value: NTSTATUS - The return status for the operation --*/ { KEVENT Event; PLIST_ENTRY Links; PVCB Vcb; PIRP NewIrp; IO_STATUS_BLOCK Iosb; BOOLEAN VcbPresent; NTSTATUS Status; PAGED_CODE(); // // Make sure we don't get any pop-ups. // SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS ); // // Initialize an event for doing calls down to // our target device objects. // KeInitializeEvent( &Event, NotificationEvent, FALSE ); // // Indicate that shutdown has started. // SetFlag( CdData.Flags, CD_FLAGS_SHUTDOWN ); // // Get everyone else out of the way // CdAcquireCdData( IrpContext ); // // Now walk through all the mounted Vcb's and shutdown the target // device objects. // Links = CdData.VcbQueue.Flink; while (Links != &CdData.VcbQueue) { Vcb = CONTAINING_RECORD( Links, VCB, VcbLinks ); // // Move to the next link now since the current Vcb may be deleted. // Links = Links->Flink; // // If we have already been called before for this volume // (and yes this does happen), skip this volume as no writes // have been allowed since the first shutdown. // if (FlagOn( Vcb->VcbState, VCB_STATE_SHUTDOWN ) || (Vcb->VcbCondition != VcbMounted)) { continue ; } #pragma prefast(suppress: 28103) CdAcquireVcbExclusive( IrpContext, Vcb, FALSE ); CdPurgeVolume( IrpContext, Vcb, FALSE ); // // Build an irp for this volume stack - our own irp is probably too small and // each stack may have a different stack size. // NewIrp = IoBuildSynchronousFsdRequest( IRP_MJ_SHUTDOWN, Vcb->TargetDeviceObject, NULL, 0, NULL, &Event, &Iosb ); if (NewIrp != NULL) { Status = IoCallDriver( Vcb->TargetDeviceObject, NewIrp ); if (Status == STATUS_PENDING) { ( VOID )KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL ); } KeClearEvent( &Event ); } SetFlag( Vcb->VcbState, VCB_STATE_SHUTDOWN ); // // Attempt to punch the volume down. // VcbPresent = CdCheckForDismount( IrpContext, Vcb, FALSE ); if (VcbPresent) { CdReleaseVcb( IrpContext, Vcb ); } } CdReleaseCdData( IrpContext ); IoUnregisterFileSystem( CdData.FileSystemDeviceObject ); IoDeleteDevice( CdData.FileSystemDeviceObject ); CdCompleteRequest( IrpContext, Irp, STATUS_SUCCESS ); return STATUS_SUCCESS; } |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials