ReactOS  0.4.15-dev-5496-g599ba9c
iofunc.c File Reference
#include <ntoskrnl.h>
#include <ioevent.h>
#include <debug.h>
#include "internal/io_i.h"
Include dependency graph for iofunc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define CHECK_LENGTH(class, struct)
 

Functions

VOID NTAPI IopCleanupAfterException (IN PFILE_OBJECT FileObject, IN PIRP Irp OPTIONAL, IN PKEVENT Event OPTIONAL, IN PKEVENT LocalEvent OPTIONAL)
 
NTSTATUS NTAPI IopFinalizeAsynchronousIo (IN NTSTATUS SynchStatus, IN PKEVENT Event, IN PIRP Irp, IN KPROCESSOR_MODE PreviousMode, IN PIO_STATUS_BLOCK KernelIosb, OUT PIO_STATUS_BLOCK IoStatusBlock)
 
NTSTATUS NTAPI IopPerformSynchronousRequest (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
 
NTSTATUS NTAPI IopDeviceFsIoControl (IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength OPTIONAL, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength OPTIONAL, IN BOOLEAN IsDevIoCtl)
 
NTSTATUS NTAPI IopQueryDeviceInformation (IN PFILE_OBJECT FileObject, IN ULONG InformationClass, IN ULONG Length, OUT PVOID Information, OUT PULONG ReturnedLength, IN BOOLEAN File)
 
NTSTATUS NTAPI IopGetFileInformation (IN PFILE_OBJECT FileObject, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInfoClass, OUT PVOID Buffer, OUT PULONG ReturnedLength)
 
NTSTATUS NTAPI IopGetBasicInformationFile (IN PFILE_OBJECT FileObject, OUT PFILE_BASIC_INFORMATION BasicInfo)
 
NTSTATUS NTAPI IopOpenLinkOrRenameTarget (OUT PHANDLE Handle, IN PIRP Irp, IN PFILE_RENAME_INFORMATION RenameInfo, IN PFILE_OBJECT FileObject)
 
static ULONG IopGetFileMode (IN PFILE_OBJECT FileObject)
 
static BOOLEAN IopGetMountFlag (IN PDEVICE_OBJECT DeviceObject)
 
static BOOLEAN IopVerifyDriverObjectOnStack (IN PDEVICE_OBJECT DeviceObject, IN PDRIVER_OBJECT DriverObject)
 
static NTSTATUS IopGetDriverPathInformation (IN PFILE_OBJECT FileObject, IN PFILE_FS_DRIVER_PATH_INFORMATION DriverPathInfo, IN ULONG Length)
 
NTSTATUS NTAPI IoSynchronousPageWrite (IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
 
NTSTATUS NTAPI IoPageRead (IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
 
NTSTATUS NTAPI IoQueryFileInformation (IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
 
NTSTATUS NTAPI IoQueryVolumeInformation (IN PFILE_OBJECT FileObject, IN FS_INFORMATION_CLASS FsInformationClass, IN ULONG Length, OUT PVOID FsInformation, OUT PULONG ReturnedLength)
 
NTSTATUS NTAPI IoSetInformation (IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, IN PVOID FileInformation)
 
NTSTATUS NTAPI NtDeviceIoControlFile (IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength OPTIONAL, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength OPTIONAL)
 
NTSTATUS NTAPI NtFsControlFile (IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength OPTIONAL, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength OPTIONAL)
 
NTSTATUS NTAPI NtFlushBuffersFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
 
NTSTATUS NTAPI NtNotifyChangeDirectoryFile (IN HANDLE FileHandle, IN HANDLE EventHandle OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG BufferSize, IN ULONG CompletionFilter, IN BOOLEAN WatchTree)
 
NTSTATUS NTAPI NtLockFile (IN HANDLE FileHandle, IN HANDLE EventHandle OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER ByteOffset, IN PLARGE_INTEGER Length, IN ULONG Key, IN BOOLEAN FailImmediately, IN BOOLEAN ExclusiveLock)
 
NTSTATUS NTAPI NtQueryDirectoryFile (IN HANDLE FileHandle, IN HANDLE EventHandle OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass, IN BOOLEAN ReturnSingleEntry, IN PUNICODE_STRING FileName OPTIONAL, IN BOOLEAN RestartScan)
 
NTSTATUS NTAPI NtQueryEaFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN ReturnSingleEntry, IN PVOID EaList OPTIONAL, IN ULONG EaListLength, IN PULONG EaIndex OPTIONAL, IN BOOLEAN RestartScan)
 
NTSTATUS NTAPI NtQueryInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
 
NTSTATUS NTAPI NtQueryQuotaInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN ReturnSingleEntry, IN PVOID SidList OPTIONAL, IN ULONG SidListLength, IN PSID StartSid OPTIONAL, IN BOOLEAN RestartScan)
 
NTSTATUS NTAPI NtReadFile (IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER ByteOffset OPTIONAL, IN PULONG Key OPTIONAL)
 
NTSTATUS NTAPI NtReadFileScatter (IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK UserIoStatusBlock, IN FILE_SEGMENT_ELEMENT BufferDescription [], IN ULONG BufferLength, IN PLARGE_INTEGER ByteOffset, IN PULONG Key OPTIONAL)
 
NTSTATUS NTAPI NtSetEaFile (IN HANDLE FileHandle, IN PIO_STATUS_BLOCK IoStatusBlock, IN PVOID EaBuffer, IN ULONG EaBufferSize)
 
NTSTATUS NTAPI NtSetInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID FileInformation, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInformationClass)
 
NTSTATUS NTAPI NtSetQuotaInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID Buffer, IN ULONG BufferLength)
 
NTSTATUS NTAPI NtUnlockFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER ByteOffset, IN PLARGE_INTEGER Length, IN ULONG Key OPTIONAL)
 
NTSTATUS NTAPI NtWriteFile (IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER ByteOffset OPTIONAL, IN PULONG Key OPTIONAL)
 
NTSTATUS NTAPI NtWriteFileGather (IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK UserIoStatusBlock, IN FILE_SEGMENT_ELEMENT BufferDescription [], IN ULONG BufferLength, IN PLARGE_INTEGER ByteOffset, IN PULONG Key OPTIONAL)
 
NTSTATUS NTAPI NtQueryVolumeInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FsInformation, IN ULONG Length, IN FS_INFORMATION_CLASS FsInformationClass)
 
NTSTATUS NTAPI NtSetVolumeInformationFile (IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PVOID FsInformation, IN ULONG Length, IN FS_INFORMATION_CLASS FsInformationClass)
 
NTSTATUS NTAPI NtCancelDeviceWakeupRequest (IN HANDLE DeviceHandle)
 
NTSTATUS NTAPI NtRequestDeviceWakeup (IN HANDLE DeviceHandle)
 

Variables

volatile LONG IoPageReadIrpAllocationFailure = 0
 
volatile LONG IoPageReadNonPagefileIrpAllocationFailure = 0
 

Macro Definition Documentation

◆ CHECK_LENGTH

#define CHECK_LENGTH (   class,
  struct 
)
Value:
case class: \
if (Length < sizeof(struct)) \
break
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file iofunc.c.

Function Documentation

◆ IoPageRead()

NTSTATUS NTAPI IoPageRead ( IN PFILE_OBJECT  FileObject,
IN PMDL  Mdl,
IN PLARGE_INTEGER  Offset,
IN PKEVENT  Event,
IN PIO_STATUS_BLOCK  StatusBlock 
)

Definition at line 1201 of file iofunc.c.

1206 {
1207  PIRP Irp;
1208  PIO_STACK_LOCATION StackPtr;
1210  IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p\n",
1211  FileObject, Mdl, Offset);
1212 
1213  /* Get the Device Object */
1215 
1216  /* Allocate IRP */
1217  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1218  /* If allocation failed, try to see whether we can use
1219  * the reserve IRP
1220  */
1221  if (Irp == NULL)
1222  {
1223  /* We will use it only for paging file */
1225  {
1227  Irp = IopAllocateReserveIrp(DeviceObject->StackSize);
1228  }
1229  else
1230  {
1232  }
1233 
1234  /* If allocation failed (not a paging file or too big stack size)
1235  * Fail for real
1236  */
1237  if (Irp == NULL)
1238  {
1240  }
1241  }
1242 
1243  /* Get the Stack */
1244  StackPtr = IoGetNextIrpStackLocation(Irp);
1245 
1246  /* Create the IRP Settings */
1247  Irp->MdlAddress = Mdl;
1248  Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
1249  Irp->UserIosb = StatusBlock;
1250  Irp->UserEvent = Event;
1251  Irp->RequestorMode = KernelMode;
1252  Irp->Flags = IRP_PAGING_IO |
1253  IRP_NOCACHE |
1256  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1257  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1258 
1259  /* Set the Stack Settings */
1260  StackPtr->Parameters.Read.Length = MmGetMdlByteCount(Mdl);
1261  StackPtr->Parameters.Read.ByteOffset = *Offset;
1262  StackPtr->MajorFunction = IRP_MJ_READ;
1263  StackPtr->FileObject = FileObject;
1264 
1265  /* Call the Driver */
1266  return IoCallDriver(DeviceObject, Irp);
1267 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define MmGetMdlVirtualAddress(_Mdl)
#define IRP_NOCACHE
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define IO_API_DEBUG
Definition: io.h:21
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
PIRP NTAPI IopAllocateReserveIrp(IN CCHAR StackSize)
Definition: irp.c:573
#define InterlockedExchangeAdd
Definition: interlocked.h:181
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
volatile LONG IoPageReadNonPagefileIrpAllocationFailure
Definition: iofunc.c:21
#define IOTRACE(x, fmt,...)
Definition: io.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
volatile LONG IoPageReadIrpAllocationFailure
Definition: iofunc.c:20
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define IRP_INPUT_OPERATION
#define MmGetMdlByteCount(_Mdl)
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define IRP_PAGING_IO
#define IRP_MJ_READ
Definition: rdpdr.c:46
BOOLEAN NTAPI MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject)
Definition: pagefile.c:119
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by MiReadFilePage(), MiReadPageFile(), and MmMakeSegmentResident().

◆ IopCleanupAfterException()

VOID NTAPI IopCleanupAfterException ( IN PFILE_OBJECT  FileObject,
IN PIRP Irp  OPTIONAL,
IN PKEVENT Event  OPTIONAL,
IN PKEVENT LocalEvent  OPTIONAL 
)

Definition at line 27 of file iofunc.c.

