Create Usb bulk storage template.

svn path=/trunk/; revision=17390
This commit is contained in:
James Tabor 2005-08-14 22:27:15 +00:00
parent 69594926a7
commit 89d916e2c9
5 changed files with 253 additions and 0 deletions

View file

@ -0,0 +1,154 @@
/*
* ReactOS kernel
* Copyright (C) 2001, 2002, 2003, 2004, 2005 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* Universal Serial Bus Bulk Storage Driver
*
* Written by James Tabor
*
*/
/* INCLUDES ******************************************************************/
#define NDEBUG
#define INITGUID
#include "usbstor.h"
/* PUBLIC AND PRIVATE FUNCTIONS **********************************************/
NTSTATUS STDCALL
IrpStub(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
NTSTATUS Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
NTSTATUS STDCALL
AddDevice(IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT pdo)
{
return STATUS_SUCCESS;
}
VOID STDCALL
DriverUnload(PDRIVER_OBJECT DriverObject)
{
}
VOID STDCALL
StartIo(PUSBSTOR_DEVICE_EXTENSION DeviceExtension,
PIRP Irp)
{
}
static NTSTATUS STDCALL
DispatchClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchCleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchScsi(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
return STATUS_SUCCESS;
}
static NTSTATUS STDCALL
DispatchPower(PDEVICE_OBJECT fido, PIRP Irp)
{
DPRINT1("USBSTOR: IRP_MJ_POWER unimplemented\n");
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
/*
* Standard DriverEntry method.
*/
NTSTATUS STDCALL
DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
{
ULONG i;
DPRINT("********* USB Storage *********\n");
DriverObject->DriverUnload = DriverUnload;
DriverObject->DriverExtension->AddDevice = AddDevice;
for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
DriverObject->MajorFunction[i] = IrpStub;
DriverObject->DriverStartIo = (PVOID)StartIo;
DriverObject->MajorFunction[IRP_MJ_CREATE] = DispatchClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = DispatchCleanup;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl;
DriverObject->MajorFunction[IRP_MJ_READ] = DispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_WRITE] = DispatchReadWrite;
/* Scsi Miniport support */
DriverObject->MajorFunction[IRP_MJ_SCSI] = DispatchScsi;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = DispatchSystemControl;
DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
DriverObject->MajorFunction[IRP_MJ_POWER] = DispatchPower;
return STATUS_SUCCESS;
}

View file

@ -0,0 +1,2 @@
LIBRARY usbstor.sys
EXPORTS

View file

@ -0,0 +1,83 @@
#include <ddk/ntddk.h>
#include <ddk/usbdi.h>
#include <ddk/usbiodef.h>
#include <initguid.h>
#include <debug.h>
#define USB_STOR_TAG TAG('u','s','b','s')
#define USB_MAXCHILDREN (16)
NTSTATUS STDCALL
IoAttachDeviceToDeviceStackSafe(
IN PDEVICE_OBJECT SourceDevice,
IN PDEVICE_OBJECT TargetDevice,
OUT PDEVICE_OBJECT *AttachedToDeviceObject);
typedef struct _USBSTOR_DEVICE_EXTENSION
{
BOOLEAN IsFDO;
struct usb_device* dev;
PDEVICE_OBJECT LowerDevice;
PDEVICE_OBJECT Children[USB_MAXCHILDREN];
/* Fields valid only when IsFDO == FALSE */
UNICODE_STRING DeviceDescription; // REG_SZ
UNICODE_STRING DeviceId; // REG_SZ
UNICODE_STRING InstanceId; // REG_SZ
UNICODE_STRING HardwareIds; // REG_MULTI_SZ
UNICODE_STRING CompatibleIds; // REG_MULTI_SZ
UNICODE_STRING SymbolicLinkName;
} USBSTOR_DEVICE_EXTENSION, *PUSBSTOR_DEVICE_EXTENSION;
/* cleanup.c */
NTSTATUS STDCALL
UsbStorCleanup(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
/* fdo.c */
NTSTATUS STDCALL
UsbStorPnpFdo(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
NTSTATUS
UsbStorDeviceControlFdo(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
/* misc.c */
NTSTATUS
ForwardIrpAndWait(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
NTSTATUS STDCALL
ForwardIrpAndForget(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
NTSTATUS
UsbStorDuplicateUnicodeString(
OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source,
IN POOL_TYPE PoolType);
NTSTATUS
UsbStorInitMultiSzString(
OUT PUNICODE_STRING Destination,
... /* list of PCSZ */);
/* pdo.c */
NTSTATUS STDCALL
UsbStorPnpPdo(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);
NTSTATUS
UsbStorDeviceControlPdo(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp);

View file

@ -0,0 +1,5 @@
#define REACTOS_VERSION_DLL
#define REACTOS_STR_FILE_DESCRIPTION "USB Storage Device Driver\0"
#define REACTOS_STR_INTERNAL_NAME "usbstor\0"
#define REACTOS_STR_ORIGINAL_FILENAME "usbstor.sys\0"
#include <reactos/version.rc>

View file

@ -0,0 +1,9 @@
<module name="usbstor" type="kernelmodedriver" installbase="system32/drivers" installname="usbstor.sys" warnings="true">
<define name="__USE_W32API" />
<define name="DEBUG_MODE" />
<include base="ntoskrnl">include</include>
<library>ntoskrnl</library>
<library>hal</library>
<file>usbstor.c</file>
<file>usbstor.rc</file>
</module>