ReactOS  0.4.14-dev-604-gcfdd483
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
 

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

◆ 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 1199 of file iofunc.c.

1204 {
1205  PIRP Irp;
1206  PIO_STACK_LOCATION StackPtr;
1208  IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p \n",
1209  FileObject, Mdl, Offset);
1210 
1211  /* Get the Device Object */
1213 
1214  /* Allocate IRP */
1216  /* If allocation failed, try to see whether we can use
1217  * the reserve IRP
1218  */
1219  if (Irp == NULL)
1220  {
1221  /* We will use it only for paging file */
1223  {
1226  }
1227  else
1228  {
1230  }
1231 
1232  /* If allocation failed (not a paging file or too big stack size)
1233  * Fail for real
1234  */
1235  if (Irp == NULL)
1236  {
1238  }
1239  }
1240 
1241  /* Get the Stack */
1242  StackPtr = IoGetNextIrpStackLocation(Irp);
1243 
1244  /* Create the IRP Settings */
1245  Irp->MdlAddress = Mdl;
1246  Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
1247  Irp->UserIosb = StatusBlock;
1248  Irp->UserEvent = Event;
1249  Irp->RequestorMode = KernelMode;
1250  Irp->Flags = IRP_PAGING_IO |
1251  IRP_NOCACHE |
1254  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1255  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1256 
1257  /* Set the Stack Settings */
1258  StackPtr->Parameters.Read.Length = MmGetMdlByteCount(Mdl);
1259  StackPtr->Parameters.Read.ByteOffset = *Offset;
1260  StackPtr->MajorFunction = IRP_MJ_READ;
1261  StackPtr->FileObject = FileObject;
1262 
1263  /* Call the Driver */
1264  return IoCallDriver(DeviceObject, Irp);
1265 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define MmGetMdlVirtualAddress(_Mdl)
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_NOCACHE
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define IO_API_DEBUG
Definition: io.h:21
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PIRP NTAPI IopAllocateReserveIrp(IN CCHAR StackSize)
Definition: irp.c:573
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define InterlockedExchangeAdd
Definition: interlocked.h:181
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:2647
volatile LONG IoPageReadIrpAllocationFailure
Definition: iofunc.c:20
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define IRP_INPUT_OPERATION
#define MmGetMdlByteCount(_Mdl)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_PAGING_IO
#define IRP_MJ_READ
Definition: rdpdr.c:46
BOOLEAN NTAPI MmIsFileObjectAPagingFile(PFILE_OBJECT FileObject)
Definition: pagefile.c:109
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define IRP_SYNCHRONOUS_PAGING_IO

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

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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

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 195 of file iofunc.c.

