2 * ReactOS Floppy Driver
3 * Copyright (C) 2004, Vizzini (vizzini@plasmic.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * PROJECT: ReactOS Floppy Driver
21 * PURPOSE: IOCTL Routines
22 * PROGRAMMER: Vizzini (vizzini@plasmic.com)
24 * 15-Feb-2004 vizzini - Created
26 * - All IOCTL documentation taken from the DDK
27 * - This driver tries to support all of the IOCTLs that the DDK floppy
30 * TODO: Add support to GET_MEDIA_TYPES for non-1.44 disks
31 * TODO: Implement format
39 DeviceIoctl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
41 * FUNCTION: Queue IOCTL IRPs
43 * DeviceObject: DeviceObject that is the target of the IRP
46 * STATUS_SUCCESS in all cases, so far
48 * - We can't just service these immediately because, even though some
49 * are able to run at DISPATCH, they'll get out of sync with other
50 * read/write or ioctl irps.
56 Irp
->Tail
.Overlay
.DriverContext
[0] = DeviceObject
;
57 IoCsqInsertIrp(&Csq
, Irp
, NULL
);
59 return STATUS_PENDING
;
64 DeviceIoctlPassive(PDRIVE_INFO DriveInfo
, PIRP Irp
)
66 * FUNCTION: Handles IOCTL requests at PASSIVE_LEVEL
68 * DriveInfo: Drive that the IOCTL is directed at
69 * Irp: IRP with the request in it
72 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
73 ULONG OutputLength
= Stack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
74 PVOID OutputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
75 ULONG Code
= Stack
->Parameters
.DeviceIoControl
.IoControlCode
;
78 TRACE_(FLOPPY
, "DeviceIoctl called\n");
79 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
80 Irp
->IoStatus
.Information
= 0;
83 * First the non-change-sensitive ioctls
85 if(Code
== IOCTL_DISK_GET_MEDIA_TYPES
)
87 PDISK_GEOMETRY Geometry
= OutputBuffer
;
88 INFO_(FLOPPY
, "IOCTL_DISK_GET_MEDIA_TYPES Called\n");
90 if(OutputLength
< sizeof(DISK_GEOMETRY
))
92 INFO_(FLOPPY
, "IOCTL_DISK_GET_MEDIA_TYPES: insufficient buffer; returning STATUS_INVALID_PARAMETER\n");
93 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
94 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
99 * for now, this driver only supports 3.5" HD media
101 Geometry
->MediaType
= F3_1Pt44_512
;
102 Geometry
->Cylinders
.QuadPart
= 80;
103 Geometry
->TracksPerCylinder
= 2 * 18;
104 Geometry
->SectorsPerTrack
= 18;
105 Geometry
->BytesPerSector
= 512;
107 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
108 Irp
->IoStatus
.Information
= sizeof(DISK_GEOMETRY
);
109 INFO_(FLOPPY
, "Ioctl: completing with STATUS_SUCCESS\n");
110 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
116 * Now, check to see if the volume needs to be verified. If so,
117 * return STATUS_VERIFY_REQUIRED.
119 * NOTE: This code, which is outside of the switch and if/else blocks,
120 * will implicity catch and correctly service IOCTL_DISK_CHECK_VERIFY.
121 * Therefore if we see one below in the switch, we can return STATUS_SUCCESS
124 if(DriveInfo
->DeviceObject
->Flags
& DO_VERIFY_VOLUME
&& !(Stack
->Flags
& SL_OVERRIDE_VERIFY_VOLUME
))
126 INFO_(FLOPPY
, "DeviceIoctl(): completing with STATUS_VERIFY_REQUIRED\n");
127 Irp
->IoStatus
.Status
= STATUS_VERIFY_REQUIRED
;
128 Irp
->IoStatus
.Information
= 0;
129 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
134 * Start the drive to see if the disk has changed
136 StartMotor(DriveInfo
);
139 * Check the change line, and if it's set, return
141 if(HwDiskChanged(DriveInfo
, &DiskChanged
) != STATUS_SUCCESS
)
143 WARN_(FLOPPY
, "DeviceIoctl(): unable to sense disk change; completing with STATUS_UNSUCCESSFUL\n");
144 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
145 Irp
->IoStatus
.Information
= 0;
146 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
147 StopMotor(DriveInfo
->ControllerInfo
);
153 INFO_(FLOPPY
, "DeviceIoctl(): detected disk changed; signalling media change and completing\n");
154 SignalMediaChanged(DriveInfo
->DeviceObject
, Irp
);
157 * Just guessing here - I have a choice of returning NO_MEDIA or VERIFY_REQUIRED. If there's
158 * really no disk in the drive, I'm thinking I can save time by just reporting that fact, rather
159 * than forcing windows to ask me twice. If this doesn't work, we'll need to split this up and
160 * handle the CHECK_VERIFY IOCTL separately.
162 if(ResetChangeFlag(DriveInfo
) == STATUS_NO_MEDIA_IN_DEVICE
)
163 Irp
->IoStatus
.Status
= STATUS_NO_MEDIA_IN_DEVICE
;
165 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
166 StopMotor(DriveInfo
->ControllerInfo
);
172 case IOCTL_DISK_IS_WRITABLE
:
176 INFO_(FLOPPY
, "IOCTL_DISK_IS_WRITABLE Called\n");
178 /* This IRP always has 0 information */
179 Irp
->IoStatus
.Information
= 0;
181 if(HwSenseDriveStatus(DriveInfo
) != STATUS_SUCCESS
)
183 WARN_(FLOPPY
, "IoctlDiskIsWritable(): unable to sense drive status\n");
184 Irp
->IoStatus
.Status
= STATUS_IO_DEVICE_ERROR
;
188 /* Now, read the drive's status back */
189 if(HwSenseDriveStatusResult(DriveInfo
->ControllerInfo
, &Status
) != STATUS_SUCCESS
)
191 WARN_(FLOPPY
, "IoctlDiskIsWritable(): unable to read drive status result\n");
192 Irp
->IoStatus
.Status
= STATUS_IO_DEVICE_ERROR
;
196 /* Check to see if the write flag is set. */
197 if(Status
& SR3_WRITE_PROTECT_STATUS_SIGNAL
)
199 INFO_(FLOPPY
, "IOCTL_DISK_IS_WRITABLE: disk is write protected\n");
200 Irp
->IoStatus
.Status
= STATUS_MEDIA_WRITE_PROTECTED
;
203 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
207 case IOCTL_DISK_CHECK_VERIFY
:
208 INFO_(FLOPPY
, "IOCTL_DISK_CHECK_VERIFY called\n");
209 if (OutputLength
!= 0)
211 if (OutputLength
< sizeof(ULONG
))
213 Irp
->IoStatus
.Status
= STATUS_BUFFER_TOO_SMALL
;
214 Irp
->IoStatus
.Information
= 0;
218 *((PULONG
)OutputBuffer
) = DriveInfo
->DiskChangeCount
;
219 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
220 Irp
->IoStatus
.Information
= sizeof(ULONG
);
225 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
226 Irp
->IoStatus
.Information
= 0;
230 case IOCTL_DISK_GET_DRIVE_GEOMETRY
:
232 INFO_(FLOPPY
, "IOCTL_DISK_GET_DRIVE_GEOMETRY Called\n");
233 if(OutputLength
< sizeof(DISK_GEOMETRY
))
235 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
239 /* This still works right even if DriveInfo->DiskGeometry->MediaType = Unknown */
240 memcpy(OutputBuffer
, &DriveInfo
->DiskGeometry
, sizeof(DISK_GEOMETRY
));
241 Irp
->IoStatus
.Information
= sizeof(DISK_GEOMETRY
);
245 case IOCTL_DISK_FORMAT_TRACKS
:
246 case IOCTL_DISK_FORMAT_TRACKS_EX
:
247 ERR_(FLOPPY
, "Format called; not supported yet\n");
248 Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
;
249 Irp
->IoStatus
.Information
= 0;
252 case IOCTL_DISK_GET_PARTITION_INFO
:
253 INFO_(FLOPPY
, "IOCTL_DISK_GET_PARTITION_INFO Called; not supported by a floppy driver\n");
254 Irp
->IoStatus
.Status
= STATUS_INVALID_DEVICE_REQUEST
;
255 Irp
->IoStatus
.Information
= 0;
259 ERR_(FLOPPY
, "UNKNOWN IOCTL CODE: 0x%x\n", Code
);
260 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
261 Irp
->IoStatus
.Information
= 0;
265 INFO_(FLOPPY
, "ioctl: completing with status 0x%x\n", Irp
->IoStatus
.Status
);
266 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
268 StopMotor(DriveInfo
->ControllerInfo
);