コード例 #1
0
ファイル: VBoxUsbTool.cpp プロジェクト: miguelinux/vbox
VBOXUSBTOOL_DECL(NTSTATUS) VBoxUsbToolIoInternalCtlSendAsync(PDEVICE_OBJECT pDevObj, ULONG uCtl, void *pvArg1, void *pvArg2,
        PKEVENT pEvent, PIO_STATUS_BLOCK pIoStatus)
{
    NTSTATUS Status;
    PIRP pIrp;
    PIO_STACK_LOCATION pSl;
    KIRQL Irql = KeGetCurrentIrql();
    Assert(Irql == PASSIVE_LEVEL);

    pIrp = IoBuildDeviceIoControlRequest(uCtl, pDevObj, NULL, 0, NULL, 0, TRUE, pEvent, pIoStatus);
    if (!pIrp)
    {
        WARN(("IoBuildDeviceIoControlRequest failed!!\n"));
        pIoStatus->Status = STATUS_INSUFFICIENT_RESOURCES;
        pIoStatus->Information = 0;
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* Get the next stack location as that is used for the new irp */
    pSl = IoGetNextIrpStackLocation(pIrp);
    pSl->Parameters.Others.Argument1 = pvArg1;
    pSl->Parameters.Others.Argument2 = pvArg2;

    Status = IoCallDriver(pDevObj, pIrp);

    return Status;
}
int FlFdcDeviceIo(int DeviceObject , int Ioctl , int Data ) 
{ int ntStatus ;
  int irp ;
  int irpStack ;
  int doneEvent = __VERIFIER_nondet_int() ;
  int ioStatus = __VERIFIER_nondet_int() ;
  int irp__Tail__Overlay__CurrentStackLocation = __VERIFIER_nondet_int() ;
  int irpStack__Parameters__DeviceIoControl__Type3InputBuffer ;
  long __cil_tmp11 ;

  {
  {
  irp = IoBuildDeviceIoControlRequest(Ioctl, DeviceObject, 0, 0, 0, 0, 1, doneEvent,
                                      ioStatus);
  }
  if (irp == 0) {
    return (-1073741670);
  }
  {
  irpStack = irp__Tail__Overlay__CurrentStackLocation - 1;
  irpStack__Parameters__DeviceIoControl__Type3InputBuffer = Data;
  ntStatus = IofCallDriver(DeviceObject, irp);
  }
  {
  __cil_tmp11 = (long )ntStatus;
  if (__cil_tmp11 == 259L) {
    {
    KeWaitForSingleObject(doneEvent, Suspended, KernelMode, 0, 0);
    ntStatus = myStatus;
    }
  }
  }
  return (ntStatus);
}
}
コード例 #3
0
ファイル: filter.c プロジェクト: Tudi/PG2-firewall
static void setfilter(PacketFilterExtensionPtr fn) {
	UNICODE_STRING name;
	PDEVICE_OBJECT device=NULL;
	PFILE_OBJECT file=NULL;
	NTSTATUS status;

	RtlInitUnicodeString(&name, DD_IPFLTRDRVR_DEVICE_NAME);
	status=IoGetDeviceObjectPointer(&name, STANDARD_RIGHTS_ALL, &file, &device);

	if(NT_SUCCESS(status)) {
		KEVENT event;
		IO_STATUS_BLOCK iostatus;
		PF_SET_EXTENSION_HOOK_INFO hookinfo;
		PIRP irp;

		hookinfo.ExtensionPointer=fn;
		KeInitializeEvent(&event, NotificationEvent, FALSE);

		irp=IoBuildDeviceIoControlRequest(
			IOCTL_PF_SET_EXTENSION_POINTER, device, &hookinfo,
			sizeof(PF_SET_EXTENSION_HOOK_INFO), NULL, 0, FALSE, &event, &iostatus);

		if(irp && IoCallDriver(device, irp)==STATUS_PENDING)
			KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);

		if(file) ObDereferenceObject(file);
	}
}
コード例 #4
0
ファイル: fdo.c プロジェクト: HBelusca/NasuTek-Odyssey
NTSTATUS
SubmitUrbToRootHub(IN PDEVICE_OBJECT Pdo, IN ULONG IoControlCode, IN PURB Urb)
{
    PIRP Irp;
    IO_STATUS_BLOCK IoStatus;
    NTSTATUS Status;
    PIO_STACK_LOCATION Stack = NULL;

    Irp = IoBuildDeviceIoControlRequest(IoControlCode,
                                        Pdo,
                                        NULL, 0,
                                        NULL, 0,
                                        TRUE,
                                        NULL,
                                        &IoStatus);

    if (Irp == NULL)
    {
        DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n");
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* Initialize the status block before sending the IRP */
    IoStatus.Status = STATUS_NOT_SUPPORTED;
    IoStatus.Information = 0;

    Stack = IoGetNextIrpStackLocation(Irp);

    Stack->Parameters.Others.Argument1 = Urb;
    Stack->Parameters.Others.Argument2 = NULL;

    Status = IoCallDriver(Pdo, Irp);

    return Status;
}
コード例 #5
0
ファイル: Irp.cpp プロジェクト: daynix/UsbDk
NTSTATUS CIoControlIrp::Create(PDEVICE_OBJECT TargetDevice,
                               ULONG IoControlCode,
                               bool IsInternal,
                               PVOID InputBuffer,
                               ULONG InputBufferLength,
                               PVOID OutputBuffer,
                               ULONG OutputBufferLength)
{
    m_Irp = IoBuildDeviceIoControlRequest(IoControlCode,
                                          TargetDevice,
                                          InputBuffer,
                                          InputBufferLength,
                                          OutputBuffer,
                                          OutputBufferLength,
                                          IsInternal ? TRUE : FALSE,
                                          m_Event,
                                          &m_IoControlStatus);

    if (m_Irp == nullptr)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    ObReferenceObject(TargetDevice);
    m_TargetDevice = TargetDevice;
    return STATUS_SUCCESS;
}
コード例 #6
0
ファイル: tdi.c プロジェクト: hoangduit/reactos
NTSTATUS TdiQueryDeviceControl(
    PFILE_OBJECT FileObject,
    ULONG IoControlCode,
    PVOID InputBuffer,
    ULONG InputBufferLength,
    PVOID OutputBuffer,
    ULONG OutputBufferLength,
    PULONG Return)
/*
 * FUNCTION: Queries a device for information
 * ARGUMENTS:
 *     FileObject         = Pointer to file object
 *     IoControlCode      = I/O control code
 *     InputBuffer        = Pointer to buffer with input data
 *     InputBufferLength  = Length of InputBuffer
 *     OutputBuffer       = Address of buffer to place output data
 *     OutputBufferLength = Length of OutputBuffer
 * RETURNS:
 *     Status of operation
 */
{
    PDEVICE_OBJECT DeviceObject;
    IO_STATUS_BLOCK Iosb;
    NTSTATUS Status;
    KEVENT Event;
    PIRP Irp;

    if (!FileObject) {
        AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
        return STATUS_INVALID_PARAMETER;
    }

    DeviceObject = IoGetRelatedDeviceObject(FileObject);
    if (!DeviceObject) {
        AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
        return STATUS_INVALID_PARAMETER;
    }

    KeInitializeEvent(&Event, NotificationEvent, FALSE);

    Irp = IoBuildDeviceIoControlRequest(IoControlCode,
                                        DeviceObject,
                                        InputBuffer,
                                        InputBufferLength,
                                        OutputBuffer,
                                        OutputBufferLength,
                                        FALSE,
                                        &Event,
                                        &Iosb);
    if (!Irp)
        return STATUS_INSUFFICIENT_RESOURCES;

    Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);

    if (Return)
        *Return = Iosb.Information;

    return Status;
}
コード例 #7
0
ファイル: device.c プロジェクト: hoangduit/reactos
NTSTATUS
APIENTRY
EngFileIoControl(
    IN PFILE_OBJECT pFileObject,
    IN DWORD dwIoControlCode,
    IN PVOID lpInBuffer,
    IN SIZE_T nInBufferSize,
    OUT PVOID lpOutBuffer,
    IN SIZE_T nOutBufferSize,
    OUT PULONG_PTR lpInformation)
{
    PDEVICE_OBJECT pDeviceObject;
    KEVENT Event;
    PIRP pIrp;
    IO_STATUS_BLOCK Iosb;
    NTSTATUS Status;

    /* Get corresponding device object */
    pDeviceObject = IoGetRelatedDeviceObject(pFileObject);
    if (!pDeviceObject)
    {
        return STATUS_INVALID_PARAMETER;
    }

    /* Initialize an event */
    KeInitializeEvent(&Event, SynchronizationEvent, FALSE);

    /* Build IO control IRP */
    pIrp = IoBuildDeviceIoControlRequest(dwIoControlCode,
                                         pDeviceObject,
                                         lpInBuffer,
                                         (ULONG)nInBufferSize,
                                         lpOutBuffer,
                                         (ULONG)nOutBufferSize,
                                         FALSE,
                                         &Event,
                                         &Iosb);
    if (!pIrp)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* Call the driver */
    Status = IoCallDriver(pDeviceObject, pIrp);

    /* Wait if neccessary */
    if (Status == STATUS_PENDING)
    {
        KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
        Status = Iosb.Status;
    }

    /* Return information to the caller about the operation. */
    *lpInformation = Iosb.Information;

    /* This function returns NTSTATUS */
    return Status;
}
コード例 #8
0
ファイル: compmisc.c プロジェクト: HBelusca/NasuTek-Odyssey
NTSTATUS
NTAPI
BatteryIoctl(IN ULONG IoControlCode, 
             IN PDEVICE_OBJECT DeviceObject,
             IN PVOID InputBuffer,
             IN ULONG InputBufferLength,
             IN PVOID OutputBuffer,
             IN ULONG OutputBufferLength,
             IN BOOLEAN InternalDeviceIoControl)
{
    IO_STATUS_BLOCK IoStatusBlock;
    KEVENT Event;
    NTSTATUS Status;
    PIRP Irp;
    PAGED_CODE();
    if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");

    /* Initialize the event and IRP */
    KeInitializeEvent(&Event, SynchronizationEvent, 0);
    Irp = IoBuildDeviceIoControlRequest(IoControlCode,
                                        DeviceObject,
                                        InputBuffer,
                                        InputBufferLength,
                                        OutputBuffer,
                                        OutputBufferLength,
                                        InternalDeviceIoControl,
                                        &Event,
                                        &IoStatusBlock);
    if (Irp)
    {
        /* Call the class driver miniport */
        Status = IofCallDriver(DeviceObject, Irp);
        if (Status == STATUS_PENDING)
        {
            /* Wait for result */
            KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
            Status = IoStatusBlock.Status;
        }
        
        /* Print failure */
        if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
            DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
        
        /* Done */
        if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
    }
    else
    {
        /* Out of memory */
        if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
        Status = STATUS_INSUFFICIENT_RESOURCES;
    }
    
    /* Return status */
    return Status;
}
コード例 #9
0
ファイル: libusb_driver.c プロジェクト: mcuee/libusb-win32
NTSTATUS call_usbd(libusb_device_t *dev, void *urb, ULONG control_code,  
                   int timeout)
{
  KEVENT event;
  NTSTATUS status;
  IRP *irp;
  IO_STACK_LOCATION *next_irp_stack;
  LARGE_INTEGER _timeout;
  IO_STATUS_BLOCK io_status;

  if(timeout > LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT)
    {
      timeout = LIBUSB_MAX_CONTROL_TRANSFER_TIMEOUT;
    }

  KeInitializeEvent(&event, NotificationEvent, FALSE);

  irp = IoBuildDeviceIoControlRequest(control_code, dev->target_device,
                                      NULL, 0, NULL, 0, TRUE,
                                      NULL, &io_status);

  if(!irp)
    {
      return STATUS_NO_MEMORY;
    }

  next_irp_stack = IoGetNextIrpStackLocation(irp);
  next_irp_stack->Parameters.Others.Argument1 = urb;
  next_irp_stack->Parameters.Others.Argument2 = NULL;

  IoSetCompletionRoutine(irp, on_usbd_complete, &event, TRUE, TRUE, TRUE); 

  status = IoCallDriver(dev->target_device, irp);
    
  if(status == STATUS_PENDING)
    {
      _timeout.QuadPart = -(timeout * 10000);
      
      if(KeWaitForSingleObject(&event, Executive, KernelMode,
                               FALSE, &_timeout) == STATUS_TIMEOUT)
        {
          DEBUG_ERROR("call_usbd(): request timed out");
          IoCancelIrp(irp);
        }
    }

  /* wait until completion routine is called */
  KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);

  status = irp->IoStatus.Status;
  
  /* complete the request */
  IoCompleteRequest(irp, IO_NO_INCREMENT);

  return status;
}
コード例 #10
0
ファイル: fsctl.c プロジェクト: GYGit/reactos
NTSTATUS
FFSGetPartition(
	IN PDEVICE_OBJECT DeviceObject,
	OUT ULONGLONG     *StartOffset)
{
    CHAR                  Buffer[2048];
    PIRP                  Irp;
    IO_STATUS_BLOCK       IoStatus;
    KEVENT                Event;
    NTSTATUS              Status;
    PARTITION_INFORMATION *PartInfo;

    PAGED_CODE();

    if (IsFlagOn(DeviceObject->Characteristics, FILE_FLOPPY_DISKETTE))
    {
        *StartOffset = 0;
        return STATUS_SUCCESS;
    }

    KeInitializeEvent(&Event, NotificationEvent, FALSE);

    Irp = IoBuildDeviceIoControlRequest(
			IOCTL_DISK_GET_PARTITION_INFO,
			DeviceObject,
			NULL,
			0,
			Buffer,
			2048,
			FALSE,
			&Event,
			&IoStatus);

    if (!Irp)
	{
		return STATUS_INSUFFICIENT_RESOURCES;
	}

    Status = IoCallDriver(DeviceObject, Irp);
    if (!NT_SUCCESS(Status))
	{
		return Status;
	}

    Status = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
    if (!NT_SUCCESS(Status))
	{
		return Status;
	}

    PartInfo = (PARTITION_INFORMATION *)Buffer;
    *StartOffset = PartInfo->StartingOffset.QuadPart;

    return Status;
}
コード例 #11
0
ファイル: blockdev.c プロジェクト: hoangduit/reactos
BOOLEAN
NTAPI
FsRecGetDeviceSectors(IN PDEVICE_OBJECT DeviceObject,
                      IN ULONG SectorSize,
                      OUT PLARGE_INTEGER SectorCount)
{
    PARTITION_INFORMATION PartitionInfo;
    IO_STATUS_BLOCK IoStatusBlock;
    KEVENT Event;
    PIRP Irp;
    NTSTATUS Status;
    ULONG Remainder;
    PAGED_CODE();

    /* Only needed for disks */
    if (DeviceObject->DeviceType != FILE_DEVICE_DISK) return FALSE;

    /* Build the information IRP */
    KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
    Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO,
                                        DeviceObject,
                                        NULL,
                                        0,
                                        &PartitionInfo,
                                        sizeof(PARTITION_INFORMATION),
                                        FALSE,
                                        &Event,
                                        &IoStatusBlock);
    if (!Irp) return FALSE;

    /* Override verification */
    IoGetNextIrpStackLocation(Irp)->Flags |= SL_OVERRIDE_VERIFY_VOLUME;

    /* Do the request */
    Status = IoCallDriver(DeviceObject, Irp);
    if (Status == STATUS_PENDING)
    {
        /* Wait for completion */
        KeWaitForSingleObject(&Event,
                              Executive,
                              KernelMode,
                              FALSE,
                              NULL);
        Status = IoStatusBlock.Status;
    }

    /* Fail if we couldn't get the data */
    if (!NT_SUCCESS(Status)) return FALSE;

    /* Otherwise, return the number of sectors */
    *SectorCount = RtlExtendedLargeIntegerDivide(PartitionInfo.PartitionLength,
                                                 SectorSize,
                                                 &Remainder);
    return TRUE;
}
コード例 #12
0
ファイル: init.c プロジェクト: MelcherSt/dokany
NTSTATUS
DokanSendIoContlToMountManager(__in ULONG IoControlCode, __in PVOID InputBuffer,
                               __in ULONG Length, __out PVOID OutputBuffer,
                               __in ULONG OutputLength) {
  NTSTATUS status;
  UNICODE_STRING mountManagerName;
  PFILE_OBJECT mountFileObject;
  PDEVICE_OBJECT mountDeviceObject;
  PIRP irp;
  KEVENT driverEvent;
  IO_STATUS_BLOCK iosb;

  DDbgPrint("=> DokanSendIoContlToMountManager\n");

  RtlInitUnicodeString(&mountManagerName, MOUNTMGR_DEVICE_NAME);

  status = IoGetDeviceObjectPointer(&mountManagerName, FILE_READ_ATTRIBUTES,
                                    &mountFileObject, &mountDeviceObject);

  if (!NT_SUCCESS(status)) {
    DDbgPrint("  IoGetDeviceObjectPointer failed: 0x%x\n", status);
    return status;
  }

  KeInitializeEvent(&driverEvent, NotificationEvent, FALSE);

  irp = IoBuildDeviceIoControlRequest(IoControlCode, mountDeviceObject,
                                      InputBuffer, Length, OutputBuffer,
                                      OutputLength, FALSE, &driverEvent, &iosb);

  if (irp == NULL) {
    DDbgPrint("  IoBuildDeviceIoControlRequest failed\n");
    return STATUS_INSUFFICIENT_RESOURCES;
  }

  status = IoCallDriver(mountDeviceObject, irp);

  if (status == STATUS_PENDING) {
    KeWaitForSingleObject(&driverEvent, Executive, KernelMode, FALSE, NULL);
  }
  status = iosb.Status;

  ObDereferenceObject(mountFileObject);
  // Don't dereference mountDeviceObject, mountFileObject is enough

  if (NT_SUCCESS(status)) {
    DDbgPrint("  IoCallDriver success\n");
  } else {
    DDbgPrint("  IoCallDriver failed: 0x%x\n", status);
  }

  DDbgPrint("<= DokanSendIoContlToMountManager\n");

  return status;
}
コード例 #13
0
ファイル: filter.c プロジェクト: Cecildt/peerblock
static void setfilter(PacketFilterExtensionPtr fn)
{
	UNICODE_STRING name;
	PDEVICE_OBJECT device=NULL;
	PFILE_OBJECT file=NULL;
	NTSTATUS status;

	DbgPrint("pbfilter:  > Entering setfilter()\n");
	RtlInitUnicodeString(&name, DD_IPFLTRDRVR_DEVICE_NAME);
	status=IoGetDeviceObjectPointer(&name, STANDARD_RIGHTS_ALL, &file, &device);

	if(NT_SUCCESS(status))
	{
		KEVENT event;
		IO_STATUS_BLOCK iostatus;
		PF_SET_EXTENSION_HOOK_INFO hookinfo;
		PIRP irp;

		DbgPrint("pbfilter:    got devobj\n");
		hookinfo.ExtensionPointer=fn;
		KeInitializeEvent(&event, NotificationEvent, FALSE);

		irp=IoBuildDeviceIoControlRequest(
				IOCTL_PF_SET_EXTENSION_POINTER, device, &hookinfo,
				sizeof(PF_SET_EXTENSION_HOOK_INFO), NULL, 0, FALSE, &event, &iostatus);

		DbgPrint("pbfilter:    calling into driver\n");
		if(irp && IoCallDriver(device, irp)==STATUS_PENDING)
		{
			DbgPrint("pbfilter:    waiting for IRP to complete\n");
			KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
		}
		else
		{
			DbgPrint("pbfilter:    IRP not pending (or no IRP?)\n");
		}

		if(file)
		{
			DbgPrint("pbfilter:    Dereferencing file\n");
			ObDereferenceObject(file);
		}
		else
		{
			DbgPrint("pbfilter:    no file to dereference\n");
		}
	}
	else
	{
		DbgPrint("pbfilter:  * ERROR: unable to get IpFltDrv DevObj, status:[0x%lX]\n", status);
	}

	DbgPrint("pbfilter:  < Leaving setfilter()\n");
}
コード例 #14
0
ファイル: fsctrl.c プロジェクト: RPG-7/reactos
/*************************************************************************
*
* Function: Ext2MountVolume()
*
* Description:
*	This routine is used for querying the partition information.
*
* Expected Interrupt Level (for execution) :
*  IRQL_PASSIVE_LEVEL 
*
* Arguments:
*
*	TargetDeviceObject - The target of the query
*	PartitionInformation - Receives the result of the query
*
* Return Value:
*
*	NTSTATUS - The return status for the operation
*
*************************************************************************/
NTSTATUS
Ext2GetPartitionInfo (
    IN PDEVICE_OBJECT TargetDeviceObject,
    IN PPARTITION_INFORMATION PartitionInformation
    )
{
    PIRP Irp;
    KEVENT *PtrEvent = NULL;
    NTSTATUS Status;
    IO_STATUS_BLOCK Iosb;

    //
    //  Query the partition table
    //
	PtrEvent = ( KEVENT * )Ext2AllocatePool( NonPagedPool, Ext2QuadAlign( sizeof( KEVENT ) )  );
	



    KeInitializeEvent( PtrEvent, NotificationEvent, FALSE );
	
    Irp = IoBuildDeviceIoControlRequest( IOCTL_DISK_GET_PARTITION_INFO,
                                         TargetDeviceObject,
                                         NULL,
                                         0,
                                         PartitionInformation,
                                         sizeof(PARTITION_INFORMATION),
                                         FALSE,
                                         PtrEvent,
                                         &Iosb );

    if ( Irp == NULL ) 
	{
		DebugTrace( DEBUG_TRACE_FREE, "Freeing  = %lX [FS Ctrl]", PtrEvent);
		ExFreePool( PtrEvent );
		return 0;
    }

    Status = IoCallDriver( TargetDeviceObject, Irp );

    if ( Status == STATUS_PENDING ) {

        (VOID) KeWaitForSingleObject( PtrEvent,
                                      Executive,
                                      KernelMode,
                                      FALSE,
                                      (PLARGE_INTEGER)NULL );

        Status = Iosb.Status;
    }
	DebugTrace( DEBUG_TRACE_FREE, "Freeing  = %lX [FS Ctrl]", PtrEvent);
	ExFreePool( PtrEvent );
    return Status;
}
コード例 #15
0
ファイル: block.c プロジェクト: dond2008/ext2fsd
NTSTATUS
Ext2DiskIoControl (
    IN PDEVICE_OBJECT   DeviceObject,
    IN ULONG            IoctlCode,
    IN PVOID            InputBuffer,
    IN ULONG            InputBufferSize,
    IN OUT PVOID        OutputBuffer,
    IN OUT PULONG       OutputBufferSize)
{
    ULONG           OutBufferSize = 0;
    KEVENT          Event;
    PIRP            Irp;
    IO_STATUS_BLOCK IoStatus;
    NTSTATUS        Status;

    ASSERT(DeviceObject != NULL);

    if (OutputBufferSize)
    {
        OutBufferSize = *OutputBufferSize;
    }

    KeInitializeEvent(&Event, NotificationEvent, FALSE);

    Irp = IoBuildDeviceIoControlRequest(
              IoctlCode,
              DeviceObject,
              InputBuffer,
              InputBufferSize,
              OutputBuffer,
              OutBufferSize,
              FALSE,
              &Event,
              &IoStatus
          );

    if (Irp == NULL) {
        DEBUG(DL_ERR, ( "Ext2DiskIoControl: failed to build Irp!\n"));
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    Status = IoCallDriver(DeviceObject, Irp);

    if (Status == STATUS_PENDING)  {
        KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
        Status = IoStatus.Status;
    }

    if (OutputBufferSize) {
        *OutputBufferSize = (ULONG)(IoStatus.Information);
    }

    return Status;
}
コード例 #16
0
ファイル: notify.c プロジェクト: Strongc/reactos
/*
 * @implemented
 */
VOID
SendOnlineNotification(IN PUNICODE_STRING SymbolicName)
{
    PIRP Irp;
    KEVENT Event;
    NTSTATUS Status;
    PFILE_OBJECT FileObject;
    PIO_STACK_LOCATION Stack;
    PDEVICE_OBJECT DeviceObject;
    IO_STATUS_BLOCK IoStatusBlock;

    /* Get device object */
    Status = IoGetDeviceObjectPointer(SymbolicName,
                                      FILE_READ_ATTRIBUTES,
                                      &FileObject,
                                      &DeviceObject);
    if (!NT_SUCCESS(Status))
    {
        return;
    }

    /* And attached device object */
    DeviceObject = IoGetAttachedDeviceReference(FileObject->DeviceObject);

    /* And send VOLUME_ONLINE */
    KeInitializeEvent(&Event, NotificationEvent, FALSE);
    Irp = IoBuildDeviceIoControlRequest(IOCTL_VOLUME_ONLINE,
                                        DeviceObject,
                                        NULL, 0,
                                        NULL, 0,
                                        FALSE,
                                        &Event,
                                        &IoStatusBlock);
    if (!Irp)
    {
        goto Cleanup;
    }

    Stack = IoGetNextIrpStackLocation(Irp);
    Stack->FileObject = FileObject;

    Status = IoCallDriver(DeviceObject, Irp);
    if (Status == STATUS_PENDING)
    {
        KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
    }

Cleanup:
    ObDereferenceObject(DeviceObject);
    ObDereferenceObject(FileObject);

    return;
}
コード例 #17
0
NTSTATUS
RosKmdRapAdapter::SetVC4Power(
        bool    bOn)
{
    PIRP pIrp = NULL;
    KEVENT ioCompleted;
    IO_STATUS_BLOCK statusBlock;
    MAILBOX_SET_POWER_VC4 setPowerVC4;

    KeInitializeEvent(&ioCompleted, NotificationEvent, FALSE);

    INIT_MAILBOX_SET_POWER_VC4(&setPowerVC4, bOn);

    pIrp = IoBuildDeviceIoControlRequest(
        IOCTL_MAILBOX_PROPERTY,
        m_pRpiqDevice,
        &setPowerVC4,
        sizeof(setPowerVC4),
        &setPowerVC4,
        sizeof(setPowerVC4),
        false,
        &ioCompleted,
        &statusBlock);
    if (NULL == pIrp)
    {
        return STATUS_NO_MEMORY;
    }

    NTSTATUS status;

    status = IoCallDriver(m_pRpiqDevice, pIrp);

    if (status == STATUS_PENDING)
    {
        KeWaitForSingleObject(&ioCompleted, Executive, KernelMode, FALSE, NULL);
        status = statusBlock.Status;
    }

    if (STATUS_SUCCESS != status)
    {
        return status;
    }

    if (setPowerVC4.Header.RequestResponse == RESPONSE_SUCCESS)
    {
        return STATUS_SUCCESS;
    }
    else
    {
        return STATUS_INVALID_PARAMETER;
    }
}
コード例 #18
0
ファイル: utils.c プロジェクト: tigtigtig/ndas4windows
static
NTSTATUS
LfsFiltIoControl(
	IN  HANDLE			ControlFileHandle,
	IN	PFILE_OBJECT	ControlFileObject,
	IN	ULONG    		IoControlCode,
	IN	PVOID    		InputBuffer OPTIONAL,
	IN	ULONG    		InputBufferLength,
	OUT PVOID	    	OutputBuffer OPTIONAL,
	IN	ULONG    		OutputBufferLength
	)
{
	NTSTATUS		ntStatus;
	PDEVICE_OBJECT	deviceObject;
	PIRP			irp;
	KEVENT	    	event;
	IO_STATUS_BLOCK	ioStatus;

	UNREFERENCED_PARAMETER(ControlFileHandle);

	Bus_KdPrint_Def(BUS_DBG_SS_TRACE, ("Entered\n"));

	deviceObject = IoGetRelatedDeviceObject(ControlFileObject);
	
	KeInitializeEvent(&event, NotificationEvent, FALSE);

	irp = IoBuildDeviceIoControlRequest(
			IoControlCode,
			deviceObject,
			InputBuffer,
			InputBufferLength,
			OutputBuffer,
			OutputBufferLength,
			FALSE,
			&event,
			&ioStatus
			);
	
	if (irp == NULL) {
		return STATUS_INSUFFICIENT_RESOURCES;
	}

	ntStatus = IoCallDriver(deviceObject, irp);
	if (ntStatus == STATUS_PENDING)
	{
		KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
		ntStatus = ioStatus.Status;
	}

	return ntStatus;
}
コード例 #19
0
ファイル: volume.c プロジェクト: HBelusca/NasuTek-Odyssey
/*
 * @implemented
 */
VOID
NTAPI
IopLoadFileSystemDriver(IN PDEVICE_OBJECT DeviceObject)
{
    IO_STATUS_BLOCK IoStatusBlock;
    PIO_STACK_LOCATION StackPtr;
    KEVENT Event;
    PIRP Irp;
    NTSTATUS Status;
    PDEVICE_OBJECT AttachedDeviceObject = DeviceObject;
    PAGED_CODE();

    /* Loop as long as we're attached */
    while (AttachedDeviceObject->AttachedDevice)
    {
        /* Get the attached device object */
        AttachedDeviceObject = AttachedDeviceObject->AttachedDevice;
    }

    /* Initialize the event and build the IRP */
    KeInitializeEvent(&Event, NotificationEvent, FALSE);
    Irp = IoBuildDeviceIoControlRequest(IRP_MJ_DEVICE_CONTROL,
                                        AttachedDeviceObject,
                                        NULL,
                                        0,
                                        NULL,
                                        0,
                                        FALSE,
                                        &Event,
                                        &IoStatusBlock);
    if (Irp)
    {
        /* Set the major and minor functions */
        StackPtr = IoGetNextIrpStackLocation(Irp);
        StackPtr->MajorFunction = IRP_MJ_FILE_SYSTEM_CONTROL;
        StackPtr->MinorFunction = IRP_MN_LOAD_FILE_SYSTEM;

        /* Call the driver */
        Status = IoCallDriver(AttachedDeviceObject, Irp);
        if (Status == STATUS_PENDING)
        {
            /* Wait on it */
            KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
        }
    }

    /* Dereference DO - FsRec? - Comment out call, since it breaks up 2nd stage boot, needs more research. */
//  IopDecrementDeviceObjectRef(AttachedDeviceObject, TRUE);
}
コード例 #20
0
VOID RecoveryThread(PVOID Arg)
{
    PIO_STACK_LOCATION stack;
    IO_STATUS_BLOCK    IoStatus;
    KEVENT             Event;
    PIRP               Irp;
    NTSTATUS           status;

    PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)Arg;

    while(1)
    {
        // the main part of the driver will signal us when we need to fix things
        KeWaitForSingleObject(&pdx->RecoveryEvent, Executive, KernelMode, FALSE, NULL);
    
        if(pdx->RecoveryExit) break;
        
        KeInitializeEvent(&Event, SynchronizationEvent, FALSE);

        // reset our device
        Irp = IoBuildDeviceIoControlRequest(
                                             IOCTL_INTERNAL_USB_RESET_PORT,
                                             pdx->LowerDeviceObject,
                                             NULL,
                                             0,
                                             NULL,
                                             0,
                                             TRUE,
                                             &Event,
                                             &IoStatus
                                           );

        stack = IoGetNextIrpStackLocation(Irp);
        
        status = IoCallDriver(pdx->LowerDeviceObject, Irp);

        if(STATUS_PENDING == status)
        {
            KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
            
            status = IoStatus.Status;
        }

        // start polling again
        StartPolling(pdx);
    }

    PsTerminateSystemThread(STATUS_SUCCESS);
}
コード例 #21
0
ファイル: detect.c プロジェクト: GYGit/reactos
static NTSTATUS
DeviceIoControl(
	IN PDEVICE_OBJECT DeviceObject,
	IN ULONG CtlCode,
	IN PVOID InputBuffer OPTIONAL,
	IN ULONG_PTR InputBufferSize,
	IN OUT PVOID OutputBuffer OPTIONAL,
	IN OUT PULONG_PTR OutputBufferSize)
{
	KEVENT Event;
	PIRP Irp;
	IO_STATUS_BLOCK IoStatus;
	NTSTATUS Status;

	KeInitializeEvent (&Event, NotificationEvent, FALSE);

	Irp = IoBuildDeviceIoControlRequest(CtlCode,
		DeviceObject,
		InputBuffer,
		InputBufferSize,
		OutputBuffer,
		(OutputBufferSize) ? *OutputBufferSize : 0,
		FALSE,
		&Event,
		&IoStatus);
	if (Irp == NULL)
	{
		WARN_(SERENUM, "IoBuildDeviceIoControlRequest() failed\n");
		return STATUS_INSUFFICIENT_RESOURCES;
	}

	Status = IoCallDriver(DeviceObject, Irp);

	if (Status == STATUS_PENDING)
	{
		INFO_(SERENUM, "Operation pending\n");
		KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
		Status = IoStatus.Status;
	}

	if (OutputBufferSize)
	{
		*OutputBufferSize = IoStatus.Information;
	}

	return Status;
}
コード例 #22
0
ファイル: fsctl.c プロジェクト: GYGit/reactos
BOOLEAN
FFSIsMediaWriteProtected(
	IN PFFS_IRP_CONTEXT   IrpContext,
	IN PDEVICE_OBJECT     TargetDevice)
{
	PIRP            Irp;
	KEVENT          Event;
	NTSTATUS        Status;
	IO_STATUS_BLOCK IoStatus;

    PAGED_CODE();

	KeInitializeEvent(&Event, NotificationEvent, FALSE);

	Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_IS_WRITABLE,
			TargetDevice,
			NULL,
			0,
			NULL,
			0,
			FALSE,
			&Event,
			&IoStatus);

	if (Irp == NULL)
	{
		return FALSE;
	}

	SetFlag(IoGetNextIrpStackLocation(Irp)->Flags, SL_OVERRIDE_VERIFY_VOLUME);

	Status = IoCallDriver(TargetDevice, Irp);

	if (Status == STATUS_PENDING)
	{

		(VOID) KeWaitForSingleObject(&Event,
					      Executive,
					      KernelMode,
					      FALSE,
					      (PLARGE_INTEGER)NULL);

		Status = IoStatus.Status;
	}

	return (BOOLEAN)(Status == STATUS_MEDIA_WRITE_PROTECTED);
}
コード例 #23
0
/**
 * Internal I/O Control call worker.
 *
 * @returns VBox status code.
 * @param   pDeviceObject   The device object to call.
 * @param   pFileObject     The file object for the connection.
 * @param   uReq            The request.
 * @param   pReq            The request packet.
 */
