ReactOS  0.4.13-dev-698-g77671f0
ioctl.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for ioctl.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI DeviceIoctl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI DeviceIoctlPassive (PDRIVE_INFO DriveInfo, PIRP Irp)
 

Function Documentation

◆ DeviceIoctl()

NTSTATUS NTAPI DeviceIoctl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 39 of file ioctl.c.

52 {
54  ASSERT(Irp);
55 
56  Irp->Tail.Overlay.DriverContext[0] = DeviceObject;
58 
59  return STATUS_PENDING;
60 }
_In_ PIRP Irp
Definition: csq.h:116
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
IO_CSQ Csq
Definition: csqrtns.c:46

◆ DeviceIoctlPassive()

VOID NTAPI DeviceIoctlPassive ( PDRIVE_INFO  DriveInfo,
PIRP  Irp 
)

Definition at line 64 of file ioctl.c.

71 {
73  ULONG OutputLength = Stack->Parameters.DeviceIoControl.OutputBufferLength;
74  PVOID OutputBuffer = Irp->AssociatedIrp.SystemBuffer;
75  ULONG Code = Stack->Parameters.DeviceIoControl.IoControlCode;
76  BOOLEAN DiskChanged;
77 
78  TRACE_(FLOPPY, "DeviceIoctl called\n");
79  Irp->IoStatus.Status = STATUS_SUCCESS;
80  Irp->IoStatus.Information = 0;
81 
82  /*
83  * First the non-change-sensitive ioctls
84  */
86  {
87  PDISK_GEOMETRY Geometry = OutputBuffer;
88  INFO_(FLOPPY, "IOCTL_DISK_GET_MEDIA_TYPES Called\n");
89 
90  if(OutputLength < sizeof(DISK_GEOMETRY))
91  {
92  INFO_(FLOPPY, "IOCTL_DISK_GET_MEDIA_TYPES: insufficient buffer; returning STATUS_INVALID_PARAMETER\n");
93  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
95  return;
96  }
97 
98  /*
99  * for now, this driver only supports 3.5" HD media
100  */
101  Geometry->MediaType = F3_1Pt44_512;
102  Geometry->Cylinders.QuadPart = 80;
103  Geometry->TracksPerCylinder = 2 * 18;
104  Geometry->SectorsPerTrack = 18;
105  Geometry->BytesPerSector = 512;
106 
107  Irp->IoStatus.Status = STATUS_SUCCESS;
108  Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
109  INFO_(FLOPPY, "Ioctl: completing with STATUS_SUCCESS\n");
111 
112  return;
113  }
114 
115  /*
116  * Now, check to see if the volume needs to be verified. If so,
117  * return STATUS_VERIFY_REQUIRED.
118  *
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
122  * immediately.
123  */
124  if(DriveInfo->DeviceObject->Flags & DO_VERIFY_VOLUME && !(Stack->Flags & SL_OVERRIDE_VERIFY_VOLUME))
125  {
126  INFO_(FLOPPY, "DeviceIoctl(): completing with STATUS_VERIFY_REQUIRED\n");
127  Irp->IoStatus.Status = STATUS_VERIFY_REQUIRED;
128  Irp->IoStatus.Information = 0;
130  return;
131  }
132 
133  /*
134  * Start the drive to see if the disk has changed
135  */
136  StartMotor(DriveInfo);
137 
138  /*
139  * Check the change line, and if it's set, return
140  */
141  if(HwDiskChanged(DriveInfo, &DiskChanged) != STATUS_SUCCESS)
142  {
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;
147  StopMotor(DriveInfo->ControllerInfo);
148  return;
149  }
150 
151  if(DiskChanged)
152  {
153  INFO_(FLOPPY, "DeviceIoctl(): detected disk changed; signalling media change and completing\n");
154  SignalMediaChanged(DriveInfo->DeviceObject, Irp);
155 
156  /*
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.
161  */
163  Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
164 
166  StopMotor(DriveInfo->ControllerInfo);
167  return;
168  }
169 
170  switch(Code)
171  {
173  {
174  UCHAR Status;
175 
176  INFO_(FLOPPY, "IOCTL_DISK_IS_WRITABLE Called\n");
177 
178  /* This IRP always has 0 information */
179  Irp->IoStatus.Information = 0;
180 
181  if(HwSenseDriveStatus(DriveInfo) != STATUS_SUCCESS)
182  {
183  WARN_(FLOPPY, "IoctlDiskIsWritable(): unable to sense drive status\n");
184  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
185  break;
186  }
187 
188  /* Now, read the drive's status back */
190  {
191  WARN_(FLOPPY, "IoctlDiskIsWritable(): unable to read drive status result\n");
192  Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
193  break;
194  }
195 
196  /* Check to see if the write flag is set. */
198  {
199  INFO_(FLOPPY, "IOCTL_DISK_IS_WRITABLE: disk is write protected\n");
200  Irp->IoStatus.Status = STATUS_MEDIA_WRITE_PROTECTED;
201  }
202  else
203  Irp->IoStatus.Status = STATUS_SUCCESS;
204  }
205  break;
206 
208  INFO_(FLOPPY, "IOCTL_DISK_CHECK_VERIFY called\n");
209  if (OutputLength != 0)
210  {
211  if (OutputLength < sizeof(ULONG))
212  {
213  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
214  Irp->IoStatus.Information = 0;
215  }
216  else
217  {
218  *((PULONG)OutputBuffer) = DriveInfo->DiskChangeCount;
219  Irp->IoStatus.Status = STATUS_SUCCESS;
220  Irp->IoStatus.Information = sizeof(ULONG);
221  }
222  }
223  else
224  {
225  Irp->IoStatus.Status = STATUS_SUCCESS;
226  Irp->IoStatus.Information = 0;
227  }
228  break;
229 
231  {
232  INFO_(FLOPPY, "IOCTL_DISK_GET_DRIVE_GEOMETRY Called\n");
233  if(OutputLength < sizeof(DISK_GEOMETRY))
234  {
235  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
236  break;
237  }
238 
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);
242  break;
243  }
244 
247  ERR_(FLOPPY, "Format called; not supported yet\n");
248  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
249  Irp->IoStatus.Information = 0;
250  break;
251 
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;
256  break;
257 
258  default:
259  ERR_(FLOPPY, "UNKNOWN IOCTL CODE: 0x%x\n", Code);
260  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
261  Irp->IoStatus.Information = 0;
262  break;
263  }
264 
265  INFO_(FLOPPY, "ioctl: completing with status 0x%x\n", Irp->IoStatus.Status);
267 
268  StopMotor(DriveInfo->ControllerInfo);
269  return;
270 }
ULONG DiskChangeCount
Definition: floppy.h:53
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
#define INFO_(ch,...)
Definition: debug.h:159
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ERR_(ch,...)
Definition: debug.h:156
#define IOCTL_DISK_CHECK_VERIFY
Definition: cdrw_usr.h:175
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
NTSTATUS NTAPI HwDiskChanged(PDRIVE_INFO DriveInfo, PBOOLEAN DiskChanged)
Definition: hardware.c:785
VOID NTAPI StopMotor(PCONTROLLER_INFO ControllerInfo)
Definition: floppy.c:135
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
ULONG BytesPerSector
Definition: ntdddisk.h:376
ULONG TracksPerCylinder
Definition: ntdddisk.h:374
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
struct _CONTROLLER_INFO * ControllerInfo
Definition: fdc.h:23
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
PDEVICE_OBJECT DeviceObject
Definition: fdc.h:26
#define SR3_WRITE_PROTECT_STATUS_SIGNAL
Definition: hardware.h:161
#define IOCTL_DISK_FORMAT_TRACKS
Definition: cdrw_usr.h:171
unsigned char BOOLEAN
#define IoCompleteRequest
Definition: irp.c:1240
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
NTSTATUS NTAPI HwSenseDriveStatusResult(PCONTROLLER_INFO ControllerInfo, PUCHAR Status)
Definition: hardware.c:836
#define IOCTL_DISK_GET_MEDIA_TYPES
Definition: cdrw_usr.h:182
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define Code
Definition: deflate.h:80
#define TRACE_(x)
Definition: compat.h:66
NTSTATUS NTAPI ResetChangeFlag(PDRIVE_INFO DriveInfo)
Definition: floppy.c:291
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:372
ULONG SectorsPerTrack
Definition: ntdddisk.h:375
MEDIA_TYPE MediaType
Definition: ntdddisk.h:373
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DISK_GEOMETRY DiskGeometry
Definition: floppy.h:49
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _DISK_GEOMETRY DISK_GEOMETRY
unsigned int * PULONG
Definition: retypes.h:1
#define IOCTL_DISK_FORMAT_TRACKS_EX
Definition: cdrw_usr.h:173
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
NTSTATUS NTAPI HwSenseDriveStatus(PDRIVE_INFO DriveInfo)
Definition: hardware.c:287
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define WARN_(ch,...)
Definition: debug.h:157
VOID NTAPI SignalMediaChanged(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: floppy.c:1010
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
VOID NTAPI StartMotor(PDRIVE_INFO DriveInfo)
Definition: floppy.c:96
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by QueueThread().