[abstraction] Rework IRP handlers, move boot-disk probing code
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 26 Aug 2009 05:01:23 +0000 (01:01 -0400)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 26 Aug 2009 05:01:23 +0000 (01:01 -0400)
- Changed my mind about IRP handlers; we use an IRPHandler function
  type now
- We used to probe for a MEMDISK and/or an AoE target (via aBFT)
  in the bus code; we call these functions in probe.c from
  DriverEntry() now
- driver.c handles device creation and closing now, and passes on
  any other IRPs to the device's particular Dispatch() function.
  Currently, there is only a Bus and Disk device type, where Disk
  should really be abstracted some more to split AoE from MEMDISK

All of the 'include's are looking really messy right now, but we
_should_ be on our way to being cleaner, where modules should not
need to know so much about other modules.

14 files changed:
Makefile
config.bat
src/aoedisk.c
src/aoedisk.h
src/bus.c
src/bus.h
src/disk.h
src/driver.c
src/driver.h
src/mount.c
src/mount.h
src/probe.c [new file with mode: 0644]
src/probe.h [new file with mode: 0644]
src/ramdisk.h

index eae2a95..7f13bd2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 INCLUDES := $(shell echo | cpp -v 2>&1 | sed -n '/\#include "..." search starts here:/,/End of search list./p' | grep "^ " | sed "s/^ \(.*\)$$/-I\1\/ddk/" | tr "\n" " " | sed "s/ $$//" | sed ":start;s/\/[^\/]*\/\.\.\//\//;t start")
 
 # Next line is duplicated in config.bat, edit both when adding files.
-c := driver.c registry.c bus.c aoedisk.c aoe.c protocol.c debug.c
+c := driver.c registry.c bus.c aoedisk.c aoe.c protocol.c debug.c probe.c
 h := driver.h aoe.h protocol.h mount.h portable.h
 
 # This is also duplicated in config.bat.
@@ -95,10 +95,15 @@ src/obj/debug.o: src/debug.c src/portable.h src/driver.h src/mount.h Makefile
        @rm -rf src/obj/debug.o src/obj/aoe.tmp src/obj/aoe.exp bin/aoe32.sys bin/aoe64.sys bin/aoe32.pdb bin/aoe64.pdb bin/loader64.exe
        gcc $(INCLUDES) -c -Wall src/debug.c -o src/obj/debug.o
 
-src/obj/aoe.tmp: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o Makefile
+src/obj/probe.o: src/probe.c src/portable.h src/driver.h src/mount.h Makefile
+       @mkdir -p src/obj
+       @rm -rf src/obj/probe.o src/obj/aoe.tmp src/obj/aoe.exp bin/aoe32.sys bin/aoe64.sys bin/aoe32.pdb bin/aoe64.pdb bin/loader64.exe
+       gcc $(INCLUDES) -c -Wall src/probe.c -o src/obj/probe.o
+
+src/obj/aoe.tmp: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o probe.o Makefile
        @mkdir -p src/obj
        @rm -rf src/obj/aoe.tmp src/obj/aoe.exp bin/aoe32.sys bin/aoe64.sys bin/aoe32.pdb bin/aoe64.pdb bin/loader64.exe
-       @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o -Wl,--base-file,src/obj/aoe.tmp -Wl,--entry,_DriverEntry@8 -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o null
+       @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o -Wl,--base-file,src/obj/aoe.tmp -Wl,--entry,_DriverEntry@8 -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o null
        @rm -rf null.exe
 
 src/obj/aoe.exp: src/obj/aoe.tmp Makefile
@@ -106,8 +111,8 @@ src/obj/aoe.exp: src/obj/aoe.tmp Makefile
        @rm -rf src/obj/aoe.exp bin/aoe32.sys bin/aoe64.sys bin/aoe32.pdb bin/aoe64.pdb bin/loader64.exe
        @dlltool --dllname aoe32.sys --base-file src/obj/aoe.tmp --output-exp src/obj/aoe.exp
 
-bin/aoe32.sys: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/aoe.exp Makefile
+bin/aoe32.sys: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o src/obj/aoe.exp Makefile
        @mkdir -p bin
        @rm -rf bin/aoe32.sys bin/aoe64.sys bin/aoe32.pdb bin/aoe64.pdb bin/loader64.exe
-       @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o -Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,src/obj/aoe.exp -mdll -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o bin/aoe32.sys
+       @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o -Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,src/obj/aoe.exp -mdll -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o bin/aoe32.sys
 #      strip bin/aoe32.sys
index bb05a0c..d1e130d 100644 (file)
@@ -2,5 +2,5 @@ rem This is the root directory of the ddk.
 set ddkdir=c:\winddk\6001.18001\r
 \r
 rem Next two lines are duplicated in Makefile, edit both when adding files or changing pxe style.\r
-set c=driver.c registry.c bus.c aoedisk.c aoe.c protocol.c debug.c\r
+set c=driver.c registry.c bus.c aoedisk.c aoe.c protocol.c debug.c probe.c\r
 set pxestyle=asm\r
index f01ce8c..f10c14a 100644 (file)
@@ -128,19 +128,7 @@ typedef struct _DISK_CDB16
 DEFINE_GUID ( GUID_BUS_TYPE_INTERNAL, 0x2530ea73L, 0x086b, 0x11d1, 0xa0, 0x9f,
                                                        0x00, 0xc0, 0x4f, 0xc3, 0x40, 0xb1 );
 
-/* in this file -- but shouldn't be */
-static NTSTATUS STDCALL BusGetDeviceCapabilities (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PDEVICE_CAPABILITIES DeviceCapabilities
- );
-
-NTSTATUS STDCALL
-Disk_DispatchPnP (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Disk_DispatchPnP )
 {
        NTSTATUS Status;
        PDEVICE_RELATIONS DeviceRelations;
@@ -153,6 +141,9 @@ Disk_DispatchPnP (
        switch ( Stack->MinorFunction )
                {
                        case IRP_MN_QUERY_ID:
+                               /*
+                                * TODO: AoE specifics are in here; move them
+                                */
                                if ( ( String =
                                                         ( PWCHAR ) ExAllocatePool ( NonPagedPool,
                                                                                                                                                                         ( 512 * sizeof ( WCHAR ) ) ) ) ==
@@ -346,11 +337,11 @@ Disk_DispatchPnP (
                                        }
                                if ( !NT_SUCCESS
                                                 ( Status =
-                                                        BusGetDeviceCapabilities ( ( ( PDRIVER_DEVICEEXTENSION )
-                                                                                                                                                                               DeviceExtension->Disk.
-                                                                                                                                                                               Parent->DeviceExtension )->
-                                                                                                                                                                       Bus.LowerDeviceObject,
-                                                                                                                                                                       &ParentDeviceCapabilities ) ) )
+                                                        Bus_GetDeviceCapabilities ( ( ( PDRIVER_DEVICEEXTENSION )
+                                                                                                                                                                                DeviceExtension->Disk.Parent->
+                                                                                                                                                                                DeviceExtension )->Bus.
+                                                                                                                                                                        LowerDeviceObject,
+                                                                                                                                                                        &ParentDeviceCapabilities ) ) )
                                        break;
                                RtlCopyMemory ( DeviceCapabilities->DeviceState,
                                                                                                ParentDeviceCapabilities.DeviceState,
@@ -462,13 +453,7 @@ Disk_DispatchPnP (
        return Status;
 }
 
-NTSTATUS STDCALL
-Disk_DispatchSCSI (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Disk_DispatchSCSI )
 {
        NTSTATUS Status;
        PSCSI_REQUEST_BLOCK Srb;
@@ -504,11 +489,11 @@ Disk_DispatchSCSI (
                                                                                         || Cdb->AsByte[0] == SCSIOP_WRITE16 )
                                                                                {
                                                                                        REVERSE_BYTES_QUAD ( &StartSector,
-                                                                                                                                                                        &( ( ( PDISK_CDB16 )
-                                                                                                                                                                                               Cdb )->LogicalBlock[0] ) );
+                                                                                                                                                                        &( ( ( PDISK_CDB16 ) Cdb )->
+                                                                                                                                                                                       LogicalBlock[0] ) );
                                                                                        REVERSE_BYTES ( &SectorCount,
-                                                                                                                                                       &( ( ( PDISK_CDB16 )
-                                                                                                                                                                        Cdb )->TransferLength[0] ) );
+                                                                                                                                                       &( ( ( PDISK_CDB16 ) Cdb )->
+                                                                                                                                                                TransferLength[0] ) );
                                                                                }
                                                                        else
                                                                                {
@@ -556,12 +541,12 @@ Disk_DispatchSCSI (
                                                                                }
 
                                                                        if ( ( ( ( PUCHAR ) Srb->DataBuffer -
-                                                                                                        ( PUCHAR )
-                                                                                                        MmGetMdlVirtualAddress ( Irp->MdlAddress ) ) +
-                                                                                                ( PUCHAR )
-                                                                                                MmGetSystemAddressForMdlSafe ( Irp->MdlAddress,
-                                                                                                                                                                                                                               HighPagePriority ) ) ==
-                                                                                        NULL )
+                                                                                                        ( PUCHAR ) MmGetMdlVirtualAddress ( Irp->
+                                                                                                                                                                                                                                                        MdlAddress ) ) +
+                                                                                                ( PUCHAR ) MmGetSystemAddressForMdlSafe ( Irp->
+                                                                                                                                                                                                                                                                        MdlAddress,
+                                                                                                                                                                                                                                                                        HighPagePriority ) )
+                                                                                        == NULL )
                                                                                {
                                                                                        Status = STATUS_INSUFFICIENT_RESOURCES;
                                                                                        Irp->IoStatus.Information = 0;
@@ -576,12 +561,14 @@ Disk_DispatchSCSI (
                                                                                                                                                                         SectorCount,
                                                                                                                                                                         ( ( PUCHAR ) Srb->DataBuffer -
                                                                                                                                                                                 ( PUCHAR )
-                                                                                                                                                                                MmGetMdlVirtualAddress
-                                                                                                                                                                                ( Irp->MdlAddress ) ) +
+                                                                                                                                                                                MmGetMdlVirtualAddress ( Irp->
+                                                                                                                                                                                                                                                                                       MdlAddress ) )
+                                                                                                                                                                        +
                                                                                                                                                                         ( PUCHAR )
-                                                                                                                                                                        MmGetSystemAddressForMdlSafe
-                                                                                                                                                                        ( Irp->MdlAddress,
-                                                                                                                                                                                HighPagePriority ), Irp );
+                                                                                                                                                                        MmGetSystemAddressForMdlSafe ( Irp->
+                                                                                                                                                                                                                                                                                                       MdlAddress,
+                                                                                                                                                                                                                                                                                                       HighPagePriority ),
+                                                                                                                                                                        Irp );
                                                                                }
                                                                        else
                                                                                {
@@ -590,12 +577,14 @@ Disk_DispatchSCSI (
                                                                                                                                                                         SectorCount,
                                                                                                                                                                         ( ( PUCHAR ) Srb->DataBuffer -
                                                                                                                                                                                 ( PUCHAR )
-                                                                                                                                                                                MmGetMdlVirtualAddress
-                                                                                                                                                                                ( Irp->MdlAddress ) ) +
+                                                                                                                                                                                MmGetMdlVirtualAddress ( Irp->
+                                                                                                                                                                                                                                                                                       MdlAddress ) )
+                                                                                                                                                                        +
                                                                                                                                                                         ( PUCHAR )
-                                                                                                                                                                        MmGetSystemAddressForMdlSafe
-                                                                                                                                                                        ( Irp->MdlAddress,
-                                                                                                                                                                                HighPagePriority ), Irp );
+                                                                                                                                                                        MmGetSystemAddressForMdlSafe ( Irp->
+                                                                                                                                                                                                                                                                                                       MdlAddress,
+                                                                                                                                                                                                                                                                                                       HighPagePriority ),
+                                                                                                                                                                        Irp );
                                                                                }
                                                                        break;
                                                                case SCSIOP_VERIFY:
