1 /* $Id: driver.c,v 1.3 2002/06/12 14:05:03 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/driver.c
6 * PURPOSE: Manage devices
7 * PROGRAMMER: David Welch (welch@cwcom.net)
12 /* INCLUDES ****************************************************************/
15 #include <ddk/ntddk.h>
16 #include <internal/io.h>
17 #include <internal/po.h>
18 #include <internal/ldr.h>
19 #include <internal/id.h>
20 #include <internal/pool.h>
21 #include <internal/registry.h>
26 #include <internal/debug.h>
28 /* GLOBALS *******************************************************************/
30 POBJECT_TYPE EXPORTED IoDriverObjectType
= NULL
;
32 #define TAG_DRIVER TAG('D', 'R', 'V', 'R')
33 #define TAG_DRIVER_EXTENSION TAG('D', 'R', 'V', 'E')
35 #define DRIVER_REGISTRY_KEY_BASENAME L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
38 /* FUNCTIONS ***************************************************************/
41 IopCreateDriver(PVOID ObjectBody
,
44 POBJECT_ATTRIBUTES ObjectAttributes
)
46 DPRINT("LdrCreateModule(ObjectBody %x, Parent %x, RemainingPath %S)\n",
50 if (RemainingPath
!= NULL
&& wcschr(RemainingPath
+ 1, '\\') != NULL
)
52 return(STATUS_UNSUCCESSFUL
);
55 return(STATUS_SUCCESS
);
60 IopInitDriverImplementation(VOID
)
62 /* Register the process object type */
63 IoDriverObjectType
= ExAllocatePool(NonPagedPool
, sizeof(OBJECT_TYPE
));
64 IoDriverObjectType
->Tag
= TAG('D', 'R', 'V', 'R');
65 IoDriverObjectType
->TotalObjects
= 0;
66 IoDriverObjectType
->TotalHandles
= 0;
67 IoDriverObjectType
->MaxObjects
= ULONG_MAX
;
68 IoDriverObjectType
->MaxHandles
= ULONG_MAX
;
69 IoDriverObjectType
->PagedPoolCharge
= 0;
70 IoDriverObjectType
->NonpagedPoolCharge
= sizeof(DRIVER_OBJECT
);
71 IoDriverObjectType
->Dump
= NULL
;
72 IoDriverObjectType
->Open
= NULL
;
73 IoDriverObjectType
->Close
= NULL
;
74 IoDriverObjectType
->Delete
= NULL
;
75 IoDriverObjectType
->Parse
= NULL
;
76 IoDriverObjectType
->Security
= NULL
;
77 IoDriverObjectType
->QueryName
= NULL
;
78 IoDriverObjectType
->OkayToClose
= NULL
;
79 IoDriverObjectType
->Create
= IopCreateDriver
;
80 IoDriverObjectType
->DuplicationNotify
= NULL
;
81 RtlInitUnicodeString(&IoDriverObjectType
->TypeName
, L
"Driver");
84 /**********************************************************************
89 * Loads a device driver.
93 * Name of the service to load (registry key).
101 NtLoadDriver(IN PUNICODE_STRING DriverServiceName
)
103 PDEVICE_NODE DeviceNode
;
106 PMODULE_OBJECT ModuleObject
;
107 WCHAR Buffer
[MAX_PATH
];
112 /* FIXME: this should lookup the filename from the registry */
114 /* Use IopRootDeviceNode for now */
115 Status
= IopCreateDeviceNode(IopRootDeviceNode
, NULL
, &DeviceNode
);
116 if (!NT_SUCCESS(Status
))
121 Status
= LdrLoadModule(DriverServiceName
, &ModuleObject
);
122 if (!NT_SUCCESS(Status
))
124 DPRINT1("LdrLoadModule() failed (Status %lx)\n", Status
);
125 IopFreeDeviceNode(DeviceNode
);
129 /* Set a service name for the device node */
131 /* Get the service name from the module name */
132 Start
= wcsrchr(ModuleObject
->BaseName
.Buffer
, L
'\\');
134 Start
= ModuleObject
->BaseName
.Buffer
;
138 Ext
= wcsrchr(ModuleObject
->BaseName
.Buffer
, L
'.');
140 Length
= Ext
- Start
;
142 Length
= wcslen(Start
);
144 wcsncpy(Buffer
, Start
, Length
);
145 RtlCreateUnicodeString(&DeviceNode
->ServiceName
, Buffer
);
147 Status
= IopInitializeDriver(ModuleObject
->EntryPoint
, DeviceNode
);
148 if (!NT_SUCCESS(Status
))
150 DPRINT1("IopInitializeDriver() failed (Status %lx)\n", Status
);
151 ObDereferenceObject(ModuleObject
);
152 IopFreeDeviceNode(DeviceNode
);
160 NtUnloadDriver(IN PUNICODE_STRING DriverServiceName
)