206 {
210  PIRP Irp;
211  PIO_STACK_LOCATION StackPtr;
212  PKEVENT EventObject = NULL;
213  BOOLEAN LockedForSynch = FALSE;
214  ULONG AccessType;
220 
221  PAGED_CODE();
222 
223  IOTRACE(IO_CTL_DEBUG, "Handle: %p. CTL: %lx. Type: %lx \n",
224  DeviceHandle, IoControlCode, IsDevIoCtl);
225 
226  /* Get the access type */
228 
229  /* Check if we came from user mode */
230  if (PreviousMode != KernelMode)
231  {
232  _SEH2_TRY
233  {
234  /* Probe the status block */
236 
237  /* Check if this is buffered I/O */
238  if (AccessType == METHOD_BUFFERED)
239  {
240  /* Check if we have an output buffer */
241  if (OutputBuffer)
242  {
243  /* Probe the output buffer */
246  sizeof(CHAR));
247  }
248  else
249  {
250  /* Make sure the caller can't fake this as we depend on this */
251  OutputBufferLength = 0;
252  }
253  }
254 
255  /* Check if we we have an input buffer I/O */
256  if (AccessType != METHOD_NEITHER)
257  {
258  /* Check if we have an input buffer */
259  if (InputBuffer)
260  {
261  /* Probe the input buffer */
263  }
264  else
265  {
266  /* Make sure the caller can't fake this as we depend on this */
267  InputBufferLength = 0;
268  }
269  }
270  }
272  {
273  /* Return the exception code */
275  }
276  _SEH2_END;
277  }
278 
279  /* Don't check for access rights right now, KernelMode can do anything */
281  0,
283  PreviousMode,
284  (PVOID*)&FileObject,
286  if (!NT_SUCCESS(Status)) return Status;
287 
288  /* Can't use an I/O completion port and an APC in the same time */
289  if ((FileObject->CompletionContext) && (UserApcRoutine))
290  {
291  /* Fail */
294  }
295 
296  /* Check if we from user mode */
297  if (PreviousMode != KernelMode)
298  {
299  /* Get the access mask */
300  DesiredAccess = (ACCESS_MASK)((IoControlCode >> 14) & 3);
301 
302  /* Check if we can open it */
303  if ((DesiredAccess != FILE_ANY_ACCESS) &&
304  (HandleInformation.GrantedAccess & DesiredAccess) != DesiredAccess)
305  {
306  /* Dereference the file object and fail */
308  return STATUS_ACCESS_DENIED;
309  }
310  }
311 
312  /* Check for an event */
313  if (Event)
314  {
315  /* Reference it */
319  PreviousMode,
320  (PVOID*)&EventObject,
321  NULL);
322  if (!NT_SUCCESS(Status))
323  {
324  /* Dereference the file object and fail */
326  return Status;
327  }
328 
329  /* Clear it */
330  KeClearEvent(EventObject);
331  }
332 
333  /* Check if this is a file that was opened for Synch I/O */
334  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
335  {
336  /* Lock it */
338  if (Status != STATUS_SUCCESS)
339  {
340  if (EventObject) ObDereferenceObject(EventObject);
342  return Status;
343  }
344 
345  /* Remember to unlock later */
346  LockedForSynch = TRUE;
347  }
348 
349  /* Check if this is a direct open or not */
350  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
351  {
352  /* It's a direct open, get the attached device */
354  }
355  else
356  {
357  /* Otherwise get the related device */
359  }
360 
361  /* If this is a device I/O, try to do it with FastIO path */
362  if (IsDevIoCtl)
363  {
364  PFAST_IO_DISPATCH FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
365 
366  /* Check whether FSD is FastIO aware and provide an appropriate routine */
368  {
369  IO_STATUS_BLOCK KernelIosb;
370 
371  /* If we have an output buffer coming from usermode */
373  {
374  /* Probe it according to its usage */
375  _SEH2_TRY
376  {
377  if (AccessType == METHOD_IN_DIRECT)
378  {
380  }
381  else if (AccessType == METHOD_OUT_DIRECT)
382  {
384  }
385  }
387  {
388  /* Cleanup after exception and return */
390 
391  /* Return the exception code */
393  }
394  _SEH2_END;
395  }
396 
397  /* If we are dismounting a volume, increase the dismount count */
399  {
400  InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
401  }
402 
403  /* Call the FSD */
405  TRUE,
406  InputBuffer,
408  OutputBuffer,
411  &KernelIosb,
412  DeviceObject))
413  {
414  IO_COMPLETION_CONTEXT CompletionInfo = { NULL, NULL };
415 
416  /* Write the IOSB back */
417  _SEH2_TRY
418  {
419  *IoStatusBlock = KernelIosb;
420 
421  }
423  {
424  KernelIosb.Status = _SEH2_GetExceptionCode();
425  }
426  _SEH2_END;
427 
428  /* Backup our complete context in case it exists */
429  if (FileObject->CompletionContext)
430  {
431  CompletionInfo = *(FileObject->CompletionContext);
432  }
433 
434  /* If we had an event, signal it */
435  if (Event)
436  {
437  KeSetEvent(EventObject, IO_NO_INCREMENT, FALSE);
438  ObDereferenceObject(EventObject);
439  }
440 
441  /* If FO was locked, unlock it */
442  if (LockedForSynch)
443  {
445  }
446 
447  /* Set completion if required */
448  if (CompletionInfo.Port != NULL && UserApcContext != NULL)
449  {
450  if (!NT_SUCCESS(IoSetIoCompletion(CompletionInfo.Port,
451  CompletionInfo.Key,
452  UserApcContext,
453  KernelIosb.Status,
454  KernelIosb.Information,
455  TRUE)))
456  {
458  }
459  }
460 
461  /* We're done with FastIO! */
463  return KernelIosb.Status;
464  }
465  }
466  }
467 
468  /* Clear the event */
469  KeClearEvent(&FileObject->Event);
470 
471  /* Allocate IRP */
473  if (!Irp) return IopCleanupFailedIrp(FileObject, EventObject, NULL);
474 
475  /* Setup the IRP */
476  Irp->UserIosb = IoStatusBlock;
477  Irp->UserEvent = EventObject;
478  Irp->Overlay.AsynchronousParameters.UserApcRoutine = UserApcRoutine;
479  Irp->Overlay.AsynchronousParameters.UserApcContext = UserApcContext;
480  Irp->Cancel = FALSE;
481  Irp->CancelRoutine = NULL;
482  Irp->PendingReturned = FALSE;
483  Irp->RequestorMode = PreviousMode;
484  Irp->MdlAddress = NULL;
485  Irp->AssociatedIrp.SystemBuffer = NULL;
486  Irp->Flags = 0;
487  Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
488  Irp->Tail.Overlay.OriginalFileObject = FileObject;
489  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
490 
491  /* Set stack location settings */
492  StackPtr = IoGetNextIrpStackLocation(Irp);
493  StackPtr->FileObject = FileObject;
494  StackPtr->MajorFunction = IsDevIoCtl ?
497  StackPtr->MinorFunction = 0; /* Minor function 0 is IRP_MN_USER_FS_REQUEST */
498  StackPtr->Control = 0;
499  StackPtr->Flags = 0;
500  StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
501 
502  /* Set the IOCTL Data */
503  StackPtr->Parameters.DeviceIoControl.IoControlCode = IoControlCode;
504  StackPtr->Parameters.DeviceIoControl.InputBufferLength = InputBufferLength;
505  StackPtr->Parameters.DeviceIoControl.OutputBufferLength =
507 
509 
510  /* Handle the Methods */
511  switch (AccessType)
512  {
513  /* Buffered I/O */
514  case METHOD_BUFFERED:
515 
516  /* Enter SEH for allocations */
517  _SEH2_TRY
518  {
519  /* Select the right Buffer Length */
522 
523  /* Make sure there is one */
524  if (BufferLength)
525  {
526  /* Allocate the System Buffer */
527  Irp->AssociatedIrp.SystemBuffer =
529  BufferLength,
530  TAG_SYS_BUF);
531 
532  /* Check if we got a buffer */
533  if (InputBuffer)
534  {
535  /* Copy into the System Buffer */
536  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
537  InputBuffer,
539  }
540 
541  /* Write the flags */
543  if (OutputBuffer) Irp->Flags |= IRP_INPUT_OPERATION;
544 
545  /* Save the Buffer */
546  Irp->UserBuffer = OutputBuffer;
547  }
548  else
549  {
550  /* Clear the Flags and Buffer */
551  Irp->UserBuffer = NULL;
552  }
553  }
555  {
556  /* Cleanup after exception and return */
559  }
560  _SEH2_END;
561  break;
562 
563  /* Direct I/O */
564  case METHOD_IN_DIRECT:
565  case METHOD_OUT_DIRECT:
566 
567  /* Enter SEH */
568  _SEH2_TRY
569  {
570  /* Check if we got an input buffer */
571  if ((InputBufferLength) && (InputBuffer))
572  {
573  /* Allocate the System Buffer */
574  Irp->AssociatedIrp.SystemBuffer =
577  TAG_SYS_BUF);
578 
579  /* Copy into the System Buffer */
580  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
581  InputBuffer,
583 
584  /* Write the flags */
586  }
587 
588  /* Check if we got an output buffer */
589  if (OutputBufferLength)
590  {
591  /* Allocate the System Buffer */
592  Irp->MdlAddress = IoAllocateMdl(OutputBuffer,
594  FALSE,
595  FALSE,
596  Irp);
597  if (!Irp->MdlAddress)
598  {
599  /* Raise exception we'll catch */
601  }
602 
603  /* Do the probe */
604  MmProbeAndLockPages(Irp->MdlAddress,
605  PreviousMode,
606  (AccessType == METHOD_IN_DIRECT) ?
608  }
609  }
611  {
612  /* Cleanup after exception and return */
615  }
616  _SEH2_END;
617  break;
618 
619  case METHOD_NEITHER:
620 
621  /* Just save the Buffer */
622  Irp->UserBuffer = OutputBuffer;
623  StackPtr->Parameters.DeviceIoControl.Type3InputBuffer = InputBuffer;
624  }
625 
626  /* Use deferred completion for FS I/O */
627  if (!IsDevIoCtl)
628  {
629  Irp->Flags |= IRP_DEFER_IO_COMPLETION;
630  }
631 
632  /* If we are dismounting a volume, increaase the dismount count */
634  {
635  InterlockedIncrement((PLONG)&SharedUserData->DismountCount);
636  }
637 
638  /* Perform the call */
640  Irp,
641  FileObject,
642  !IsDevIoCtl,
643  PreviousMode,
644  LockedForSynch,
646 }
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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:2931
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#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:1744
_In_ PIRP Irp
Definition: csq.h:116
#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:96
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
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
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
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:22
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
_SEH2_TRY
Definition: create.c:4250
#define METHOD_IN_DIRECT
Definition: nt_native.h:595
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
#define IO_CTL_DEBUG
Definition: io.h:22
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
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:496
#define METHOD_NEITHER
Definition: nt_native.h:597
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
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
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:76
#define IRP_MJ_FILE_SYSTEM_CONTROL
_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:1955
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:1700
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#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:935
#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
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define TAG_SYS_BUF
Definition: tag.h:80
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define IRP_DEFER_IO_COMPLETION
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
signed int * PLONG
Definition: retypes.h:5
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

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 }
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
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 PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define STATUS_USER_APC
Definition: ntstatus.h:78
_SEH2_END
Definition: create.c:4424
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

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

◆ IopGetBasicInformationFile()

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

Definition at line 837 of file iofunc.c.

839 {
843 
844  PAGED_CODE();
845 
846  /* Try to do it the fast way if possible */
848  if (DeviceObject->DriverObject->FastIoDispatch != NULL &&
849  DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo != NULL &&
850  DeviceObject->DriverObject->FastIoDispatch->FastIoQueryBasicInfo(FileObject,
851  ((FileObject->Flags & FO_SYNCHRONOUS_IO) != 0),
852  BasicInfo,
853  &IoStatusBlock,
854  DeviceObject))
855  {
856  return IoStatusBlock.Status;
857  }
858 
859  /* In case it failed, fall back to IRP-based method */
861 }
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define PAGED_CODE()
Definition: video.h:57
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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:775

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 1082 of file iofunc.c.

1085 {
1086  KIRQL OldIrql;
1087  NTSTATUS Status;
1088  UNICODE_STRING DriverName;
1090 
1091  /* Make sure the structure is consistent (ie, driver name fits into the buffer) */
1092  if (Length - FIELD_OFFSET(FILE_FS_DRIVER_PATH_INFORMATION, DriverName) < DriverPathInfo->DriverNameLength)
1093  {
1094  return STATUS_INVALID_PARAMETER;
1095  }
1096 
1097  /* Setup the whole driver name */
1098  DriverName.Length = DriverPathInfo->DriverNameLength;
1099  DriverName.MaximumLength = DriverPathInfo->DriverNameLength;
1100  DriverName.Buffer = &DriverPathInfo->DriverName[0];
1101 
1102  /* Ask Ob for such driver */
1103  Status = ObReferenceObjectByName(&DriverName,
1105  NULL,
1106  0,
1108  KernelMode,
1109  NULL,
1110  (PVOID*)&DriverObject);
1111  /* No such driver, bail out */
1112  if (!NT_SUCCESS(Status))
1113  {
1114  return Status;
1115  }
1116 
1117  /* Lock the devices database, we'll browse it */
1119  /* If we have a VPB, browse the stack from the volume */
1120  if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL)
1121  {
1122  DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->Vpb->DeviceObject, DriverObject);
1123  }
1124  /* Otherwise, do it from the normal device */
1125  else
1126  {
1127  DriverPathInfo->DriverInPath = IopVerifyDriverObjectOnStack(FileObject->DeviceObject, DriverObject);
1128  }
1130 
1131  /* No longer needed */
1133 
1134  return STATUS_SUCCESS;
1135 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
POBJECT_TYPE IoDriverObjectType
Definition: driver.c:32
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
Status
Definition: gdiplustypes.h:24
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
return STATUS_SUCCESS
Definition: btrfs.c:2938
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:411
static BOOLEAN IopVerifyDriverObjectOnStack(IN PDEVICE_OBJECT DeviceObject, IN PDRIVER_OBJECT DriverObject)
Definition: iofunc.c:1057

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 775 of file iofunc.c.