@@ -603,11 +592,11 @@ Disk_DispatchSCSI (
                                                                        if ( Cdb->AsByte[0] == SCSIOP_VERIFY16 )
                                                                                {
                                                                                        REVERSE_BYTES_QUAD ( &StartSector,
-                                                                                                                                                                        &( ( ( PDISK_CDB16 )
-                                                                                                                                                                                               Cdb )->LogicalBlock[0] ) );
+                                                                                                                                                                        &( ( ( PDISK_CDB16 ) Cdb )->
+                                                                                                                                                                                       LogicalBlock[0] ) );
                                                                                        REVERSE_BYTES ( &SectorCount,
-                                                                                                                                                       &( ( ( PDISK_CDB16 )
-                                                                                                                                                                        Cdb )->TransferLength[0] ) );
+                                                                                                                                                       &( ( ( PDISK_CDB16 ) Cdb )->
+                                                                                                                                                                TransferLength[0] ) );
                                                                                }
                                                                        else
                                                                                {
@@ -627,22 +616,21 @@ Disk_DispatchSCSI (
                                                                case SCSIOP_READ_CAPACITY:
                                                                        Temp = SECTORSIZE;
                                                                        REVERSE_BYTES ( &
-                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA )
-                                                                                                                                                       Srb->DataBuffer )->BytesPerBlock ),
-                                                                                                                                       &Temp );
+                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA ) Srb->
+                                                                                                                                                       DataBuffer )->BytesPerBlock ), &Temp );
                                                                        if ( ( DeviceExtension->Disk.LBADiskSize - 1 ) > 0xffffffff )
                                                                                {
-                                                                                       ( ( PREAD_CAPACITY_DATA ) Srb->
-                                                                                               DataBuffer )->LogicalBlockAddress = -1;
+                                                                                       ( ( PREAD_CAPACITY_DATA ) Srb->DataBuffer )->
+                                                                                               LogicalBlockAddress = -1;
                                                                                }
                                                                        else
                                                                                {
                                                                                        Temp =
                                                                                                ( ULONG ) ( DeviceExtension->Disk.LBADiskSize - 1 );
                                                                                        REVERSE_BYTES ( &
-                                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA )
-                                                                                                                                                                       Srb->DataBuffer )->
-                                                                                                                                                               LogicalBlockAddress ), &Temp );
+                                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA ) Srb->
+                                                                                                                                                                       DataBuffer )->LogicalBlockAddress ),
+                                                                                                                                                       &Temp );
                                                                                }
                                                                        Irp->IoStatus.Information = sizeof ( READ_CAPACITY_DATA );
                                                                        Srb->SrbStatus = SRB_STATUS_SUCCESS;
@@ -651,15 +639,13 @@ Disk_DispatchSCSI (
                                                                case SCSIOP_READ_CAPACITY16:
                                                                        Temp = SECTORSIZE;
                                                                        REVERSE_BYTES ( &
-                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA_EX )
-                                                                                                                                                       Srb->DataBuffer )->BytesPerBlock ),
-                                                                                                                                       &Temp );
+                                                                                                                                       ( ( ( PREAD_CAPACITY_DATA_EX ) Srb->
+                                                                                                                                                       DataBuffer )->BytesPerBlock ), &Temp );
                                                                        LargeTemp = DeviceExtension->Disk.LBADiskSize - 1;
                                                                        REVERSE_BYTES_QUAD ( &
-                                                                                                                                                        ( ( ( PREAD_CAPACITY_DATA_EX )
-                                                                                                                                                                        Srb->DataBuffer )->
-                                                                                                                                                                LogicalBlockAddress.QuadPart ),
-                                                                                                                                                        &LargeTemp );
+                                                                                                                                                        ( ( ( PREAD_CAPACITY_DATA_EX ) Srb->
+                                                                                                                                                                        DataBuffer )->LogicalBlockAddress.
+                                                                                                                                                                QuadPart ), &LargeTemp );
                                                                        Irp->IoStatus.Information = sizeof ( READ_CAPACITY_DATA_EX );
                                                                        Srb->SrbStatus = SRB_STATUS_SUCCESS;
                                                                        Status = STATUS_SUCCESS;
@@ -722,13 +708,7 @@ Disk_DispatchSCSI (
        return Status;
 }
 
