* Sync up to trunk head (r65270).
[reactos.git] / drivers / storage / fdc / fdc / fdc.c
1 /*
2 * PROJECT: ReactOS Floppy Disk Controller Driver
3 * LICENSE: GNU GPLv2 only as published by the Free Software Foundation
4 * FILE: drivers/storage/fdc/fdc/fdc.c
5 * PURPOSE: Main Driver Routines
6 * PROGRAMMERS: Eric Kohl
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "fdc.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* GLOBALS ********************************************************************/
17
18 ULONG ControllerCount = 0;
19
20 /* FUNCTIONS ******************************************************************/
21
22 static
23 NTSTATUS
24 NTAPI
25 FdcAddDevice(
26 IN PDRIVER_OBJECT DriverObject,
27 IN PDEVICE_OBJECT Pdo)
28 {
29 PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
30 PDEVICE_OBJECT Fdo = NULL;
31 NTSTATUS Status;
32
33 DPRINT("FdcAddDevice()\n");
34
35 ASSERT(DriverObject);
36 ASSERT(Pdo);
37
38 /* Create functional device object */
39 Status = IoCreateDevice(DriverObject,
40 sizeof(FDO_DEVICE_EXTENSION),
41 NULL,
42 FILE_DEVICE_CONTROLLER,
43 FILE_DEVICE_SECURE_OPEN,
44 FALSE,
45 &Fdo);
46 if (NT_SUCCESS(Status))
47 {
48 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
49 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
50
51 DeviceExtension->Common.IsFDO = TRUE;
52 DeviceExtension->Common.DeviceObject = Fdo;
53
54 DeviceExtension->Pdo = Pdo;
55
56 Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
57 if (!NT_SUCCESS(Status))
58 {
59 DPRINT1("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
60 IoDeleteDevice(Fdo);
61 return Status;
62 }
63
64
65 Fdo->Flags |= DO_DIRECT_IO;
66 Fdo->Flags |= DO_POWER_PAGABLE;
67
68 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
69 }
70
71 return Status;
72 }
73
74
75 static
76 VOID
77 NTAPI
78 FdcDriverUnload(IN PDRIVER_OBJECT DriverObject)
79 {
80 DPRINT("FdcDriverUnload()\n");
81 }
82
83
84 static
85 NTSTATUS
86 NTAPI
87 FdcCreate(IN PDEVICE_OBJECT DeviceObject,
88 IN PIRP Irp)
89 {
90 DPRINT("FdcCreate()\n");
91
92 Irp->IoStatus.Status = STATUS_SUCCESS;
93 Irp->IoStatus.Information = FILE_OPENED;
94
95 IoCompleteRequest( Irp, IO_NO_INCREMENT );
96
97 return STATUS_SUCCESS;
98 }
99
100
101 static
102 NTSTATUS
103 NTAPI
104 FdcClose(IN PDEVICE_OBJECT DeviceObject,
105 IN PIRP Irp)
106 {
107 DPRINT("FdcClose()\n");
108
109 Irp->IoStatus.Status = STATUS_SUCCESS;
110 Irp->IoStatus.Information = 0;
111
112 IoCompleteRequest(Irp, IO_NO_INCREMENT);
113
114 return STATUS_SUCCESS;
115 }
116
117
118 static
119 NTSTATUS
120 NTAPI
121 FdcPnp(IN PDEVICE_OBJECT DeviceObject,
122 IN PIRP Irp)
123 {
124 PCOMMON_DEVICE_EXTENSION Common = DeviceObject->DeviceExtension;
125
126 DPRINT("FdcPnP()\n");
127 if (Common->IsFDO)
128 {
129 return FdcFdoPnp(DeviceObject,
130 Irp);
131 }
132 else
133 {
134 return FdcPdoPnp(DeviceObject,
135 Irp);
136 }
137 }
138
139
140 static
141 NTSTATUS
142 NTAPI
143 FdcPower(IN PDEVICE_OBJECT DeviceObject,
144 IN PIRP Irp)
145 {
146 DPRINT("FdcPower()\n");
147 return STATUS_UNSUCCESSFUL;
148 }
149
150
151 NTSTATUS
152 NTAPI
153 DriverEntry(IN PDRIVER_OBJECT DriverObject,
154 IN PUNICODE_STRING RegistryPath)
155 {
156 DPRINT("FDC: DriverEntry()\n");
157
158 DriverObject->MajorFunction[IRP_MJ_CREATE] = FdcCreate;
159 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FdcClose;
160 // DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FdcDeviceControl;
161 DriverObject->MajorFunction[IRP_MJ_PNP] = FdcPnp;
162 DriverObject->MajorFunction[IRP_MJ_POWER] = FdcPower;
163
164 DriverObject->DriverExtension->AddDevice = FdcAddDevice;
165 DriverObject->DriverUnload = FdcDriverUnload;
166
167 return STATUS_SUCCESS;
168 }