780 {
781  PIRP Irp;
782  KEVENT Event;
784  PIO_STACK_LOCATION Stack;
787 
788  PAGED_CODE();
789 
790  /* Allocate an IRP */
794  if (Irp == NULL)
795  {
798  }
799 
800  /* Init event */
802 
803  /* Setup the IRP */
804  Irp->UserIosb = &IoStatusBlock;
805  Irp->UserEvent = &Event;
806  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
807  Irp->RequestorMode = KernelMode;
808  Irp->AssociatedIrp.SystemBuffer = Buffer;
810  Irp->Tail.Overlay.OriginalFileObject = FileObject;
811  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
812 
815  Stack->FileObject = FileObject;
816  Stack->Parameters.QueryFile.FileInformationClass = FileInfoClass;
817  Stack->Parameters.QueryFile.Length = Length;
818 
819 
820  /* Queue the IRP */
822 
823  /* Call the driver */
825  if (Status == STATUS_PENDING)
826  {
829  }
830 
832  return Status;
833 }
#define IRP_OB_QUERY_NAME
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
#define PAGED_CODE()
Definition: video.h:57
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_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:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#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
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
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by IopGetBasicInformationFile(), and IopQueryNameInternal().

◆ IopGetFileMode()

static ULONG IopGetFileMode ( IN PFILE_OBJECT  FileObject)
static

Definition at line 1002 of file iofunc.c.

1003 {
1004  ULONG Mode = 0;
1005 
1006  if (FileObject->Flags & FO_WRITE_THROUGH)
1008 
1009  if (FileObject->Flags & FO_SEQUENTIAL_ONLY)
1011 
1014 
1015  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1016  {
1017  if (FileObject->Flags & FO_ALERTABLE_IO)
1019  else
1021  }
1022 
1023  if (FileObject->Flags & FO_DELETE_ON_CLOSE)
1025 
1026  return Mode;
1027 }
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
_In_ ULONG Mode
Definition: hubbusif.h:303
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1735
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
#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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FO_SEQUENTIAL_ONLY
Definition: iotypes.h:1737
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define FO_DELETE_ON_CLOSE
Definition: iotypes.h:1749
#define FO_ALERTABLE_IO
Definition: iotypes.h:1734
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define FO_WRITE_THROUGH
Definition: iotypes.h:1736

Referenced by NtQueryInformationFile().

◆ IopGetMountFlag()

static BOOLEAN IopGetMountFlag ( IN PDEVICE_OBJECT  DeviceObject)
static

Definition at line 1031 of file iofunc.c.

1032 {
1033  KIRQL OldIrql;
1034  PVPB Vpb;
1035  BOOLEAN Mounted;
1036 
1037  /* Assume not mounted */
1038  Mounted = FALSE;
1039 
1040  /* Check whether we have the mount flag */
1042 
1043  Vpb = DeviceObject->Vpb;
1044  if (Vpb != NULL &&
1045  BooleanFlagOn(Vpb->Flags, VPB_MOUNTED))
1046  {
1047  Mounted = TRUE;
1048  }
1049 
1051 
1052  return Mounted;
1053 }
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1209
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: iotypes.h:166
#define VPB_MOUNTED
Definition: iotypes.h:1764
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1220
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664

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 865 of file iofunc.c.

869 {
873  PIO_STACK_LOCATION Stack;
874  PFILE_OBJECT TargetFileObject;
876  FILE_BASIC_INFORMATION BasicInfo;
880 
881  PAGED_CODE();
882 
883  /* First, establish whether our target is a directory */
884  if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
885  {
887  if (!NT_SUCCESS(Status))
888  {
889  return Status;
890  }
891 
892  if (BasicInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
894  }
895  }
896 
897  /* Setup the string to the target */
898  FileName.Buffer = RenameInfo->FileName;
899  FileName.Length = RenameInfo->FileNameLength;
900  FileName.MaximumLength = RenameInfo->FileNameLength;
901 
903  &FileName,
905  RenameInfo->RootDirectory,
906  NULL);
907 
908  /* And open its parent directory
909  * Use hint if specified
910  */
912  {
913  PFILE_OBJECT_EXTENSION FileObjectExtension;
914 
916 
917  FileObjectExtension = FileObject->FileObjectExtension;
921  &IoStatusBlock,
922  NULL,
923  0,
925  FILE_OPEN,
927  NULL,
928  0,
930  NULL,
932  FileObjectExtension->TopDeviceObjectHint);
933  }
934  else
935  {
939  &IoStatusBlock,
940  NULL,
941  0,
943  FILE_OPEN,
945  NULL,
946  0,
948  NULL,
950  }
951 
952  if (!NT_SUCCESS(Status))
953  {
954  return Status;
955  }
956 
957  /* Once open, continue only if:
958  * Target exists and we're allowed to overwrite it
959  */
961  if (Stack->Parameters.SetFile.FileInformationClass == FileLinkInformation &&
962  !RenameInfo->ReplaceIfExists &&
964  {
967  }
968 
969  /* Now, we'll get the associated device of the target, to check for same device location
970  * So, get the FO first
971  */
975  KernelMode,
976  (PVOID *)&TargetFileObject,
978  if (!NT_SUCCESS(Status))
979  {
981  return Status;
982  }
983 
984  /* We can dereference, we have the handle */
985  ObDereferenceObject(TargetFileObject);
986  /* If we're not on the same device, error out **/
988  {
990  return STATUS_NOT_SAME_DEVICE;
991  }
992 
993  /* Return parent directory file object and handle */
994  Stack->Parameters.SetFile.FileObject = TargetFileObject;
995  *Handle = TargetHandle;
996 
997  return STATUS_SUCCESS;
998 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
PDEVICE_OBJECT TopDeviceObjectHint
Definition: io.h:98
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FILE_EXISTS
Definition: nt_native.h:772
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:508
#define STATUS_NOT_SAME_DEVICE
Definition: ntstatus.h:434
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1744
_In_ PIRP Irp
Definition: csq.h:116
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
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define PAGED_CODE()
Definition: video.h:57
#define FILE_SHARE_READ
Definition: compat.h:125
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:496
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:509
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_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:1955
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
NTSTATUS NTAPI IopGetBasicInformationFile(IN PFILE_OBJECT FileObject, OUT PFILE_BASIC_INFORMATION BasicInfo)
Definition: iofunc.c:837
#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:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
struct _FileName FileName
Definition: fatprocs.h:884
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define FO_OPENED_CASE_SENSITIVE
Definition: iotypes.h:1750
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define IO_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:6996
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE TargetHandle
Definition: obfuncs.h:429
ULONG ACCESS_MASK
Definition: nt_native.h:40

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  ASSERT(!Irp->PendingReturned);
153  IopCompleteRequest(&Irp->Tail.Apc,
154  &NormalRoutine,
155  &NormalContext,
156  (PVOID*)&FileObject,
157  &NormalContext);
159  }
160  }
161 
162  /* Check if this was synch I/O */
163  if (SynchIo)
164  {
165  /* Make sure the IRP was completed, but returned pending */
166  if (Status == STATUS_PENDING)
167  {
168  /* Wait for the IRP */
170  Executive,
171  PreviousMode,
172  (FileObject->Flags &
173  FO_ALERTABLE_IO) != 0,
174  NULL);
175  if ((Status == STATUS_ALERTED) || (Status == STATUS_USER_APC))
176  {
177  /* Abort the request */
179  }
180 
181  /* Set the final status */
182  Status = FileObject->FinalStatus;
183  }
184 
185  /* Release the file lock */
187  }
188 
189  /* Return status */
190  return Status;
191 }
VOID NTAPI IopCompleteRequest(IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
Definition: irp.c:238
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
VOID NTAPI IopAbortInterruptedIrp(IN PKEVENT EventObject, IN PIRP Irp)
Definition: irp.c:67
_In_ PIRP Irp
Definition: csq.h:116
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 PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOTRACE(x, fmt,...)
Definition: io.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
#define STATUS_USER_APC
Definition: ntstatus.h:78
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1734
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:77
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:632
#define APC_LEVEL
Definition: env_spec_w32.h:695

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 650 of file iofunc.c.

656 {
658  PIRP Irp;
660  PIO_STACK_LOCATION StackPtr;
661  BOOLEAN LocalEvent = FALSE;
662  KEVENT Event;
664  PAGED_CODE();
665  IOTRACE(IO_API_DEBUG, "Handle: %p. CTL: %lx. Type: %lx \n",
667 
668  /* Reference the object */
670 
671  /* Check if this is a file that was opened for Synch I/O */
672  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
673  {
674  /* Lock it */
676 
677  /* Use File Object event */
678  KeClearEvent(&FileObject->Event);
679  }
680  else
681  {
682  /* Use local event */
684  LocalEvent = TRUE;
685  }
686 
687  /* Get the Device Object */
689 
690  /* Allocate the IRP */
692  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
693 
694  /* Set the IRP */
695  Irp->Tail.Overlay.OriginalFileObject = FileObject;
696  Irp->RequestorMode = KernelMode;
697  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
698  Irp->UserIosb = &IoStatusBlock;
699  Irp->UserEvent = (LocalEvent) ? &Event : NULL;
700  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
701  Irp->Flags |= IRP_BUFFERED_IO;
702  Irp->AssociatedIrp.SystemBuffer = Information;
703  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
704 
705  /* Set the Stack Data */
706  StackPtr = IoGetNextIrpStackLocation(Irp);
709  StackPtr->FileObject = FileObject;
710 
711  /* Check which type this is */
712  if (File)
713  {
714  /* Set Parameters */
715  StackPtr->Parameters.QueryFile.FileInformationClass = InformationClass;
716  StackPtr->Parameters.QueryFile.Length = Length;
717  }
718  else
719  {
720  /* Set Parameters */
721  StackPtr->Parameters.QueryVolume.FsInformationClass = InformationClass;
722  StackPtr->Parameters.QueryVolume.Length = Length;
723  }
724 
725  /* Queue the IRP */
727 
728  /* Call the Driver */
730 
731  /* Check if this was synch I/O */
732  if (!LocalEvent)
733  {
734  /* Check if the request is pending */
735  if (Status == STATUS_PENDING)
736  {
737  /* Wait on the file object */
739  Executive,
740  KernelMode,
741  (FileObject->Flags &
742  FO_ALERTABLE_IO) != 0,
743  NULL);
744  if (Status == STATUS_ALERTED)
745  {
746  /* Abort the operation */
748  }
749 
750  /* Get the final status */
751  Status = FileObject->FinalStatus;
752  }
753 
754  /* Release the file lock */
756  }
757  else if (Status == STATUS_PENDING)
758  {
759  /* Wait on the local event and get the final status */
761  Executive,
762  KernelMode,
763  FALSE,
764  NULL);
766  }
767 
768  /* Return the Length and Status. ReturnedLength is NOT optional */
770  return Status;
771 }
#define TRUE
Definition: types.h:120
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
_In_ PIRP Irp
Definition: csq.h:116
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
#define PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#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:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#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
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1734
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:1714
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
Iosb Information
Definition: create.c:4377