31 {
32  PAGED_CODE();
33  IOTRACE(IO_API_DEBUG, "IRP: %p. FO: %p\n", Irp, FileObject);
34 
35  if (Irp)
36  {
37  /* Check if we had a buffer */
38  if (Irp->AssociatedIrp.SystemBuffer)
39  {
40  /* Free it */
41  ExFreePool(Irp->AssociatedIrp.SystemBuffer);
42  }
43 
44  /* Free the mdl */
45  if (Irp->MdlAddress) IoFreeMdl(Irp->MdlAddress);
46 
47  /* Free the IRP */
48  IoFreeIrp(Irp);
49  }
50 
51  /* Check if we had a file lock */
52  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
53  {
54  /* Release it */
56  }
57 
58  /* Check if we had an event */
60 
61  /* Check if we had a local event */
62  if (LocalEvent) ExFreePool(LocalEvent);
63 
64  /* Derefenrce the FO */
66 }
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
_In_ PIRP Irp
Definition: csq.h:116
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define IOTRACE(x, fmt,...)
Definition: io.h:47
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Referenced by IopDeviceFsIoControl(), NtLockFile(), NtQueryDirectoryFile(), NtQueryInformationFile(), NtQueryVolumeInformationFile(), NtReadFile(), NtSetInformationFile(), NtSetVolumeInformationFile(), NtUnlockFile(), and NtWriteFile().

◆ IopDeviceFsIoControl()

NTSTATUS NTAPI IopDeviceFsIoControl ( IN HANDLE  DeviceHandle,
IN HANDLE Event  OPTIONAL,
IN PIO_APC_ROUTINE UserApcRoutine  OPTIONAL,
IN PVOID UserApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN ULONG  IoControlCode,
IN PVOID  InputBuffer,
IN ULONG InputBufferLength  OPTIONAL,
OUT PVOID  OutputBuffer,
IN ULONG OutputBufferLength  OPTIONAL,
IN BOOLEAN  IsDevIoCtl 
)

Definition at line 197 of file iofunc.c.

208 {
212  PIRP Irp;
213  PIO_STACK_LOCATION StackPtr;
214  PKEVENT EventObject = NULL;
215  BOOLEAN LockedForSynch = FALSE;
216  ULONG AccessType;
222 
223  PAGED_CODE();
224 
225  IOTRACE(IO_CTL_DEBUG, "Handle: %p. CTL: %lx. Type: %lx\n",
226  DeviceHandle, IoControlCode, IsDevIoCtl);
227 
228  /* Get the access type */
230 
231  /* Check if we came from user mode */
232  if (PreviousMode != KernelMode)
233  {
234  _SEH2_TRY
235  {
236  /* Probe the status block */
238 
239  /* Check if this is buffered I/O */
240  if (AccessType == METHOD_BUFFERED)
241  {
242  /* Check if we have an output buffer */
243  if (OutputBuffer)
244  {
245  /* Probe the output buffer */
248  sizeof(CHAR));
249  }
250  else
251  {
252  /* Make sure the caller can't fake this as we depend on this */
253  OutputBufferLength = 0;
254  }
255  }
256 
257  /* Check if we we have an input buffer I/O */
258  if (AccessType != METHOD_NEITHER)
259  {
260  /* Check if we have an input buffer */
261  if (InputBuffer)
262  {
263  /* Probe the input buffer */
265  }
266  else
267  {
268  /* Make sure the caller can't fake this as we depend on this */
269  InputBufferLength = 0;
270  }
271  }
272  }
274  {
275  /* Return the exception code */
277  }
278  _SEH2_END;
279  }
280 
281  /* Don't check for access rights right now, KernelMode can do anything */
283  0,
285  PreviousMode,
286  (PVOID*)&FileObject,
288  if (!NT_SUCCESS(Status)) return Status;
289 
290  /* Can't use an I/O completion port and an APC at the same time */
291  if ((FileObject->CompletionContext) && (UserApcRoutine))
292  {
293  /* Fail */
296  }
297 
298  /* Check if we from user mode */
299  if (PreviousMode != KernelMode)
300  {
301  /* Get the access mask */
302  DesiredAccess = (ACCESS_MASK)((IoControlCode >> 14) & 3);
303 
304  /* Check if we can open it */
305  if ((DesiredAccess != FILE_ANY_ACCESS) &&
306  (HandleInformation.GrantedAccess & DesiredAccess) != DesiredAccess)
307  {
308  /* Dereference the file object and fail */
310  return STATUS_ACCESS_DENIED;
311  }
312  }
313 
314  /* Check for an event */
315  if (Event)
316  {
317  /* Reference it */
321  PreviousMode,
322  (PVOID*)&EventObject,
323  NULL);
324  if (!NT_SUCCESS(Status))
325  {
326  /* Dereference the file object and fail */
328  return Status;
329  }
330 
331  /* Clear it */
332  KeClearEvent(EventObject);
333  }
334 
335  /* Check if this is a file that was opened for Synch I/O */
336  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
337  {
338  /* Lock it */
340  if (Status != STATUS_SUCCESS)
341  {
342  if (EventObject) ObDereferenceObject(EventObject);
344  return Status;
345  }
346 
347  /* Remember to unlock later */
348  LockedForSynch = TRUE;
349  }
350 
351  /* Check if this is a direct open or not */
352  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
353  {
354  /* It's a direct open, get the attached device */
356  }
357  else
358  {
359  /* Otherwise get the related device */
361  }
362 
363  /* If this is a device I/O, try to do it with FastIO path */
364  if (IsDevIoCtl)
365  {
366  PFAST_IO_DISPATCH FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
367 
368  /* Check whether FSD is FastIO aware and provide an appropriate routine */
370  {
371  IO_STATUS_BLOCK KernelIosb;
372 
373  /* If we have an output buffer coming from usermode */
375  {
376  /* Probe it according to its usage */
377  _SEH2_TRY
378  {
379  if (AccessType == METHOD_IN_DIRECT)
380  {
382  }
383  else if (AccessType == METHOD_OUT_DIRECT)
384  {
386  }
387  }
389  {
390  /* Cleanup after exception and return */
392 
393  /* Return the exception code */
395  }
396  _SEH2_END;
397  }
398 
399  /* If we are dismounting a volume, increase the dismount count */
401  {
402  InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
403  }
404 
405  /* Call the FSD */
407  TRUE,
408  InputBuffer,
410  OutputBuffer,
413  &KernelIosb,
414  DeviceObject))
415  {
416  IO_COMPLETION_CONTEXT CompletionInfo = { NULL, NULL };
417 
418  /* Write the IOSB back */
419  _SEH2_TRY
420  {
421  *IoStatusBlock = KernelIosb;
422 
423  }
425  {
426  KernelIosb.Status = _SEH2_GetExceptionCode();
427  }
428  _SEH2_END;
429 
430  /* Backup our complete context in case it exists */
431  if (FileObject->CompletionContext)
432  {
433  CompletionInfo = *(FileObject->CompletionContext);
434  }
435 
436  /* If we had an event, signal it */
437  if (Event)
438  {
439  KeSetEvent(EventObject, IO_NO_INCREMENT, FALSE);
440  ObDereferenceObject(EventObject);
441  }
442 
443  /* If FO was locked, unlock it */
444  if (LockedForSynch)
445  {
447  }
448 
449  /* Set completion if required */
450  if (CompletionInfo.Port != NULL && UserApcContext != NULL)
451  {
452  if (!NT_SUCCESS(IoSetIoCompletion(CompletionInfo.Port,
453  CompletionInfo.Key,
454  UserApcContext,
455  KernelIosb.Status,
456  KernelIosb.Information,
457  TRUE)))
458  {
460  }
461  }
462 
463  /* We're done with FastIO! */
465  return KernelIosb.Status;
466  }
467  }
468  }
469 
470  /* Clear the event */
471  KeClearEvent(&FileObject->Event);
472 
473  /* Allocate IRP */
474  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
475  if (!Irp) return IopCleanupFailedIrp(FileObject, EventObject, NULL);
476 
477  /* Setup the IRP */
478  Irp->UserIosb = IoStatusBlock;
479  Irp->UserEvent = EventObject;
480  Irp->Overlay.AsynchronousParameters.UserApcRoutine = UserApcRoutine;
481  Irp->Overlay.AsynchronousParameters.UserApcContext = UserApcContext;
482  Irp->Cancel = FALSE;
483  Irp->CancelRoutine = NULL;
484  Irp->PendingReturned = FALSE;
485  Irp->RequestorMode = PreviousMode;
486  Irp->MdlAddress = NULL;
487  Irp->AssociatedIrp.SystemBuffer = NULL;
488  Irp->Flags = 0;
489  Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
490  Irp->Tail.Overlay.OriginalFileObject = FileObject;
491  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
492 
493  /* Set stack location settings */
494  StackPtr = IoGetNextIrpStackLocation(Irp);
495  StackPtr->FileObject = FileObject;
496  StackPtr->MajorFunction = IsDevIoCtl ?
499  StackPtr->MinorFunction = 0; /* Minor function 0 is IRP_MN_USER_FS_REQUEST */
500  StackPtr->Control = 0;
501  StackPtr->Flags = 0;
502  StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
503 
504  /* Set the IOCTL Data */
505  StackPtr->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
506  StackPtr->Parameters.DeviceIoControl.InputBufferLength = InputBufferLength;
507  StackPtr->Parameters.DeviceIoControl.OutputBufferLength =
509 
511 
512  /* Handle the Methods */
513  switch (AccessType)
514  {
515  /* Buffered I/O */
516  case METHOD_BUFFERED:
517 
518  /* Enter SEH for allocations */
519  _SEH2_TRY
520  {
521  /* Select the right Buffer Length */
524 
525  /* Make sure there is one */
526  if (BufferLength)
527  {
528  /* Allocate the System Buffer */
529  Irp->AssociatedIrp.SystemBuffer =
531  BufferLength,
532  TAG_SYS_BUF);
533 
534  /* Check if we got a buffer */
535  if (InputBuffer)
536  {
537  /* Copy into the System Buffer */
538  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
539  InputBuffer,
541  }
542 
543  /* Write the flags */
545  if (OutputBuffer) Irp->Flags |= IRP_INPUT_OPERATION;
546 
547  /* Save the Buffer */
548  Irp->UserBuffer = OutputBuffer;
549  }
550  else
551  {
552  /* Clear the Flags and Buffer */
553  Irp->UserBuffer = NULL;
554  }
555  }
557  {
558  /* Cleanup after exception and return */
561  }
562  _SEH2_END;
563  break;
564 
565  /* Direct I/O */
566  case METHOD_IN_DIRECT:
567  case METHOD_OUT_DIRECT:
568 
569  /* Enter SEH */
570  _SEH2_TRY
571  {
572  /* Check if we got an input buffer */
573  if ((InputBufferLength) && (InputBuffer))
574  {
575  /* Allocate the System Buffer */
576  Irp->AssociatedIrp.SystemBuffer =
579  TAG_SYS_BUF);
580 
581  /* Copy into the System Buffer */
582  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
583  InputBuffer,
585 
586  /* Write the flags */
588  }
589 
590  /* Check if we got an output buffer */
591  if (OutputBufferLength)
592  {
593  /* Allocate the System Buffer */
594  Irp->MdlAddress = IoAllocateMdl(OutputBuffer,
596  FALSE,
597  FALSE,
598  Irp);
599  if (!Irp->MdlAddress)
600  {
601  /* Raise exception we'll catch */
603  }
604 
605  /* Do the probe */
606  MmProbeAndLockPages(Irp->MdlAddress,
607  PreviousMode,
608  (AccessType == METHOD_IN_DIRECT) ?
610  }
611  }
613  {
614  /* Cleanup after exception and return */
617  }
618  _SEH2_END;
619  break;
620 
621  case METHOD_NEITHER:
622 
623  /* Just save the Buffer */
624  Irp->UserBuffer = OutputBuffer;
625  StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = InputBuffer;
626  }
627 
628  /* Use deferred completion for FS I/O */
629  if (!IsDevIoCtl)
630  {
631  Irp->Flags |= IRP_DEFER_IO_COMPLETION;
632  }
633 
634  /* If we are dismounting a volume, increaase the dismount count */
636  {
637  InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
638  }
639 
640  /* Perform the call */
642  Irp,
643  FileObject,
644  !IsDevIoCtl,
645  PreviousMode,
646  LockedForSynch,
648 }
_SEH2_TRY
Definition: create.c:4226
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
PVOID NTAPI ExAllocatePoolWithQuotaTag(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
Definition: expool.c:2984
#define FILE_ANY_ACCESS
Definition: nt_native.h:609
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1787
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define ExRaiseStatus
Definition: ntoskrnl.h:108
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3062
NTSTATUS NTAPI IoSetIoCompletion(IN PVOID IoCompletion, IN PVOID KeyContext, IN PVOID ApcContext, IN NTSTATUS IoStatus, IN ULONG_PTR IoStatusInformation, IN BOOLEAN Quota)
Definition: iocomp.c:147
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
_SEH2_END
Definition: create.c:4400
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
#define METHOD_IN_DIRECT
Definition: nt_native.h:595
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
#define IO_CTL_DEBUG
Definition: io.h:22
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define METHOD_NEITHER
Definition: nt_native.h:597
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
#define METHOD_OUT_DIRECT
Definition: nt_native.h:596
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:78
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
VOID NTAPI IopCleanupAfterException(IN PFILE_OBJECT FileObject, IN PIRP Irp OPTIONAL, IN PKEVENT Event OPTIONAL, IN PKEVENT LocalEvent OPTIONAL)
Definition: iofunc.c:27
NTSTATUS NTAPI IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
Definition: iofunc.c:119
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define SharedUserData
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
PFAST_IO_DEVICE_CONTROL FastIoDeviceControl
Definition: iotypes.h:1743
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define IRP_INPUT_OPERATION
#define IRP_BUFFERED_IO
#define InterlockedIncrement
Definition: armddk.h:53
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define IO_METHOD_FROM_CTL_CODE(C)
Definition: mup.h:11
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1385
#define METHOD_BUFFERED
Definition: nt_native.h:594
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define IRP_DEALLOCATE_BUFFER
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define TAG_SYS_BUF
Definition: tag.h:87
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_DEFER_IO_COMPLETION
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
signed int * PLONG
Definition: retypes.h:5
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define PAGED_CODE()

Referenced by NtDeviceIoControlFile(), and NtFsControlFile().

◆ IopFinalizeAsynchronousIo()

NTSTATUS NTAPI IopFinalizeAsynchronousIo ( IN NTSTATUS  SynchStatus,
IN PKEVENT  Event,
IN PIRP  Irp,
IN KPROCESSOR_MODE  PreviousMode,
IN PIO_STATUS_BLOCK  KernelIosb,
OUT PIO_STATUS_BLOCK  IoStatusBlock 
)

Definition at line 70 of file iofunc.c.

76 {
77  NTSTATUS FinalStatus = SynchStatus;
78  PAGED_CODE();
79  IOTRACE(IO_API_DEBUG, "IRP: %p. Status: %lx\n", Irp, SynchStatus);
80 
81  /* Make sure the IRP was completed, but returned pending */
82  if (FinalStatus == STATUS_PENDING)
83  {
84  /* Wait for the IRP */
85  FinalStatus = KeWaitForSingleObject(Event,
86  Executive,
88  FALSE,
89  NULL);
90  if (FinalStatus == STATUS_USER_APC)
91  {
92  /* Abort the request */
94  }
95 
96  /* Set the final status */
97  FinalStatus = KernelIosb->Status;
98  }
99 
100  /* Wrap potential user-mode write in SEH */
101  _SEH2_TRY
102  {
103  *IoStatusBlock = *KernelIosb;
104  }
106  {
107  /* Get the exception code */
108  FinalStatus = _SEH2_GetExceptionCode();
109  }
110  _SEH2_END;
111 
112  /* Free the event and return status */
113  ExFreePool(Event);
114  return FinalStatus;
115 }
_SEH2_TRY
Definition: create.c:4226
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_END
Definition: create.c:4400
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IO_API_DEBUG
Definition: io.h:21
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define STATUS_PENDING
Definition: ntstatus.h:82
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define STATUS_USER_APC
Definition: ntstatus.h:78
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Referenced by NtFlushBuffersFile(), NtQueryVolumeInformationFile(), NtSetVolumeInformationFile(), and NtUnlockFile().

◆ IopGetBasicInformationFile()

NTSTATUS NTAPI IopGetBasicInformationFile ( IN PFILE_OBJECT  FileObject,
OUT PFILE_BASIC_INFORMATION  BasicInfo 
)

Definition at line 839 of file iofunc.c.

841 {
845 
846  PAGED_CODE();
847 
848  /* Try to do it the fast way if possible */
850  if (DeviceObject->DriverObject->FastIoDispatch != NULL &&
851  DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo != NULL &&
852  DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo(FileObject,
853  ((FileObject->Flags & FO_SYNCHRONOUS_IO) != 0),
854  BasicInfo,
855  &IoStatusBlock,
856  DeviceObject))
857  {
858  return IoStatusBlock.Status;
859  }
860 
861  /* In case it failed, fall back to IRP-based method */
863 }
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IopGetFileInformation(IN PFILE_OBJECT FileObject, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInfoClass, OUT PVOID Buffer, OUT PULONG ReturnedLength)
Definition: iofunc.c:777
#define PAGED_CODE()

Referenced by IopOpenLinkOrRenameTarget().

◆ IopGetDriverPathInformation()

static NTSTATUS IopGetDriverPathInformation ( IN PFILE_OBJECT  FileObject,
IN PFILE_FS_DRIVER_PATH_INFORMATION  DriverPathInfo,
IN ULONG  Length 
)
static

Definition at line 1084 of file iofunc.c.

1087 {
1088  KIRQL OldIrql;
1089  NTSTATUS Status;
1090  UNICODE_STRING DriverName;
1092 
1093  /* Make sure the structure is consistent (ie, driver name fits into the buffer) */
1094  if (Length - FIELD_OFFSET(FILE_FS_DRIVER_PATH_INFORMATION, DriverName) < DriverPathInfo->DriverNameLength)
1095  {
1096  return STATUS_INVALID_PARAMETER;
1097  }
1098 
1099  /* Setup the whole driver name */
1100  DriverName.Length = DriverPathInfo->DriverNameLength;
1101  DriverName.MaximumLength = DriverPathInfo->DriverNameLength;
1102  DriverName.Buffer = &DriverPathInfo->DriverName[0];
1103 
1104  /* Ask Ob for such driver */
1105  Status = ObReferenceObjectByName(&DriverName,
1107  NULL,
1108  0,
1110  KernelMode,
1111  NULL,
1112  (PVOID*)&DriverObject);
1113  /* No such driver, bail out */
1114  if (!NT_SUCCESS(Status))
1115  {
1116  return Status;
1117  }
1118 
1119  /* Lock the devices database, we'll browse it */
1121  /* If we have a VPB, browse the stack from the volume */
1122  if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL)
1123  {
1124  DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->Vpb->DeviceObject, DriverObject);
1125  }
1126  /* Otherwise, do it from the normal device */
1127  else
1128  {
1129  DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->DeviceObject, DriverObject);
1130  }
1132 
1133  /* No longer needed */
1135 
1136  return STATUS_SUCCESS;
1137 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
POBJECT_TYPE IoDriverObjectType
Definition: driver.c:33
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI ObReferenceObjectByName(IN PUNICODE_STRING ObjectPath, IN ULONG Attributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext, OUT PVOID *ObjectPtr)
Definition: obref.c:409
static BOOLEAN IopVerifyDriverObjectOnStack(IN PDEVICE_OBJECT DeviceObject, IN PDRIVER_OBJECT DriverObject)
Definition: iofunc.c:1059

