#include "driver.h"
#include "disk.h"
#include "bus.h"
+#include "bus_pnp.h"
#include "aoe.h"
#include "mount.h"
#include "debug.h"
IN disk__type Disk,
IN winvblock__bool Boot
);
-static NTSTATUS STDCALL Bus_IoCompletionRoutine (
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp,
- IN PKEVENT Event
- );
typedef struct _BUS_TARGETLIST
{
Disk.DiskType == OpticalDisc ? FILE_DEVICE_CD_ROM : FILE_DEVICE_DISK;
ULONG DiskType2 =
Disk.DiskType ==
- OpticalDisc ? FILE_READ_ONLY_DEVICE | FILE_REMOVABLE_MEDIA : Disk.DiskType
- == FloppyDisk ? FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE : 0;
+ OpticalDisc ? FILE_READ_ONLY_DEVICE | FILE_REMOVABLE_MEDIA : Disk.
+ DiskType == FloppyDisk ? FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE : 0;
DBG ( "Entry\n" );
/*
return TRUE;
}
-static
-irp__handler_decl (
- pnp_start_dev
- )
-{
- NTSTATUS status;
- KEVENT event;
- bus__type_ptr bus_ptr;
-
- bus_ptr = get_bus_ptr ( DeviceExtension );
- KeInitializeEvent ( &event, NotificationEvent, FALSE );
- IoCopyCurrentIrpStackLocationToNext ( Irp );
- IoSetCompletionRoutine ( Irp,
- ( PIO_COMPLETION_ROUTINE ) Bus_IoCompletionRoutine,
- ( PVOID ) & event, TRUE, TRUE, TRUE );
- status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
- if ( status == STATUS_PENDING )
- {
- DBG ( "Locked\n" );
- KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
- }
- if ( NT_SUCCESS ( status = Irp->IoStatus.Status ) )
- {
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = Started;
- }
- status = STATUS_SUCCESS;
- Irp->IoStatus.Status = status;
- IoCompleteRequest ( Irp, IO_NO_INCREMENT );
- *completion_ptr = TRUE;
- return status;
-}
-
-static
-irp__handler_decl (
- foo
- )
-{
- DBG ( "BUS PNP test\n" );
- return STATUS_SUCCESS;
-}
-
irp__handling handling_table[] = {
/*
* Major, minor, any major?, any minor?, handler
* Note that the fall-through case must come FIRST!
* Why? It sets completion to true, so others won't be called
*/
- {IRP_MJ_PNP, IRP_MN_START_DEVICE, FALSE, FALSE, pnp_start_dev}
+ {IRP_MJ_PNP, 0, FALSE, TRUE, bus_pnp__simple}
+ ,
+ {IRP_MJ_PNP, IRP_MN_START_DEVICE, FALSE, FALSE, bus_pnp__start_dev}
+ ,
+ {IRP_MJ_PNP, IRP_MN_REMOVE_DEVICE, FALSE, FALSE, bus_pnp__remove_dev}
,
- {IRP_MJ_PNP, IRP_MN_QUERY_DEVICE_RELATIONS, FALSE, FALSE, foo}
+ {IRP_MJ_PNP, IRP_MN_QUERY_DEVICE_RELATIONS, FALSE, FALSE,
+ bus_pnp__query_dev_relations}
};
size_t handling_table_size = sizeof ( handling_table );
-irp__handler_decl ( Bus_DispatchPnP )
-{
- NTSTATUS Status;
- KEVENT Event;
- PDEVICE_RELATIONS DeviceRelations;
- bus__type_ptr bus_ptr;
- disk__type_ptr Walker,
- Next;
- ULONG Count;
-
- /*
- * Establish a pointer into the bus device's extension space
- */
- bus_ptr = get_bus_ptr ( DeviceExtension );
-
- switch ( Stack->MinorFunction )
- {
- case IRP_MN_REMOVE_DEVICE:
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = Deleted;
- Irp->IoStatus.Information = 0;
- Irp->IoStatus.Status = STATUS_SUCCESS;
- IoSkipCurrentIrpStackLocation ( Irp );
- Status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
- Walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
- while ( Walker != NULL )
- {
- Next = Walker->next_sibling_ptr;
- IoDeleteDevice ( Walker->dev_ext_ptr->Self );
- Walker = Next;
- }
- bus_ptr->Children = 0;
- bus_ptr->first_child_ptr = NULL;
- IoDetachDevice ( bus_ptr->LowerDeviceObject );
- IoDeleteDevice ( DeviceExtension->Self );
- return Status;
- case IRP_MN_QUERY_DEVICE_RELATIONS:
- if ( Stack->Parameters.QueryDeviceRelations.Type != BusRelations
- || Irp->IoStatus.Information )
- {
- Status = Irp->IoStatus.Status;
- break;
- }
- Count = 0;
- Walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
- while ( Walker != NULL )
- {
- Count++;
- Walker = Walker->next_sibling_ptr;
- }
- DeviceRelations =
- ( PDEVICE_RELATIONS ) ExAllocatePool ( NonPagedPool,
- sizeof ( DEVICE_RELATIONS ) +
- ( sizeof ( PDEVICE_OBJECT ) *
- Count ) );
- if ( DeviceRelations == NULL )
- {
- Irp->IoStatus.Information = 0;
- Status = STATUS_INSUFFICIENT_RESOURCES;
- break;
- }
- DeviceRelations->Count = Count;
-
- Count = 0;
- Walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
- while ( Walker != NULL )
- {
- ObReferenceObject ( Walker->dev_ext_ptr->Self );
- DeviceRelations->Objects[Count] = Walker->dev_ext_ptr->Self;
- Count++;
- Walker = Walker->next_sibling_ptr;
- }
- Irp->IoStatus.Information = ( ULONG_PTR ) DeviceRelations;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_QUERY_PNP_DEVICE_STATE:
- Irp->IoStatus.Information = 0;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_QUERY_STOP_DEVICE:
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = StopPending;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_CANCEL_STOP_DEVICE:
- DeviceExtension->State = DeviceExtension->OldState;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_STOP_DEVICE:
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = Stopped;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_QUERY_REMOVE_DEVICE:
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = RemovePending;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_CANCEL_REMOVE_DEVICE:
- DeviceExtension->State = DeviceExtension->OldState;
- Status = STATUS_SUCCESS;
- break;
- case IRP_MN_SURPRISE_REMOVAL:
- DeviceExtension->OldState = DeviceExtension->State;
- DeviceExtension->State = SurpriseRemovePending;
- Status = STATUS_SUCCESS;
- break;
- default:
- Status = Irp->IoStatus.Status;
- }
-
- Irp->IoStatus.Status = Status;
- IoSkipCurrentIrpStackLocation ( Irp );
- Status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
- return Status;
-}
-
irp__handler_decl ( Bus_DispatchDeviceControl )
{
NTSTATUS Status;
TargetWalker = TargetWalker->Next;
}
RtlCopyMemory ( Irp->AssociatedIrp.SystemBuffer, Targets,
- ( Stack->Parameters.
- DeviceIoControl.OutputBufferLength <
+ ( Stack->Parameters.DeviceIoControl.
+ OutputBufferLength <
( sizeof ( MOUNT_TARGETS ) +
( Count *
- sizeof ( MOUNT_TARGET ) ) ) ? Stack->
- Parameters.DeviceIoControl.OutputBufferLength
- : ( sizeof ( MOUNT_TARGETS ) +
- ( Count * sizeof ( MOUNT_TARGET ) ) ) ) );
+ sizeof ( MOUNT_TARGET ) ) ) ? Stack->Parameters.
+ DeviceIoControl.
+ OutputBufferLength : ( sizeof ( MOUNT_TARGETS ) +
+ ( Count *
+ sizeof
+ ( MOUNT_TARGET ) ) ) ) );
ExFreePool ( Targets );
KeReleaseSpinLock ( &Bus_Globals_TargetListSpinLock, Irql );
DiskWalker = DiskWalker->next_sibling_ptr;
}
RtlCopyMemory ( Irp->AssociatedIrp.SystemBuffer, Disks,
- ( Stack->Parameters.
- DeviceIoControl.OutputBufferLength <
+ ( Stack->Parameters.DeviceIoControl.
+ OutputBufferLength <
( sizeof ( MOUNT_DISKS ) +
( Count *
- sizeof ( MOUNT_DISK ) ) ) ? Stack->
- Parameters.DeviceIoControl.OutputBufferLength
- : ( sizeof ( MOUNT_DISKS ) +
- ( Count * sizeof ( MOUNT_DISK ) ) ) ) );
+ sizeof ( MOUNT_DISK ) ) ) ? Stack->Parameters.
+ DeviceIoControl.
+ OutputBufferLength : ( sizeof ( MOUNT_DISKS ) +
+ ( Count *
+ sizeof
+ ( MOUNT_DISK ) ) ) ) );
ExFreePool ( Disks );
Status = STATUS_SUCCESS;
IoSkipCurrentIrpStackLocation ( Irp );
Status = PoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
break;
- case IRP_MJ_PNP:
- Status =
- Bus_DispatchPnP ( DeviceObject, Irp, Stack, DeviceExtension,
- completion_ptr );
- break;
case IRP_MJ_SYSTEM_CONTROL:
Status =
Bus_DispatchSystemControl ( DeviceObject, Irp, Stack,
return Status;
}
-static NTSTATUS STDCALL
-Bus_IoCompletionRoutine (
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp,
- IN PKEVENT Event
- )
-{
- KeSetEvent ( Event, 0, FALSE );
- return STATUS_MORE_PROCESSING_REQUIRED;
-}
-
NTSTATUS STDCALL
Bus_GetDeviceCapabilities (
IN PDEVICE_OBJECT DeviceObject,
sizeof ( bus__type );
RtlCopyMemory ( bus_dev_ext_ptr->irp_handler_stack_ptr,
driver__handling_table, driver__handling_table_size );
- RtlCopyMemory ( ( winvblock__uint8 * ) bus_dev_ext_ptr->
- irp_handler_stack_ptr + driver__handling_table_size,
- handling_table, handling_table_size );
+ RtlCopyMemory ( ( winvblock__uint8 * ) bus_dev_ext_ptr->irp_handler_stack_ptr
+ + driver__handling_table_size, handling_table,
+ handling_table_size );
bus_dev_ext_ptr->irp_handler_stack_size =
( driver__handling_table_size +
handling_table_size ) / sizeof ( irp__handling );
--- /dev/null
+/**
+ * Copyright (C) 2009, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ * Copyright 2006-2008, V.
+ * For WinAoE contact information, see http://winaoe.org/
+ *
+ * This file is part of WinVBlock, derived from WinAoE.
+ *
+ * WinVBlock 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.
+ *
+ * WinVBlock 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 WinVBlock. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @file
+ *
+ * Bus PnP IRP handling
+ *
+ */
+
+#include <ntddk.h>
+
+#include "winvblock.h"
+#include "portable.h"
+#include "irp.h"
+#include "driver.h"
+#include "disk.h"
+#include "bus.h"
+#include "debug.h"
+
+static NTSTATUS STDCALL
+Bus_IoCompletionRoutine (
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp,
+ IN PKEVENT Event
+ )
+{
+ KeSetEvent ( Event, 0, FALSE );
+ return STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+irp__handler_decl ( bus_pnp__start_dev )
+{
+ NTSTATUS status;
+ KEVENT event;
+ bus__type_ptr bus_ptr;
+
+ bus_ptr = get_bus_ptr ( DeviceExtension );
+ KeInitializeEvent ( &event, NotificationEvent, FALSE );
+ IoCopyCurrentIrpStackLocationToNext ( Irp );
+ IoSetCompletionRoutine ( Irp,
+ ( PIO_COMPLETION_ROUTINE ) Bus_IoCompletionRoutine,
+ ( PVOID ) & event, TRUE, TRUE, TRUE );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ if ( status == STATUS_PENDING )
+ {
+ DBG ( "Locked\n" );
+ KeWaitForSingleObject ( &event, Executive, KernelMode, FALSE, NULL );
+ }
+ if ( NT_SUCCESS ( status = Irp->IoStatus.Status ) )
+ {
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = Started;
+ }
+ status = STATUS_SUCCESS;
+ Irp->IoStatus.Status = status;
+ IoCompleteRequest ( Irp, IO_NO_INCREMENT );
+ *completion_ptr = TRUE;
+ return status;
+}
+
+irp__handler_decl ( bus_pnp__remove_dev )
+{
+ NTSTATUS status;
+ bus__type_ptr bus_ptr;
+ disk__type_ptr walker,
+ next;
+
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = Deleted;
+ Irp->IoStatus.Information = 0;
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ IoSkipCurrentIrpStackLocation ( Irp );
+ bus_ptr = get_bus_ptr ( DeviceExtension );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
+ while ( walker != NULL )
+ {
+ next = walker->next_sibling_ptr;
+ IoDeleteDevice ( walker->dev_ext_ptr->Self );
+ walker = next;
+ }
+ bus_ptr->Children = 0;
+ bus_ptr->first_child_ptr = NULL;
+ IoDetachDevice ( bus_ptr->LowerDeviceObject );
+ IoDeleteDevice ( DeviceExtension->Self );
+ *completion_ptr = TRUE;
+ return status;
+}
+
+irp__handler_decl ( bus_pnp__query_dev_relations )
+{
+ NTSTATUS status;
+ bus__type_ptr bus_ptr;
+ ULONG count;
+ disk__type_ptr walker;
+ PDEVICE_RELATIONS dev_relations;
+
+ bus_ptr = get_bus_ptr ( DeviceExtension );
+ if ( Stack->Parameters.QueryDeviceRelations.Type != BusRelations
+ || Irp->IoStatus.Information )
+ {
+ status = Irp->IoStatus.Status;
+ IoSkipCurrentIrpStackLocation ( Irp );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ *completion_ptr = TRUE;
+ return status;
+ }
+ count = 0;
+ walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
+ while ( walker != NULL )
+ {
+ count++;
+ walker = walker->next_sibling_ptr;
+ }
+ dev_relations =
+ ( PDEVICE_RELATIONS ) ExAllocatePool ( NonPagedPool,
+ sizeof ( DEVICE_RELATIONS ) +
+ ( sizeof ( PDEVICE_OBJECT ) *
+ count ) );
+ if ( dev_relations == NULL )
+ {
+ Irp->IoStatus.Information = 0;
+ status = STATUS_INSUFFICIENT_RESOURCES;
+ Irp->IoStatus.Status = status;
+ IoSkipCurrentIrpStackLocation ( Irp );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ *completion_ptr = TRUE;
+ return status;
+ }
+ dev_relations->Count = count;
+
+ count = 0;
+ walker = ( disk__type_ptr ) bus_ptr->first_child_ptr;
+ while ( walker != NULL )
+ {
+ ObReferenceObject ( walker->dev_ext_ptr->Self );
+ dev_relations->Objects[count] = walker->dev_ext_ptr->Self;
+ count++;
+ walker = walker->next_sibling_ptr;
+ }
+ Irp->IoStatus.Information = ( ULONG_PTR ) dev_relations;
+ status = STATUS_SUCCESS;
+ Irp->IoStatus.Status = status;
+ IoSkipCurrentIrpStackLocation ( Irp );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ *completion_ptr = TRUE;
+ return status;
+}
+
+irp__handler_decl ( bus_pnp__simple )
+{
+ NTSTATUS status;
+ bus__type_ptr bus_ptr;
+
+ bus_ptr = get_bus_ptr ( DeviceExtension );
+ switch ( Stack->MinorFunction )
+ {
+ case IRP_MN_QUERY_PNP_DEVICE_STATE:
+ Irp->IoStatus.Information = 0;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_QUERY_STOP_DEVICE:
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = StopPending;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_CANCEL_STOP_DEVICE:
+ DeviceExtension->State = DeviceExtension->OldState;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_STOP_DEVICE:
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = Stopped;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_QUERY_REMOVE_DEVICE:
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = RemovePending;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_CANCEL_REMOVE_DEVICE:
+ DeviceExtension->State = DeviceExtension->OldState;
+ status = STATUS_SUCCESS;
+ break;
+ case IRP_MN_SURPRISE_REMOVAL:
+ DeviceExtension->OldState = DeviceExtension->State;
+ DeviceExtension->State = SurpriseRemovePending;
+ status = STATUS_SUCCESS;
+ break;
+ default:
+ status = Irp->IoStatus.Status;
+ }
+
+ Irp->IoStatus.Status = status;
+ IoSkipCurrentIrpStackLocation ( Irp );
+ status = IoCallDriver ( bus_ptr->LowerDeviceObject, Irp );
+ *completion_ptr = TRUE;
+ return status;
+}