Referenced by IoQueryFileInformation(), and IoQueryVolumeInformation().

◆ IopVerifyDriverObjectOnStack()

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

Definition at line 1057 of file iofunc.c.

1059 {
1060  PDEVICE_OBJECT StackDO;
1061 
1062  /* Browse our whole device stack, trying to find the appropriate driver */
1064  while (StackDO != NULL)
1065  {
1066  /* We've found the driver, return success */
1067  if (StackDO->DriverObject == DriverObject)
1068  {
1069  return TRUE;
1070  }
1071 
1072  /* Move to the next */
1073  StackDO = StackDO->AttachedDevice;
1074  }
1075 
1076  /* We only reach there if driver was not found */
1077  return FALSE;
1078 }
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase(IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:1485
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

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 1272 of file iofunc.c.

1277 {
1278  /* Call the shared routine */
1281  Length,
1284  TRUE);
1285 }
#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:650
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187

Referenced by IopParseDevice(), IopQueryNameInternal(), MmCreateCacheSection(), and MmCreateDataFileSection().

◆ 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 1292 of file iofunc.c.

1297 {
1298  /* Call the shared routine */
1301  Length,
1302  FsInformation,
1304  FALSE);
1305 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1329
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:650
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_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 1312 of file iofunc.c.

1316 {
1318  PIRP Irp;
1320  PIO_STACK_LOCATION StackPtr;
1321  BOOLEAN LocalEvent = FALSE;
1322  KEVENT Event;
1323  NTSTATUS Status;
1324  PAGED_CODE();
1325  IOTRACE(IO_API_DEBUG, "FileObject: %p. Class: %lx. Length: %lx \n",
1327 
1328  /* Reference the object */
1330 
1331  /* Check if this is a file that was opened for Synch I/O */
1332  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1333  {
1334  /* Lock it */
1336 
1337  /* Use File Object event */
1338  KeClearEvent(&FileObject->Event);
1339  }
1340  else
1341  {
1342  /* Use local event */
1344  LocalEvent = TRUE;
1345  }
1346 
1347  /* Get the Device Object */
1349 
1350  /* Allocate the IRP */
1352  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, NULL);
1353 
1354  /* Set the IRP */
1355  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1356  Irp->RequestorMode = KernelMode;
1357  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
1358  Irp->UserIosb = &IoStatusBlock;
1359  Irp->UserEvent = (LocalEvent) ? &Event : NULL;
1360  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
1361  Irp->Flags |= IRP_BUFFERED_IO;
1362  Irp->AssociatedIrp.SystemBuffer = FileInformation;
1363  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1364 
1365  /* Set the Stack Data */
1366  StackPtr = IoGetNextIrpStackLocation(Irp);
1368  StackPtr->FileObject = FileObject;
1369 
1370  /* Set Parameters */
1371  StackPtr->Parameters.SetFile.FileInformationClass = FileInformationClass;
1372  StackPtr->Parameters.SetFile.Length = Length;
1373 
1374  /* Queue the IRP */
1376 
1377  /* Call the Driver */
1379 
1380  /* Check if this was synch I/O */
1381  if (!LocalEvent)
1382  {
1383  /* Check if the request is pending */
1384  if (Status == STATUS_PENDING)
1385  {
1386  /* Wait on the file object */
1388  Executive,
1389  KernelMode,
1390  (FileObject->Flags &
1391  FO_ALERTABLE_IO) != 0,
1392  NULL);
1393  if (Status == STATUS_ALERTED)
1394  {
1395  /* Abort the operation */
1397  }
1398 
1399  /* Get the final status */
1400  Status = FileObject->FinalStatus;
1401  }
1402 
1403  /* Release the file lock */
1405  }
1406  else if (Status == STATUS_PENDING)
1407  {
1408  /* Wait on the local event and get the final status */
1410  Executive,
1411  KernelMode,
1412  FALSE,
1413  NULL);
1415  }
1416 
1417  /* Return the status */
1418  return Status;
1419 }
#define TRUE
Definition: types.h:120
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
_In_ PIRP Irp
Definition: csq.h:116
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 PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define IOTRACE(x, fmt,...)
Definition: io.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#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
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FO_ALERTABLE_IO
Definition: iotypes.h:1734
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:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Referenced by MmCreateCacheSection(), MmCreateDataFileSection(), MmCreateSection(), and MmExtendCacheSection().