Referenced by NtQueryVolumeInformationFile().

◆ IopGetFileInformation()

NTSTATUS NTAPI IopGetFileInformation ( IN PFILE_OBJECT  FileObject,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInfoClass,
OUT PVOID  Buffer,
OUT PULONG  ReturnedLength 
)

Definition at line 777 of file iofunc.c.

782 {
783  PIRP Irp;
784  KEVENT Event;
789 
790  PAGED_CODE();
791 
792  /* Allocate an IRP */
795  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
796  if (Irp == NULL)
797  {
800  }
801 
802  /* Init event */
804 
805  /* Setup the IRP */
806  Irp->UserIosb = &IoStatusBlock;
807  Irp->UserEvent = &Event;
808  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
809  Irp->RequestorMode = KernelMode;
810  Irp->AssociatedIrp.SystemBuffer = Buffer;
812  Irp->Tail.Overlay.OriginalFileObject = FileObject;
813  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
814 
816  Stack->MajorFunction = IRP_MJ_QUERY_INFORMATION;
817  Stack->FileObject = FileObject;
818  Stack->Parameters.QueryFile.FileInformationClass = FileInfoClass;
819  Stack->Parameters.QueryFile.Length = Length;
820 
821 
822  /* Queue the IRP */
824 
825  /* Call the driver */
827  if (Status == STATUS_PENDING)
828  {
831  }
832 
834  return Status;
835 }
#define IRP_OB_QUERY_NAME
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IRP_BUFFERED_IO
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define ObReferenceObject
Definition: obfuncs.h:204
#define IRP_SYNCHRONOUS_API
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define PAGED_CODE()

Referenced by IopGetBasicInformationFile(), and IopQueryNameInternal().

◆ IopGetFileMode()

static ULONG IopGetFileMode ( IN PFILE_OBJECT  FileObject)
static

Definition at line 1004 of file iofunc.c.

