Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenshutdown.c
Go to the documentation of this file.
00001 /************************************************************************* 00002 * 00003 * File: shutdown.c 00004 * 00005 * Module: Ext2 File System Driver (Kernel mode execution only) 00006 * 00007 * Description: 00008 * Contains code to handle the "shutdown notification" dispatch entry point. 00009 * 00010 * Author: Manoj Paul Joseph 00011 * 00012 * 00013 *************************************************************************/ 00014 00015 #include "ext2fsd.h" 00016 00017 // define the file specific bug-check id 00018 #define EXT2_BUG_CHECK_ID EXT2_FILE_SHUTDOWN 00019 #define DEBUG_LEVEL (DEBUG_TRACE_SHUTDOWN) 00020 00021 00022 /************************************************************************* 00023 * 00024 * Function: Ext2Shutdown() 00025 * 00026 * Description: 00027 * All disk-based FSDs can expect to receive this shutdown notification 00028 * request whenever the system is about to be halted gracefully. If you 00029 * design and implement a network redirector, you must register explicitly 00030 * for shutdown notification by invoking the IoRegisterShutdownNotification() 00031 * routine from your driver entry. 00032 * 00033 * Note that drivers that register to receive shutdown notification get 00034 * invoked BEFORE disk-based FSDs are told about the shutdown notification. 00035 * 00036 * Expected Interrupt Level (for execution) : 00037 * 00038 * IRQL_PASSIVE_LEVEL 00039 * 00040 * Return Value: Irrelevant. 00041 * 00042 *************************************************************************/ 00043 NTSTATUS NTAPI Ext2Shutdown( 00044 PDEVICE_OBJECT DeviceObject, // the logical volume device object 00045 PIRP Irp) // I/O Request Packet 00046 { 00047 NTSTATUS RC = STATUS_SUCCESS; 00048 PtrExt2IrpContext PtrIrpContext = NULL; 00049 BOOLEAN AreWeTopLevel = FALSE; 00050 00051 DebugTrace(DEBUG_TRACE_IRP_ENTRY, "Shutdown IRP received...", 0); 00052 00053 FsRtlEnterFileSystem(); 00054 ASSERT(DeviceObject); 00055 ASSERT(Irp); 00056 00057 // set the top level context 00058 AreWeTopLevel = Ext2IsIrpTopLevel(Irp); 00059 00060 try 00061 { 00062 00063 // get an IRP context structure and issue the request 00064 PtrIrpContext = Ext2AllocateIrpContext(Irp, DeviceObject); 00065 ASSERT(PtrIrpContext); 00066 00067 RC = Ext2CommonShutdown(PtrIrpContext, Irp); 00068 00069 } 00070 except (Ext2ExceptionFilter(PtrIrpContext, GetExceptionInformation())) 00071 { 00072 00073 RC = Ext2ExceptionHandler(PtrIrpContext, Irp); 00074 00075 Ext2LogEvent(EXT2_ERROR_INTERNAL_ERROR, RC); 00076 } 00077 00078 if (AreWeTopLevel) 00079 { 00080 IoSetTopLevelIrp(NULL); 00081 } 00082 00083 FsRtlExitFileSystem(); 00084 00085 return(RC); 00086 } 00087 00088 00089 /************************************************************************* 00090 * 00091 * Function: Ext2CommonShutdown() 00092 * 00093 * Description: 00094 * The actual work is performed here. Basically, all we do here is 00095 * internally invoke a flush on all mounted logical volumes. This, in 00096 * tuen, will result in all open file streams being flushed to disk. 00097 * 00098 * Expected Interrupt Level (for execution) : 00099 * 00100 * IRQL_PASSIVE_LEVEL 00101 * 00102 * Return Value: Irrelevant 00103 * 00104 *************************************************************************/ 00105 NTSTATUS NTAPI Ext2CommonShutdown( 00106 PtrExt2IrpContext PtrIrpContext, 00107 PIRP PtrIrp) 00108 { 00109 NTSTATUS RC = STATUS_SUCCESS; 00110 PIO_STACK_LOCATION PtrIoStackLocation = NULL; 00111 00112 try 00113 { 00114 // First, get a pointer to the current I/O stack location 00115 PtrIoStackLocation = IoGetCurrentIrpStackLocation(PtrIrp); 00116 ASSERT(PtrIoStackLocation); 00117 00118 // (a) Block all new "mount volume" requests by acquiring an appropriate 00119 // global resource/lock. 00120 // (b) Go through your linked list of mounted logical volumes and for 00121 // each such volume, do the following: 00122 // (i) acquire the volume resource exclusively 00123 // (ii) invoke Ext2FlushLogicalVolume() (internally) to flush the 00124 // open data streams belonging to the volume from the system 00125 // cache 00126 // (iii) Invoke the physical/virtual/logical target device object 00127 // on which the volume is mounted and inform this device 00128 // about the shutdown request (Use IoBuildSynchronousFsdRequest() 00129 // to create an IRP with MajorFunction = IRP_MJ_SHUTDOWN that you 00130 // will then issue to the target device object). 00131 // (iv) Wait for the completion of the shutdown processing by the target 00132 // device object 00133 // (v) Release the VCB resource you will have acquired in (i) above. 00134 00135 // Once you have processed all the mounted logical volumes, you can release 00136 // all acquired global resources and leave (in peace :-) 00137 00138 00139 00140 /*//////////////////////////////////////////// 00141 // 00142 // Update the Group... 00143 // 00144 if( PtrVCB->LogBlockSize ) 00145 { 00146 // First block contains the descriptors... 00147 VolumeByteOffset.QuadPart = LogicalBlockSize; 00148 } 00149 else 00150 { 00151 // Second block contains the descriptors... 00152 VolumeByteOffset.QuadPart = LogicalBlockSize * 2; 00153 } 00154 00155 NumberOfBytesToRead = sizeof( struct ext2_group_desc ); 00156 NumberOfBytesToRead = Ext2Align( NumberOfBytesToRead, LogicalBlockSize ); 00157 00158 if (!CcMapData( PtrVCB->PtrStreamFileObject, 00159 &VolumeByteOffset, 00160 NumberOfBytesToRead, 00161 TRUE, 00162 &PtrBCB, 00163 &PtrCacheBuffer )) 00164 { 00165 DebugTrace(DEBUG_TRACE_ERROR, "Cache read failiure while reading in volume meta data", 0); 00166 try_return( Status = STATUS_INSUFFICIENT_RESOURCES ); 00167 } 00168 else 00169 { 00170 // 00171 // Saving up Often Used Group Descriptor Information in the VCB... 00172 // 00173 unsigned int DescIndex ; 00174 00175 DebugTrace(DEBUG_TRACE_MISC, "Cache hit while reading in volume meta data", 0); 00176 PtrGroupDescriptor = (PEXT2_GROUP_DESCRIPTOR )PtrCacheBuffer; 00177 for( DescIndex = 0; DescIndex < PtrVCB->NoOfGroups; DescIndex++ ) 00178 { 00179 PtrVCB->PtrGroupDescriptors[ DescIndex ].InodeTablesBlock 00180 = PtrGroupDescriptor[ DescIndex ].bg_inode_table; 00181 00182 PtrVCB->PtrGroupDescriptors[ DescIndex ].InodeBitmapBlock 00183 = PtrGroupDescriptor[ DescIndex ].bg_inode_bitmap 00184 ; 00185 PtrVCB->PtrGroupDescriptors[ DescIndex ].BlockBitmapBlock 00186 = PtrGroupDescriptor[ DescIndex ].bg_block_bitmap 00187 ; 00188 PtrVCB->PtrGroupDescriptors[ DescIndex ].FreeBlocksCount 00189 = PtrGroupDescriptor[ DescIndex ].bg_free_blocks_count; 00190 00191 PtrVCB->PtrGroupDescriptors[ DescIndex ].FreeInodesCount 00192 = PtrGroupDescriptor[ DescIndex ].bg_free_inodes_count; 00193 } 00194 CcUnpinData( PtrBCB ); 00195 PtrBCB = NULL; 00196 } 00197 */ 00198 00199 } 00200 finally 00201 { 00202 00203 // See the read/write examples for how to fill in this portion 00204 00205 } // end of "finally" processing 00206 00207 return(RC); 00208 } Generated on Sun May 27 2012 04:17:43 for ReactOS by
1.7.6.1
|