◆ 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 1144 of file iofunc.c.

1149 {
1150  PIRP Irp;
1151  PIO_STACK_LOCATION StackPtr;
1153  IOTRACE(IO_API_DEBUG, "FileObject: %p. Mdl: %p. Offset: %p \n",
1154  FileObject, Mdl, Offset);
1155 
1156  /* Is the write originating from Cc? */
1157  if (FileObject->SectionObjectPointer != NULL &&
1158  FileObject->SectionObjectPointer->SharedCacheMap != NULL)
1159  {
1160  ++CcDataFlushes;
1162  }
1163 
1164  /* Get the Device Object */
1166 
1167  /* Allocate IRP */
1169  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
1170 
1171  /* Get the Stack */
1172  StackPtr = IoGetNextIrpStackLocation(Irp);
1173 
1174  /* Create the IRP Settings */
1175  Irp->MdlAddress = Mdl;
1176  Irp->UserBuffer = MmGetMdlVirtualAddress(Mdl);
1177  Irp->UserIosb = StatusBlock;
1178  Irp->UserEvent = Event;
1179  Irp->RequestorMode = KernelMode;
1181  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1182  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1183 
1184  /* Set the Stack Settings */
1185  StackPtr->Parameters.Write.Length = MmGetMdlByteCount(Mdl);
1186  StackPtr->Parameters.Write.ByteOffset = *Offset;
1187  StackPtr->MajorFunction = IRP_MJ_WRITE;
1188  StackPtr->FileObject = FileObject;
1189 
1190  /* Call the Driver */
1191  return IoCallDriver(DeviceObject, Irp);
1192 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define MmGetMdlVirtualAddress(_Mdl)
_In_ PIRP Irp
Definition: csq.h:116
ULONG CcDataFlushes
Definition: copy.c:51
#define IRP_NOCACHE
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define IO_API_DEBUG
Definition: io.h:21
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
ULONG CcDataPages
Definition: copy.c:50
#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:2647
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define MmGetMdlByteCount(_Mdl)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#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:2772
#define IRP_SYNCHRONOUS_PAGING_IO

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

◆ NtCancelDeviceWakeupRequest()

NTSTATUS NTAPI NtCancelDeviceWakeupRequest ( IN HANDLE  DeviceHandle)

Definition at line 4565 of file iofunc.c.

4566 {
4567  UNIMPLEMENTED;
4568  return STATUS_NOT_IMPLEMENTED;
4569 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

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 1428 of file iofunc.c.

1438 {
1439  /* Call the Generic Function */
1441  Event,
1442  UserApcRoutine,
1443  UserApcContext,
1444  IoStatusBlock,
1445  IoControlCode,
1446  InputBuffer,
1448  OutputBuffer,
1450  TRUE);
1451 }
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
CHAR InputBuffer[80]
Definition: conmgr.c:33
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
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:195
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
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 1485 of file iofunc.c.

1487 {
1489  PIRP Irp;
1490  PIO_STACK_LOCATION StackPtr;
1491  NTSTATUS Status;
1493  PKEVENT Event = NULL;
1494  BOOLEAN LocalEvent = FALSE;
1495  OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
1497  IO_STATUS_BLOCK KernelIosb;
1498  PAGED_CODE();
1499  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1500 
1501  if (PreviousMode != KernelMode)
1502  {
1503  /* Protect probes */
1504  _SEH2_TRY
1505  {
1506  /* Probe the I/O Status block */
1508  }
1510  {
1511  /* Return the exception code */
1513  }
1514  _SEH2_END;
1515  }
1516 
1517  /* Get the File Object */
1519  0,
1521  PreviousMode,
1522  (PVOID*)&FileObject,
1523  &ObjectHandleInfo);
1524  if (!NT_SUCCESS(Status)) return Status;
1525 
1526  /*
1527  * Check if the handle has either FILE_WRITE_DATA or FILE_APPEND_DATA was
1528  * granted. However, if this is a named pipe, make sure we don't ask for
1529  * FILE_APPEND_DATA as it interferes with the FILE_CREATE_PIPE_INSTANCE
1530  * access right!
1531  */
1532  if (!(ObjectHandleInfo.GrantedAccess &
1533  ((!(FileObject->Flags & FO_NAMED_PIPE) ? FILE_APPEND_DATA : 0) |
1534  FILE_WRITE_DATA)))
1535  {
1536  /* We failed */
1538  return STATUS_ACCESS_DENIED;
1539  }
1540 
1541  /* Check if we should use Sync IO or not */
1542  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1543  {
1544  /* Lock it */
1546  if (Status != STATUS_SUCCESS)
1547  {
1549  return Status;
1550  }
1551  }
1552  else
1553  {
1554  /* Use local event */
1556  if (!Event)
1557  {
1558  /* We failed */
1561  }
1563  LocalEvent = TRUE;
1564  }
1565 
1566  /* Get the Device Object */
1568 
1569  /* Clear the event */
1570  KeClearEvent(&FileObject->Event);
1571 
1572  /* Allocate the IRP */
1574  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
1575 
1576  /* Set up the IRP */
1577  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
1578  Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
1579  Irp->UserEvent = (LocalEvent) ? Event : NULL;
1580  Irp->RequestorMode = PreviousMode;
1581  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1582  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1583  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
1584 
1585  /* Set up Stack Data */
1586  StackPtr = IoGetNextIrpStackLocation(Irp);
1587  StackPtr->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
1588  StackPtr->FileObject = FileObject;
1589 
1590  /* Call the Driver */
1592  Irp,
1593  FileObject,
1594  FALSE,
1595  PreviousMode,
1596  !LocalEvent,
1598 
1599  /* Check if this was async I/O */
1600  if (LocalEvent)
1601  {
1602  /* It was, finalize this request */
1604  Event,
1605  Irp,
1606  PreviousMode,
1607  &KernelIosb,
1608  IoStatusBlock);
1609  }
1610 
1611  /* Return the Status */
1612  return Status;
1613 }
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_IO
Definition: tag.h:69
#define IRP_MJ_FLUSH_BUFFERS
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
_SEH2_TRY
Definition: create.c:4250
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
HANDLE FileHandle
Definition: stats.c:38
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:496
ACCESS_MASK GrantedAccess
Definition: iotypes.h:158
#define FO_NAMED_PIPE
Definition: iotypes.h:1739
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
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:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IRP_SYNCHRONOUS_API
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
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

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 1458 of file iofunc.c.

1468 {
1469  /* Call the Generic Function */
1471  Event,
1472  UserApcRoutine,
1473  UserApcContext,
1474  IoStatusBlock,
1475  IoControlCode,
1476  InputBuffer,
1478  OutputBuffer,
1480  FALSE);
1481 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
CHAR InputBuffer[80]
Definition: conmgr.c:33
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
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:195
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
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 1754 of file iofunc.c.

