Implemented driver shutdown registration

svn path=/trunk/; revision=1348
This commit is contained in:
Eric Kohl 2000-09-10 13:54:01 +00:00
parent 18fb33cd77
commit f6975e3ad4
5 changed files with 161 additions and 19 deletions

View file

@ -96,15 +96,25 @@ enum
/*
* Possible flags for the device object flags
*/
#define DO_BUFFERED_IO (0x1)
#define DO_DIRECT_IO (0x2)
#define DO_UNLOAD_PENDING 0x00000001
#define DO_VERIFY_VOLUME 0x00000002
#define DO_BUFFERED_IO 0x00000004
#define DO_EXCLUSIVE 0x00000008
#define DO_DIRECT_IO 0x00000010
#define DO_MAP_IO_BUFFER 0x00000020
#define DO_DEVICE_HAS_NAME 0x00000040
#define DO_DEVICE_INITIALIZING 0x00000080
#define DO_SYSTEM_BOOT_PARTITION 0x00000100
#define DO_LONG_TERM_REQUESTS 0x00000200
#define DO_NEVER_LAST_DEVICE 0x00000400
#define DO_SHUTDOWN_REGISTERED 0x00000800
/*
* Possible device types
*/
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006

View file

@ -1,4 +1,4 @@
/* $Id: io.h,v 1.4 2000/08/24 19:07:49 ekohl Exp $
/* $Id: io.h,v 1.5 2000/09/10 13:52:55 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -60,6 +60,9 @@ PIRP IoBuildSynchronousFsdRequestWithMdl(ULONG MajorFunction,
PKEVENT Event,
PIO_STATUS_BLOCK IoStatusBlock);
VOID IoShutdownIoManager(VOID);
VOID IoInitShutdownNotification(VOID);
VOID IoShutdownRegisteredDevices(VOID);
NTSTATUS STDCALL IoPageRead (PFILE_OBJECT FileObject,
PMDL Mdl,
PLARGE_INTEGER Offset,

View file

@ -1,4 +1,4 @@
/* $Id: device.c,v 1.20 2000/08/19 01:20:52 ekohl Exp $
/* $Id: device.c,v 1.21 2000/09/10 13:54:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -86,7 +86,36 @@ VOID
STDCALL
IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
PDEVICE_OBJECT Previous;
if (DeviceObject->Flags & DO_SHUTDOWN_REGISTERED)
IoUnregisterShutdownNotification(DeviceObject);
/* remove the timer if it exists */
if (DeviceObject->Timer)
{
IoStopTimer(DeviceObject);
ExFreePool(DeviceObject->Timer);
}
/* free device extension */
if (DeviceObject->DeviceObjectExtension)
ExFreePool (DeviceObject->DeviceObjectExtension);
/* remove device from driver device list */
Previous = DeviceObject->DriverObject->DeviceObject;
if (Previous == DeviceObject)
{
DeviceObject->DriverObject->DeviceObject = DeviceObject->NextDevice;
}
else
{
while (Previous->NextDevice != DeviceObject)
Previous = Previous->NextDevice;
Previous->NextDevice = DeviceObject->NextDevice;
}
ObDereferenceObject (DeviceObject);
}
@ -181,7 +210,7 @@ IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
PDEVICE_OBJECT
STDCALL
IoAttachDeviceToDeviceStack(PDEVICE_OBJECT SourceDevice,
PDEVICE_OBJECT TargetDevice)
PDEVICE_OBJECT TargetDevice)
{
PDEVICE_OBJECT AttachedDevice;
@ -199,8 +228,8 @@ IoAttachDeviceToDeviceStack(PDEVICE_OBJECT SourceDevice,
VOID
STDCALL
IoRegisterDriverReinitialization(PDRIVER_OBJECT DriverObject,
PDRIVER_REINITIALIZE ReinitRoutine,
PVOID Context)
PDRIVER_REINITIALIZE ReinitRoutine,
PVOID Context)
{
UNIMPLEMENTED;
}
@ -253,8 +282,8 @@ NTSTATUS IoInitializeDriver(PDRIVER_INITIALIZE DriverEntry)
NTSTATUS
STDCALL
IoAttachDevice(PDEVICE_OBJECT SourceDevice,
PUNICODE_STRING TargetDevice,
PDEVICE_OBJECT* AttachedDevice)
PUNICODE_STRING TargetDevice,
PDEVICE_OBJECT* AttachedDevice)
/*
* FUNCTION: Layers a device over the highest device in a device stack
* ARGUMENTS:
@ -313,7 +342,7 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
* Success or failure
* DeviceObject : Contains a pointer to allocated device object
* if the call succeeded
* NOTES: See the DDK documentation for more information
* NOTES: See the DDK documentation for more information
*/
{
PDEVICE_OBJECT CreatedDeviceObject;
@ -347,7 +376,7 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
NULL,
IoDeviceObjectType);
}
*DeviceObject = NULL;
if (CreatedDeviceObject == NULL)
@ -367,7 +396,7 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
}
CreatedDeviceObject->Type = DeviceType;
CreatedDeviceObject->DriverObject = DriverObject;
CreatedDeviceObject->DriverObject = DriverObject;
CreatedDeviceObject->CurrentIrp = NULL;
CreatedDeviceObject->Flags = 0;