-NTSTATUS STDCALL
-Disk_DispatchDeviceControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Disk_DispatchDeviceControl )
 {
        NTSTATUS Status;
        ULONG CopySize;
@@ -749,9 +729,9 @@ Disk_DispatchDeviceControl (
                                        {
                                                CopySize =
                                                        ( Stack->Parameters.DeviceIoControl.OutputBufferLength <
-                                                               sizeof ( STORAGE_ADAPTER_DESCRIPTOR ) ? Stack->
-                                                               Parameters.DeviceIoControl.
-                                                               OutputBufferLength : sizeof ( STORAGE_ADAPTER_DESCRIPTOR ) );
+                                                               sizeof ( STORAGE_ADAPTER_DESCRIPTOR ) ? Stack->Parameters.
+                                                               DeviceIoControl.OutputBufferLength :
+                                                               sizeof ( STORAGE_ADAPTER_DESCRIPTOR ) );
                                                StorageAdapterDescriptor.Version =
                                                        sizeof ( STORAGE_ADAPTER_DESCRIPTOR );
                                                StorageAdapterDescriptor.Size =
@@ -778,9 +758,9 @@ Disk_DispatchDeviceControl (
                                        {
                                                CopySize =
                                                        ( Stack->Parameters.DeviceIoControl.OutputBufferLength <
-                                                               sizeof ( STORAGE_DEVICE_DESCRIPTOR ) ? Stack->
-                                                               Parameters.DeviceIoControl.
-                                                               OutputBufferLength : sizeof ( STORAGE_DEVICE_DESCRIPTOR ) );
+                                                               sizeof ( STORAGE_DEVICE_DESCRIPTOR ) ? Stack->Parameters.
+                                                               DeviceIoControl.OutputBufferLength :
+                                                               sizeof ( STORAGE_DEVICE_DESCRIPTOR ) );
                                                StorageDeviceDescriptor.Version =
                                                        sizeof ( STORAGE_DEVICE_DESCRIPTOR );
                                                StorageDeviceDescriptor.Size =
@@ -812,8 +792,8 @@ Disk_DispatchDeviceControl (
                        case IOCTL_DISK_GET_DRIVE_GEOMETRY:
                                CopySize =
                                        ( Stack->Parameters.DeviceIoControl.OutputBufferLength <
-                                               sizeof ( DISK_GEOMETRY ) ? Stack->Parameters.DeviceIoControl.
-                                               OutputBufferLength : sizeof ( DISK_GEOMETRY ) );
+                                               sizeof ( DISK_GEOMETRY ) ? Stack->Parameters.
+                                               DeviceIoControl.OutputBufferLength : sizeof ( DISK_GEOMETRY ) );
                                DiskGeometry.MediaType = FixedMedia;
                                DiskGeometry.Cylinders.QuadPart = DeviceExtension->Disk.Cylinders;
                                DiskGeometry.TracksPerCylinder = DeviceExtension->Disk.Heads;
@@ -827,8 +807,8 @@ Disk_DispatchDeviceControl (
                        case IOCTL_SCSI_GET_ADDRESS:
                                CopySize =
                                        ( Stack->Parameters.DeviceIoControl.OutputBufferLength <
-                                               sizeof ( SCSI_ADDRESS ) ? Stack->Parameters.DeviceIoControl.
-                                               OutputBufferLength : sizeof ( SCSI_ADDRESS ) );
+                                               sizeof ( SCSI_ADDRESS ) ? Stack->Parameters.
+                                               DeviceIoControl.OutputBufferLength : sizeof ( SCSI_ADDRESS ) );
                                ScsiAdress.Length = sizeof ( SCSI_ADDRESS );
                                ScsiAdress.PortNumber = 0;
                                ScsiAdress.PathId = 0;
@@ -849,13 +829,7 @@ Disk_DispatchDeviceControl (
        return Status;
 }
 
-NTSTATUS STDCALL
-Disk_DispatchSystemControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Disk_DispatchSystemControl )
 {
        NTSTATUS Status;
 
@@ -864,52 +838,38 @@ Disk_DispatchSystemControl (
        return Status;
 }
 
-/* FIXME put in SCSI */
-static NTSTATUS STDCALL
-BusGetDeviceCapabilities (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PDEVICE_CAPABILITIES DeviceCapabilities
- )
+IRPHandler_Declaration ( Disk_Dispatch )
 {
-       IO_STATUS_BLOCK ioStatus;
-       KEVENT pnpEvent;
-       NTSTATUS status;
-       PDEVICE_OBJECT targetObject;
-       PIO_STACK_LOCATION irpStack;
-       PIRP pnpIrp;
-
-       RtlZeroMemory ( DeviceCapabilities, sizeof ( DEVICE_CAPABILITIES ) );
-       DeviceCapabilities->Size = sizeof ( DEVICE_CAPABILITIES );
-       DeviceCapabilities->Version = 1;
-       DeviceCapabilities->Address = -1;
-       DeviceCapabilities->UINumber = -1;
-
-       KeInitializeEvent ( &pnpEvent, NotificationEvent, FALSE );
-       targetObject = IoGetAttachedDeviceReference ( DeviceObject );
-       pnpIrp =
-               IoBuildSynchronousFsdRequest ( IRP_MJ_PNP, targetObject, NULL, 0, NULL,
-                                                                                                                                        &pnpEvent, &ioStatus );
-       if ( pnpIrp == NULL )
-               {
-                       status = STATUS_INSUFFICIENT_RESOURCES;
-               }
-       else
+       NTSTATUS Status;
+       switch ( Stack->MajorFunction )
                {
-                       pnpIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
-                       irpStack = IoGetNextIrpStackLocation ( pnpIrp );
-                       RtlZeroMemory ( irpStack, sizeof ( IO_STACK_LOCATION ) );
-                       irpStack->MajorFunction = IRP_MJ_PNP;
-                       irpStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES;
-                       irpStack->Parameters.DeviceCapabilities.Capabilities =
-                               DeviceCapabilities;
-                       status = IoCallDriver ( targetObject, pnpIrp );
-                       if ( status == STATUS_PENDING )
-                               {
-                                       KeWaitForSingleObject ( &pnpEvent, Executive, KernelMode, FALSE,
-                                                                                                                                       NULL );
-                                       status = ioStatus.Status;
-                               }
+                       case IRP_MJ_POWER:
+                               PoStartNextPowerIrp ( Irp );
+                               Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
+                               IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+                               Status = STATUS_NOT_SUPPORTED;
+                               break;
+                       case IRP_MJ_PNP:
+                               Status =
+                                       Disk_DispatchPnP ( DeviceObject, Irp, Stack, DeviceExtension );
+                               break;
+                       case IRP_MJ_SYSTEM_CONTROL:
+                               Status =
+                                       Disk_DispatchSystemControl ( DeviceObject, Irp, Stack,
+                                                                                                                                                        DeviceExtension );
+                               break;
+                       case IRP_MJ_DEVICE_CONTROL:
+                               Status =
+                                       Disk_DispatchDeviceControl ( DeviceObject, Irp, Stack,
+                                                                                                                                                        DeviceExtension );
+                               break;
+                       case IRP_MJ_SCSI:
+                               Status =
+                                       Disk_DispatchSCSI ( DeviceObject, Irp, Stack, DeviceExtension );
+                               break;
+                       default:
+                               Status = STATUS_NOT_SUPPORTED;
+                               Irp->IoStatus.Status = Status;
+                               IoCompleteRequest ( Irp, IO_NO_INCREMENT );
                }
-       ObDereferenceObject ( targetObject );
-       return status;
 }
index 7dd8d90..9b989c5 100644 (file)
@@ -40,32 +40,24 @@ typedef struct _AOEDISK_AOEDISK
 } AOEDISK_AOEDISK,
 *PAOEDISK_AOEDISK;
 
-extern NTSTATUS STDCALL Disk_DispatchPnP (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Disk_Dispatch
  );
 
-extern NTSTATUS STDCALL Disk_DispatchSCSI (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Disk_DispatchPnP
  );
 
-extern NTSTATUS STDCALL Disk_DispatchDeviceControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Disk_DispatchSCSI
  );
 
-extern NTSTATUS STDCALL Disk_DispatchSystemControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Disk_DispatchDeviceControl
+ );
+
+extern IRPHandler_Declaration (
+       Disk_DispatchSystemControl
  );
 
 #endif                                                                                                 /* _AOEDISK_H */
index f426f30..89ca8d8 100644 (file)
--- a/src/bus.c
+++ b/src/bus.c
 #include "debug.h"
 #include "mdi.h"
 #include "protocol.h"
+#include "probe.h"
 
 /* in this file */