1764 {
1766  PLARGE_INTEGER LocalLength = NULL;
1767  PIRP Irp;
1768  PIO_STACK_LOCATION StackPtr;
1770  PKEVENT Event = NULL;
1771  BOOLEAN LockedForSync = FALSE;
1773  LARGE_INTEGER CapturedByteOffset, CapturedLength;
1774  NTSTATUS Status;
1777  PAGED_CODE();
1778  CapturedByteOffset.QuadPart = 0;
1779  CapturedLength.QuadPart = 0;
1780  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1781 
1782  /* Get File Object */
1784  0,
1786  PreviousMode,
1787  (PVOID*)&FileObject,
1789  if (!NT_SUCCESS(Status)) return Status;
1790 
1791  /* Check if we're called from user mode */
1792  if (PreviousMode != KernelMode)
1793  {
1794  /* Must have either FILE_READ_DATA or FILE_WRITE_DATA access */
1795  if (!(HandleInformation.GrantedAccess &
1797  {
1799  return STATUS_ACCESS_DENIED;
1800  }
1801 
1802  /* Enter SEH for probing */
1803  _SEH2_TRY
1804  {
1805  /* Probe the I/O STatus block */
1807 
1808  /* Probe and capture the large integers */
1809  CapturedByteOffset = ProbeForReadLargeInteger(ByteOffset);
1810  CapturedLength = ProbeForReadLargeInteger(Length);
1811  }
1813  {
1814  /* Dereference the object and return exception code */
1817  }
1818  _SEH2_END;
1819  }
1820  else
1821  {
1822  /* Otherwise, capture them directly */
1823  CapturedByteOffset = *ByteOffset;
1824  CapturedLength = *Length;
1825  }
1826 
1827  /* Check if we have an event handle */
1828  if (EventHandle)
1829  {
1830  /* Reference it */
1834  PreviousMode,
1835  (PVOID *)&Event,
1836  NULL);
1837  if (Status != STATUS_SUCCESS) return Status;
1839  }
1840 
1841  /* Get the device object */
1843 
1844  /* Try to do it the FastIO way if possible */
1845  FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
1847  {
1848  IO_STATUS_BLOCK KernelIosb;
1849 
1851  &CapturedByteOffset,
1852  &CapturedLength,
1854  Key,
1856  ExclusiveLock,
1857  &KernelIosb,
1858  DeviceObject))
1859  {
1860  /* Write the IOSB back */
1861  _SEH2_TRY
1862  {
1863  *IoStatusBlock = KernelIosb;
1864  }
1866  {
1867  KernelIosb.Status = _SEH2_GetExceptionCode();
1868  }
1869  _SEH2_END;
1870 
1871  /* If we had an event, signal it */
1872  if (EventHandle)
1873  {
1876  }
1877 
1878  /* Set completion if required */
1879  if (FileObject->CompletionContext != NULL && ApcContext != NULL)
1880  {
1881  if (!NT_SUCCESS(IoSetIoCompletion(FileObject->CompletionContext->Port,
1882  FileObject->CompletionContext->Key,
1883  ApcContext,
1884  KernelIosb.Status,
1885  KernelIosb.Information,
1886  TRUE)))
1887  {
1889  }
1890  }
1891 
1892  FileObject->LockOperation = TRUE;
1893 
1894  /* We're done with FastIO! */
1896  return KernelIosb.Status;
1897  }
1898  }
1899 
1900  /* Check if we should use Sync IO or not */
1901  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1902  {
1903  /* Lock it */
1905  if (Status != STATUS_SUCCESS)
1906  {
1909  return Status;
1910  }
1911  LockedForSync = TRUE;
1912  }
1913 
1914  /* Clear File Object event */
1915  KeClearEvent(&FileObject->Event);
1916  FileObject->LockOperation = TRUE;
1917 
1918  /* Allocate the IRP */
1920  if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
1921 
1922  /* Set up the IRP */
1923  Irp->RequestorMode = PreviousMode;
1924  Irp->UserIosb = IoStatusBlock;
1925  Irp->UserEvent = Event;
1926  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1927  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1928  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
1929  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
1930 
1931  /* Set up Stack Data */
1932  StackPtr = IoGetNextIrpStackLocation(Irp);
1933  StackPtr->MajorFunction = IRP_MJ_LOCK_CONTROL;
1934  StackPtr->MinorFunction = IRP_MN_LOCK;
1935  StackPtr->FileObject = FileObject;
1936 
1937  /* Allocate local buffer */
1938  LocalLength = ExAllocatePoolWithTag(NonPagedPool,
1939  sizeof(LARGE_INTEGER),
1940  TAG_LOCK);
1941  if (!LocalLength)
1942  {
1943  /* Allocating failed, clean up and return failure */
1946  }
1947 
1948  /* Set the length */
1949  *LocalLength = CapturedLength;
1950  Irp->Tail.Overlay.AuxiliaryBuffer = (PVOID)LocalLength;
1951  StackPtr->Parameters.LockControl.Length = LocalLength;
1952 
1953  /* Set Parameters */
1954  StackPtr->Parameters.LockControl.ByteOffset = CapturedByteOffset;
1955  StackPtr->Parameters.LockControl.Key = Key;
1956 
1957  /* Set Flags */
1958  if (FailImmediately) StackPtr->Flags = SL_FAIL_IMMEDIATELY;
1959  if (ExclusiveLock) StackPtr->Flags |= SL_EXCLUSIVE_LOCK;
1960 
1961  /* Perform the call */
1963  Irp,
1964  FileObject,
1965  FALSE,
1966  PreviousMode,
1967  LockedForSync,
1969 }
#define TAG_LOCK
Definition: tag.h:46
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
#define KeGetPreviousMode()
Definition: ketypes.h:1107
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
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
#define PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
_SEH2_TRY
Definition: create.c:4250
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
HANDLE FileHandle
Definition: stats.c:38
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:496
#define FILE_READ_DATA
Definition: nt_native.h:628
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
Definition: fatprocs.h:2697
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define FILE_WRITE_DATA
Definition: nt_native.h:631
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ProbeForReadLargeInteger(Ptr)
Definition: probe.h:75
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
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:719
#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:1696
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define SL_EXCLUSIVE_LOCK
Definition: iotypes.h:1790
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define IRP_MN_LOCK
Definition: iotypes.h:4054
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
Definition: fatprocs.h:2697
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#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:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
#define SL_FAIL_IMMEDIATELY
Definition: iotypes.h:1789
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

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 1620 of file iofunc.c.

1629 {
1630  PIRP Irp;
1631  PKEVENT Event = NULL;
1634  PIO_STACK_LOCATION IoStack;
1636  NTSTATUS Status;
1637  BOOLEAN LockedForSync = FALSE;
1638  PAGED_CODE();
1639  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
1640 
1641  /* Check if we're called from user mode */
1642  if (PreviousMode != KernelMode)
1643  {
1644  /* Enter SEH for probing */
1645  _SEH2_TRY
1646  {
1647  /* Probe the I/O STatus block */
1649 
1650  /* Probe the buffer */
1652  }
1654  {
1655  /* Return the exception code */
1657  }
1658  _SEH2_END;
1659 
1660  /* Check if CompletionFilter is valid */
1662  {
1663  return STATUS_INVALID_PARAMETER;
1664  }
1665  }
1666 
1667  /* Get File Object */
1671  PreviousMode,
1672  (PVOID*)&FileObject,
1673  NULL);
1674  if (!NT_SUCCESS(Status)) return Status;
1675 
1676  /* Check if we have an event handle */
1677  if (EventHandle)
1678  {
1679  /* Reference it */
1683  PreviousMode,
1684  (PVOID *)&Event,
1685  NULL);
1686  if (Status != STATUS_SUCCESS)
1687  {
1689  return Status;
1690  }
1692  }
1693 
1694  /* Check if we should use Sync IO or not */
1695  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
1696  {
1697  /* Lock it */
1699  if (Status != STATUS_SUCCESS)
1700  {
1703  return Status;
1704  }
1705  LockedForSync = TRUE;
1706  }
1707 
1708  /* Clear File Object event */
1709  KeClearEvent(&FileObject->Event);
1710 
1711  /* Get the device object */
1713 
1714  /* Allocate the IRP */
1716  if (!Irp) return IopCleanupFailedIrp(FileObject, Event, NULL);
1717 
1718  /* Set up the IRP */
1719  Irp->RequestorMode = PreviousMode;
1720  Irp->UserIosb = IoStatusBlock;
1721  Irp->UserEvent = Event;
1722  Irp->UserBuffer = Buffer;
1723  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1724  Irp->Tail.Overlay.OriginalFileObject = FileObject;
1725  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
1726  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
1727 
1728  /* Set up Stack Data */
1729  IoStack = IoGetNextIrpStackLocation(Irp);
1732  IoStack->FileObject = FileObject;
1733 
1734  /* Set parameters */
1735  IoStack->Parameters.NotifyDirectory.CompletionFilter = CompletionFilter;
1736  IoStack->Parameters.NotifyDirectory.Length = BufferSize;
1737  if (WatchTree) IoStack->Flags = SL_WATCH_TREE;
1738 
1739  /* Perform the call */
1741  Irp,
1742  FileObject,
1743  FALSE,
1744  PreviousMode,
1745  LockedForSync,
1747 }
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY
Definition: rdpdr.c:56
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define TRUE
Definition: types.h:120
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
#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:2239
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
#define PAGED_CODE()
Definition: video.h:57
#define IO_API_DEBUG
Definition: io.h:21
_SEH2_TRY
Definition: create.c:4250
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
HANDLE FileHandle
Definition: stats.c:38
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:496
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
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:719
#define IOTRACE(x, fmt,...)
Definition: io.h:47
#define SL_WATCH_TREE
Definition: iotypes.h:1796
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG CompletionFilter
Definition: fltkernel.h:2239
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:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define FILE_NOTIFY_VALID_MASK
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

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 1976 of file iofunc.c.