1005 {
1006  ULONG Mode = 0;
1007 
1008  if (FileObject->Flags & FO_WRITE_THROUGH)
1010 
1011  if (FileObject->Flags & FO_SEQUENTIAL_ONLY)
1013 
1016 
1017  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1018  {
1019  if (FileObject->Flags & FO_ALERTABLE_IO)
1021  else
1023  }
1024 
1025  if (FileObject->Flags & FO_DELETE_ON_CLOSE)
1027 
1028  return Mode;
1029 }
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
_In_ ULONG Mode
Definition: hubbusif.h:303
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1778
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define FO_SEQUENTIAL_ONLY
Definition: iotypes.h:1780
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define FO_DELETE_ON_CLOSE
Definition: iotypes.h:1792
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define FO_WRITE_THROUGH
Definition: iotypes.h:1779

Referenced by NtQueryInformationFile().

◆ IopGetMountFlag()

static BOOLEAN IopGetMountFlag ( IN PDEVICE_OBJECT  DeviceObject)
static

Definition at line 1033 of file iofunc.c.

1034 {
1035  KIRQL OldIrql;
1036  PVPB Vpb;
1037  BOOLEAN Mounted;
1038 
1039  /* Assume not mounted */
1040  Mounted = FALSE;
1041 
1042  /* Check whether we have the mount flag */
1044 
1045  Vpb = DeviceObject->Vpb;
1046  if (Vpb != NULL &&
1047  BooleanFlagOn(Vpb->Flags, VPB_MOUNTED))
1048  {
1049  Mounted = TRUE;
1050  }
1051 
1053 
1054  return Mounted;
1055 }
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1204
PVPB Vpb
Definition: cdstruc.h:511
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
#define NULL
Definition: types.h:112
Definition: iotypes.h:189
#define VPB_MOUNTED
Definition: iotypes.h:1807
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1215
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1673

Referenced by NtQueryVolumeInformationFile().

◆ IopOpenLinkOrRenameTarget()

NTSTATUS NTAPI IopOpenLinkOrRenameTarget ( OUT PHANDLE  Handle,
IN PIRP  Irp,
IN PFILE_RENAME_INFORMATION  RenameInfo,
IN PFILE_OBJECT  FileObject 
)

Definition at line 867 of file iofunc.c.

871 {
876  PFILE_OBJECT TargetFileObject;
878  FILE_BASIC_INFORMATION BasicInfo;
882 
883  PAGED_CODE();
884 
885  /* First, establish whether our target is a directory */
886  if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
887  {
889  if (!NT_SUCCESS(Status))
890  {
891  return Status;
892  }
893 
894  if (BasicInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
896  }
897  }
898 
899  /* Setup the string to the target */
900  FileName.Buffer = RenameInfo->FileName;
901  FileName.Length = RenameInfo->FileNameLength;
902  FileName.MaximumLength = RenameInfo->FileNameLength;
903 
905  &FileName,
907  RenameInfo->RootDirectory,
908  NULL);
909 
910  /* And open its parent directory
911  * Use hint if specified
912  */
914  {
915  PFILE_OBJECT_EXTENSION FileObjectExtension;
916 
918 
919  FileObjectExtension = FileObject->FileObjectExtension;
923  &IoStatusBlock,
924  NULL,
925  0,
927  FILE_OPEN,
929  NULL,
930  0,
932  NULL,
934  FileObjectExtension->TopDeviceObjectHint);
935  }
936  else
937  {
941  &IoStatusBlock,
942  NULL,
943  0,
945  FILE_OPEN,
947  NULL,
948  0,
950  NULL,
952  }
953 
954  if (!NT_SUCCESS(Status))
955  {
956  return Status;
957  }
958 
959  /* Once open, continue only if:
960  * Target exists and we're allowed to overwrite it
961  */
963  if (Stack->Parameters.SetFile.FileInformationClass == FileLinkInformation &&
964  !RenameInfo->ReplaceIfExists &&
966  {
969  }
970 
971  /* Now, we'll get the associated device of the target, to check for same device location
972  * So, get the FO first
973  */
977  KernelMode,
978  (PVOID *)&TargetFileObject,
980  if (!NT_SUCCESS(Status))
981  {
983  return Status;
984  }
985 
986  /* We can dereference, we have the handle */
987  ObDereferenceObject(TargetFileObject);
988  /* If we're not on the same device, error out **/
990  {
992  return STATUS_NOT_SAME_DEVICE;
993  }
994 
995  /* Return parent directory file object and handle */
996  Stack->Parameters.SetFile.FileObject = TargetFileObject;
997  *Handle = TargetHandle;
998 
999  return STATUS_SUCCESS;
1000 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
PDEVICE_OBJECT TopDeviceObjectHint
Definition: io.h:102
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FILE_EXISTS
Definition: nt_native.h:772
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:540
#define STATUS_NOT_SAME_DEVICE
Definition: ntstatus.h:448
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1787
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoCreateFileSpecifyDeviceObjectHint(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options, IN PVOID DeviceObject)
Definition: file.c:3049
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define FILE_SHARE_READ
Definition: compat.h:136
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
_In_ PIRP Irp
Definition: csq.h:116
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:541
#define FILE_WRITE_DATA
Definition: nt_native.h:631
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:40
* PFILE_OBJECT
Definition: iotypes.h:1998
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
NTSTATUS NTAPI IopGetBasicInformationFile(IN PFILE_OBJECT FileObject, OUT PFILE_BASIC_INFORMATION BasicInfo)
Definition: iofunc.c:839
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
#define SYNCHRONIZE
Definition: nt_native.h:61
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define FILE_OPEN
Definition: from_kernel.h:54
struct _FileName FileName
Definition: fatprocs.h:893
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3009
_In_ HANDLE Handle
Definition: extypes.h:390
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65
#define FO_OPENED_CASE_SENSITIVE
Definition: iotypes.h:1793
#define IO_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:7352
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE TargetHandle
Definition: obfuncs.h:429
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define PAGED_CODE()

Referenced by NtSetInformationFile().

◆ IopPerformSynchronousRequest()

NTSTATUS NTAPI IopPerformSynchronousRequest ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PFILE_OBJECT  FileObject,
IN BOOLEAN  Deferred,
IN KPROCESSOR_MODE  PreviousMode,
IN BOOLEAN  SynchIo,
IN IOP_TRANSFER_TYPE  TransferType 
)

Definition at line 119 of file iofunc.c.

