Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygenDiskIO.c
Go to the documentation of this file.
00001 /************************************************************************* 00002 * 00003 * File: DiskIO.c 00004 * 00005 * Module: Ext2 File System Driver (Kernel mode execution only) 00006 * 00007 * Description: 00008 * Should contain code to handle Disk IO. 00009 * 00010 * 00011 * Author: Manoj Paul Joseph 00012 * 00013 * 00014 *************************************************************************/ 00015 00016 #include "ext2fsd.h" 00017 00018 #define EXT2_BUG_CHECK_ID EXT2_FILE_DISK_IO 00019 00020 #define DEBUG_LEVEL ( DEBUG_TRACE_DISKIO ) 00021 00022 00023 /************************************************************************* 00024 * 00025 * Function: Ext2ReadLogicalBlocks() 00026 * 00027 * Description: 00028 * The higherlevel functions will use this to read in logical blocks 00029 * This function deals with the logical to physical block translation 00030 * 00031 * LogicalBlock - This is a 1 based index. 00032 * That is, the first block is Block 1 00033 * 00034 * Expected Interrupt Level (for execution) : 00035 * 00036 * IRQL_PASSIVE_LEVEL 00037 * 00038 * Return Value: The Status of the Read IO 00039 * 00040 *************************************************************************/ 00041 NTSTATUS NTAPI Ext2ReadLogicalBlocks ( 00042 PDEVICE_OBJECT PtrTargetDeviceObject, // the Target Device Object 00043 VOID *Buffer, // The Buffer that takes the data read in 00044 LARGE_INTEGER StartLogicalBlock, // The logical block from which reading is to start 00045 unsigned int NoOfLogicalBlocks // The no. of logical blocks to be read 00046 ) 00047 { 00048 // The Status to be returned... 00049 NTSTATUS Status = STATUS_SUCCESS; 00050 00051 // The Device Object representing the mounted volume 00052 PDEVICE_OBJECT PtrVolumeDeviceObject = NULL; 00053 00054 // Volume Control Block 00055 PtrExt2VCB PtrVCB = NULL; 00056 00057 // Logical Block Size 00058 ULONG LogicalBlockSize; 00059 00060 // Physical Block Size 00061 ULONG PhysicalBlockSize; 00062 00063 // The starting Physical Block No... 00064 LARGE_INTEGER StartPhysicalBlock; 00065 00066 unsigned int NoOfPhysicalBlocks; 00067 00068 00069 00070 // Done with declerations... 00071 // Now for some code ;) 00072 00073 // Getting the Logical and Physical Sector sizes 00074 PtrVolumeDeviceObject = PtrTargetDeviceObject->Vpb->DeviceObject; 00075 ASSERT( PtrVolumeDeviceObject ); 00076 PtrVCB = (PtrExt2VCB)(PtrVolumeDeviceObject->DeviceExtension); 00077 ASSERT(PtrVCB); 00078 ASSERT(PtrVCB->NodeIdentifier.NodeType == EXT2_NODE_TYPE_VCB); 00079 00080 LogicalBlockSize = EXT2_MIN_BLOCK_SIZE << PtrVCB->LogBlockSize; 00081 PhysicalBlockSize = PtrTargetDeviceObject->SectorSize; 00082 00083 NoOfPhysicalBlocks = NoOfLogicalBlocks * LogicalBlockSize / PhysicalBlockSize; 00084 00085 StartPhysicalBlock.QuadPart = ( StartLogicalBlock.QuadPart ) * 00086 ( LogicalBlockSize / PhysicalBlockSize ); 00087 00088 Status = Ext2ReadPhysicalBlocks( PtrTargetDeviceObject, 00089 Buffer, StartPhysicalBlock, NoOfPhysicalBlocks ); 00090 00091 return Status; 00092 } 00093 00094 /************************************************************************* 00095 * 00096 * Function: Ext2ReadPhysicalBlocks() 00097 * 00098 * Description: 00099 * The higherlevel functions will use this to read in physical blocks 00100 * 00101 * PhysicalBlock - This is a 0 based number. 00102 * That is, the first block is Block 0 00103 * 00104 * Expected Interrupt Level (for execution) : 00105 * 00106 * IRQL_PASSIVE_LEVEL 00107 * 00108 * Return Value: The Status of the Read IO 00109 * 00110 *************************************************************************/ 00111 NTSTATUS NTAPI Ext2ReadPhysicalBlocks ( 00112 PDEVICE_OBJECT PtrTargetDeviceObject, // the Target Device Object 00113 VOID *Buffer, // The Buffer that takes the data read in 00114 LARGE_INTEGER StartPhysicalBlock, // The block from which reading is to start 00115 unsigned int NoOfBlocks // The no. of blocks to be read 00116 ) 00117 { 00118 // The Status to be returned... 00119 NTSTATUS Status = STATUS_SUCCESS; 00120 00121 // Physical Block Size 00122 ULONG PhysicalBlockSize; 00123 00124 // No of bytes to read 00125 ULONG NumberOfBytesToRead; 00126 00127 // Synchronisation Event 00128 KEVENT Event; 00129 00130 // IRP 00131 PIRP Irp; 00132 00133 // Status Block 00134 IO_STATUS_BLOCK Iosb; 00135 00136 // Byte Offset 00137 LARGE_INTEGER ByteOffset; 00138 00139 // Done with declerations... 00140 // Now for some code ;) 00141 00142 // Getting the Physical Sector size 00143 PhysicalBlockSize = PtrTargetDeviceObject->SectorSize; 00144 00145 NumberOfBytesToRead = PhysicalBlockSize * NoOfBlocks; 00146 00147 ByteOffset.QuadPart = StartPhysicalBlock.QuadPart * PhysicalBlockSize; 00148 00149 try 00150 { 00151 // 00152 // Initialize the event we're going to use 00153 // 00154 KeInitializeEvent( &Event, NotificationEvent, FALSE ); 00155 00156 // 00157 // Build the irp for the operation and also set the overrride flag 00158 // 00159 Irp = IoBuildSynchronousFsdRequest( IRP_MJ_READ, 00160 PtrTargetDeviceObject, 00161 Buffer, 00162 NumberOfBytesToRead, 00163 &ByteOffset , 00164 &Event, 00165 &Iosb ); 00166 00167 if ( Irp == NULL ) 00168 { 00169 DebugTrace(DEBUG_TRACE_MISC, " !!!! Unable to create an IRP", 0 ); 00170 Status = STATUS_INSUFFICIENT_RESOURCES; 00171 try_return(); 00172 } 00173 00174 // 00175 // Call the device to do the read and wait for it to finish. 00176 // 00177 Status = IoCallDriver( PtrTargetDeviceObject, Irp ); 00178 00179 // 00180 // Check if it is done already!!!! 00181 // 00182 if (Status == STATUS_PENDING) 00183 { 00184 // 00185 // Read not done yet... 00186 // Wait till it is... 00187 // 00188 (VOID)KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, (PLARGE_INTEGER)NULL ); 00189 Status = Iosb.Status; 00190 } 00191 00192 try_exit: NOTHING; 00193 } 00194 finally 00195 { 00196 if (!NT_SUCCESS(Status)) 00197 { 00198 if( Status == STATUS_VERIFY_REQUIRED ) 00199 { 00200 DebugTrace(DEBUG_TRACE_MISC, " !!!! Verify Required! Failed to read disk",0 ); 00201 } 00202 else if (Status == STATUS_INVALID_PARAMETER) 00203 { 00204 DebugTrace(DEBUG_TRACE_MISC, " !!!! Invalid Parameter! Failed to read disk",0 ); 00205 } 00206 else 00207 { 00208 DebugTrace(DEBUG_TRACE_MISC, " !!!! Failed to read disk! Status returned = %d", Status ); 00209 } 00210 } 00211 } 00212 return Status; 00213 } 00214 00215 Generated on Sun May 27 2012 04:27:38 for ReactOS by
1.7.6.1
|