[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 05/14 v2] Add IOCTLs to query instance, name and protocol



From: Owen Smith <owen.smith@xxxxxxxxxx>

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 include/xencons_device.h |  17 +++++++
 src/xencons/console.c    | 112 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/xencons/pdo.c        |   8 +++-
 3 files changed, 133 insertions(+), 4 deletions(-)

diff --git a/include/xencons_device.h b/include/xencons_device.h
index eaf57d8..c9ae2ef 100644
--- a/include/xencons_device.h
+++ b/include/xencons_device.h
@@ -36,4 +36,21 @@
 DEFINE_GUID(GUID_XENCONS_DEVICE,
             0xd3edd21, 0x8ef9, 0x4dff, 0x85, 0x6c, 0x8c, 0x68, 0xbf, 0x4f, 
0xdc, 0xa3);
 
+#define __IOCTL_XENCONS_BEGIN   0x800
+
+#define IOCTL_XENCONS_GET_INSTANCE  CTL_CODE(FILE_DEVICE_UNKNOWN,       \
+                                             __IOCTL_XENCONS_BEGIN + 0, \
+                                             METHOD_BUFFERED,           \
+                                             FILE_ANY_ACCESS)
+
+#define IOCTL_XENCONS_GET_NAME      CTL_CODE(FILE_DEVICE_UNKNOWN,       \
+                                             __IOCTL_XENCONS_BEGIN + 1, \
+                                             METHOD_BUFFERED,           \
+                                             FILE_ANY_ACCESS)
+
+#define IOCTL_XENCONS_GET_PROTOCOL  CTL_CODE(FILE_DEVICE_UNKNOWN,       \
+                                             __IOCTL_XENCONS_BEGIN + 2, \
+                                             METHOD_BUFFERED,           \
+                                             FILE_ANY_ACCESS)
+
 #endif  // _XENCONS_DEVICE_H
diff --git a/src/xencons/console.c b/src/xencons/console.c
index 83ae916..b9abe83 100755
--- a/src/xencons/console.c
+++ b/src/xencons/console.c
@@ -36,6 +36,8 @@
 #include <ntstrsafe.h>
 #include <stdlib.h>
 
+#include <xencons_device.h>
+
 #include "driver.h"
 #include "console.h"
 #include "stream.h"
@@ -206,8 +208,8 @@ fail1:
     return status;
 }
 
-NTSTATUS
-ConsolePutQueue(
+static FORCEINLINE NTSTATUS
+__ConsolePutQueue(
     IN  PXENCONS_CONSOLE    Console,
     IN  PIRP                Irp
     )
@@ -239,6 +241,112 @@ fail1:
     return status;
 }
 
+static FORCEINLINE NTSTATUS
+__ConsoleDeviceControl(
+    IN  PXENCONS_CONSOLE    Console,
+    IN  PIRP                Irp
+    )
+{
+    PIO_STACK_LOCATION      StackLocation;
+    ULONG                   IoControlCode;
+    ULONG                   InputBufferLength;
+    ULONG                   OutputBufferLength;
+    PVOID                   Buffer;
+    PCHAR                   Value;
+    ULONG                   Length;
+    NTSTATUS                status;
+
+    UNREFERENCED_PARAMETER(Console);
+
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    IoControlCode = StackLocation->Parameters.DeviceIoControl.IoControlCode;
+    InputBufferLength = 
StackLocation->Parameters.DeviceIoControl.InputBufferLength;
+    OutputBufferLength = 
StackLocation->Parameters.DeviceIoControl.OutputBufferLength;
+    Buffer = Irp->AssociatedIrp.SystemBuffer;
+
+    switch (IoControlCode) {
+    case IOCTL_XENCONS_GET_INSTANCE:
+        Value = "0";
+        break;
+    case IOCTL_XENCONS_GET_NAME:
+        Value = "default";
+        break;
+    case IOCTL_XENCONS_GET_PROTOCOL:
+        Value = "vt100";
+        break;
+    default:
+        Value = NULL;
+        break;
+    }
+
+    status = STATUS_NOT_SUPPORTED;
+    if (Value == NULL)
+        goto fail1;
+
+    status = STATUS_INVALID_PARAMETER;
+    if (InputBufferLength != 0)
+        goto fail2;
+
+    Length = (ULONG)strlen(Value) + 1;
+    Irp->IoStatus.Information = Length;
+
+    status = STATUS_INVALID_BUFFER_SIZE;
+    if (OutputBufferLength == 0)
+        goto fail3;
+
+    RtlZeroMemory(Buffer, OutputBufferLength);
+    if (OutputBufferLength < Length)
+        goto fail4;
+
+    RtlCopyMemory(Buffer, Value, Length);
+    
+    return STATUS_SUCCESS;
+
+fail4:
+    Error("fail4\n");
+
+fail3:
+    Error("fail3\n");
+
+fail2:
+    Error("fail2\n");
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
+NTSTATUS
+ConsolePutQueue(
+    IN  PXENCONS_CONSOLE    Console,
+    IN  PIRP                Irp
+    )
+{
+    PIO_STACK_LOCATION      StackLocation;
+    NTSTATUS                status;
+
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+
+    switch (StackLocation->MajorFunction) {
+    case IRP_MJ_READ:
+    case IRP_MJ_WRITE:
+        status = __ConsolePutQueue(Console, Irp);
+        break;
+
+    case IRP_MJ_DEVICE_CONTROL:
+        status = __ConsoleDeviceControl(Console, Irp);
+        break;
+
+    default:
+        ASSERT(FALSE);
+        status = STATUS_NOT_SUPPORTED;
+        break;
+    }
+
+    return status;
+}
+
 NTSTATUS
 ConsoleD3ToD0(
     IN  PXENCONS_CONSOLE    Console
diff --git a/src/xencons/pdo.c b/src/xencons/pdo.c
index 077c7e2..62f366c 100755
--- a/src/xencons/pdo.c
+++ b/src/xencons/pdo.c
@@ -1735,7 +1735,7 @@ PdoDispatchClose(
 }
 
 static DECLSPEC_NOINLINE NTSTATUS
-PdoDispatchReadWrite(
+PdoDispatchReadWriteControl(
     IN  PXENCONS_PDO    Pdo,
     IN  PIRP            Irp
     )
@@ -1743,6 +1743,8 @@ PdoDispatchReadWrite(
     NTSTATUS            status;
 
     status = ConsolePutQueue(Pdo->Console, Irp);
+    if (status == STATUS_SUCCESS)
+        goto done;
     if (status != STATUS_PENDING)
         goto fail1;
 
@@ -1751,6 +1753,7 @@ PdoDispatchReadWrite(
 fail1:
     Error("fail1 (%08x)\n", status);
 
+done:
     Irp->IoStatus.Status = status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
@@ -1807,7 +1810,8 @@ PdoDispatch(
 
     case IRP_MJ_READ:
     case IRP_MJ_WRITE:
-        status = PdoDispatchReadWrite(Pdo, Irp);
+    case IRP_MJ_DEVICE_CONTROL:
+        status = PdoDispatchReadWriteControl(Pdo, Irp);
         break;
 
     default:
-- 
2.8.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.