xref: /reactos/sdk/lib/drivers/ntoskrnl_vista/io.c (revision 0c2cdcae)
1 /*
2  * PROJECT:     ReactOS Kernel - Vista+ APIs
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Io functions of Vista+
5  * COPYRIGHT:   2016 Pierre Schweitzer (pierre@reactos.org)
6  *              2020 Victor Perevertkin (victor.perevertkin@reactos.org)
7  */
8 
9 #include <ntdef.h>
10 #include <ntifs.h>
11 
12 typedef struct _EX_WORKITEM_CONTEXT
13 {
14     PIO_WORKITEM WorkItem;
15     PIO_WORKITEM_ROUTINE_EX WorkItemRoutineEx;
16     PVOID Context;
17 } EX_WORKITEM_CONTEXT, *PEX_WORKITEM_CONTEXT;
18 
19 #define TAG_IOWI 'IWOI'
20 
21 NTKRNLVISTAAPI
22 NTSTATUS
23 NTAPI
24 IoGetIrpExtraCreateParameter(IN PIRP Irp,
25                              OUT PECP_LIST *ExtraCreateParameter)
26 {
27     /* Check we have a create operation */
28     if (!BooleanFlagOn(Irp->Flags, IRP_CREATE_OPERATION))
29     {
30         return STATUS_INVALID_PARAMETER;
31     }
32 
33     /* If so, return user buffer */
34     *ExtraCreateParameter = Irp->UserBuffer;
35     return STATUS_SUCCESS;
36 }
37 
38 _Function_class_(IO_WORKITEM_ROUTINE)
39 static
40 VOID
41 NTAPI
42 IopWorkItemExCallback(
43     PDEVICE_OBJECT DeviceObject,
44     PVOID Ctx)
45 {
46     PEX_WORKITEM_CONTEXT context = Ctx;
47 
48     context->WorkItemRoutineEx(DeviceObject, context->Context, context->WorkItem);
49     ExFreePoolWithTag(context, TAG_IOWI);
50 }
51 
52 NTKRNLVISTAAPI
53 VOID
54 NTAPI
55 IoQueueWorkItemEx(
56     _Inout_ PIO_WORKITEM IoWorkItem,
57     _In_ PIO_WORKITEM_ROUTINE_EX WorkerRoutine,
58     _In_ WORK_QUEUE_TYPE QueueType,
59     _In_opt_ __drv_aliasesMem PVOID Context)
60 {
61     PEX_WORKITEM_CONTEXT newContext = ExAllocatePoolWithTag(NonPagedPoolMustSucceed, sizeof(*newContext), TAG_IOWI);
62     newContext->WorkItem = IoWorkItem;
63     newContext->WorkItemRoutineEx = WorkerRoutine;
64     newContext->Context = Context;
65 
66     IoQueueWorkItem(IoWorkItem, IopWorkItemExCallback, QueueType, newContext);
67 }
68 
69 _IRQL_requires_max_(PASSIVE_LEVEL)
70 _Must_inspect_result_
71 NTKRNLVISTAAPI
72 NTSTATUS
73 NTAPI
74 IoSetDevicePropertyData(
75     _In_ PDEVICE_OBJECT Pdo,
76     _In_ CONST DEVPROPKEY *PropertyKey,
77     _In_ LCID Lcid,
78     _In_ ULONG Flags,
79     _In_ DEVPROPTYPE Type,
80     _In_ ULONG Size,
81     _In_opt_ PVOID Data)
82 {
83     return STATUS_NOT_IMPLEMENTED;
84 }
85 
86 _IRQL_requires_max_(PASSIVE_LEVEL)
87 _Must_inspect_result_
88 NTKRNLVISTAAPI
89 NTSTATUS
90 NTAPI
91 IoGetDevicePropertyData(
92     _In_ PDEVICE_OBJECT Pdo,
93     _In_ CONST DEVPROPKEY *PropertyKey,
94     _In_ LCID Lcid,
95     _Reserved_ ULONG Flags,
96     _In_ ULONG Size,
97     _Out_ PVOID Data,
98     _Out_ PULONG RequiredSize,
99     _Out_ PDEVPROPTYPE Type)
100 {
101     return STATUS_NOT_IMPLEMENTED;
102 }
103 
104 _IRQL_requires_max_(PASSIVE_LEVEL)
105 _Must_inspect_result_
106 NTKRNLVISTAAPI
107 NTSTATUS
108 IoSetDeviceInterfacePropertyData(
109     _In_ PUNICODE_STRING SymbolicLinkName,
110     _In_ CONST DEVPROPKEY *PropertyKey,
111     _In_ LCID Lcid,
112     _In_ ULONG Flags,
113     _In_ DEVPROPTYPE Type,
114     _In_ ULONG Size,
115     _In_reads_bytes_opt_(Size) PVOID Data)
116 {
117     return STATUS_NOT_IMPLEMENTED;
118 }
119 
120 NTKRNLVISTAAPI
121 IO_PRIORITY_HINT
122 NTAPI
123 IoGetIoPriorityHint(
124     _In_ PIRP Irp)
125 {
126     return IoPriorityNormal;
127 }
128 
129 NTKRNLVISTAAPI
130 VOID
131 IoSetMasterIrpStatus(
132     _Inout_ PIRP MasterIrp,
133     _In_ NTSTATUS Status)
134 {
135     NTSTATUS MasterStatus = MasterIrp->IoStatus.Status;
136 
137     if (Status == STATUS_FT_READ_FROM_COPY)
138     {
139         return;
140     }
141 
142     if ((Status == STATUS_VERIFY_REQUIRED) ||
143         (MasterStatus == STATUS_SUCCESS && !NT_SUCCESS(Status)) ||
144         (!NT_SUCCESS(MasterStatus) && !NT_SUCCESS(Status) && Status > MasterStatus))
145     {
146         MasterIrp->IoStatus.Status = Status;
147     }
148 }
149