static int supR0IdcNtCallInternal(PDEVICE_OBJECT pDeviceObject, PFILE_OBJECT pFileObject, uint32_t uReq, PSUPDRVIDCREQHDR pReq)
{
    int                 rc;
    IO_STATUS_BLOCK     IoStatusBlock;
    KEVENT              Event;
    PIRP                pIrp;
    NTSTATUS            rcNt;

    /*
     * Build the request.
     */
    KeInitializeEvent(&Event, NotificationEvent, FALSE);
    pIrp = IoBuildDeviceIoControlRequest(uReq,              /* IoControlCode */
                                         pDeviceObject,
                                         pReq,              /* InputBuffer */
                                         pReq->cb,          /* InputBufferLength */
                                         pReq,              /* OutputBuffer */
                                         pReq->cb,          /* OutputBufferLength */
                                         TRUE,              /* InternalDeviceIoControl (=> IRP_MJ_INTERNAL_DEVICE_CONTROL) */
                                         &Event,            /* Event */
                                         &IoStatusBlock);   /* IoStatusBlock */
    if (pIrp)
    {
        IoGetNextIrpStackLocation(pIrp)->FileObject = pFileObject;

        /*
         * Call the driver, wait for an async request to complete (should never happen).
         */
        rcNt = IoCallDriver(pDeviceObject, pIrp);
        if (rcNt == STATUS_PENDING)
        {
            rcNt = KeWaitForSingleObject(&Event,            /* Object */
                                         Executive,         /* WaitReason */
                                         KernelMode,        /* WaitMode */
                                         FALSE,             /* Alertable */
                                         NULL);             /* TimeOut */
            rcNt = IoStatusBlock.Status;
        }
        if (NT_SUCCESS(rcNt))
            rc = pReq->rc;
        else
            rc = RTErrConvertFromNtStatus(rcNt);
    }
    else
        rc = VERR_NO_MEMORY;
    return rc;
}
コード例 #24
0
ファイル: SendDIOC.c プロジェクト: hackshields/antivirus
NTSTATUS SendDIOC(PUNICODE_STRING uDeviceName, ULONG IoControlCode,PVOID InputBuffer,ULONG InputBufferLength,PVOID OutputBuffer,ULONG OutputBufferLength)
{
	HANDLE              hPidDrv;
	OBJECT_ATTRIBUTES   ObjAttr;
	IO_STATUS_BLOCK     ioStatus;
	PDEVICE_OBJECT      DevObj;
	PFILE_OBJECT        fileObject;
	NTSTATUS            ntStatus;
	KEVENT              Event;
	PIRP                Irp;
	//	PIO_STACK_LOCATION irpSp;
	//	RtlInitUnicodeString(&us,L"\\Device\\"KLPID_NAME);
	
	InitializeObjectAttributes(&ObjAttr,uDeviceName,OBJ_CASE_INSENSITIVE,NULL,NULL);
	ntStatus=ZwCreateFile(&hPidDrv,SYNCHRONIZE|FILE_ANY_ACCESS,&ObjAttr,&ioStatus,NULL,0,FILE_SHARE_READ|FILE_SHARE_WRITE,FILE_OPEN,FILE_SYNCHRONOUS_IO_NONALERT,NULL,0);
	if(NT_SUCCESS(ntStatus)) {
		ntStatus=ObReferenceObjectByHandle(hPidDrv,FILE_READ_DATA,NULL,KernelMode,(PVOID*)&fileObject,NULL);
		if(NT_SUCCESS(ntStatus)) {
			if((DevObj=IoGetRelatedDeviceObject(fileObject))!=NULL) {
				KeInitializeEvent(&Event,NotificationEvent,FALSE);
				Irp=IoBuildDeviceIoControlRequest(IoControlCode,DevObj,InputBuffer,InputBufferLength,OutputBuffer,OutputBufferLength,FALSE,&Event,&ioStatus);
				if(Irp!=NULL) {
					//					irpSp=IoGetNextIrpStackLocation(Irp);
					//					irpSp->FileObject = fileObject;
					ntStatus=IoCallDriver(DevObj,Irp);
					if(ntStatus==STATUS_PENDING) {
						KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,(PLARGE_INTEGER)NULL);
						ntStatus = ioStatus.Status;
					}
				} else {
					//					HOOKKdPrint(4, ("HOOK: IoBuildDeviceIoControlRequest failed\n"));
					ntStatus=STATUS_UNSUCCESSFUL;
				}
			} else {
				//				HOOKKdPrint(1, ("HOOK: IoGetRelatedDeviceObject %S failed \n",us.Buffer));
				ntStatus=STATUS_UNSUCCESSFUL;
			}
			ObDereferenceObject(fileObject);
		} else {
			//			HOOKKdPrint(1, ("HOOK: ObReferenceObjectByHandle %S failed status=%x\n",us.Buffer,ntStatus));
		}
		ZwClose(hPidDrv);
	} else {
		//		HOOKKdPrint(1, ("HOOK: ZwCreateFile %S failed status=%x\n",us.Buffer,ntStatus));
	}
	return ntStatus;
}
コード例 #25
0
ファイル: fs_rec.c プロジェクト: aldertotori/fs_rec
BOOLEAN FsRecGetDeviceSectors(PDEVICE_OBJECT DeviceObject,ULONG BytesPerSector,OUT PLARGE_INTEGER SectorCount)
{
	KEVENT			Event;
	IO_STATUS_BLOCK	IoStatus;
	LARGE_INTEGER	Length;
	PIRP			Irp;
	NTSTATUS		Status;
	LARGE_INTEGER	Divide;
	ULONG			Remainder;

	if( DeviceObject->DeviceType == FILE_DEVICE_DISK)
	{
		KeInitializeEvent(&Event,SynchronizationEvent,FALSE);

		Irp = IoBuildDeviceIoControlRequest(
					IOCTL_DISK_GET_LENGTH_INFO,	// 7405C
					DeviceObject,
					NULL,
					0,
					(PVOID)&Length,
					sizeof(LARGE_INTEGER),
					FALSE,
					&Event,
					&IoStatus);
		if(Irp)
		{
			(IoGetNextIrpStackLocation(Irp))->Flags |= IRP_PAGING_IO;
		
			Status = IoCallDriver(DeviceObject,Irp);
			
			if(Status == STATUS_PENDING)
			{
				KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
				Status = IoStatus.Status;
			}
			
			if(NT_SUCCESS(Status))
			{
				Divide = RtlExtendedLargeIntegerDivide(Length,BytesPerSector,&Remainder);
				SectorCount->QuadPart = Divide.QuadPart;
				return TRUE;
			}
		}
	}

	return FALSE;
}
コード例 #26
0
ファイル: main.c プロジェクト: 0vercl0k/stuffz
BOOL FindDiskGeometry(PDEVICE_OBJECT pDevHdDevice, PDISK_GEOMETRY pDiskGeo)
{
    KEVENT event              = {0};
    PIRP pIrp                 = NULL;
    IO_STATUS_BLOCK ioStatus  = {0};
    NTSTATUS status           = 0;
    PDEVICE_EXTENSION pDevExt = NULL;

    pDevExt = (PDEVICE_EXTENSION)pDevHdDevice->DeviceExtension;
    KeInitializeEvent(&event, NotificationEvent, FALSE);
    DbgPrint("Building IRP which will be send to the HardDisk 0 device..");
    pIrp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY,
                                         pDevHdDevice,
                                         NULL,
                                         0,
                                         pDiskGeo,
                                         sizeof(DISK_GEOMETRY),
                                         FALSE,
                                         &event,
                                         &ioStatus
                                        );
    if(pIrp == NULL)
    {
        DbgPrint("\n[!] Error at IoBuildSynchronousFsdRequest().\n");
        return STATUS_UNSUCCESSFUL;
    }

    DbgPrint("[OK] -> 0x%x.\n", pIrp);

    DbgPrint("Calling the driver..");
    status = IoCallDriver(pDevHdDevice, pIrp);

    if(status == STATUS_PENDING)
	{
	    DbgPrint("Waiting it handles our query..");
        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE,	NULL);
        status = ioStatus.Status;

        if(!NT_SUCCESS(status))
        {
            DbgPrint("\n[!] Error at IoCallDriver+KeWaitForSingleObject : 0x%x.\n", status);
            return FALSE;
        }
    }

    return TRUE;
}
コード例 #27
0
ファイル: parvdm.c プロジェクト: BillTheBest/WinNT4
VOID
ParReleasePortInfoToPortDevice(
    IN  PDEVICE_EXTENSION   Extension
)

