aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/km/src/nt_namespace/device.c
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-15 14:05:29 +0200
committerEgor Tensin <egor@tensin.name>2026-06-15 14:12:29 +0200
commitb3eef140da853414776c8e03a70629a613a25ed0 (patch)
treedcdb314d2fdd92f501c09f3ae5681a731cb00dee /km/src/nt_namespace/device.c
parentwdk10: disable the packaging target (diff)
downloadwindows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.tar.gz
windows7-drivers-b3eef140da853414776c8e03a70629a613a25ed0.zip
workflows/ci: add clang-format job
Diffstat (limited to 'km/src/nt_namespace/device.c')
-rw-r--r--km/src/nt_namespace/device.c81
1 files changed, 32 insertions, 49 deletions
diff --git a/km/src/nt_namespace/device.c b/km/src/nt_namespace/device.c
index 6d88dc4..afb9813 100644
--- a/km/src/nt_namespace/device.c
+++ b/km/src/nt_namespace/device.c
@@ -5,14 +5,14 @@
* Distributed under the MIT License.
*/
-#include "control_codes.h"
#include "device.h"
+
+#include "control_codes.h"
#include "nt2dos.h"
#include <ntddk.h>
-static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp)
-{
+static NTSTATUS device_open(DEVICE_OBJECT* device_object, IRP* irp) {
NTSTATUS status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER(device_object);
@@ -23,25 +23,22 @@ static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp)
return status;
}
-typedef NTSTATUS (*ioctl_handler)(
- void *, unsigned long,
- void *, unsigned long,
- ULONG_PTR *);
+typedef NTSTATUS (*ioctl_handler)(void*, unsigned long, void*, unsigned long, ULONG_PTR*);
static NTSTATUS handle_convert_nt_path(
- void *in_buf,
+ void* in_buf,
unsigned long in_buf_size,
- void *out_buf,
+ void* out_buf,
unsigned long out_buf_size,
- ULONG_PTR *nbwritten)
-{
+ ULONG_PTR* nbwritten
+) {
UNICODE_STRING uUnresolved, uResolved;
NTSTATUS status = STATUS_SUCCESS;
- DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR *) in_buf);
+ DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR*)in_buf);
DbgPrint("nt_namespace: unresolved size: %lu\n", in_buf_size);
- RtlInitUnicodeString(&uUnresolved, (WCHAR *) in_buf);
+ RtlInitUnicodeString(&uUnresolved, (WCHAR*)in_buf);
status = nt2dos(&uResolved, &uUnresolved);
if (!NT_SUCCESS(status))
@@ -52,8 +49,7 @@ static NTSTATUS handle_convert_nt_path(
DbgPrint("nt_namespace: resolved path: %wZ\n", &uResolved);
DbgPrint("nt_namespace: resolved size: %Iu\n", *nbwritten);
- if (out_buf_size < *nbwritten)
- {
+ if (out_buf_size < *nbwritten) {
status = STATUS_BUFFER_OVERFLOW;
goto free_resolved;
}
@@ -67,10 +63,9 @@ free_resolved:
return status;
}
-static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp)
-{
- IO_STACK_LOCATION *io_stack_loc;
- void* in_buf, *out_buf;
+static NTSTATUS device_ioctl(DEVICE_OBJECT* device_object, IRP* irp) {
+ IO_STACK_LOCATION* io_stack_loc;
+ void *in_buf, *out_buf;
unsigned long in_buf_size, out_buf_size;
ioctl_handler handler;
NTSTATUS status = STATUS_UNSUCCESSFUL;
@@ -85,8 +80,7 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp)
in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength;
out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength;
- switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode)
- {
+ switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) {
case CONVERT_NT_PATH:
handler = handle_convert_nt_path;
break;
@@ -96,10 +90,8 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp)
goto complete_request;
}
- status = irp->IoStatus.Status = handler(
- in_buf, in_buf_size,
- out_buf, out_buf_size,
- &irp->IoStatus.Information);
+ status = irp->IoStatus.Status =
+ handler(in_buf, in_buf_size, out_buf, out_buf_size, &irp->IoStatus.Information);
complete_request:
IoCompleteRequest(irp, IO_NO_INCREMENT);
@@ -107,25 +99,20 @@ complete_request:
return status;
}
-typedef struct
-{
- const wchar_t *path;
- const wchar_t *symlink;
-}
-DeviceInfo;
+typedef struct {
+ const wchar_t* path;
+ const wchar_t* symlink;
+} DeviceInfo;
-typedef struct
-{
- DEVICE_OBJECT *object;
+typedef struct {
+ DEVICE_OBJECT* object;
UNICODE_STRING path;
UNICODE_STRING symlink;
-}
-Device;
+} Device;
#define NUMOF_DEVICES 1
-static DeviceInfo devices_info[NUMOF_DEVICES] =
-{
+static DeviceInfo devices_info[NUMOF_DEVICES] = {
{
L"\\Device\\nt_namespace",
L"\\DosDevices\\nt_namespace",
@@ -134,21 +121,18 @@ static DeviceInfo devices_info[NUMOF_DEVICES] =
static Device devices[NUMOF_DEVICES];
-static void destroy_device(int i)
-{
+static void destroy_device(int i) {
IoDeleteSymbolicLink(&devices[i].symlink);
IoDeleteDevice(devices[i].object);
}
-void destroy_devices()
-{
+void destroy_devices() {
int i;
for (i = 0; i < NUMOF_DEVICES; ++i)
destroy_device(i);
}
-static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i)
-{
+static NTSTATUS set_up_device(DRIVER_OBJECT* driver_object, int i) {
NTSTATUS status = STATUS_SUCCESS;
RtlInitUnicodeString(&devices[i].path, devices_info[i].path);
@@ -161,7 +145,8 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i)
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
- &devices[i].object);
+ &devices[i].object
+ );
if (!NT_SUCCESS(status))
return status;
@@ -169,8 +154,7 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i)
devices[i].object->Flags |= DO_BUFFERED_IO;
devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING;
- if (!NT_SUCCESS(status = IoCreateSymbolicLink(
- &devices[i].symlink, &devices[i].path)))
+ if (!NT_SUCCESS(status = IoCreateSymbolicLink(&devices[i].symlink, &devices[i].path)))
goto delete_device;
return status;
@@ -181,8 +165,7 @@ delete_device:
return status;
}
-NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object)
-{
+NTSTATUS set_up_devices(DRIVER_OBJECT* driver_object) {
int i, j;
NTSTATUS status = STATUS_SUCCESS;