126 {
128  PKNORMAL_ROUTINE NormalRoutine;
129  PVOID NormalContext = NULL;
130  KIRQL OldIrql;
131  PAGED_CODE();
132  IOTRACE(IO_API_DEBUG, "IRP: %p. DO: %p. FO: %p\n",
134 
135  /* Queue the IRP */
137 
138  /* Update operation counts */
139  IopUpdateOperationCount(TransferType);
140 
141  /* Call the driver */
143 
144  /* Check if we're optimizing this case */
145  if (Deferred)
146  {
147  /* We are! Check if the IRP wasn't completed */
148  if (Status != STATUS_PENDING)
149  {
150  /* Complete it ourselves */
151  NormalRoutine = NULL;
152  NormalContext = NULL;
153  ASSERT(!Irp->PendingReturned);
155  IopCompleteRequest(&Irp->Tail.Apc,
156  &NormalRoutine,
157  &NormalContext,
158  (PVOID*)&FileObject,
159  &NormalContext);
161  }
162  }
163 
164  /* Check if this was synch I/O */
165  if (SynchIo)
166  {
167  /* Make sure the IRP was completed, but returned pending */
168  if (Status == STATUS_PENDING)
169  {
170  /* Wait for the IRP */
172  Executive,
173  PreviousMode,
174  (FileObject->Flags &
175  FO_ALERTABLE_IO) != 0,
176  NULL);
177  if ((Status == STATUS_ALERTED) || (Status == STATUS_USER_APC))
178  {
179  /* Abort the request */
181  }
182 
183  /* Set the final status */
184  Status = FileObject->FinalStatus;
185  }
186 
187  /* Release the file lock */
189  }
190 
191  /* Return status */
192  return Status;
193 }
VOID NTAPI IopCompleteRequest(IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
Definition: irp.c:238
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_ALERTED
Definition: ntstatus.h:80
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IO_API_DEBUG
Definition: io.h:21
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOTRACE(x, fmt,...)
Definition: io.h:47
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
#define STATUS_USER_APC
Definition: ntstatus.h:78
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:82
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:684
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define PAGED_CODE()

Referenced by IopDeviceFsIoControl(), NtFlushBuffersFile(), NtLockFile(), NtNotifyChangeDirectoryFile(), NtQueryDirectoryFile(), NtQueryVolumeInformationFile(), NtReadFile(), NtSetVolumeInformationFile(), NtUnlockFile(), and NtWriteFile().

◆ IopQueryDeviceInformation()

NTSTATUS NTAPI IopQueryDeviceInformation ( IN PFILE_OBJECT  FileObject,
IN ULONG  InformationClass,
IN ULONG  Length,
OUT PVOID  Information,
OUT PULONG  ReturnedLength,
IN BOOLEAN  File 
)

Definition at line 652 of file iofunc.c.

658 {
660  PIRP Irp;
662  PIO_STACK_LOCATION StackPtr;
663  BOOLEAN LocalEvent = FALSE;
664  KEVENT Event;
666  PAGED_CODE();
667  IOTRACE(IO_API_DEBUG, "Handle: %p. CTL: %lx. Type: %lx\n",
669 
670  /* Reference the object */
672 
673  /* Check if this is a file that was opened for Synch I/O */
674  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
675  {
676  /* Lock it */
678 
679  /* Use File Object event */
680  KeClearEvent(&FileObject->Event);
681  }
682  else
683  {
684  /* Use local event */
686  LocalEvent = TRUE;
687  }
688 
689  /* Get the Device Object */
691 
692  /* Allocate the IRP */
693  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
694  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
695 
696  /* Set the IRP */
697  Irp->Tail.Overlay.OriginalFileObject = FileObject;
698  Irp->RequestorMode = KernelMode;
699  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
700  Irp->UserIosb = &IoStatusBlock;
701  Irp->UserEvent = (LocalEvent) ? &Event : NULL;
702  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
703  Irp->Flags |= IRP_BUFFERED_IO;
704  Irp->AssociatedIrp.SystemBuffer = Information;
705  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
706 
707  /* Set the Stack Data */
708  StackPtr = IoGetNextIrpStackLocation(Irp);
711  StackPtr->FileObject = FileObject;
712 
713  /* Check which type this is */
714  if (File)
715  {
716  /* Set Parameters */
717  StackPtr->Parameters.QueryFile.FileInformationClass = InformationClass;
718  StackPtr->Parameters.QueryFile.Length = Length;
719  }
720  else
721  {
722  /* Set Parameters */
723  StackPtr->Parameters.QueryVolume.FsInformationClass = InformationClass;
724  StackPtr->Parameters.QueryVolume.Length = Length;
725  }
726 
727  /* Queue the IRP */
729 
730  /* Call the Driver */
732 
733  /* Check if this was synch I/O */
734  if (!LocalEvent)
735  {
736  /* Check if the request is pending */
737  if (Status == STATUS_PENDING)
738  {
739  /* Wait on the file object */
741  Executive,
742  KernelMode,
743  (FileObject->Flags &
744  FO_ALERTABLE_IO) != 0,
745  NULL);
746  if (Status == STATUS_ALERTED)
747  {
748  /* Abort the operation */
750  }
751 
752  /* Get the final status */
753  Status = FileObject->FinalStatus;
754  }
755 
756  /* Release the file lock */
758  }
759  else if (Status == STATUS_PENDING)
760  {
761  /* Wait on the local event and get the final status */
763  Executive,
764  KernelMode,
765  FALSE,
766  NULL);
768  }
769 
770  /* Return the Length and Status. ReturnedLength is NOT optional */
772  return Status;
773 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define STATUS_ALERTED
Definition: ntstatus.h:80
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1044
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
unsigned char BOOLEAN
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOTRACE(x, fmt,...)
Definition: io.h:47
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IRP_BUFFERED_IO
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define IRP_SYNCHRONOUS_API
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
Definition: File.h:15
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1713
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define PAGED_CODE()

Referenced by IoQueryFileInformation(), and IoQueryVolumeInformation().

◆ IopVerifyDriverObjectOnStack()

static BOOLEAN IopVerifyDriverObjectOnStack ( IN PDEVICE_OBJECT  DeviceObject,
IN PDRIVER_OBJECT  DriverObject 
)
static

Definition at line 1059 of file iofunc.c.

1061 {
1062  PDEVICE_OBJECT StackDO;
1063 
1064  /* Browse our whole device stack, trying to find the appropriate driver */
1066  while (StackDO != NULL)
1067  {
1068  /* We've found the driver, return success */
1069  if (StackDO->DriverObject == DriverObject)
1070  {
1071  return TRUE;
1072  }
1073 
1074  /* Move to the next */
1075  StackDO = StackDO->AttachedDevice;
1076  }
1077 
1078  /* We only reach there if driver was not found */
1079  return FALSE;
1080 }
#define TRUE
Definition: types.h:120
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase(IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:1485
#define NULL
Definition: types.h:112

Referenced by IopGetDriverPathInformation().

◆ IoQueryFileInformation()

NTSTATUS NTAPI IoQueryFileInformation ( IN PFILE_OBJECT  FileObject,
IN FILE_INFORMATION_CLASS  FileInformationClass,
IN ULONG  Length,
OUT PVOID  FileInformation,
OUT PULONG  ReturnedLength 
)

Definition at line 1274 of file iofunc.c.

1279 {
1280  /* Call the shared routine */
1283  Length,
1286  TRUE);
1287 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
NTSTATUS NTAPI IopQueryDeviceInformation(IN PFILE_OBJECT FileObject, IN ULONG InformationClass, IN ULONG Length, OUT PVOID Information, OUT PULONG ReturnedLength, IN BOOLEAN File)
Definition: iofunc.c:652
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187

Referenced by IopParseDevice(), and IopQueryNameInternal().

◆ IoQueryVolumeInformation()

NTSTATUS NTAPI IoQueryVolumeInformation ( IN PFILE_OBJECT  FileObject,
IN FS_INFORMATION_CLASS  FsInformationClass,
IN ULONG  Length,
OUT PVOID  FsInformation,
OUT PULONG  ReturnedLength 
)

Definition at line 1294 of file iofunc.c.

1299 {
1300  /* Call the shared routine */
1303  Length,
1304  FsInformation,
1306  FALSE);
1307 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI IopQueryDeviceInformation(IN PFILE_OBJECT FileObject, IN ULONG InformationClass, IN ULONG Length, OUT PVOID Information, OUT PULONG ReturnedLength, IN BOOLEAN File)
Definition: iofunc.c:652
#define FALSE
Definition: types.h:117
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187

Referenced by NtCreatePagingFile().

◆ IoSetInformation()

NTSTATUS NTAPI IoSetInformation ( IN PFILE_OBJECT  FileObject,
IN FILE_INFORMATION_CLASS  FileInformationClass,
IN ULONG  Length,
IN PVOID  FileInformation 
)

Definition at line 1314 of file iofunc.c.

1318 {
1320  PIRP Irp;
1322  PIO_STACK_LOCATION StackPtr;
1323  BOOLEAN LocalEvent = FALSE;
1324  KEVENT Event;
1325  NTSTATUS Status;
1326  PAGED_CODE();
1327  IOTRACE(IO_API_DEBUG, "FileObject: %p. Class: %lx. Length: %lx\n",
1329 
1330  /* Reference the object */
1332 
1333  /* Check if this is a file that was opened for Synch I/O */
1334  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1335  {
1336  /* Lock it */
1338 
1339  /* Use File Object event */
1340  KeClearEvent(&FileObject->Event);
1341  }
1342  else
1343  {
1344  /* Use local event */
1346  LocalEvent = TRUE;
1347  }
1348 
1349  /* Get the Device Object */
1351 
1352  /* Allocate the IRP */
1353  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1354  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
1355 
1356  /* Set the IRP */
1357  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1358  Irp->RequestorMode = KernelMode;
1359  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
1360  Irp->UserIosb = &IoStatusBlock;
1361  Irp->UserEvent = (LocalEvent) ? &Event : NULL;
1362  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
1363  Irp->Flags |= IRP_BUFFERED_IO;
1364  Irp->AssociatedIrp.SystemBuffer = FileInformation;
1365  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1366 
1367  /* Set the Stack Data */
1368  StackPtr = IoGetNextIrpStackLocation(Irp);
1370  StackPtr->FileObject = FileObject;
1371 
1372  /* Set Parameters */
1373  StackPtr->Parameters.SetFile.FileInformationClass = FileInformationClass;
1374  StackPtr->Parameters.SetFile.Length = Length;
1375 
1376  /* Queue the IRP */
1378 
1379  /* Call the Driver */
1381 
1382  /* Check if this was synch I/O */
1383  if (!LocalEvent)
1384  {
1385  /* Check if the request is pending */
1386  if (Status == STATUS_PENDING)
1387  {
1388  /* Wait on the file object */
1390  Executive,
1391  KernelMode,
1392  (FileObject->Flags &
1393  FO_ALERTABLE_IO) != 0,
1394  NULL);
1395  if (Status == STATUS_ALERTED)
1396  {
1397  /* Abort the operation */
1399  }
1400 
1401  /* Get the final status */
1402  Status = FileObject->FinalStatus;
1403  }
1404 
1405  /* Release the file lock */
1407  }
1408  else if (Status == STATUS_PENDING)
1409  {
1410  /* Wait on the local event and get the final status */
1412  Executive,
1413  KernelMode,
1414  FALSE,
1415  NULL);
1417  }
1418 
1419  /* Return the status */
1420  return Status;
1421 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define STATUS_ALERTED
Definition: ntstatus.h:80
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
unsigned char BOOLEAN
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOTRACE(x, fmt,...)
Definition: io.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define IRP_BUFFERED_IO
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define ObReferenceObject
Definition: obfuncs.h:204
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_SYNCHRONOUS_API
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define PAGED_CODE()

Referenced by MmCreateDataFileSection().

◆ IoSynchronousPageWrite()

NTSTATUS NTAPI IoSynchronousPageWrite ( IN PFILE_OBJECT  FileObject,
IN PMDL  Mdl,
IN PLARGE_INTEGER  Offset,
IN PKEVENT  Event,
IN PIO_STATUS_BLOCK  StatusBlock 
)

Definition at line 1146 of file iofunc.c.

1151 {
1152  PIRP Irp;
1153  PIO_STACK_LOCATION StackPtr;
1155  IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p\n",
1156  FileObject, Mdl, Offset);
1157 
1158  /* Is the write originating from Cc? */
1159  if (FileObject->SectionObjectPointer != NULL &&
1160  FileObject->SectionObjectPointer->SharedCacheMap != NULL)
1161  {
1162  ++CcDataFlushes;
1164  }
1165 
1166  /* Get the Device Object */
1168 
1169  /* Allocate IRP */
1170  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1171  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
1172 
1173  /* Get the Stack */
1174  StackPtr = IoGetNextIrpStackLocation(Irp);
1175 
1176  /* Create the IRP Settings */
1177  Irp->MdlAddress = Mdl;
1178  Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
1179  Irp->UserIosb = StatusBlock;
1180  Irp->UserEvent = Event;
1181  Irp->RequestorMode = KernelMode;
1183  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1184  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1185 
1186  /* Set the Stack Settings */
1187  StackPtr->Parameters.Write.Length = MmGetMdlByteCount(Mdl);
1188  StackPtr->Parameters.Write.ByteOffset = *Offset;
1189  StackPtr->MajorFunction = IRP_MJ_WRITE;
1190  StackPtr->FileObject = FileObject;
1191 
1192  /* Call the Driver */
1193  return IoCallDriver(DeviceObject, Irp);
1194 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define MmGetMdlVirtualAddress(_Mdl)
ULONG CcDataFlushes
Definition: copy.c:44
#define IRP_NOCACHE
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define IO_API_DEBUG
Definition: io.h:21
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
ULONG CcDataPages
Definition: copy.c:43
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define BYTES_TO_PAGES(Size)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define MmGetMdlByteCount(_Mdl)
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define IRP_PAGING_IO
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by CcZeroData(), MiWritePage(), and MmWriteToSwapPage().

◆ NtCancelDeviceWakeupRequest()

NTSTATUS NTAPI NtCancelDeviceWakeupRequest ( IN HANDLE  DeviceHandle)

Definition at line 4638 of file iofunc.c.

4639 {
4640  UNIMPLEMENTED;
4641  return STATUS_NOT_IMPLEMENTED;
4642 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CancelDeviceWakeupRequest().

◆ NtDeviceIoControlFile()

NTSTATUS NTAPI NtDeviceIoControlFile ( IN HANDLE  DeviceHandle,
IN HANDLE Event  OPTIONAL,
IN PIO_APC_ROUTINE UserApcRoutine  OPTIONAL,
IN PVOID UserApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN ULONG  IoControlCode,
IN PVOID  InputBuffer,
IN ULONG InputBufferLength  OPTIONAL,
OUT PVOID  OutputBuffer,
IN ULONG OutputBufferLength  OPTIONAL 
)

Definition at line 1430 of file iofunc.c.

1440 {
1441  /* Call the Generic Function */
1443  Event,
1444  UserApcRoutine,
1445  UserApcContext,
1446  IoStatusBlock,
1447  IoControlCode,
1448  InputBuffer,
1450  OutputBuffer,
1452  TRUE);
1453 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define TRUE
Definition: types.h:120
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
NTSTATUS NTAPI IopDeviceFsIoControl(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength OPTIONAL, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength OPTIONAL, IN BOOLEAN IsDevIoCtl)
Definition: iofunc.c:197
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

◆ NtFlushBuffersFile()

NTSTATUS NTAPI NtFlushBuffersFile ( IN HANDLE  FileHandle,
OUT PIO_STATUS_BLOCK  IoStatusBlock 
)

Definition at line 1487 of file iofunc.c.

1489 {
1491  PIRP Irp;
1492  PIO_STACK_LOCATION StackPtr;
1493  NTSTATUS Status;
1495  PKEVENT Event = NULL;
1496  BOOLEAN LocalEvent = FALSE;
1497  OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
1499  IO_STATUS_BLOCK KernelIosb;
1500  PAGED_CODE();
1501  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1502 
1503  if (PreviousMode != KernelMode)
1504  {
1505  /* Protect probes */
1506  _SEH2_TRY
1507  {
1508  /* Probe the I/O Status block */
1510  }
1512  {
1513  /* Return the exception code */
1515  }
1516  _SEH2_END;
1517  }
1518 
1519  /* Get the File Object */
1521  0,
1523  PreviousMode,
1524  (PVOID*)&FileObject,
1525  &ObjectHandleInfo);
1526  if (!NT_SUCCESS(Status)) return Status;
1527 
1528  /*
1529  * Check if the handle has either FILE_WRITE_DATA or FILE_APPEND_DATA was
1530  * granted. However, if this is a named pipe, make sure we don't ask for
1531  * FILE_APPEND_DATA as it interferes with the FILE_CREATE_PIPE_INSTANCE
1532  * access right!
1533  */
1534  if (!(ObjectHandleInfo.GrantedAccess &
1535  ((!(FileObject->Flags & FO_NAMED_PIPE) ? FILE_APPEND_DATA : 0) |
1536  FILE_WRITE_DATA)))
1537  {
1538  /* We failed */
1540  return STATUS_ACCESS_DENIED;
1541  }
1542 
1543  /* Check if we should use Sync IO or not */
1544  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1545  {
1546  /* Lock it */
1548  if (Status != STATUS_SUCCESS)
1549  {
1551  return Status;
1552  }
1553  }
1554  else
1555  {
1556  /* Use local event */
1558  if (!Event)
1559  {
1560  /* We failed */
1563  }
1565  LocalEvent = TRUE;
1566  }
1567 
1568  /* Get the Device Object */
1570 
1571  /* Clear the event */
1572  KeClearEvent(&FileObject->Event);
1573 
1574  /* Allocate the IRP */
1575  Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
1576  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
1577 
1578  /* Set up the IRP */
1579  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
1580  Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
1581  Irp->UserEvent = (LocalEvent) ? Event : NULL;
1582  Irp->RequestorMode = PreviousMode;
1583  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1584  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1585  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
1586 
1587  /* Set up Stack Data */
1588  StackPtr = IoGetNextIrpStackLocation(Irp);
1589  StackPtr->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
1590  StackPtr->FileObject = FileObject;
1591 
1592  /* Call the Driver */
1594  Irp,
1595  FileObject,
1596  FALSE,
1597  PreviousMode,
1598  !LocalEvent,
1600 
1601  /* Check if this was async I/O */
1602  if (LocalEvent)
1603  {
1604  /* It was, finalize this request */
1606  Event,
1607  Irp,
1608  PreviousMode,
1609  &KernelIosb,
1610  IoStatusBlock);
1611  }
1612 
1613  /* Return the Status */
1614  return Status;
1615 }
_SEH2_TRY
Definition: create.c:4226
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_IO
Definition: tag.h:80
#define IRP_MJ_FLUSH_BUFFERS
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
#define KeGetPreviousMode()
Definition: ketypes.h:1108
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_SEH2_END
Definition: create.c:4400
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
ACCESS_MASK GrantedAccess
Definition: iotypes.h:181
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define FO_NAMED_PIPE
Definition: iotypes.h:1782
unsigned char BOOLEAN
#define FILE_WRITE_DATA
Definition: nt_native.h:631
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ObDereferenceObject
Definition: obfuncs.h:203
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
NTSTATUS NTAPI IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
Definition: iofunc.c:119
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define IRP_SYNCHRONOUS_API
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
NTSTATUS NTAPI IopFinalizeAsynchronousIo(IN NTSTATUS SynchStatus, IN PKEVENT Event, IN PIRP Irp, IN KPROCESSOR_MODE PreviousMode, IN PIO_STATUS_BLOCK KernelIosb, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: iofunc.c:70
#define PAGED_CODE()

Referenced by FlushFileBuffers(), LogfpFlushFile(), and START_TEST().

◆ NtFsControlFile()

NTSTATUS NTAPI NtFsControlFile ( IN HANDLE  DeviceHandle,
IN HANDLE Event  OPTIONAL,
IN PIO_APC_ROUTINE UserApcRoutine  OPTIONAL,
IN PVOID UserApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN ULONG  IoControlCode,
IN PVOID  InputBuffer,
IN ULONG InputBufferLength  OPTIONAL,
OUT PVOID  OutputBuffer,
IN ULONG OutputBufferLength  OPTIONAL 
)

Definition at line 1460 of file iofunc.c.

1470 {
1471  /* Call the Generic Function */
1473  Event,
1474  UserApcRoutine,
1475  UserApcContext,
1476  IoStatusBlock,
1477  IoControlCode,
1478  InputBuffer,
1480  OutputBuffer,
1482  FALSE);
1483 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
NTSTATUS NTAPI IopDeviceFsIoControl(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength OPTIONAL, OUT PVOID OutputBuffer, IN ULONG OutputBufferLength OPTIONAL, IN BOOLEAN IsDevIoCtl)
Definition: iofunc.c:197
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

◆ NtLockFile()

NTSTATUS NTAPI NtLockFile ( IN HANDLE  FileHandle,
IN HANDLE EventHandle  OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine  OPTIONAL,
IN PVOID ApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PLARGE_INTEGER  ByteOffset,
IN PLARGE_INTEGER  Length,
IN ULONG  Key,
IN BOOLEAN  FailImmediately,
IN BOOLEAN  ExclusiveLock 
)

Definition at line 1764 of file iofunc.c.

1774 {
1776  PLARGE_INTEGER LocalLength = NULL;
1777  PIRP Irp;
1778  PIO_STACK_LOCATION StackPtr;
1780  PKEVENT Event = NULL;
1781  BOOLEAN LockedForSync = FALSE;
1783  LARGE_INTEGER CapturedByteOffset, CapturedLength;
1784  NTSTATUS Status;
1787  PAGED_CODE();
1788  CapturedByteOffset.QuadPart = 0;
1789  CapturedLength.QuadPart = 0;
1790  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1791 
1792  /* Get File Object */
1794  0,
1796  PreviousMode,
1797  (PVOID*)&FileObject,
1799  if (!NT_SUCCESS(Status)) return Status;
1800 
1801  /* Check if we're called from user mode */
1802  if (PreviousMode != KernelMode)
1803  {
1804  /* Can't use an I/O completion port and an APC at the same time */
1805  if ((FileObject->CompletionContext) && (ApcRoutine))
1806  {
1807  /* Fail */
1809  return STATUS_INVALID_PARAMETER;
1810  }
1811 
1812  /* Must have either FILE_READ_DATA or FILE_WRITE_DATA access */
1813  if (!(HandleInformation.GrantedAccess &
1815  {
1817  return STATUS_ACCESS_DENIED;
1818  }
1819 
1820  /* Enter SEH for probing */
1821  _SEH2_TRY
1822  {
1823  /* Probe the I/O STatus block */
1825 
1826  /* Probe and capture the large integers */
1827  CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
1828  CapturedLength = ProbeForReadLargeInteger(Length);
1829  }
1831  {
1832  /* Dereference the object and return exception code */
1835  }
1836  _SEH2_END;
1837  }
1838  else
1839  {
1840  /* Otherwise, capture them directly */
1841  CapturedByteOffset = *ByteOffset;
1842  CapturedLength = *Length;
1843  }
1844 
1845  /* Check if we have an event handle */
1846  if (EventHandle)
1847  {
1848  /* Reference it */
1852  PreviousMode,
1853  (PVOID *)&Event,
1854  NULL);
1855  if (Status != STATUS_SUCCESS) return Status;
1857  }
1858 
1859  /* Get the device object */
1861 
1862  /* Try to do it the FastIO way if possible */
1863  FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
1865  {
1866  IO_STATUS_BLOCK KernelIosb;
1867 
1869  &CapturedByteOffset,
1870  &CapturedLength,
1872  Key,
1874  ExclusiveLock,
1875  &KernelIosb,
1876  DeviceObject))
1877  {
1878  /* Write the IOSB back */
1879  _SEH2_TRY
1880  {
1881  *IoStatusBlock = KernelIosb;
1882  }
1884  {
1885  KernelIosb.Status = _SEH2_GetExceptionCode();
1886  }
1887  _SEH2_END;
1888 
1889  /* If we had an event, signal it */
1890  if (EventHandle)
1891  {
1894  }
1895 
1896  /* Set completion if required */
1897  if (FileObject->CompletionContext != NULL && ApcContext != NULL)
1898  {
1899  if (!NT_SUCCESS(IoSetIoCompletion(FileObject->CompletionContext->Port,
1900  FileObject->CompletionContext->Key,
1901  ApcContext,
1902  KernelIosb.Status,
1903  KernelIosb.Information,
1904  TRUE)))
1905  {
1907  }
1908  }
1909 
1910  FileObject->LockOperation = TRUE;
1911 
1912  /* We're done with FastIO! */
1914  return KernelIosb.Status;
1915  }
1916  }
1917 
1918  /* Check if we should use Sync IO or not */
1919  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1920  {
1921  /* Lock it */
1923  if (Status != STATUS_SUCCESS)
1924  {
1927  return Status;
1928  }
1929  LockedForSync = TRUE;
1930  }
1931 
1932  /* Clear File Object event */
1933  KeClearEvent(&FileObject->Event);
1934  FileObject->LockOperation = TRUE;
1935 
1936  /* Allocate the IRP */
1937  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1938  if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
1939 
1940  /* Set up the IRP */
1941  Irp->RequestorMode = PreviousMode;
1942  Irp->UserIosb = IoStatusBlock;
1943  Irp->UserEvent = Event;
1944  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1945  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1946  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
1947  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
1948 
1949  /* Set up Stack Data */
1950  StackPtr = IoGetNextIrpStackLocation(Irp);
1951  StackPtr->MajorFunction = IRP_MJ_LOCK_CONTROL;
1952  StackPtr->MinorFunction = IRP_MN_LOCK;
1953  StackPtr->FileObject = FileObject;
1954 
1955  /* Allocate local buffer */
1956  LocalLength = ExAllocatePoolWithTag(NonPagedPool,
1957  sizeof(LARGE_INTEGER),
1958  TAG_LOCK);
1959  if (!LocalLength)
1960  {
1961  /* Allocating failed, clean up and return failure */
1964  }
1965 
1966  /* Set the length */
1967  *LocalLength = CapturedLength;
1968  Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength;
1969  StackPtr->Parameters.LockControl.Length = LocalLength;
1970 
1971  /* Set Parameters */
1972  StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset;
1973  StackPtr->Parameters.LockControl.Key = Key;
1974 
1975  /* Set Flags */
1976  if (FailImmediately) StackPtr->Flags = SL_FAIL_IMMEDIATELY;
1977  if (ExclusiveLock) StackPtr->Flags |= SL_EXCLUSIVE_LOCK;
1978 
1979  /* Perform the call */
1981  Irp,
1982  FileObject,
1983  FALSE,
1984  PreviousMode,
1985  LockedForSync,
1987 }
_SEH2_TRY
Definition: create.c:4226
#define TAG_LOCK
Definition: tag.h:63
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:725
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1108
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoSetIoCompletion(IN PVOID IoCompletion, IN PVOID KeyContext, IN PVOID ApcContext, IN NTSTATUS IoStatus, IN ULONG_PTR IoStatusInformation, IN BOOLEAN Quota)
Definition: iocomp.c:147
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_SEH2_END
Definition: create.c:4400
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_READ_DATA
Definition: nt_native.h:628
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
Definition: fatprocs.h:2709
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFKEY * Key
Definition: wdfdevice.h:2654
void * PVOID
Definition: retypes.h:9
#define FILE_WRITE_DATA
Definition: nt_native.h:631
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ObDereferenceObject
Definition: obfuncs.h:203
_In_ ACCESS_MASK _In_opt_ POBJECT_TYPE _In_ KPROCESSOR_MODE _Out_ PVOID _Out_opt_ POBJECT_HANDLE_INFORMATION HandleInformation
Definition: obfuncs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
VOID NTAPI IopCleanupAfterException(IN PFILE_OBJECT FileObject, IN PIRP Irp OPTIONAL, IN PKEVENT Event OPTIONAL, IN PKEVENT LocalEvent OPTIONAL)
Definition: iofunc.c:27
NTSTATUS NTAPI IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
Definition: iofunc.c:119
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:725
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PFAST_IO_LOCK FastIoLock
Definition: iotypes.h:1739
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define SL_EXCLUSIVE_LOCK
Definition: iotypes.h:1833
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define IRP_MN_LOCK
Definition: iotypes.h:4410
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
Definition: fatprocs.h:2709
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
LONGLONG QuadPart
Definition: typedefs.h:114
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:725
#define PAGED_CODE()
#define SL_FAIL_IMMEDIATELY
Definition: iotypes.h:1832
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857

Referenced by LockFile(), and LockFileEx().

◆ NtNotifyChangeDirectoryFile()

NTSTATUS NTAPI NtNotifyChangeDirectoryFile ( IN HANDLE  FileHandle,
IN HANDLE EventHandle  OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine  OPTIONAL,
IN PVOID ApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
OUT PVOID  Buffer,
IN ULONG  BufferSize,
IN ULONG  CompletionFilter,
IN BOOLEAN  WatchTree 
)

Definition at line 1622 of file iofunc.c.

1631 {
1632  PIRP Irp;
1633  PKEVENT Event = NULL;
1636  PIO_STACK_LOCATION IoStack;
1638  NTSTATUS Status;
1639  BOOLEAN LockedForSync = FALSE;
1640  PAGED_CODE();
1641  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1642 
1643  /* Check if we're called from user mode */
1644  if (PreviousMode != KernelMode)
1645  {
1646  /* Enter SEH for probing */
1647  _SEH2_TRY
1648  {
1649  /* Probe the I/O STatus block */
1651 
1652  /* Probe the buffer */
1654  }
1656  {
1657  /* Return the exception code */
1659  }
1660  _SEH2_END;
1661 
1662  /* Check if CompletionFilter is valid */
1664  {
1665  return STATUS_INVALID_PARAMETER;
1666  }
1667  }
1668 
1669  /* Get File Object */
1673  PreviousMode,
1674  (PVOID*)&FileObject,
1675  NULL);
1676  if (!NT_SUCCESS(Status)) return Status;
1677 
1678  /* Can't use an I/O completion port and an APC at the same time */
1679  if ((FileObject->CompletionContext) && (ApcRoutine))
1680  {
1681  /* Fail */
1683  return STATUS_INVALID_PARAMETER;
1684  }
1685 
1686  /* Check if we have an event handle */
1687  if (EventHandle)
1688  {
1689  /* Reference it */
1693  PreviousMode,
1694  (PVOID *)&Event,
1695  NULL);
1696  if (Status != STATUS_SUCCESS)
1697  {
1699  return Status;
1700  }
1702  }
1703 
1704  /* Check if we should use Sync IO or not */
1705  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1706  {
1707  /* Lock it */
1709  if (Status != STATUS_SUCCESS)
1710  {
1713  return Status;
1714  }
1715  LockedForSync = TRUE;
1716  }
1717 
1718  /* Clear File Object event */
1719  KeClearEvent(&FileObject->Event);
1720 
1721  /* Get the device object */
1723 
1724  /* Allocate the IRP */
1725  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1726  if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
1727 
1728  /* Set up the IRP */
1729  Irp->RequestorMode = PreviousMode;
1730  Irp->UserIosb = IoStatusBlock;
1731  Irp->UserEvent = Event;
1732  Irp->UserBuffer = Buffer;
1733  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1734  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1735  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
1736  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
1737 
1738  /* Set up Stack Data */
1739  IoStack = IoGetNextIrpStackLocation(Irp);
1742  IoStack->FileObject = FileObject;
1743 
1744  /* Set parameters */
1745  IoStack->Parameters.NotifyDirectory.CompletionFilter = CompletionFilter;
1746  IoStack->Parameters.NotifyDirectory.Length = BufferSize;
1747  if (WatchTree) IoStack->Flags = SL_WATCH_TREE;
1748 
1749  /* Perform the call */
1751  Irp,
1752  FileObject,
1753  FALSE,
1754  PreviousMode,
1755  LockedForSync,
1757 }
_SEH2_TRY
Definition: create.c:4226
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:725
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY
Definition: rdpdr.c:56
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN WatchTree
Definition: fltkernel.h:2238
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3062
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_SEH2_END
Definition: create.c:4400
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
unsigned char BOOLEAN
Definition: bufpool.h:45
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ObDereferenceObject
Definition: obfuncs.h:203
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
NTSTATUS NTAPI IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
Definition: iofunc.c:119
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:725
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define SL_WATCH_TREE
Definition: iotypes.h:1839
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG CompletionFilter
Definition: fltkernel.h:2238
unsigned int ULONG
Definition: retypes.h:1
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define FILE_NOTIFY_VALID_MASK
#define PAGED_CODE()
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857