1987 {
1988  PIRP Irp;
1991  PIO_STACK_LOCATION StackPtr;
1993  NTSTATUS Status;
1994  BOOLEAN LockedForSynch = FALSE;
1995  PKEVENT Event = NULL;
1996  volatile PVOID AuxBuffer = NULL;
1997  PMDL Mdl;
1998  UNICODE_STRING CapturedFileName;
1999  PUNICODE_STRING SearchPattern;
2000  PAGED_CODE();
2001  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
2002 
2003  /* Check if we came from user mode */
2004  if (PreviousMode != KernelMode)
2005  {
2006  /* Enter SEH for probing */
2007  _SEH2_TRY
2008  {
2009  /* Probe the I/O Status Block */
2011 
2012  /* Probe the file information */
2014 
2015  /* Check if we have a file name */
2016  if (FileName)
2017  {
2018  /* Capture it */
2019  CapturedFileName = ProbeForReadUnicodeString(FileName);
2020  if (CapturedFileName.Length)
2021  {
2022  /* Probe its buffer */
2023  ProbeForRead(CapturedFileName.Buffer,
2024  CapturedFileName.Length,
2025  1);
2026  }
2027 
2028  /* Allocate the auxiliary buffer */
2029  AuxBuffer = ExAllocatePoolWithTag(NonPagedPool,
2030  CapturedFileName.Length +
2031  sizeof(UNICODE_STRING),
2032  TAG_SYSB);
2033  RtlCopyMemory((PVOID)((ULONG_PTR)AuxBuffer +
2034  sizeof(UNICODE_STRING)),
2035  CapturedFileName.Buffer,
2036  CapturedFileName.Length);
2037 
2038  /* Setup the search pattern */
2039  SearchPattern = (PUNICODE_STRING)AuxBuffer;
2040  SearchPattern->Buffer = (PWCHAR)((ULONG_PTR)AuxBuffer +
2041  sizeof(UNICODE_STRING));
2042  SearchPattern->Length = CapturedFileName.Length;
2043  SearchPattern->MaximumLength = CapturedFileName.Length;
2044  }
2045  }
2047  {
2048  /* Free buffer and return the exception code */
2049  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2051  }
2052  _SEH2_END;
2053  }
2054 
2055  /* Get File Object */
2059  PreviousMode,
2060  (PVOID *)&FileObject,
2061  NULL);
2062  if (!NT_SUCCESS(Status))
2063  {
2064  /* Fail */
2065  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2066  return Status;
2067  }
2068 
2069  /* Are there two associated completion routines? */
2070  if (FileObject->CompletionContext != NULL && ApcRoutine != NULL)
2071  {
2073  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2074  return STATUS_INVALID_PARAMETER;
2075  }
2076 
2077  /* Check if we have an even handle */
2078  if (EventHandle)
2079  {
2080  /* Get its pointer */
2084  PreviousMode,
2085  (PVOID *)&Event,
2086  NULL);
2087  if (!NT_SUCCESS(Status))
2088  {
2089  /* Fail */
2090  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2092  return Status;
2093  }
2094 
2095  /* Clear it */
2097  }
2098 
2099  /* Check if this is a file that was opened for Synch I/O */
2100  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2101  {
2102  /* Lock it */
2104  if (Status != STATUS_SUCCESS)
2105  {
2108  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2109  return Status;
2110  }
2111 
2112  /* Remember to unlock later */
2113  LockedForSynch = TRUE;
2114  }
2115 
2116  /* Get the device object */
2118 
2119  /* Clear the File Object's event */
2120  KeClearEvent(&FileObject->Event);
2121 
2122  /* Allocate the IRP */
2124  if (!Irp) return IopCleanupFailedIrp(FileObject, EventHandle, AuxBuffer);
2125 
2126  /* Set up the IRP */
2127  Irp->RequestorMode = PreviousMode;
2128  Irp->UserIosb = IoStatusBlock;
2129  Irp->UserEvent = Event;
2130  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2131  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2132  Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
2133  Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
2134  Irp->MdlAddress = NULL;
2135  Irp->Tail.Overlay.AuxiliaryBuffer = AuxBuffer;
2136  Irp->AssociatedIrp.SystemBuffer = NULL;
2137 
2138  /* Check if this is buffered I/O */
2140  {
2141  /* Allocate a buffer */
2142  Irp->AssociatedIrp.SystemBuffer = ExAllocatePoolWithTag(NonPagedPool,
2143  Length,
2144  TAG_SYSB);
2145  if (!Irp->AssociatedIrp.SystemBuffer)
2146  {
2147  /* Allocating failed, clean up and return the exception code */
2149  if (AuxBuffer) ExFreePoolWithTag(AuxBuffer, TAG_SYSB);
2150 
2151  /* Return the exception code */
2153  }
2154 
2155  /* Set the buffer and flags */
2156  Irp->UserBuffer = FileInformation;
2157  Irp->Flags = (IRP_BUFFERED_IO |
2160  }
2161  else if (DeviceObject->Flags & DO_DIRECT_IO)
2162  {
2163  _SEH2_TRY
2164  {
2165  /* Allocate an MDL */
2169  }
2171  {
2172  /* Allocating failed, clean up and return the exception code */
2175  }
2176  _SEH2_END;
2177  }
2178  else
2179  {
2180  /* No allocation flags, and use the buffer directly */
2181  Irp->UserBuffer = FileInformation;
2182  }
2183 
2184  /* Set up Stack Data */
2185  StackPtr = IoGetNextIrpStackLocation(Irp);
2186  StackPtr->FileObject = FileObject;
2189 
2190  /* Set Parameters */
2191  StackPtr->Parameters.QueryDirectory.FileInformationClass =
2193  StackPtr->Parameters.QueryDirectory.FileName = AuxBuffer;
2194  StackPtr->Parameters.QueryDirectory.FileIndex = 0;
2195  StackPtr->Parameters.QueryDirectory.Length = Length;
2196  StackPtr->Flags = 0;
2197  if (RestartScan) StackPtr->Flags = SL_RESTART_SCAN;
2199 
2200  /* Set deferred I/O */
2201  Irp->Flags |= IRP_DEFER_IO_COMPLETION;
2202 
2203  /* Perform the call */
2205  Irp,
2206  FileObject,
2207  TRUE,
2208  PreviousMode,
2209  LockedForSynch,
2211 }
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define ProbeForWriteIoStatusBlock(Ptr)
Definition: probe.h:52
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ BOOLEAN _In_ ULONG _In_opt_ PULONG _In_ BOOLEAN RestartScan
Definition: fltkernel.h:2298
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PIRP Irp
Definition: csq.h:116
#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:2295
#define ExRaiseStatus
Definition: ntoskrnl.h:96
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:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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:54
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
POBJECT_TYPE ExEventObjectType
Definition: event.c:22
#define PAGED_CODE()
Definition: video.h:57
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define IO_API_DEBUG
Definition: io.h:21
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1733
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
HANDLE FileHandle
Definition: stats.c:38
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:496
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1955
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:719
#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:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define SL_RETURN_SINGLE_ENTRY
Definition: iotypes.h:1793
_SEH2_END
Definition: create.c:4424
#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:935
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define SL_RESTART_SCAN
Definition: iotypes.h:1792
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
struct _UNICODE_STRING UNICODE_STRING
#define TAG_SYSB
Definition: tag.h:105
#define IRP_DEALLOCATE_BUFFER
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:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define IRP_DEFER_IO_COMPLETION
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

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 2218 of file iofunc.c.