-static BOOLEAN STDCALL Bus_AddChild (
+static IRPHandler_Declaration (
+       Bus_DispatchNotSupported
+ );
+static IRPHandler_Declaration (
+       Bus_DispatchPower
+ );
+BOOLEAN STDCALL Bus_AddChild (
        IN PDEVICE_OBJECT BusDeviceObject,
        IN PUCHAR ClientMac,
        IN ULONG Major,
@@ -72,7 +79,7 @@ typedef struct _BUS_ABFT
 
 typedef struct _BUS_TARGETLIST
 {
-       TARGET Target;
+       MOUNT_TARGET Target;
        struct _BUS_TARGETLIST *Next;
 } BUS_TARGETLIST,
 *PBUS_TARGETLIST;
@@ -80,7 +87,7 @@ typedef struct _BUS_TARGETLIST
 static PBUS_TARGETLIST Bus_Globals_TargetList = NULL;
 static KSPIN_LOCK Bus_Globals_TargetListSpinLock;
 static ULONG Bus_Globals_NextDisk = 0;
-static MDI_PATCHAREA Bus_Globals_BootMemdisk;
+PDEVICE_OBJECT Bus_Globals_Self = NULL;
 
 NTSTATUS STDCALL
 Bus_Start (
@@ -116,214 +123,6 @@ Bus_Stop (
        IoDeleteSymbolicLink ( &DosDeviceName );
 }
 
-NTSTATUS STDCALL
-Bus_AddDevice (
-       IN PDRIVER_OBJECT DriverObject,
-       IN PDEVICE_OBJECT PhysicalDeviceObject
- )
-{
-       NTSTATUS Status;
-       PHYSICAL_ADDRESS PhysicalAddress;
-       PUCHAR PhysicalMemory;
-       PMDI_PATCHAREA MemdiskPtr;
-       UINT32 Int13Hook;
-       UINT16 RealSeg,
-        RealOff;
-       UINT Offset,
-        Checksum,
-        i;
-       BUS_ABFT AOEBootRecord;
-       BOOLEAN FoundAbft = FALSE,
-               FoundMemdisk = FALSE;
-       UNICODE_STRING DeviceName,
-        DosDeviceName;
-       PDRIVER_DEVICEEXTENSION DeviceExtension;
-       PDEVICE_OBJECT DeviceObject;
-       static BOOLEAN Started = FALSE;
-
-       DBG ( "Entry\n" );
-       if ( Started )
-               return STATUS_SUCCESS;
-       RtlInitUnicodeString ( &DeviceName, L"\\Device\\AoE" );
-       RtlInitUnicodeString ( &DosDeviceName, L"\\DosDevices\\AoE" );
-       if ( !NT_SUCCESS
-                        ( Status =
-                                IoCreateDevice ( DriverObject, sizeof ( DRIVER_DEVICEEXTENSION ),
-                                                                                                       &DeviceName, FILE_DEVICE_CONTROLLER,
-                                                                                                       FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject ) ) )
-               {
-                       return Error ( "Bus_AddDevice IoCreateDevice", Status );
-               }
-       if ( !NT_SUCCESS
-                        ( Status = IoCreateSymbolicLink ( &DosDeviceName, &DeviceName ) ) )
-               {
-                       IoDeleteDevice ( DeviceObject );
-                       return Error ( "Bus_AddDevice IoCreateSymbolicLink", Status );
-               }
-
-       DeviceExtension = ( PDRIVER_DEVICEEXTENSION ) DeviceObject->DeviceExtension;
-       RtlZeroMemory ( DeviceExtension, sizeof ( DRIVER_DEVICEEXTENSION ) );
-       DeviceExtension->IsBus = TRUE;
-       DeviceExtension->DriverObject = DriverObject;
-       DeviceExtension->Self = DeviceObject;
-       DeviceExtension->State = NotStarted;
-       DeviceExtension->OldState = NotStarted;
-       DeviceExtension->Bus.PhysicalDeviceObject = PhysicalDeviceObject;
-       DeviceExtension->Bus.Children = 0;
-       DeviceExtension->Bus.ChildList = NULL;
-       KeInitializeSpinLock ( &DeviceExtension->Bus.SpinLock );
-       DeviceObject->Flags |= DO_DIRECT_IO;    /* FIXME? */
-       DeviceObject->Flags |= DO_POWER_INRUSH; /* FIXME? */
-       if ( PhysicalDeviceObject != NULL )
-               {
-                       if ( ( DeviceExtension->Bus.LowerDeviceObject =
-                                                IoAttachDeviceToDeviceStack ( DeviceObject,
-                                                                                                                                                                        PhysicalDeviceObject ) ) == NULL )
-                               {
-                                       IoDeleteDevice ( DeviceObject );
-                                       return Error ( "AddDevice IoAttachDeviceToDeviceStack",
-                                                                                                STATUS_NO_SUCH_DEVICE );
-                               }
-               }
-       DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-
-       /*
-        * Find a MEMDISK.  Start by looking at the IDT and following
-        * the INT 0x13 hook.  This discovery strategy is extremely poor
-        * at the moment.  The eventual goal is to discover MEMDISK RAM disks
-        * as well as GRUB4DOS-mapped RAM disks.  Slight modifications to both
-        * will help with this.
-        */
-       PhysicalAddress.QuadPart = 0LL;
-       PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0x100000, MmNonCached );
-       if ( !PhysicalMemory )
-               {
-                       DBG ( "Could not map low memory\n" );
-               }
-       else
-               {
-                       RealSeg = *( ( PUINT16 ) & PhysicalMemory[0x13 * 4 + 2] );
-                       RealOff = *( ( PUINT16 ) & PhysicalMemory[0x13 * 4] );
-                       Int13Hook = ( ( ( UINT32 ) RealSeg ) << 4 ) + ( ( UINT32 ) RealOff );
-                       DBG ( "INT 0x13 Segment: 0x%04x\n", RealSeg );
-                       DBG ( "INT 0x13 Offset: 0x%04x\n", RealOff );
-                       DBG ( "INT 0x13 Hook: 0x%08x\n", Int13Hook );
-                       for ( Offset = 0; Offset < 0x100000 - sizeof ( MDI_PATCHAREA );
-                                               Offset += 2 )
-                               {
-                                       MemdiskPtr = ( PMDI_PATCHAREA ) & PhysicalMemory[Offset];
-                                       if ( MemdiskPtr->mdi_bytes != 0x1e )
-                                               continue;
-                                       DBG ( "Found MEMDISK sig #1: 0x%08x\n", Offset );
-                                       if ( ( MemdiskPtr->mdi_version_major != 3 )
-                                                        || ( MemdiskPtr->mdi_version_minor != 82 ) )
-                                               continue;
-                                       DBG ( "Found MEMDISK sig #2\n" );
-                                       DBG ( "MEMDISK DiskBuf: 0x%08x\n", MemdiskPtr->diskbuf );
-                                       DBG ( "MEMDISK DiskSize: 0x%08x sectors\n", MemdiskPtr->disksize );
-                                       FoundMemdisk = TRUE;
-                                       RtlCopyMemory ( &Bus_Globals_BootMemdisk, MemdiskPtr,
-                                                                                                       sizeof ( MDI_PATCHAREA ) );
-                                       break;
-                               }
-                       MmUnmapIoSpace ( PhysicalMemory, 0x100000 );
-               }
-       /*
-        * Find aBFT
-        */
-       PhysicalAddress.QuadPart = 0LL;
-       PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0xa0000, MmNonCached );
-       if ( !PhysicalMemory )
-               {
-                       DBG ( "Could not map low memory\n" );
-               }
-       else
-               {
-                       for ( Offset = 0; Offset < 0xa0000; Offset += 0x10 )
-                               {
-                                       if ( ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Signature ==
-                                                        0x54464261 )
-                                               {
-                                                       Checksum = 0;
-                                                       for ( i = 0;
-                                                                               i < ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Length;
-                                                                               i++ )
-                                                               Checksum += PhysicalMemory[Offset + i];
-                                                       if ( Checksum & 0xff )
-                                                               continue;
-                                                       if ( ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Revision != 1 )
-                                                               {
-                                                                       DBG ( "Found aBFT with mismatched revision v%d at "
-                                                                                               "segment 0x%4x. want v1.\n",
-                                                                                               ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Revision,
-                                                                                               ( Offset / 0x10 ) );
-                                                                       continue;
-                                                               }
-                                                       DBG ( "Found aBFT at segment: 0x%04x\n", ( Offset / 0x10 ) );
-                                                       RtlCopyMemory ( &AOEBootRecord, &PhysicalMemory[Offset],
-                                                                                                                       sizeof ( BUS_ABFT ) );
-                                                       FoundAbft = TRUE;
-                                                       break;
-                                               }
-                               }
-                       MmUnmapIoSpace ( PhysicalMemory, 0xa0000 );
-               }
-
-#ifdef RIS
-       FoundAbft = TRUE;
-       RtlCopyMemory ( AOEBootRecord.ClientMac, "\x00\x0c\x29\x34\x69\x34", 6 );
-       AOEBootRecord.Major = 0;
-       AOEBootRecord.Minor = 10;
-#endif
-
-       if ( FoundMemdisk )
-               {
-                       if ( !Bus_AddChild ( DeviceObject, NULL, 0, 0, TRUE ) )
-                               DBG ( "Bus_AddChild() failed for MEMDISK\n" );
-                       else if ( DeviceExtension->Bus.PhysicalDeviceObject != NULL )
-                               {
-                                       IoInvalidateDeviceRelations ( DeviceExtension->Bus.
-                                                                                                                                                               PhysicalDeviceObject, BusRelations );
-                               }
-               }
-       else
-               {
-                       DBG ( "Not booting from MEMDISK...\n" );
-               }
-
-       if ( FoundAbft )
-               {
-                       DBG ( "Boot from client NIC %02x:%02x:%02x:%02x:%02x:%02x to major: "
-                                               "%d minor: %d\n", AOEBootRecord.ClientMac[0],
-                                               AOEBootRecord.ClientMac[1], AOEBootRecord.ClientMac[2],
-                                               AOEBootRecord.ClientMac[3], AOEBootRecord.ClientMac[4],
-                                               AOEBootRecord.ClientMac[5], AOEBootRecord.Major,
-                                               AOEBootRecord.Minor );
-                       if ( !Bus_AddChild
-                                        ( DeviceObject, AOEBootRecord.ClientMac, AOEBootRecord.Major,
-                                                AOEBootRecord.Minor, TRUE ) )
-                               DBG ( "Bus_AddChild() failed for aBFT AoE disk\n" );
-                       else
-                               {
-                                       if ( DeviceExtension->Bus.PhysicalDeviceObject != NULL )
-                                               {
-                                                       IoInvalidateDeviceRelations ( DeviceExtension->Bus.
-                                                                                                                                                                               PhysicalDeviceObject,
-                                                                                                                                                                               BusRelations );
-                                               }
-                               }
-               }
-       else
-               {
-                       DBG ( "Not booting from aBFT AoE disk...\n" );
-               }
-#ifdef RIS
-       DeviceExtension->State = Started;
-#endif
-       Started = TRUE;
-       return STATUS_SUCCESS;
-}
-
 VOID STDCALL
 Bus_AddTarget (
        IN PUCHAR ClientMac,
@@ -408,7 +207,7 @@ Bus_CleanupTargetList (
  *
  * Returns TRUE for success, FALSE for failure
  */
-static BOOLEAN STDCALL
+BOOLEAN STDCALL
 Bus_AddChild (
        IN PDEVICE_OBJECT BusDeviceObject,
        IN PUCHAR ClientMac,
@@ -455,6 +254,7 @@ Bus_AddChild (
         */
        RtlZeroMemory ( DeviceExtension, sizeof ( DRIVER_DEVICEEXTENSION ) );
        DeviceExtension->IsBus = FALSE;
+       DeviceExtension->Dispatch = Disk_Dispatch;
        DeviceExtension->Self = DeviceObject;
        DeviceExtension->DriverObject = BusDeviceExtension->DriverObject;
        DeviceExtension->State = NotStarted;
@@ -484,10 +284,11 @@ Bus_AddChild (
                }
        else
                {
-                       DeviceExtension->Disk.RAMDisk.DiskBuf = Bus_Globals_BootMemdisk.diskbuf;
+                       DeviceExtension->Disk.RAMDisk.DiskBuf =
+                               Probe_Globals_BootMemdisk.diskbuf;
                        DeviceExtension->Disk.LBADiskSize =
                                DeviceExtension->Disk.RAMDisk.DiskSize =
-                               Bus_Globals_BootMemdisk.disksize;
+                               Probe_Globals_BootMemdisk.disksize;
                        DeviceExtension->IsMemdisk = TRUE;
                }
        /*
@@ -504,9 +305,9 @@ Bus_AddChild (
                }
        else
                {
-                       DeviceExtension->Disk.Cylinders = Bus_Globals_BootMemdisk.cylinders;
-                       DeviceExtension->Disk.Heads = Bus_Globals_BootMemdisk.heads;
-                       DeviceExtension->Disk.Sectors = Bus_Globals_BootMemdisk.disksize;
+                       DeviceExtension->Disk.Cylinders = Probe_Globals_BootMemdisk.cylinders;
+                       DeviceExtension->Disk.Heads = Probe_Globals_BootMemdisk.heads;
+                       DeviceExtension->Disk.Sectors = Probe_Globals_BootMemdisk.disksize;
                }
 
        DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
@@ -528,13 +329,7 @@ Bus_AddChild (
        return TRUE;
 }
 
-NTSTATUS STDCALL
-Bus_DispatchPnP (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Bus_DispatchPnP )
 {
        NTSTATUS Status;
        KEVENT Event;
@@ -601,14 +396,12 @@ Bus_DispatchPnP (
                                                Count++;
                                                Walker = Walker->Disk.Next;
                                        }
-
-                               if ( ( DeviceRelations =
-                                                        ( PDEVICE_RELATIONS ) ExAllocatePool ( NonPagedPool,
-                                                                                                                                                                                                                       sizeof
-                                                                                                                                                                                                                       ( DEVICE_RELATIONS ) +
-                                                                                                                                                                                                                       ( sizeof
-                                                                                                                                                                                                                               ( PDEVICE_OBJECT ) *
-                                                                                                                                                                                                                               Count ) ) ) == NULL )
+                               DeviceRelations =
+                                       ( PDEVICE_RELATIONS ) ExAllocatePool ( NonPagedPool,
+                                                                                                                                                                                                sizeof ( DEVICE_RELATIONS ) +
+                                                                                                                                                                                                ( sizeof ( PDEVICE_OBJECT ) *
+                                                                                                                                                                                                        Count ) );
+                               if ( DeviceRelations == NULL )
                                        {
                                                Irp->IoStatus.Information = 0;
                                                Status = STATUS_INSUFFICIENT_RESOURCES;
@@ -669,13 +462,7 @@ Bus_DispatchPnP (
        return Status;
 }
 
-NTSTATUS STDCALL
-Bus_DispatchDeviceControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Bus_DispatchDeviceControl )
 {
        NTSTATUS Status;
        PUCHAR Buffer;
@@ -683,8 +470,8 @@ Bus_DispatchDeviceControl (
        PBUS_TARGETLIST TargetWalker;
        PDRIVER_DEVICEEXTENSION DiskWalker,
         DiskWalkerPrevious;
-       PTARGETS Targets;
-       PDISKS Disks;
+       PMOUNT_TARGETS Targets;
+       PMOUNT_DISKS Disks;
        KIRQL Irql;
 
        switch ( Stack->Parameters.DeviceIoControl.IoControlCode )
@@ -702,10 +489,11 @@ Bus_DispatchDeviceControl (
                                        }
 
                                if ( ( Targets =
-                                                        ( PTARGETS ) ExAllocatePool ( NonPagedPool,
-                                                                                                                                                                                sizeof ( TARGETS ) +
-                                                                                                                                                                                ( Count *
-                                                                                                                                                                                        sizeof ( TARGET ) ) ) ) ==
+                                                        ( PMOUNT_TARGETS ) ExAllocatePool ( NonPagedPool,
+                                                                                                                                                                                                        sizeof ( MOUNT_TARGETS ) +
+                                                                                                                                                                                                        ( Count *
+                                                                                                                                                                                                                sizeof
+                                                                                                                                                                                                                ( MOUNT_TARGET ) ) ) ) ==
                                                 NULL )
                                        {
                                                DBG ( "ExAllocatePool Targets\n" );
@@ -714,7 +502,7 @@ Bus_DispatchDeviceControl (
                                                break;
                                        }
                                Irp->IoStatus.Information =
-                                       sizeof ( TARGETS ) + ( Count * sizeof ( TARGET ) );
+                                       sizeof ( MOUNT_TARGETS ) + ( Count * sizeof ( MOUNT_TARGET ) );
                                Targets->Count = Count;
 
                                Count = 0;
@@ -722,19 +510,19 @@ Bus_DispatchDeviceControl (
                                while ( TargetWalker != NULL )
                                        {
                                                RtlCopyMemory ( &Targets->Target[Count], &TargetWalker->Target,
-                                                                                                               sizeof ( TARGET ) );
+                                                                                                               sizeof ( MOUNT_TARGET ) );
                                                Count++;
                                                TargetWalker = TargetWalker->Next;
                                        }
                                RtlCopyMemory ( Irp->AssociatedIrp.SystemBuffer, Targets,
                                                                                                ( Stack->Parameters.
                                                                                                        DeviceIoControl.OutputBufferLength <
-                                                                                                       ( sizeof ( TARGETS ) +
+                                                                                                       ( sizeof ( MOUNT_TARGETS ) +
                                                                                                                ( Count *
-                                                                                                                       sizeof ( TARGET ) ) ) ? Stack->
+                                                                                                                       sizeof ( MOUNT_TARGET ) ) ) ? Stack->
                                                                                                        Parameters.DeviceIoControl.OutputBufferLength
-                                                                                                       : ( sizeof ( TARGETS ) +
-                                                                                                                       ( Count * sizeof ( TARGET ) ) ) ) );
+                                                                                                       : ( sizeof ( MOUNT_TARGETS ) +
+                                                                                                                       ( Count * sizeof ( MOUNT_TARGET ) ) ) ) );
                                ExFreePool ( Targets );
 
                                KeReleaseSpinLock ( &Bus_Globals_TargetListSpinLock, Irql );
@@ -752,10 +540,11 @@ Bus_DispatchDeviceControl (
                                        }
 
                                if ( ( Disks =
-                                                        ( PDISKS ) ExAllocatePool ( NonPagedPool,
-                                                                                                                                                                        sizeof ( DISKS ) +
-                                                                                                                                                                        ( Count * sizeof ( DISK ) ) ) ) ==
-                                                NULL )
+                                                        ( PMOUNT_DISKS ) ExAllocatePool ( NonPagedPool,
+                                                                                                                                                                                                sizeof ( MOUNT_DISKS ) +
+                                                                                                                                                                                                ( Count *
+                                                                                                                                                                                                        sizeof ( MOUNT_DISK ) ) ) )
+                                                == NULL )
                                        {
                                                DBG ( "ExAllocatePool Disks\n" );
                                                Irp->IoStatus.Information = 0;
@@ -763,7 +552,7 @@ Bus_DispatchDeviceControl (
                                                break;
                                        }
                                Irp->IoStatus.Information =
-                                       sizeof ( DISKS ) + ( Count * sizeof ( DISK ) );
+                                       sizeof ( MOUNT_DISKS ) + ( Count * sizeof ( MOUNT_DISK ) );
                                Disks->Count = Count;
 
                                Count = 0;
@@ -784,12 +573,12 @@ Bus_DispatchDeviceControl (
                                RtlCopyMemory ( Irp->AssociatedIrp.SystemBuffer, Disks,
                                                                                                ( Stack->Parameters.
                                                                                                        DeviceIoControl.OutputBufferLength <
-                                                                                                       ( sizeof ( DISKS ) +
+                                                                                                       ( sizeof ( MOUNT_DISKS ) +
                                                                                                                ( Count *
-                                                                                                                       sizeof ( DISK ) ) ) ? Stack->
+                                                                                                                       sizeof ( MOUNT_DISK ) ) ) ? Stack->
                                                                                                        Parameters.DeviceIoControl.OutputBufferLength
-                                                                                                       : ( sizeof ( DISKS ) +
-                                                                                                                       ( Count * sizeof ( DISK ) ) ) ) );
+                                                                                                       : ( sizeof ( MOUNT_DISKS ) +
+                                                                                                                       ( Count * sizeof ( MOUNT_DISK ) ) ) ) );
                                ExFreePool ( Disks );
 
                                Status = STATUS_SUCCESS;
@@ -859,19 +648,44 @@ Bus_DispatchDeviceControl (
        return Status;
 }
 
-NTSTATUS STDCALL
-Bus_DispatchSystemControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- )
+IRPHandler_Declaration ( Bus_DispatchSystemControl )
 {
        DBG ( "...\n" );
        IoSkipCurrentIrpStackLocation ( Irp );
        return IoCallDriver ( DeviceExtension->Bus.LowerDeviceObject, Irp );
 }
 
+IRPHandler_Declaration ( Bus_Dispatch )
+{
+       NTSTATUS Status;
+
+       switch ( Stack->MajorFunction )
+               {
+                       case IRP_MJ_POWER:
+                               PoStartNextPowerIrp ( Irp );
+                               IoSkipCurrentIrpStackLocation ( Irp );
+                               Status = PoCallDriver ( DeviceExtension->Bus.LowerDeviceObject, Irp );
+                               break;
+                       case IRP_MJ_PNP:
+                               Status = Bus_DispatchPnP ( DeviceObject, Irp, Stack, DeviceExtension );
+                               break;
+                       case IRP_MJ_SYSTEM_CONTROL:
+                               Status =
+                                       Bus_DispatchSystemControl ( DeviceObject, Irp, Stack,
+                                                                                                                                                       DeviceExtension );
+                               break;
+                       case IRP_MJ_DEVICE_CONTROL:
+                               Status =
+                                       Bus_DispatchDeviceControl ( DeviceObject, Irp, Stack,
+                                                                                                                                                       DeviceExtension );
+                               break;
+                       default:
+                               Status = STATUS_NOT_SUPPORTED;
+                               Irp->IoStatus.Status = Status;
+                               IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+               }
+}
+
 static NTSTATUS STDCALL
 Bus_IoCompletionRoutine (
        IN PDEVICE_OBJECT DeviceObject,
@@ -882,3 +696,120 @@ Bus_IoCompletionRoutine (
        KeSetEvent ( Event, 0, FALSE );
        return STATUS_MORE_PROCESSING_REQUIRED;
 }
+
+NTSTATUS STDCALL
+Bus_GetDeviceCapabilities (
+       IN PDEVICE_OBJECT DeviceObject,
+       IN PDEVICE_CAPABILITIES DeviceCapabilities
+ )
+{
+       IO_STATUS_BLOCK ioStatus;
+       KEVENT pnpEvent;
+       NTSTATUS status;
+       PDEVICE_OBJECT targetObject;
+       PIO_STACK_LOCATION irpStack;
+       PIRP pnpIrp;
+
+       RtlZeroMemory ( DeviceCapabilities, sizeof ( DEVICE_CAPABILITIES ) );
+       DeviceCapabilities->Size = sizeof ( DEVICE_CAPABILITIES );
+       DeviceCapabilities->Version = 1;
+       DeviceCapabilities->Address = -1;
+       DeviceCapabilities->UINumber = -1;
+
+       KeInitializeEvent ( &pnpEvent, NotificationEvent, FALSE );
+       targetObject = IoGetAttachedDeviceReference ( DeviceObject );
+       pnpIrp =
+               IoBuildSynchronousFsdRequest ( IRP_MJ_PNP, targetObject, NULL, 0, NULL,
+                                                                                                                                        &pnpEvent, &ioStatus );
+       if ( pnpIrp == NULL )
+               {
+                       status = STATUS_INSUFFICIENT_RESOURCES;
+               }
+       else
+               {
+                       pnpIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
+                       irpStack = IoGetNextIrpStackLocation ( pnpIrp );
+                       RtlZeroMemory ( irpStack, sizeof ( IO_STACK_LOCATION ) );
+                       irpStack->MajorFunction = IRP_MJ_PNP;
+                       irpStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES;
+                       irpStack->Parameters.DeviceCapabilities.Capabilities =
+                               DeviceCapabilities;
+                       status = IoCallDriver ( targetObject, pnpIrp );
+                       if ( status == STATUS_PENDING )
+                               {
+                                       KeWaitForSingleObject ( &pnpEvent, Executive, KernelMode, FALSE,
+                                                                                                                                       NULL );
+                                       status = ioStatus.Status;
+                               }
+               }
+       ObDereferenceObject ( targetObject );
+       return status;
+}
+
+NTSTATUS STDCALL
+Bus_AddDevice (
+       IN PDRIVER_OBJECT DriverObject,
+       IN PDEVICE_OBJECT PhysicalDeviceObject
+ )
+{
+       NTSTATUS Status;
+       UNICODE_STRING DeviceName,
+        DosDeviceName;
+       PDRIVER_DEVICEEXTENSION DeviceExtension;
+       PDEVICE_OBJECT DeviceObject;
+
+       DBG ( "Entry\n" );
+       if ( Bus_Globals_Self )
+               return STATUS_SUCCESS;
+       RtlInitUnicodeString ( &DeviceName, L"\\Device\\AoE" );
+       RtlInitUnicodeString ( &DosDeviceName, L"\\DosDevices\\AoE" );
+       if ( !NT_SUCCESS
+                        ( Status =
+                                IoCreateDevice ( DriverObject, sizeof ( DRIVER_DEVICEEXTENSION ),
+                                                                                                       &DeviceName, FILE_DEVICE_CONTROLLER,
+                                                                                                       FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject ) ) )
+               {
+                       return Error ( "Bus_AddDevice IoCreateDevice", Status );
+               }
+       if ( !NT_SUCCESS
+                        ( Status = IoCreateSymbolicLink ( &DosDeviceName, &DeviceName ) ) )
+               {
+                       IoDeleteDevice ( DeviceObject );
+                       return Error ( "Bus_AddDevice IoCreateSymbolicLink", Status );
+               }
+
+       DeviceExtension = ( PDRIVER_DEVICEEXTENSION ) DeviceObject->DeviceExtension;
+       RtlZeroMemory ( DeviceExtension, sizeof ( DRIVER_DEVICEEXTENSION ) );
+       DeviceExtension->IsBus = TRUE;
+       DeviceExtension->Dispatch = Bus_Dispatch;
+       DeviceExtension->DriverObject = DriverObject;
+       DeviceExtension->Self = DeviceObject;
+       DeviceExtension->State = NotStarted;
+       DeviceExtension->OldState = NotStarted;
+       DeviceExtension->Bus.PhysicalDeviceObject = PhysicalDeviceObject;
+       DeviceExtension->Bus.Children = 0;
+       DeviceExtension->Bus.ChildList = NULL;
+       KeInitializeSpinLock ( &DeviceExtension->Bus.SpinLock );
+       DeviceObject->Flags |= DO_DIRECT_IO;    /* FIXME? */
+       DeviceObject->Flags |= DO_POWER_INRUSH; /* FIXME? */
+       /*
+        * Add the bus to the device tree
+        */
+       if ( PhysicalDeviceObject != NULL )
+               {
+                       if ( ( DeviceExtension->Bus.LowerDeviceObject =
+                                                IoAttachDeviceToDeviceStack ( DeviceObject,
+                                                                                                                                                                        PhysicalDeviceObject ) ) == NULL )
+                               {
+                                       IoDeleteDevice ( DeviceObject );
+                                       return Error ( "AddDevice IoAttachDeviceToDeviceStack",
+                                                                                                STATUS_NO_SUCH_DEVICE );
+                               }
+               }
+       DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
+#ifdef RIS
+       DeviceExtension->State = Started;
+#endif
+       Bus_Globals_Self = DeviceObject;
+       return STATUS_SUCCESS;
+}
index b0172b8..94a6f92 100644 (file)
--- a/src/bus.h
+++ b/src/bus.h
@@ -51,25 +51,16 @@ extern NTSTATUS STDCALL Bus_AddDevice (
        IN PDEVICE_OBJECT PhysicalDeviceObject
  );
 
-extern NTSTATUS STDCALL Bus_DispatchPnP (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Bus_DispatchPnP
  );
 
-extern NTSTATUS STDCALL Bus_DispatchDeviceControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Bus_DispatchDeviceControl
  );
 
-extern NTSTATUS STDCALL Bus_DispatchSystemControl (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
+extern IRPHandler_Declaration (
+       Bus_DispatchSystemControl
  );
 
 extern VOID STDCALL Bus_AddTarget (
@@ -84,4 +75,19 @@ extern VOID STDCALL Bus_CleanupTargetList (
        void
  );
 
+extern NTSTATUS STDCALL Bus_GetDeviceCapabilities (
+       IN PDEVICE_OBJECT DeviceObject,
+       IN PDEVICE_CAPABILITIES DeviceCapabilities
+ );
+
+extern BOOLEAN STDCALL Bus_AddChild (
+       IN PDEVICE_OBJECT BusDeviceObject,
+       IN PUCHAR ClientMac,
+       IN ULONG Major,
+       IN ULONG Minor,
+       IN BOOLEAN Boot
+ );
+
+extern PDEVICE_OBJECT Bus_Globals_Self;
+
 #endif                                                                                                 /* _BUS_H */
index ccb8c04..9dfd571 100644 (file)
@@ -1,56 +1,57 @@
-/**\r
- * Copyright 2006-2008, V.\r
- * Portions copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.\r
- * For contact information, see http://winaoe.org/\r
- *\r
- * This file is part of WinAoE.\r
- *\r
- * WinAoE is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * WinAoE is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with WinAoE.  If not, see <http://www.gnu.org/licenses/>.\r
- */  \r
-#ifndef _DISK_H\r
-#  define _DISK_H\r
-       \r
-/**\r
- * @file\r
- *\r
- * Disk specifics\r
- *\r
- */ \r
-       \r
-#  include "aoedisk.h"\r
-#  include "ramdisk.h"\r
-\rtypedef struct _DISK_DISK \r
+/**
+ * Copyright 2006-2008, V.
+ * Portions copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ * For contact information, see http://winaoe.org/
+ *
+ * This file is part of WinAoE.
+ *
+ * WinAoE 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinAoE 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 WinAoE.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _DISK_H
+#  define _DISK_H
+
+/**
+ * @file
+ *
+ * Disk specifics
+ *
+ */
+
+#  include "aoedisk.h"
+#  include "ramdisk.h"
+
+typedef struct _DISK_DISK
 {
-       \rPDEVICE_OBJECT Parent;
-       \rPDRIVER_DEVICEEXTENSION Next;
-       \rKEVENT SearchEvent;
-       \rSEARCHSTATE SearchState;
-       \rKSPIN_LOCK SpinLock;
-       \rBOOLEAN BootDrive;
-       \rBOOLEAN Unmount;
-       \rULONG DiskNumber;
-       \runion \r
+       PDEVICE_OBJECT Parent;
+       PDRIVER_DEVICEEXTENSION Next;
+       KEVENT SearchEvent;
+       SEARCHSTATE SearchState;
+       KSPIN_LOCK SpinLock;
+       BOOLEAN BootDrive;
+       BOOLEAN Unmount;
+       ULONG DiskNumber;
+       union
        {
-               \rAOEDISK_AOEDISK AoE;
-               \rRAMDISK_RAMDISK RAMDisk;
-       \r};
-       \rLONGLONG LBADiskSize;
-       \rLONGLONG Cylinders;
-       \rULONG Heads;
-       \rULONG Sectors;
-       \rULONG SpecialFileCount;
-\r} DISK_DISK,
-\r*PDISK_DISK;
-\r\r
-#endif                                                                                                 /* _DISK_H */\r
+               AOEDISK_AOEDISK AoE;
+               RAMDISK_RAMDISK RAMDisk;
+       };
+       LONGLONG LBADiskSize;
+       LONGLONG Cylinders;
+       ULONG Heads;
+       ULONG Sectors;
+       ULONG SpecialFileCount;
+} DISK_DISK,
+*PDISK_DISK;
+
+#endif                                                                                                 /* _DISK_H */
index 8d10503..b91174a 100644 (file)
@@ -37,6 +37,7 @@
 #include "aoe.h"
 #include "protocol.h"
 #include "debug.h"
+#include "probe.h"
 
 /* in this file */
 static NTSTATUS STDCALL Driver_DispatchNotSupported (
@@ -44,11 +45,6 @@ static NTSTATUS STDCALL Driver_DispatchNotSupported (
        IN PIRP Irp
  );
 
-static NTSTATUS STDCALL Driver_Dispatch (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp
- );
-
 static VOID STDCALL Driver_Unload (
        IN PDRIVER_OBJECT DriverObject
  );
@@ -114,7 +110,7 @@ DriverEntry (
 
        /*
         * Set up IRP MajorFunction function table for devices
-        * this driver handles.
+        * this driver handles
         */
        for ( i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++ )
                DriverObject->MajorFunction[i] = Driver_DispatchNotSupported;
@@ -137,8 +133,10 @@ DriverEntry (
                {
                        Protocol_Stop (  );
                        AoE_Stop (  );
-                       Error ( "Bus_AddDevice", Status );
+                       return Error ( "Bus_AddDevice", Status );
                }
+       Probe_MemDisk ( Bus_Globals_Self );
+       Probe_AoE ( Bus_Globals_Self );
        return Status;
 }
 
@@ -153,7 +151,7 @@ Driver_DispatchNotSupported (
        return Irp->IoStatus.Status;
 }
 
-static NTSTATUS STDCALL
+NTSTATUS STDCALL
 Driver_Dispatch (
        IN PDEVICE_OBJECT DeviceObject,
        IN PIRP Irp
@@ -182,67 +180,16 @@ Driver_Dispatch (
                }
        switch ( Stack->MajorFunction )
                {
-                       case IRP_MJ_POWER:
-                               if ( DeviceExtension->IsBus )
-                                       {
-                                               PoStartNextPowerIrp ( Irp );
-                                               IoSkipCurrentIrpStackLocation ( Irp );
-                                               Status =
-                                                       PoCallDriver ( DeviceExtension->Bus.LowerDeviceObject, Irp );
-                                       }
-                               else
-                                       {
-                                               PoStartNextPowerIrp ( Irp );
-                                               Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
-                                               IoCompleteRequest ( Irp, IO_NO_INCREMENT );
-                                               Status = STATUS_NOT_SUPPORTED;
-                                       }
-                               break;
-                       case IRP_MJ_PNP:
-                               if ( DeviceExtension->IsBus )
-                                       Status =
-                                               Bus_DispatchPnP ( DeviceObject, Irp, Stack, DeviceExtension );
-                               else
-                                       Status =
-                                               Disk_DispatchPnP ( DeviceObject, Irp, Stack, DeviceExtension );
-                               break;
-                       case IRP_MJ_SYSTEM_CONTROL:
-                               if ( DeviceExtension->IsBus )
-                                       Status =
-                                               Bus_DispatchSystemControl ( DeviceObject, Irp, Stack,
-                                                                                                                                                               DeviceExtension );
-                               else
-                                       Status =
-                                               Disk_DispatchSystemControl ( DeviceObject, Irp, Stack,
-                                                                                                                                                                DeviceExtension );
-                               break;
-                       case IRP_MJ_DEVICE_CONTROL:
-                               if ( DeviceExtension->IsBus )
-                                       Status =
-                                               Bus_DispatchDeviceControl ( DeviceObject, Irp, Stack,
-                                                                                                                                                               DeviceExtension );
-                               else
-                                       Status =
-                                               Disk_DispatchDeviceControl ( DeviceObject, Irp, Stack,
-                                                                                                                                                                DeviceExtension );
-                               break;
                        case IRP_MJ_CREATE:
                        case IRP_MJ_CLOSE:
                                Status = STATUS_SUCCESS;
                                Irp->IoStatus.Status = Status;
                                IoCompleteRequest ( Irp, IO_NO_INCREMENT );
                                break;
-                       case IRP_MJ_SCSI:
-                               if ( !DeviceExtension->IsBus )
-                                       {
-                                               Status =
-                                                       Disk_DispatchSCSI ( DeviceObject, Irp, Stack, DeviceExtension );
-                                               break;
-                                       }
                        default:
-                               Status = STATUS_NOT_SUPPORTED;
-                               Irp->IoStatus.Status = Status;
-                               IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+                               Status =
+                                       DeviceExtension->Dispatch ( DeviceObject, Irp, Stack,
+                                                                                                                                                       DeviceExtension );
                }
 #ifdef DEBUGIRPS
        if ( Status != STATUS_PENDING )
index 75555a2..17cfc89 100644 (file)
@@ -61,18 +61,23 @@ typedef enum
 typedef struct _DRIVER_DEVICEEXTENSION DRIVER_DEVICEEXTENSION,
 *PDRIVER_DEVICEEXTENSION;
 
+#  define IRPHandler_Declaration(x) NTSTATUS STDCALL\
+                                  x (\
+                                       IN PDEVICE_OBJECT DeviceObject,\
+                                       IN PIRP Irp,\
+                                       IN PIO_STACK_LOCATION Stack,\
+                                       IN PDRIVER_DEVICEEXTENSION DeviceExtension\
+                                   )
+/*
+ * Function-type for an IRP handler. 'indent' mangles this, so it looks weird
+ */
+typedef IRPHandler_Declaration (
+        ( *DRIVER_IRPHANDLER )
+ );
+
 #  include "bus.h"
 #  include "disk.h"
 
-typedef NTSTATUS STDCALL (
-       *DRIVER_DISPATCHFUNCTION
- ) (
-       IN PDEVICE_OBJECT DeviceObject,
-       IN PIRP Irp,
-       IN PIO_STACK_LOCATION Stack,
-       IN PDRIVER_DEVICEEXTENSION DeviceExtension
- );
-
 struct _DRIVER_DEVICEEXTENSION
 {
        BOOLEAN IsBus;
@@ -81,7 +86,7 @@ struct _DRIVER_DEVICEEXTENSION
        PDRIVER_OBJECT DriverObject;
        STATE State;
        STATE OldState;
-       DRIVER_DISPATCHFUNCTION *DispatchTable;
+       DRIVER_IRPHANDLER Dispatch;
        union
        {
                struct _BUS_BUS Bus;
@@ -107,4 +112,9 @@ extern NTSTATUS STDCALL DriverEntry (
        IN PUNICODE_STRING RegistryPath
  );
 
+extern NTSTATUS STDCALL Driver_Dispatch (
+       IN PDEVICE_OBJECT DeviceObject,
+       IN PIRP Irp
+ );
+
 #endif                                                                                                 /* _DRIVER_H */
index 97f128c..36dbaaa 100644 (file)
@@ -59,8 +59,8 @@ main (
        HANDLE DeviceHandle;
        UCHAR InBuffer[1024];
        UCHAR String[256];
-       PTARGETS Targets;
-       PDISKS Disks;
+       PMOUNT_TARGETS Targets;
+       PMOUNT_DISKS Disks;
        UCHAR Mac[6];
        DWORD BytesReturned;
        ULONG Major,
@@ -112,15 +112,17 @@ main (
                {
                        case CommandScan:
                                if ( ( Targets =
-                                                        ( PTARGETS ) malloc ( sizeof ( TARGETS ) +
-                                                                                                                                                ( 32 * sizeof ( TARGET ) ) ) ) == NULL )
+                                                        ( PMOUNT_TARGETS ) malloc ( sizeof ( MOUNT_TARGETS ) +
+                                                                                                                                                                        ( 32 *
+                                                                                                                                                                                sizeof ( MOUNT_TARGET ) ) ) ) ==
+                                                NULL )
                                        {
                                                printf ( "Out of memory\n" );
                                                break;
                                        }
                                if ( !DeviceIoControl
                                                 ( DeviceHandle, IOCTL_AOE_SCAN, NULL, 0, Targets,
-                                                        ( sizeof ( TARGETS ) + ( 32 * sizeof ( TARGET ) ) ),
+                                                        ( sizeof ( MOUNT_TARGETS ) + ( 32 * sizeof ( MOUNT_TARGET ) ) ),
                                                         &BytesReturned, ( LPOVERLAPPED ) NULL ) )
                                        {
                                                printf ( "DeviceIoControl (%d)\n", ( int )GetLastError (  ) );
@@ -163,16 +165,17 @@ main (
                                break;
                        case CommandShow:
                                if ( ( Disks =
-                                                        ( PDISKS ) malloc ( sizeof ( DISKS ) +
-                                                                                                                                        ( 32 * sizeof ( DISK ) ) ) ) == NULL )
+                                                        ( PMOUNT_DISKS ) malloc ( sizeof ( MOUNT_DISKS ) +
+                                                                                                                                                                ( 32 * sizeof ( MOUNT_DISK ) ) ) ) ==
+                                                NULL )
                                        {
                                                printf ( "Out of memory\n" );
                                                break;
                                        }
                                if ( !DeviceIoControl
                                                 ( DeviceHandle, IOCTL_AOE_SHOW, NULL, 0, Disks,
-                                                        ( sizeof ( DISKS ) + ( 32 * sizeof ( DISK ) ) ), &BytesReturned,
-                                                        ( LPOVERLAPPED ) NULL ) )
+                                                        ( sizeof ( MOUNT_DISKS ) + ( 32 * sizeof ( MOUNT_DISK ) ) ),
+                                                        &BytesReturned, ( LPOVERLAPPED ) NULL ) )
                                        {
                                                printf ( "DeviceIoControl (%d)\n", ( int )GetLastError (  ) );
                                                free ( Disks );
index e745097..949cab0 100644 (file)
@@ -24,7 +24,7 @@
 /**
  * @file
  *
- * Mount command header
+ * Mount command and device control code header
  *
  */
 
@@ -43,7 +43,7 @@
                                   METHOD_BUFFERED,\
                                   FILE_READ_DATA | FILE_WRITE_DATA)
 
-typedef struct _TARGET
+typedef struct _MOUNT_TARGET
 {
        UCHAR ClientMac[6];
        UCHAR ServerMac[6];
@@ -51,17 +51,17 @@ typedef struct _TARGET
        ULONG Minor;
        LONGLONG LBASize;
        LARGE_INTEGER ProbeTime;
-} TARGET,
-*PTARGET;
+} MOUNT_TARGET,
+*PMOUNT_TARGET;
 
-typedef struct _TARGETS
+typedef struct _MOUNT_TARGETS
 {
        ULONG Count;
-       TARGET Target[];
-} TARGETS,
-*PTARGETS;
+       MOUNT_TARGET Target[];
+} MOUNT_TARGETS,
+*PMOUNT_TARGETS;
 
-typedef struct _DISK
+typedef struct _MOUNT_DISK
 {
        ULONG Disk;
        UCHAR ClientMac[6];
@@ -69,14 +69,14 @@ typedef struct _DISK
        ULONG Major;
        ULONG Minor;
        LONGLONG LBASize;
-} DISK,
-*PDISK;
+} MOUNT_DISK,
+*PMOUNT_DISK;
 
-typedef struct _DISKS
+typedef struct _MOUNT_DISKS
 {
        ULONG Count;
-       DISK Disk[];
-} DISKS,
-*PDISKS;
+       MOUNT_DISK Disk[];
+} MOUNT_DISKS,
+*PMOUNT_DISKS;
 
 #endif                                                                                                 /* _MOUNT_H */
diff --git a/src/probe.c b/src/probe.c
new file mode 100644 (file)
index 0000000..e976875
--- /dev/null
@@ -0,0 +1,222 @@
+/**
+ * Copyright 2006-2008, V.
+ * Portions copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ * For contact information, see http://winaoe.org/
+ *
+ * This file is part of WinAoE.
+ *
+ * WinAoE 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinAoE 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 WinAoE.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @file
+ *
+ * Boot-time disk probing specifics
+ *
+ */
+
+#include "portable.h"
+#include <ntddk.h>
+#include "driver.h"
+#include "debug.h"
+#include "mdi.h"
+#include "bus.h"
+
+#ifdef _MSC_VER
+#  pragma pack(1)
+#endif
+typedef struct _BUS_ABFT
+{
+       UINT Signature;                                                         /* 0x54464261 (aBFT) */
+       UINT Length;
+       UCHAR Revision;
+       UCHAR Checksum;
+       UCHAR OEMID[6];
+       UCHAR OEMTableID[8];
+       UCHAR Reserved1[12];
+       USHORT Major;
+       UCHAR Minor;
+       UCHAR Reserved2;
+       UCHAR ClientMac[6];
+} __attribute__ ( ( __packed__ ) ) BUS_ABFT, *PBUS_ABFT;
+#ifdef _MSC_VER
+#  pragma pack()
+#endif
+
+MDI_PATCHAREA Probe_Globals_BootMemdisk;
+
+VOID STDCALL
+Probe_MemDisk (
+       PDEVICE_OBJECT BusDeviceObject
+ )
+{
+       PHYSICAL_ADDRESS PhysicalAddress;
+       PUCHAR PhysicalMemory;
+       UINT16 RealSeg,
+        RealOff;
+       UINT32 Int13Hook;
+       PMDI_PATCHAREA MemdiskPtr;
+       UINT Offset;
+       BOOLEAN FoundMemdisk = FALSE;
+       PDRIVER_DEVICEEXTENSION BusDeviceExtension =
+               ( PDRIVER_DEVICEEXTENSION ) BusDeviceObject->DeviceExtension;
+
+       /*
+        * Find a MEMDISK.  Start by looking at the IDT and following
+        * the INT 0x13 hook.  This discovery strategy is extremely poor
+        * at the moment.  The eventual goal is to discover MEMDISK RAM disks
+        * as well as GRUB4DOS-mapped RAM disks.  Slight modifications to both
+        * will help with this.
+        */
+       PhysicalAddress.QuadPart = 0LL;
+       PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0x100000, MmNonCached );
+       if ( !PhysicalMemory )
+               {
+                       DBG ( "Could not map low memory\n" );
+               }
+       else
+               {
+                       RealSeg = *( ( PUINT16 ) & PhysicalMemory[0x13 * 4 + 2] );
+                       RealOff = *( ( PUINT16 ) & PhysicalMemory[0x13 * 4] );
+                       Int13Hook = ( ( ( UINT32 ) RealSeg ) << 4 ) + ( ( UINT32 ) RealOff );
+                       DBG ( "INT 0x13 Segment: 0x%04x\n", RealSeg );
+                       DBG ( "INT 0x13 Offset: 0x%04x\n", RealOff );
+                       DBG ( "INT 0x13 Hook: 0x%08x\n", Int13Hook );
+                       for ( Offset = 0; Offset < 0x100000 - sizeof ( MDI_PATCHAREA );
+                                               Offset += 2 )
+                               {
+                                       MemdiskPtr = ( PMDI_PATCHAREA ) & PhysicalMemory[Offset];
+                                       if ( MemdiskPtr->mdi_bytes != 0x1e )
+                                               continue;
+                                       DBG ( "Found MEMDISK sig #1: 0x%08x\n", Offset );
+                                       if ( ( MemdiskPtr->mdi_version_major != 3 )
+                                                        || ( MemdiskPtr->mdi_version_minor < 0x50 )
+                                                        || ( MemdiskPtr->mdi_version_minor > 0x53 ) )
+                                               continue;
+                                       DBG ( "Found MEMDISK sig #2\n" );
+                                       DBG ( "MEMDISK DiskBuf: 0x%08x\n", MemdiskPtr->diskbuf );
+                                       DBG ( "MEMDISK DiskSize: 0x%08x sectors\n", MemdiskPtr->disksize );
+                                       FoundMemdisk = TRUE;
+                                       RtlCopyMemory ( &Probe_Globals_BootMemdisk, MemdiskPtr,
+                                                                                                       sizeof ( MDI_PATCHAREA ) );
+                                       break;
+                               }
+                       MmUnmapIoSpace ( PhysicalMemory, 0x100000 );
+               }
+       if ( FoundMemdisk )
+               {
+                       if ( !Bus_AddChild ( BusDeviceObject, NULL, 0, 0, TRUE ) )
+                               DBG ( "Bus_AddChild() failed for MEMDISK\n" );
+                       else if ( BusDeviceExtension->Bus.PhysicalDeviceObject != NULL )
+                               {
+                                       IoInvalidateDeviceRelations ( BusDeviceExtension->Bus.
+                                                                                                                                                               PhysicalDeviceObject, BusRelations );
+                               }
+               }
+       else
+               {
+                       DBG ( "Not booting from MEMDISK...\n" );
+               }
+}
+
+VOID STDCALL
+Probe_AoE (
+       PDEVICE_OBJECT BusDeviceObject
+ )
+{
+       PHYSICAL_ADDRESS PhysicalAddress;
+       PUCHAR PhysicalMemory;
+       UINT Offset,
+        Checksum,
+        i;
+       BOOLEAN FoundAbft = FALSE;
+       PDRIVER_DEVICEEXTENSION BusDeviceExtension =
+               ( PDRIVER_DEVICEEXTENSION ) BusDeviceObject->DeviceExtension;
+       BUS_ABFT AOEBootRecord;
+
+       /*
+        * Find aBFT
+        */
+       PhysicalAddress.QuadPart = 0LL;
+       PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0xa0000, MmNonCached );
+       if ( !PhysicalMemory )
+               {
+                       DBG ( "Could not map low memory\n" );
+               }
+       else
+               {
+                       for ( Offset = 0; Offset < 0xa0000; Offset += 0x10 )
+                               {
+                                       if ( ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Signature ==
+                                                        0x54464261 )
+                                               {
+                                                       Checksum = 0;
+                                                       for ( i = 0;
+                                                                               i < ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Length;
+                                                                               i++ )
+                                                               Checksum += PhysicalMemory[Offset + i];
+                                                       if ( Checksum & 0xff )
+                                                               continue;
+                                                       if ( ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Revision != 1 )
+                                                               {
+                                                                       DBG ( "Found aBFT with mismatched revision v%d at "
+                                                                                               "segment 0x%4x. want v1.\n",
+                                                                                               ( ( PBUS_ABFT ) & PhysicalMemory[Offset] )->Revision,
+                                                                                               ( Offset / 0x10 ) );
+                                                                       continue;
+                                                               }
+                                                       DBG ( "Found aBFT at segment: 0x%04x\n", ( Offset / 0x10 ) );
+                                                       RtlCopyMemory ( &AOEBootRecord, &PhysicalMemory[Offset],
+                                                                                                                       sizeof ( BUS_ABFT ) );
+                                                       FoundAbft = TRUE;
+                                                       break;
+                                               }
+                               }
+                       MmUnmapIoSpace ( PhysicalMemory, 0xa0000 );
+               }
+
+#ifdef RIS
+       FoundAbft = TRUE;
+       RtlCopyMemory ( AOEBootRecord.ClientMac, "\x00\x0c\x29\x34\x69\x34", 6 );
+       AOEBootRecord.Major = 0;
+       AOEBootRecord.Minor = 10;
+#endif
+
+       if ( FoundAbft )
+               {
+                       DBG ( "Boot from client NIC %02x:%02x:%02x:%02x:%02x:%02x to major: "
+                                               "%d minor: %d\n", AOEBootRecord.ClientMac[0],
+                                               AOEBootRecord.ClientMac[1], AOEBootRecord.ClientMac[2],
+                                               AOEBootRecord.ClientMac[3], AOEBootRecord.ClientMac[4],
+                                               AOEBootRecord.ClientMac[5], AOEBootRecord.Major,
+                                               AOEBootRecord.Minor );
+                       if ( !Bus_AddChild
+                                        ( BusDeviceObject, AOEBootRecord.ClientMac, AOEBootRecord.Major,
+                                                AOEBootRecord.Minor, TRUE ) )
+                               DBG ( "Bus_AddChild() failed for aBFT AoE disk\n" );
+                       else
+                               {
+                                       if ( BusDeviceExtension->Bus.PhysicalDeviceObject != NULL )
+                                               {
+                                                       IoInvalidateDeviceRelations ( BusDeviceExtension->Bus.
+                                                                                                                                                                               PhysicalDeviceObject,
+                                                                                                                                                                               BusRelations );
+                                               }
+                               }
+               }
+       else
+               {
+                       DBG ( "Not booting from aBFT AoE disk...\n" );
+               }
+}
diff --git a/src/probe.h b/src/probe.h
new file mode 100644 (file)
index 0000000..5086fda
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2006-2008, V.
+ * Portions copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ * For contact information, see http://winaoe.org/
+ *
+ * This file is part of WinAoE.
+ *
+ * WinAoE 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinAoE 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 WinAoE.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _PROBE_H
+#  define _PROBE_H
+
+/**
+ * @file
+ *
+ * Boot-time disk probing specifics
+ *
+ */
+
+#  include <ntddk.h>
+#  include "mdi.h"
+
+extern MDI_PATCHAREA Probe_Globals_BootMemdisk;
+
+extern VOID STDCALL Probe_MemDisk (
+       PDEVICE_OBJECT BusDeviceObject
+ );
+
+extern VOID STDCALL Probe_AoE (
+       PDEVICE_OBJECT BusDeviceObject
+ );
+
+#endif                                                                                                 /* _PROBE_H */
index 3f74e34..b894b6c 100644 (file)
@@ -1,37 +1,37 @@
-/**\r
- * Copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.\r
- * For contact information, see http://winaoe.org/\r
- *\r
- * This file is part of WinAoE.\r
- *\r
- * WinAoE is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * WinAoE is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with WinAoE.  If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-#ifndef _RAMDISK_H\r
-#  define _RAMDISK_H\r
-\r
-/**\r
- * @file\r
- *\r
- * RAM disk specifics\r
- *\r
- */\r
-\r
-typedef struct _RAMDISK_RAMDISK\r
-{\r
-       UINT32 DiskBuf;\r
-       UINT32 DiskSize;\r
-} RAMDISK_RAMDISK,\r
- *PRAMDISK_RAMDISK;\r
-\r
-#endif                                                                                                 /* _RAMDISK_H */\r
+/**
+ * Copyright (C) 2009 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ * For contact information, see http://winaoe.org/
+ *
+ * This file is part of WinAoE.
+ *
+ * WinAoE 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinAoE 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 WinAoE.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _RAMDISK_H
+#  define _RAMDISK_H
+
+/**
+ * @file
+ *
+ * RAM disk specifics
+ *
+ */
+
+typedef struct _RAMDISK_RAMDISK
+{
+       UINT32 DiskBuf;
+       UINT32 DiskSize;
+} RAMDISK_RAMDISK,
+*PRAMDISK_RAMDISK;
+
+#endif                                                                                                 /* _RAMDISK_H */