Referenced by FindFirstChangeNotificationW(), FindNextChangeNotification(), and ReadDirectoryChangesW().

◆ NtQueryDirectoryFile()

NTSTATUS NTAPI NtQueryDirectoryFile ( IN HANDLE  FileHandle,
IN HANDLE EventHandle  OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine  OPTIONAL,
IN PVOID ApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
OUT PVOID  FileInformation,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInformationClass,
IN BOOLEAN  ReturnSingleEntry,
IN PUNICODE_STRING FileName  OPTIONAL,
IN BOOLEAN  RestartScan 
)

Definition at line 1994 of file iofunc.c.

2005 {
2006  PIRP Irp;
2009  PIO_STACK_LOCATION StackPtr;
2011  NTSTATUS Status;
2012  BOOLEAN LockedForSynch = FALSE;
2013  PKEVENT Event = NULL;
2014  volatile PVOID AuxBuffer = NULL;
2015  PMDL Mdl;
2016  UNICODE_STRING CapturedFileName;
2017  PUNICODE_STRING SearchPattern;
2018  PAGED_CODE();
2019  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
2020 
2021  /* Check if we came from user mode */
2022  if (PreviousMode != KernelMode)
2023  {
2024  /* Enter SEH for probing */
2025  _SEH2_TRY
2026  {
2027  /* Probe the I/O Status Block */
2029 
2030  /* Probe the file information */
2032 
2033  /* Check if we have a file name */
2034  if (FileName)
2035  {
2036  /* Capture it */
2037  CapturedFileName = ProbeForReadUnicodeString(FileName);
2038  if (CapturedFileName.Length)
2039  {
2040  /* Probe its buffer */
2041  ProbeForRead(CapturedFileName.Buffer,
2042  CapturedFileName.Length,
2043  1);
2044  }
2045 
2046  /* Allocate the auxiliary buffer */
2047  AuxBuffer = ExAllocatePoolWithTag(NonPagedPool,
2048  CapturedFileName.Length +
2049  sizeof(UNICODE_STRING),
2050  TAG_SYSB);
2051  RtlCopyMemory((PVOID)((ULONG_PTR)AuxBuffer +
2052  sizeof(UNICODE_STRING)),
2053  CapturedFileName.Buffer,
2054  CapturedFileName.Length);
2055 
2056  /* Setup the search pattern */
2057  SearchPattern = (PUNICODE_STRING)AuxBuffer;
2058  SearchPattern->Buffer = (PWCHAR)((ULONG_PTR)AuxBuffer +
2059  sizeof(UNICODE_STRING));
2060  SearchPattern->Length = CapturedFileName.Length;
2061  SearchPattern->MaximumLength = CapturedFileName.Length;
2062  }
2063  }
2065  {
2066  /* Free buffer and return the exception code */
2067  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2069  }
2070  _SEH2_END;
2071  }
2072 
2073  /* Check input parameters */
2074 
2075  switch (FileInformationClass)
2076  {
2077 #define CHECK_LENGTH(class, struct) \
2078  case class: \
2079  if (Length < sizeof(struct)) \
2080  return STATUS_INFO_LENGTH_MISMATCH; \
2081  break
2088  default:
2089  break;
2090 #undef CHECK_LENGTH
2091  }
2092 
2093  /* Get File Object */
2097  PreviousMode,
2098  (PVOID *)&FileObject,
2099  NULL);
2100  if (!NT_SUCCESS(Status))
2101  {
2102  /* Fail */
2103  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2104  return Status;
2105  }
2106 
2107  /* Are there two associated completion routines? */
2108  if (FileObject->CompletionContext != NULL && ApcRoutine != NULL)
2109  {
2111  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2112  return STATUS_INVALID_PARAMETER;
2113  }
2114 
2115  /* Check if we have an even handle */
2116  if (EventHandle)
2117  {
2118  /* Get its pointer */
2122  PreviousMode,
2123  (PVOID *)&Event,
2124  NULL);
2125  if (!NT_SUCCESS(Status))
2126  {
2127  /* Fail */
2128  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2130  return Status;
2131  }
2132 
2133  /* Clear it */
2135  }
2136 
2137  /* Check if this is a file that was opened for Synch I/O */
2138  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2139  {
2140  /* Lock it */
2142  if (Status != STATUS_SUCCESS)
2143  {
2146  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2147  return Status;
2148  }
2149 
2150  /* Remember to unlock later */
2151  LockedForSynch = TRUE;
2152  }
2153 
2154  /* Get the device object */
2156 
2157  /* Clear the File Object's event */
2158  KeClearEvent(&FileObject->Event);
2159 
2160  /* Allocate the IRP */
2161  Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
2162  if (!Irp) return IopCleanupFailedIrp(FileObject, EventHandle, AuxBuffer);
2163 
2164  /* Set up the IRP */
2165  Irp->RequestorMode = PreviousMode;
2166  Irp->UserIosb = IoStatusBlock;
2167  Irp->UserEvent = Event;
2168  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2169  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2170  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
2171  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
2172  Irp->MdlAddress = NULL;
2173  Irp->Tail.Overlay.AuxiliaryBuffer = AuxBuffer;
2174  Irp->AssociatedIrp.SystemBuffer = NULL;
2175 
2176  /* Check if this is buffered I/O */
2177  if (DeviceObject->Flags & DO_BUFFERED_IO)
2178  {
2179  /* Allocate a buffer */
2180  Irp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithTag(NonPagedPool,
2181  Length,
2182  TAG_SYSB);
2183  if (!Irp->AssociatedIrp.SystemBuffer)
2184  {
2185  /* Allocating failed, clean up and return the exception code */
2187  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2188 
2189  /* Return the exception code */
2191  }
2192 
2193  /* Set the buffer and flags */
2194  Irp->UserBuffer = FileInformation;
2195  Irp->Flags = (IRP_BUFFERED_IO |
2198  }
2199  else if (DeviceObject->Flags & DO_DIRECT_IO)
2200  {
2201  _SEH2_TRY
2202  {
2203  /* Allocate an MDL */
2207  }
2209  {
2210  /* Allocating failed, clean up and return the exception code */
2213  }
2214  _SEH2_END;
2215  }
2216  else
2217  {
2218  /* No allocation flags, and use the buffer directly */
2219  Irp->UserBuffer = FileInformation;
2220  }
2221 
2222  /* Set up Stack Data */
2223  StackPtr = IoGetNextIrpStackLocation(Irp);
2224  StackPtr->FileObject = FileObject;
2227 
2228  /* Set Parameters */
2229  StackPtr->Parameters.QueryDirectory.FileInformationClass =
2231  StackPtr->Parameters.QueryDirectory.FileName = AuxBuffer;
2232  StackPtr->Parameters.QueryDirectory.FileIndex = 0;
2233  StackPtr->Parameters.QueryDirectory.Length = Length;
2234  StackPtr->Flags = 0;
2235  if (RestartScan) StackPtr->Flags = SL_RESTART_SCAN;
2237 
2238  /* Set deferred I/O */
2239  Irp->Flags |= IRP_DEFER_IO_COMPLETION;
2240 
2241  /* Perform the call */
2243  Irp,
2244  FileObject,
2245  TRUE,
2246  PreviousMode,
2247  LockedForSynch,
2249 }
_SEH2_TRY
Definition: create.c:4226
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:725
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ BOOLEAN _In_ ULONG _In_opt_ PULONG _In_ BOOLEAN RestartScan
Definition: fltkernel.h:2297
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ BOOLEAN ReturnSingleEntry
Definition: fltkernel.h:2294
#define ExRaiseStatus
Definition: ntoskrnl.h:108
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define IRP_MN_QUERY_DIRECTORY
Definition: rdpdr.c:55
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3062
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
uint16_t * PWCHAR
Definition: typedefs.h:56
_SEH2_END
Definition: create.c:4400
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define IO_API_DEBUG
Definition: io.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
unsigned char BOOLEAN
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define CHECK_LENGTH(class, struct)
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IopCleanupFailedIrp(IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
Definition: irp.c:45
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define ObDereferenceObject
Definition: obfuncs.h:203
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
VOID NTAPI IopCleanupAfterException(IN PFILE_OBJECT FileObject, IN PIRP Irp OPTIONAL, IN PKEVENT Event OPTIONAL, IN PKEVENT LocalEvent OPTIONAL)
Definition: iofunc.c:27
NTSTATUS NTAPI IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PFILE_OBJECT FileObject, IN BOOLEAN Deferred, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SynchIo, IN IOP_TRANSFER_TYPE TransferType)
Definition: iofunc.c:119
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:725
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define SL_RETURN_SINGLE_ENTRY
Definition: iotypes.h:1836
#define IRP_INPUT_OPERATION
#define IRP_BUFFERED_IO
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define SL_RESTART_SCAN
Definition: iotypes.h:1835
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
struct _UNICODE_STRING UNICODE_STRING
#define TAG_SYSB
Definition: tag.h:96
#define IRP_DEALLOCATE_BUFFER
unsigned int ULONG
Definition: retypes.h:1
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_DEFER_IO_COMPLETION
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define PAGED_CODE()
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857

