Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenusbstor.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: drivers/usb/usbstor/usbstor.c 00005 * PURPOSE: USB block storage device driver. 00006 * PROGRAMMERS: 00007 * James Tabor 00008 Johannes Anderwald 00009 */ 00010 00011 /* INCLUDES ******************************************************************/ 00012 00013 #define NDEBUG 00014 #define INITGUID 00015 #include "usbstor.h" 00016 00017 /* PUBLIC AND PRIVATE FUNCTIONS **********************************************/ 00018 00019 NTSTATUS 00020 NTAPI 00021 USBSTOR_AddDevice( 00022 IN PDRIVER_OBJECT DriverObject, 00023 IN PDEVICE_OBJECT PhysicalDeviceObject) 00024 { 00025 NTSTATUS Status; 00026 PDEVICE_OBJECT DeviceObject; 00027 PFDO_DEVICE_EXTENSION DeviceExtension; 00028 00029 // 00030 // lets create the device 00031 // 00032 Status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_EXTENSION), 0, FILE_DEVICE_BUS_EXTENDER, FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject); 00033 00034 // 00035 // check for success 00036 // 00037 if (!NT_SUCCESS(Status)) 00038 { 00039 DPRINT1("USBSTOR_AddDevice: Failed to create FDO Status %x\n", Status); 00040 return Status; 00041 } 00042 00043 // 00044 // get device extension 00045 // 00046 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; 00047 ASSERT(DeviceExtension); 00048 00049 // 00050 // zero device extension 00051 // 00052 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION)); 00053 00054 // 00055 // initialize device extension 00056 // 00057 DeviceExtension->Common.IsFDO = TRUE; 00058 DeviceExtension->FunctionalDeviceObject = DeviceObject; 00059 DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject; 00060 DeviceExtension->LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject); 00061 00062 // 00063 // init timer 00064 // 00065 IoInitializeTimer(DeviceObject, USBSTOR_TimerRoutine, (PVOID)DeviceExtension); 00066 00067 // 00068 // did attaching fail 00069 // 00070 if (!DeviceExtension->LowerDeviceObject) 00071 { 00072 // 00073 // device removed 00074 // 00075 IoDeleteDevice(DeviceObject); 00076 00077 return STATUS_DEVICE_REMOVED; 00078 } 00079 00080 // 00081 // set device flags 00082 // 00083 DeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; 00084 00085 // 00086 // device is initialized 00087 // 00088 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; 00089 00090 00091 // 00092 // done 00093 // 00094 return STATUS_SUCCESS; 00095 } 00096 00097 VOID 00098 NTAPI 00099 USBSTOR_Unload( 00100 PDRIVER_OBJECT DriverObject) 00101 { 00102 // 00103 // no-op 00104 // 00105 } 00106 00107 NTSTATUS 00108 NTAPI 00109 USBSTOR_DispatchClose( 00110 PDEVICE_OBJECT DeviceObject, 00111 PIRP Irp) 00112 { 00113 // 00114 // function always succeeds ;) 00115 // 00116 DPRINT("USBSTOR_DispatchClose\n"); 00117 Irp->IoStatus.Information = 0; 00118 Irp->IoStatus.Status = STATUS_SUCCESS; 00119 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00120 return STATUS_SUCCESS; 00121 } 00122 00123 00124 NTSTATUS 00125 NTAPI 00126 USBSTOR_DispatchDeviceControl( 00127 PDEVICE_OBJECT DeviceObject, 00128 PIRP Irp) 00129 { 00130 NTSTATUS Status; 00131 00132 // 00133 // handle requests 00134 // 00135 Status = USBSTOR_HandleDeviceControl(DeviceObject, Irp); 00136 00137 // 00138 // complete request 00139 // 00140 Irp->IoStatus.Status = Status; 00141 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00142 00143 // 00144 // done 00145 // 00146 return Status; 00147 } 00148 00149 00150 NTSTATUS 00151 NTAPI 00152 USBSTOR_DispatchScsi( 00153 PDEVICE_OBJECT DeviceObject, 00154 PIRP Irp) 00155 { 00156 // 00157 // handle requests 00158 // 00159 return USBSTOR_HandleInternalDeviceControl(DeviceObject, Irp); 00160 } 00161 00162 NTSTATUS 00163 NTAPI 00164 USBSTOR_DispatchReadWrite( 00165 PDEVICE_OBJECT DeviceObject, 00166 PIRP Irp) 00167 { 00168 // 00169 // read write ioctl is not supported 00170 // 00171 Irp->IoStatus.Information = 0; 00172 Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; 00173 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00174 return STATUS_INVALID_PARAMETER; 00175 } 00176 00177 NTSTATUS 00178 NTAPI 00179 USBSTOR_DispatchPnp( 00180 PDEVICE_OBJECT DeviceObject, 00181 PIRP Irp) 00182 { 00183 PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension; 00184 00185 // 00186 // get common device extension 00187 // 00188 DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension; 00189 00190 // 00191 // is it for the FDO 00192 // 00193 if (DeviceExtension->IsFDO) 00194 { 00195 // 00196 // dispatch pnp request to fdo pnp handler 00197 // 00198 return USBSTOR_FdoHandlePnp(DeviceObject, Irp); 00199 } 00200 else 00201 { 00202 // 00203 // dispatch request to pdo pnp handler 00204 // 00205 return USBSTOR_PdoHandlePnp(DeviceObject, Irp); 00206 } 00207 } 00208 00209 NTSTATUS 00210 NTAPI 00211 USBSTOR_DispatchPower( 00212 PDEVICE_OBJECT DeviceObject, 00213 PIRP Irp) 00214 { 00215 UNIMPLEMENTED 00216 00217 Irp->IoStatus.Information = 0; 00218 Irp->IoStatus.Status = STATUS_SUCCESS; 00219 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00220 return STATUS_SUCCESS; 00221 } 00222 00223 00224 00225 NTSTATUS 00226 NTAPI 00227 DriverEntry( 00228 IN PDRIVER_OBJECT DriverObject, 00229 IN PUNICODE_STRING RegPath) 00230 { 00231 00232 DPRINT("********* USB Storage *********\n"); 00233 00234 // 00235 // driver unload routine 00236 // 00237 DriverObject->DriverUnload = USBSTOR_Unload; 00238 00239 // 00240 // add device function 00241 // 00242 DriverObject->DriverExtension->AddDevice = USBSTOR_AddDevice; 00243 00244 // 00245 // driver start i/o routine 00246 // 00247 DriverObject->DriverStartIo = USBSTOR_StartIo; 00248 00249 // 00250 // create / close 00251 // 00252 DriverObject->MajorFunction[IRP_MJ_CREATE] = USBSTOR_DispatchClose; 00253 DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBSTOR_DispatchClose; 00254 00255 // 00256 // scsi pass through requests 00257 // 00258 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = USBSTOR_DispatchDeviceControl; 00259 00260 // 00261 // irp dispatch read / write 00262 // 00263 DriverObject->MajorFunction[IRP_MJ_READ] = USBSTOR_DispatchReadWrite; 00264 DriverObject->MajorFunction[IRP_MJ_WRITE] = USBSTOR_DispatchReadWrite; 00265 00266 // 00267 // scsi queue ioctl 00268 // 00269 DriverObject->MajorFunction[IRP_MJ_SCSI] = USBSTOR_DispatchScsi; 00270 00271 // 00272 // pnp processing 00273 // 00274 DriverObject->MajorFunction[IRP_MJ_PNP] = USBSTOR_DispatchPnp; 00275 00276 // 00277 // power processing 00278 // 00279 DriverObject->MajorFunction[IRP_MJ_POWER] = USBSTOR_DispatchPower; 00280 00281 return STATUS_SUCCESS; 00282 } 00283 Generated on Fri May 25 2012 04:26:48 for ReactOS by
1.7.6.1
|