View file

@ -1,4 +1,4 @@
/* $Id: iomgr.c,v 1.14 2000/08/24 19:09:12 ekohl Exp $
/* $Id: iomgr.c,v 1.15 2000/09/10 13:54:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -101,6 +101,10 @@ VOID IopDeleteFile(PVOID ObjectBody)
VOID IoShutdownIoManager(VOID)
{
/* shut down all registered devices */
IoShutdownRegisteredDevices();
}
@ -236,6 +240,7 @@ VOID IoInit (VOID)
IoInitSymbolicLinkImplementation ();
IoInitFileSystemImplementation ();
IoInitVpbImplementation ();
IoInitShutdownNotification ();
/*
* Create link from '\DosDevices' to '\??' directory

View file

@ -1,4 +1,4 @@
/* $Id: shutdown.c,v 1.2 2000/03/26 19:38:26 ea Exp $
/* $Id: shutdown.c,v 1.3 2000/09/10 13:54:01 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -15,16 +15,111 @@
#include <internal/debug.h>
/* LOCAL DATA ***************************************************************/
typedef struct _SHUTDOWN_ENTRY
{
LIST_ENTRY ShutdownList;
PDEVICE_OBJECT DeviceObject;
} SHUTDOWN_ENTRY, *PSHUTDOWN_ENTRY;
static LIST_ENTRY ShutdownListHead;
static KSPIN_LOCK ShutdownListLock;
/* FUNCTIONS *****************************************************************/
VOID IoInitShutdownNotification (VOID)
{
InitializeListHead(&ShutdownListHead);
KeInitializeSpinLock(&ShutdownListLock);
}
VOID IoShutdownRegisteredDevices(VOID)
{
PSHUTDOWN_ENTRY ShutdownEntry;
PLIST_ENTRY Entry;
IO_STATUS_BLOCK StatusBlock;
PIRP Irp;
KEVENT Event;
NTSTATUS Status;
Entry = ShutdownListHead.Flink;
while (Entry != &ShutdownListHead)
{
ShutdownEntry = CONTAINING_RECORD(Entry, SHUTDOWN_ENTRY, ShutdownList);
KeInitializeEvent (&Event,
NotificationEvent,
FALSE);
Irp = IoBuildSynchronousFsdRequest (IRP_MJ_SHUTDOWN,
ShutdownEntry->DeviceObject,
NULL,
0,
NULL,
&Event,
&StatusBlock);
Status = IoCallDriver (ShutdownEntry->DeviceObject,
Irp);
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject (&Event,
Executive,
KernelMode,
FALSE,
NULL);
}
Entry = Entry->Flink;
}
}
NTSTATUS STDCALL IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
PSHUTDOWN_ENTRY Entry;
Entry = ExAllocatePool(NonPagedPool, sizeof(SHUTDOWN_ENTRY));
if (Entry == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
Entry->DeviceObject = DeviceObject;
ExInterlockedInsertHeadList(&ShutdownListHead,
&Entry->ShutdownList,
&ShutdownListLock);
DeviceObject->Flags |= DO_SHUTDOWN_REGISTERED;
return STATUS_SUCCESS;
}
VOID STDCALL IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
{
UNIMPLEMENTED;
PSHUTDOWN_ENTRY ShutdownEntry;
PLIST_ENTRY Entry;
KIRQL oldlvl;
Entry = ShutdownListHead.Flink;
while (Entry != &ShutdownListHead)
{
ShutdownEntry = CONTAINING_RECORD(Entry, SHUTDOWN_ENTRY, ShutdownList);
if (ShutdownEntry->DeviceObject == DeviceObject)
{
DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
KeAcquireSpinLock(&ShutdownListLock,&oldlvl);
RemoveEntryList(Entry);
KeReleaseSpinLock(&ShutdownListLock,oldlvl);
ExFreePool(Entry);
return;
}
Entry = Entry->Flink;
}
}
/* EOF */