ReactOS 0.4.17-dev-1190-g4c812f4
dispatch.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2008 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/dispatch.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Pierre Schweitzer
24 * UPDATE HISTORY:
25 */
26
27/* INCLUDES *****************************************************************/
28
29#include "ntfs.h"
30
31#define NDEBUG
32#include <debug.h>
33
34static LONG QueueCount = 0;
35
36/* FUNCTIONS ****************************************************************/
37
38static WORKER_THREAD_ROUTINE NtfsDoRequest;
39
40static
43{
45 DPRINT("NtfsQueueRequest(IrpContext %p), %d\n", IrpContext, QueueCount);
46
47 ASSERT(!(IrpContext->Flags & IRPCONTEXT_QUEUE) &&
48 (IrpContext->Flags & IRPCONTEXT_COMPLETE));
49 IrpContext->Flags |= IRPCONTEXT_CANWAIT;
50 IoMarkIrpPending(IrpContext->Irp);
51 ExInitializeWorkItem(&IrpContext->WorkQueueItem, NtfsDoRequest, IrpContext);
53
54 return STATUS_PENDING;
55}
56
57static
60{
61 PIRP Irp = IrpContext->Irp;
64
65 TRACE_(NTFS, "NtfsDispatch()\n");
66
68
70
71 switch (IrpContext->MajorFunction)
72 {
75 break;
76
78 Status = NtfsSetVolumeInformation(IrpContext);
79 break;
80
82 Status = NtfsQueryInformation(IrpContext);
83 break;
84
87 {
88 DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
90 }
91 else
92 {
93 Status = NtfsSetInformation(IrpContext);
94 }
95 break;
96
98 Status = NtfsDirectoryControl(IrpContext);
99 break;
100
101 case IRP_MJ_READ:
102 Status = NtfsRead(IrpContext);
103 break;
104
106 Status = NtfsDeviceControl(IrpContext);
107 break;
108
109 case IRP_MJ_WRITE:
111 {
112 DPRINT1("NTFS write-support is EXPERIMENTAL and is disabled by default!\n");
114 }
115 else
116 {
117 Status = NtfsWrite(IrpContext);
118 }
119 break;
120
121 case IRP_MJ_CLOSE:
122 Status = NtfsClose(IrpContext);
123 break;
124
125 case IRP_MJ_CLEANUP:
126 Status = NtfsCleanup(IrpContext);
127 break;
128
129 case IRP_MJ_CREATE:
130 Status = NtfsCreate(IrpContext);
131 break;
132
134 Status = NtfsFileSystemControl(IrpContext);
135 break;
136
138 Status = NtfsFlushBuffers(IrpContext);
139 break;
140
142 Status = NtfsLockControl(IrpContext);
143 break;
144 }
145
146 ASSERT((!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
147 ((IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
148 (!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && (IrpContext->Flags & IRPCONTEXT_QUEUE)));
149
150 if (IrpContext->Flags & IRPCONTEXT_COMPLETE)
151 {
152 Irp->IoStatus.Status = Status;
153 IoCompleteRequest(Irp, IrpContext->PriorityBoost);
154 }
155
156 if (IrpContext->Flags & IRPCONTEXT_QUEUE)
157 {
158 /* Reset our status flags before queueing the IRP */
159 IrpContext->Flags |= IRPCONTEXT_COMPLETE;
160 IrpContext->Flags &= ~IRPCONTEXT_QUEUE;
161 Status = NtfsQueueRequest(IrpContext);
162 }
163 else
164 {
165 ExFreeToNPagedLookasideList(&NtfsGlobalData->IrpContextLookasideList, IrpContext);
166 }
167
168 /* Cc and Mm set their own top level IRP around paging I/O, leave theirs alone */
169 if (TopLevel)
171
173
174 return Status;
175}
176
177static
178VOID
179NTAPI
181{
183 DPRINT("NtfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
184 IrpContext, ((PNTFS_IRP_CONTEXT)IrpContext)->MajorFunction, QueueCount);
185 NtfsDispatch((PNTFS_IRP_CONTEXT)IrpContext);
186}
187
188/*
189 * FUNCTION: This function manages IRP for various major functions
190 * ARGUMENTS:
191 * DriverObject = object describing this driver
192 * Irp = IRP to be passed to internal functions
193 * RETURNS: Status of I/O Request
194 */
196NTAPI
198 PIRP Irp)
199{
200 PNTFS_IRP_CONTEXT IrpContext = NULL;
202
203 TRACE_(NTFS, "NtfsFsdDispatch()\n");
204
206 if (IrpContext == NULL)
207 {
209 Irp->IoStatus.Status = Status;
211 }
212 else
213 {
214 Status = NtfsDispatch(IrpContext);
215 }
216
217 return Status;
218}
@ NTFS
Definition: IoFilesystem.c:12
unsigned char BOOLEAN
Definition: actypes.h:127
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
ARC_STATUS NtfsClose(ULONG FileId)
Definition: ntfs.c:921
ARC_STATUS NtfsRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: ntfs.c:1000
#define NULL
Definition: types.h:112
#define TRACE_(x)
Definition: compat.h:76
NTSTATUS NtfsCleanup(PNTFS_IRP_CONTEXT IrpContext)
Definition: cleanup.c:171
NTSTATUS NtfsCreate(PNTFS_IRP_CONTEXT IrpContext)
Definition: create.c:824
static NTSTATUS NtfsQueueRequest(PNTFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:42
static LONG QueueCount
Definition: dispatch.c:34
static WORKER_THREAD_ROUTINE NtfsDoRequest
Definition: dispatch.c:38
static NTSTATUS NtfsDispatch(PNTFS_IRP_CONTEXT IrpContext)
Definition: dispatch.c:59
BOOLEAN NtfsIsIrpTopLevel(PIRP Irp)
Definition: misc.c:43
PNTFS_IRP_CONTEXT NtfsAllocateIrpContext(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: misc.c:66
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:36
#define IRPCONTEXT_QUEUE
Definition: ntfs.h:507
#define IRPCONTEXT_COMPLETE
Definition: ntfs.h:506
DRIVER_DISPATCH NtfsFsdDispatch
Definition: ntfs.h:1021
#define IRPCONTEXT_CANWAIT
Definition: ntfs.h:505
NTSTATUS NtfsWrite(PNTFS_IRP_CONTEXT IrpContext)
Definition: rw.c:965
NTSTATUS NtfsQueryVolumeInformation(PNTFS_IRP_CONTEXT IrpContext)
Definition: volinfo.c:430
NTSTATUS NtfsSetVolumeInformation(PNTFS_IRP_CONTEXT IrpContext)
Definition: volinfo.c:507
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2418
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:24
IoMarkIrpPending(Irp)
_In_ PIRP Irp
Definition: kse.h:79
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NtfsDeviceControl(PNTFS_IRP_CONTEXT IrpContext)
Definition: devctl.c:36
NTSTATUS NtfsDirectoryControl(PNTFS_IRP_CONTEXT IrpContext)
Definition: dirctl.c:793
NTSTATUS NtfsQueryInformation(PNTFS_IRP_CONTEXT IrpContext)
Definition: finfo.c:470
NTSTATUS NtfsSetInformation(PNTFS_IRP_CONTEXT IrpContext)
Definition: finfo.c:1748
NTSTATUS NtfsFlushBuffers(PNTFS_IRP_CONTEXT IrpContext)
Definition: flush.c:107
NTSTATUS NtfsFileSystemControl(PNTFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1045
NTSTATUS NTAPI NtfsLockControl(_In_ PNTFS_IRP_CONTEXT IrpContext)
Definition: lockctrl.c:19
#define IoCompleteRequest
Definition: irp.c:1272
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2032
long LONG
Definition: pedump.c:60
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define DPRINT
Definition: sndvol32.h:73
BOOLEAN EnableWriteSupport
Definition: ntfs.h:182
NPAGED_LOOKASIDE_LIST IrpContextLookasideList
Definition: ntfs.h:179
UCHAR MajorFunction
Definition: ntfs.h:558
ULONG Flags
Definition: ntfs.h:556
WORK_QUEUE_ITEM WorkQueueItem
Definition: ntfs.h:560
CCHAR PriorityBoost
Definition: ntfs.h:566
#define STATUS_PENDING
Definition: telnetd.h:14
#define NTAPI
Definition: typedefs.h:36
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1703
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:727
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ CriticalWorkQueue
Definition: extypes.h:189
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define IRP_MJ_SET_VOLUME_INFORMATION
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_CLEANUP