/*++

Routine Description:

    This routine will release the port information back to the port driver.

Arguments:

    Extension   - Supplies the device extension.

Return Value:

    None.

--*/

{
    KEVENT          event;
    PIRP            irp;
    IO_STATUS_BLOCK ioStatus;
    NTSTATUS        status;

    KeInitializeEvent(&event, NotificationEvent, FALSE);

    irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_RELEASE_PARALLEL_PORT_INFO,
                                        Extension->PortDeviceObject,
                                        NULL, 0, NULL, 0,
                                        TRUE, &event, &ioStatus);

    if (!irp) {
        return;
    }

    status = IoCallDriver(Extension->PortDeviceObject, irp);

    if (!NT_SUCCESS(status)) {
        return;
    }

    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
}
コード例 #28
0
ファイル: bulkdev.c プロジェクト: stormbay/DragonVer1.0
//============================================
static NTSTATUS BulkUsb_GetPortStatus(IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG PortStatus)
{
    NTSTATUS           ntStatus;
    KEVENT             event;
    PIRP               irp;
    IO_STATUS_BLOCK    ioStatus;
    PIO_STACK_LOCATION nextStack;
    PTDeviceExtension  deviceExtension;

    deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension;
    *PortStatus = 0;
    BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_GetPortStatus - begins\n"));
    KeInitializeEvent(&event, NotificationEvent, FALSE);
    irp = IoBuildDeviceIoControlRequest(
                    IOCTL_INTERNAL_USB_GET_PORT_STATUS,
                    deviceExtension->TopOfStackDeviceObject,
                    NULL,
                    0,
                    NULL,
                    0,
                    TRUE,
                    &event,
                    &ioStatus);

    if(NULL == irp) 
	{
        BulkUsb_DbgPrint(1, ("file bulkdev: memory alloc for irp failed\n"));
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    nextStack = IoGetNextIrpStackLocation(irp);
    ASSERT(nextStack != NULL);
    nextStack->Parameters.Others.Argument1 = PortStatus;
    ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);
    if(STATUS_PENDING == ntStatus) 
	{
        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
    }
    else 
        ioStatus.Status = ntStatus;

    ntStatus = ioStatus.Status;
    BulkUsb_DbgPrint(3, ("file bulkdev: BulkUsb_GetPortStatus - ends\n"));
    return ntStatus;
}
コード例 #29
0
ファイル: dummy.c プロジェクト: ngaut/winvblock
/**
 * Produce a dummy PDO node on the main bus.
 *
 * @v DummyIds                  The PnP IDs for the dummy.  Also includes
 *                              the device type and characteristics.
 * @ret NTSTATUS                The status of the operation.
 */