2227 {
2228  UNIMPLEMENTED;
2229  return STATUS_NOT_IMPLEMENTED;
2230 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

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 2237 of file iofunc.c.

2242 {
2245  NTSTATUS Status;
2246  PIRP Irp;
2248  PIO_STACK_LOCATION StackPtr;
2250  PKEVENT Event = NULL;
2251  BOOLEAN LocalEvent = FALSE;
2252  PKNORMAL_ROUTINE NormalRoutine;
2253  PVOID NormalContext;
2254  KIRQL OldIrql;
2255  IO_STATUS_BLOCK KernelIosb;
2256  BOOLEAN CallDriver = TRUE;
2257  PFILE_ACCESS_INFORMATION AccessBuffer;
2258  PFILE_MODE_INFORMATION ModeBuffer;
2259  PFILE_ALIGNMENT_INFORMATION AlignmentBuffer;
2260  PFILE_ALL_INFORMATION AllBuffer;
2262  PAGED_CODE();
2263  IOTRACE(IO_API_DEBUG, "FileHandle: %p\n", FileHandle);
2264 
2265  /* Check if we're called from user mode */
2266  if (PreviousMode != KernelMode)
2267  {
2268  /* Validate the information class */
2269  if ((FileInformationClass < 0) ||
2272  {
2273  /* Invalid class */
2275  }
2276 
2277  /* Validate the length */
2279  {
2280  /* Invalid length */
2282  }
2283 
2284  /* Enter SEH for probing */
2285  _SEH2_TRY
2286  {
2287  /* Probe the I/O Status block */
2289 
2290  /* Probe the information */
2292  }
2294  {
2295  /* Return the exception code */
2297  }
2298  _SEH2_END;
2299  }
2300 #if DBG
2301  else
2302  {
2303  /* Validate the information class */
2304  if ((FileInformationClass < 0) ||
2307  {
2308  /* Invalid class */
2310  }
2311 
2312  /* Validate the length */
2314  {
2315  /* Invalid length */
2317  }
2318  }
2319 #endif
2320 
2321  /* Reference the Handle */
2326  PreviousMode,
2327  (PVOID *)&FileObject,
2329  if (!NT_SUCCESS(Status)) return Status;
2330 
2331  /* Check if this is a direct open or not */
2332  if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
2333  {
2334  /* Get the device object */
2335  DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
2336  }
2337  else
2338  {
2339  /* Get the device object */
2341  }
2342 
2343  /* Check if this is a file that was opened for Synch I/O */
2344  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2345  {
2346  /* Lock it */
2348  if (Status != STATUS_SUCCESS)
2349  {
2351  return Status;
2352  }
2353 
2354  /* Check if the caller just wants the position */
2356  {
2357  /* Protect write in SEH */
2358  _SEH2_TRY
2359  {
2360  /* Write the offset */
2362  CurrentByteOffset = FileObject->CurrentByteOffset;
2363 
2364  /* Fill out the I/O Status Block */
2367  }
2369  {
2370  /* Get the exception code */
2372  }
2373  _SEH2_END;
2374 
2375  /* Release the file lock, dereference the file and return */
2378  return Status;
2379  }
2380  }
2381  else
2382  {
2383  /* Use local event */
2385  if (!Event)
2386  {
2389  }
2391  LocalEvent = TRUE;
2392  }
2393 
2394  /* Check if FastIO is possible for the two available information classes */
2395  FastIoDispatch = DeviceObject->DriverObject->FastIoDispatch;
2396  if (FastIoDispatch != NULL &&
2399  {
2400  BOOLEAN Success = FALSE;
2401 
2403  {
2406  &KernelIosb,
2407  DeviceObject);
2408  }
2409  else
2410  {
2413  &KernelIosb,
2414  DeviceObject);
2415  }
2416 
2417  /* If call succeed */
2418  if (Success)
2419  {
2420  /* Write the IOSB back */
2421  _SEH2_TRY
2422  {
2423  *IoStatusBlock = KernelIosb;
2424  }
2426  {
2427  KernelIosb.Status = _SEH2_GetExceptionCode();
2428  }
2429  _SEH2_END;
2430 
2431  /* Free the event if we had one */
2432  if (LocalEvent)
2433  {
2435  }
2436 
2437  /* If FO was locked, unlock it */
2438  if (FileObject->Flags & FO_SYNCHRONOUS_IO)
2439  {
2441  }
2442 
2443  /* We're done with FastIO! */
2445  return KernelIosb.Status;
2446  }
2447  }
2448 
2449  /* Clear the File Object event */
2450  KeClearEvent(&FileObject->Event);
2451 
2452  /* Allocate the IRP */
2454  if (!Irp) return IopCleanupFailedIrp(FileObject, NULL, Event);
2455 
2456  /* Set the IRP */
2457  Irp->Tail.Overlay.OriginalFileObject = FileObject;
2458  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2459  Irp->RequestorMode = PreviousMode;
2460  Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2461  Irp->Flags = (LocalEvent) ? IRP_SYNCHRONOUS_API : 0;
2462  Irp->UserIosb = (LocalEvent) ? &KernelIosb : IoStatusBlock;
2463  Irp->UserEvent = (LocalEvent) ? Event : NULL;
2464  Irp->AssociatedIrp.SystemBuffer = NULL;
2465  Irp->MdlAddress = NULL;
2466  Irp->UserBuffer = FileInformation;
2467 
2468  /* Set the Stack Data */
2469  StackPtr = IoGetNextIrpStackLocation(Irp);
2471  StackPtr->FileObject = FileObject;
2472 
2473  /* Enter SEH */
2474  _SEH2_TRY
2475  {
2476  /* Allocate a buffer */
2477  Irp->AssociatedIrp.SystemBuffer =
2479  Length,
2480  TAG_SYSB);
2481  }
2483  {
2484  /* Allocating failed, clean up and return the exception code */
2487  }
2488  _SEH2_END;
2489 
2490  /* Set the flags */
2491  Irp->Flags |= (IRP_BUFFERED_IO |
2495 
2496  /* Set the Parameters */
2497  StackPtr->Parameters.QueryFile.FileInformationClass = FileInformationClass;
2498  StackPtr->Parameters.QueryFile.Length = Length;
2499 
2500  /* Queue the IRP */
2502 
2503  /* Update operation counts */
2505 
2506  /* Fill in file information before calling the driver.
2507  See 'File System Internals' page 485.*/
2509  {
2510  AccessBuffer = Irp->AssociatedIrp.SystemBuffer;
2511  AccessBuffer->AccessFlags = HandleInformation.GrantedAccess;
2512  Irp->IoStatus.Information = sizeof(FILE_ACCESS_INFORMATION);
2513  CallDriver = FALSE;
2514  }
2516  {
2517  ModeBuffer = Irp->AssociatedIrp.SystemBuffer;
2518  ModeBuffer->Mode = IopGetFileMode(FileObject);
2519  Irp->IoStatus.Information = sizeof(FILE_MODE_INFORMATION);
2520  CallDriver = FALSE;
2521  }
2523  {
2524  AlignmentBuffer = Irp->AssociatedIrp.SystemBuffer;
2526  Irp->IoStatus.Information = sizeof(FILE_ALIGNMENT_INFORMATION);
2527  CallDriver = FALSE;
2528  }
2530  {
2531  AllBuffer = Irp->AssociatedIrp.SystemBuffer;
2532  AllBuffer->AccessInformation.AccessFlags = HandleInformation.GrantedAccess;
2535  Irp->IoStatus.Information = sizeof(FILE_ACCESS_INFORMATION) +
2536  sizeof(FILE_MODE_INFORMATION) +
2538  }
2539 
2540  /* Call the Driver */
2541  if (CallDriver)
2542  {
2544  }
2545  else
2546  {
2548  Irp->IoStatus.Status = STATUS_SUCCESS;
2549  }
2550 
2551  if (Status == STATUS_PENDING)
2552  {
2553  /* Check if this was async I/O */
2554  if (LocalEvent)
2555  {
2556  /* Then to a non-alertable wait */
2558  Executive,
2559  PreviousMode,
2560  FALSE,
2561  NULL);
2562  if (Status ==