Referenced by FindFirstFileExW(), FindNextFileW(), GetFileInformationByHandleEx(), and lookup_manifest_file().

◆ NtQueryEaFile()

NTSTATUS NTAPI NtQueryEaFile ( IN HANDLE  FileHandle,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
OUT PVOID  Buffer,
IN ULONG  Length,
IN BOOLEAN  ReturnSingleEntry,
IN PVOID EaList  OPTIONAL,
IN ULONG  EaListLength,
IN PULONG EaIndex  OPTIONAL,
IN BOOLEAN  RestartScan 
)

Definition at line 2256 of file iofunc.c.

2265 {
2266  UNIMPLEMENTED;
2267  return STATUS_NOT_IMPLEMENTED;
2268 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CreateDirectoryExW(), and CreateFileW().

◆ NtQueryInformationFile()

NTSTATUS NTAPI NtQueryInformationFile ( IN HANDLE  FileHandle,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN PVOID  FileInformation,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInformationClass 
)

Definition at line 2275 of file iofunc.c.

2280 {
2283  NTSTATUS Status;
2284  PIRP Irp;
2286  PIO_STACK_LOCATION StackPtr;
2288  PKEVENT Event = NULL;
2289  BOOLEAN LocalEvent = FALSE;
2290  PKNORMAL_ROUTINE NormalRoutine;
2291  PVOID NormalContext;
2292  KIRQL OldIrql;
2293  IO_STATUS_BLOCK KernelIosb;
2294  BOOLEAN CallDriver = TRUE;
2295  PFILE_ACCESS_INFORMATION AccessBuffer;
2296  PFILE_MODE_INFORMATION ModeBuffer;
2297  PFILE_ALIGNMENT_INFORMATION AlignmentBuffer;
2298  PFILE_ALL_INFORMATION AllBuffer;
2300  PAGED_CODE();
2301  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
2302 
2303  /* Check if we're called from user mode */
2304  if (PreviousMode != KernelMode)
2305  {
2306  /* Validate the information class */
2307  if ((FileInformationClass < 0) ||
2310  {
2311  /* Invalid class */
2313  }
2314 
2315  /* Validate the length */
2317  {
2318  /* Invalid length */
2320  }
2321 
2322  /* Enter SEH for probing */
2323  _SEH2_TRY
2324  {
2325  /* Probe the I/O Status block */
2327 
2328  /* Probe the information */
2330  }
2332  {
2333  /* Return the exception code */
2335  }
2336  _SEH2_END;
2337  }
2338 #if DBG
2339  else
2340  {
2341  /* Validate the information class */
2342  if ((FileInformationClass < 0) ||
2345  {
2346  /* Invalid class */
2348  }
2349 
2350  /* Validate the length */
2352  {
2353  /* Invalid length */
2355  }
2356  }
2357 #endif
2358 
2359  /* Reference the Handle */
2364  PreviousMode,
2365  (PVOID *)&FileObject,
2367  if (!NT_SUCCESS(Status)) return Status;
2368 
2369  /* Check if this is a direct open or not */
2370  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
2371  {
2372  /* Get the device object */
2373  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
2374  }
2375  else
2376  {
2377  /* Get the device object */
2379  }
2380 
2381  /* Check if this is a file that was opened for Synch I/O */
2382  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2383  {
2384  /* Lock it */
2386  if (Status != STATUS_SUCCESS)
2387  {
2389  return Status;
2390  }
2391 
2392  /* Check if the caller just wants the position */
2394  {
2395  /* Protect write in SEH */
2396  _SEH2_TRY
2397  {
2398  /* Write the offset */
2400  CurrentByteOffset = FileObject->CurrentByteOffset;
2401 
2402  /* Fill out the I/O Status Block */
2405  }
2407  {
2408  /* Get the exception code */
2410  }
2411  _SEH2_END;
2412 
2413  /* Release the file lock, dereference the file and return */
2416  return Status;
2417  }
2418  }
2419  else
2420  {
2421  /* Use local event */
2423  if (!Event)
2424  {
2427  }
2429  LocalEvent = TRUE;
2430  }
2431 
2432  /* Check if FastIO is possible for the two available information classes */
2433  FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
2434  if (FastIoDispatch != NULL &&
2437  {
2438  BOOLEAN Success = FALSE;
2439 
2441  {
2444  &KernelIosb,
2445  DeviceObject);
2446  }
2447  else
2448  {
2451  &KernelIosb,
2452  DeviceObject);
2453  }
2454 
2455  /* If call succeed */
2456  if (Success)
2457  {
2458  /* Write the IOSB back */
2459  _SEH2_TRY
2460  {
2461  *IoStatusBlock = KernelIosb;
2462  }
2464  {
2465  KernelIosb.Status = _SEH2_GetExceptionCode();
2466  }
2467  _SEH2_END;
2468 
2469  /* Free the event if we had one */
2470  if (LocalEvent)
2471  {
2473  }
2474 
2475  /* If FO was locked, unlock it */
2476  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2477  {
2479  }
2480 
2481  /* We're done with FastIO! */
2483  return KernelIosb.Status;
2484  }
2485  }
2486 
2487  /* Clear the File Object event */
2488  KeClearEvent(&FileObject->Event);
2489 
2490  /* Allocate the IRP */
2491  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
2492  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
2493 
2494  /* Set the IRP */
2495  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2496  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2497  Irp->RequestorMode = PreviousMode;
2498  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2499  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
2500  Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
2501  Irp->UserEvent = (LocalEvent) ? Event : NULL;
2502  Irp->AssociatedIrp.SystemBuffer = NULL;
2503  Irp->MdlAddress = NULL;
2504  Irp->UserBuffer = FileInformation;
2505 
2506  /* Set the Stack Data */
2507  StackPtr = IoGetNextIrpStackLocation(Irp);
2509  StackPtr->FileObject = FileObject;
2510 
2511  /* Enter SEH */
2512