WVL_M_LIB NTSTATUS STDCALL WvDummyAdd(
    IN const WV_S_DUMMY_IDS * DummyIds
  ) {
    KEVENT signal;
    PIRP irp;
    IO_STATUS_BLOCK io_status = {0};
    NTSTATUS status;

    /*
     * In this function, we actually send the request through to the
     * driver via an IRP.  This is a good exercise, since we expect a
     * user-land utility to be capable of the same.
     */
    if (!WvBus.Fdo)
      return STATUS_NO_SUCH_DEVICE;

    /* Prepare the request. */
    KeInitializeEvent(&signal, SynchronizationEvent, FALSE);
    irp = IoBuildDeviceIoControlRequest(
        IOCTL_WV_DUMMY,
        WvBus.Fdo,
        (PVOID) DummyIds,
        DummyIds->Len,
        NULL,
        0,
        FALSE,
        &signal,
        &io_status
      );
    if (!irp)
      return STATUS_INSUFFICIENT_RESOURCES;

    status = IoCallDriver(WvBus.Fdo, irp);
    if (status == STATUS_PENDING) {
        KeWaitForSingleObject(
            &signal,
            Executive,
            KernelMode,
            FALSE,
            NULL
          );
        status = io_status.Status;
      }
    return status;
  }
コード例 #30
0
ファイル: sub.c プロジェクト: airhigh/wdrbd
NTSTATUS
mvolGetVolumeSize(PDEVICE_OBJECT TargetDeviceObject, PLARGE_INTEGER pVolumeSize)
{
    NTSTATUS					status;
    KEVENT						event;
    IO_STATUS_BLOCK				ioStatus;
    PIRP						newIrp;
    GET_LENGTH_INFORMATION      li;

    memset(&li, 0, sizeof(li));

    KeInitializeEvent(&event, NotificationEvent, FALSE);

    if (KeGetCurrentIrql() > APC_LEVEL)
    {
        WDRBD_ERROR("cannot run IoBuildDeviceIoControlRequest becauseof IRP(%d)\n", KeGetCurrentIrql());
    }

    newIrp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_LENGTH_INFO,
        TargetDeviceObject, NULL, 0,
        &li, sizeof(li),
        FALSE, &event, &ioStatus);
    if (!newIrp)
    {
        WDRBD_ERROR("cannot alloc new IRP\n");
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    status = IoCallDriver(TargetDeviceObject, newIrp);
    if (status == STATUS_PENDING)
    {
        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, (PLARGE_INTEGER)NULL);
        status = ioStatus.Status;
    }

    if (!NT_SUCCESS(status))
    {
        WDRBD_ERROR("cannot get volume information, err=0x%x\n", status);
        return status;
    }

    pVolumeSize->QuadPart = li.Length.QuadPart;

    return status;
}