1d1951bcc3da050dc7df91adaf80ee0ac6a96b12
[reactos.git] / reactos / drivers / filesystems / cdfs / dispatch.c
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/filesystems/cdfs/dispatch.c
22 * PURPOSE: CDROM (ISO 9660) filesystem driver
23 * PROGRAMMER: Pierre Schweitzer
24 */
25
26 /* INCLUDES *****************************************************************/
27
28 #include "cdfs.h"
29
30 #define NDEBUG
31 #include <debug.h>
32
33 static LONG QueueCount = 0;
34
35 /* FUNCTIONS ****************************************************************/
36
37 static WORKER_THREAD_ROUTINE CdfsDoRequest;
38
39 static
40 NTSTATUS
41 CdfsQueueRequest(PCDFS_IRP_CONTEXT IrpContext)
42 {
43 InterlockedIncrement(&QueueCount);
44 DPRINT("CdfsQueueRequest(IrpContext %p), %d\n", IrpContext, QueueCount);
45
46 ASSERT(!(IrpContext->Flags & IRPCONTEXT_QUEUE) &&
47 (IrpContext->Flags & IRPCONTEXT_COMPLETE));
48 IrpContext->Flags |= IRPCONTEXT_CANWAIT;
49 IoMarkIrpPending(IrpContext->Irp);
50 ExInitializeWorkItem(&IrpContext->WorkQueueItem, CdfsDoRequest, IrpContext);
51 ExQueueWorkItem(&IrpContext->WorkQueueItem, CriticalWorkQueue);
52
53 return STATUS_PENDING;
54 }
55
56 static
57 NTSTATUS
58 CdfsDispatch(PCDFS_IRP_CONTEXT IrpContext)
59 {
60 PIRP Irp = IrpContext->Irp;
61 NTSTATUS Status = STATUS_UNSUCCESSFUL;
62
63 DPRINT("CdfsDispatch()\n");
64
65 FsRtlEnterFileSystem();
66
67 CdfsIsIrpTopLevel(Irp);
68
69 switch (IrpContext->MajorFunction)
70 {
71 case IRP_MJ_QUERY_VOLUME_INFORMATION:
72 Status = CdfsQueryVolumeInformation(IrpContext);
73 break;
74
75 case IRP_MJ_SET_VOLUME_INFORMATION:
76 Status = CdfsSetVolumeInformation(IrpContext);
77 break;
78
79 case IRP_MJ_QUERY_INFORMATION:
80 Status = CdfsQueryInformation(IrpContext);
81 break;
82
83 case IRP_MJ_SET_INFORMATION:
84 Status = CdfsSetInformation(IrpContext);
85 break;
86
87 case IRP_MJ_DIRECTORY_CONTROL:
88 Status = CdfsDirectoryControl(IrpContext);
89 break;
90
91 case IRP_MJ_READ:
92 // Status = CdfsRead(IrpContext);
93 break;
94
95 case IRP_MJ_DEVICE_CONTROL:
96 Status = CdfsDeviceControl(IrpContext);
97 break;
98
99 case IRP_MJ_WRITE:
100 // Status = CdfsWrite(IrpContext);
101 break;
102
103 case IRP_MJ_CLOSE:
104 // Status = CdfsClose(IrpContext);
105 break;
106
107 case IRP_MJ_CREATE:
108 // Status = CdfsCreate(IrpContext);
109 break;
110
111 case IRP_MJ_FILE_SYSTEM_CONTROL:
112 Status = CdfsFileSystemControl(IrpContext);
113 break;
114 }
115
116 ASSERT((!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
117 ((IrpContext->Flags & IRPCONTEXT_COMPLETE) && !(IrpContext->Flags & IRPCONTEXT_QUEUE)) ||
118 (!(IrpContext->Flags & IRPCONTEXT_COMPLETE) && (IrpContext->Flags & IRPCONTEXT_QUEUE)));
119
120 if (IrpContext->Flags & IRPCONTEXT_COMPLETE)
121 {
122 Irp->IoStatus.Status = Status;
123 IoCompleteRequest(Irp, IrpContext->PriorityBoost);
124 }
125
126 if (IrpContext->Flags & IRPCONTEXT_QUEUE)
127 {
128 /* Reset our status flags before queueing the IRP */
129 IrpContext->Flags |= IRPCONTEXT_COMPLETE;
130 IrpContext->Flags &= ~IRPCONTEXT_QUEUE;
131 Status = CdfsQueueRequest(IrpContext);
132 }
133 else
134 {
135 ExFreeToNPagedLookasideList(&CdfsGlobalData->IrpContextLookasideList, IrpContext);
136 }
137
138 IoSetTopLevelIrp(NULL);
139 FsRtlExitFileSystem();
140
141 return Status;
142 }
143
144 static
145 VOID
146 NTAPI
147 CdfsDoRequest(PVOID IrpContext)
148 {
149 InterlockedDecrement(&QueueCount);
150 DPRINT("CdfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
151 IrpContext, ((PCDFS_IRP_CONTEXT)IrpContext)->MajorFunction, QueueCount);
152 CdfsDispatch((PCDFS_IRP_CONTEXT)IrpContext);
153 }
154
155 /*
156 * FUNCTION: This function manages IRP for various major functions
157 * ARGUMENTS:
158 * DriverObject = object describing this driver
159 * Irp = IRP to be passed to internal functions
160 * RETURNS: Status of I/O Request
161 */
162 NTSTATUS
163 NTAPI
164 CdfsFsdDispatch(
165 PDEVICE_OBJECT DeviceObject,
166 PIRP Irp)
167 {
168 PCDFS_IRP_CONTEXT IrpContext = NULL;
169 NTSTATUS Status;
170
171 DPRINT("CdfsFsdDispatch()\n");
172
173 IrpContext = CdfsAllocateIrpContext(DeviceObject, Irp);
174 if (IrpContext == NULL)
175 {
176 Status = STATUS_INSUFFICIENT_RESOURCES;
177 Irp->IoStatus.Status = Status;
178 IoCompleteRequest(Irp, IO_NO_INCREMENT);
179 }
180 else
181 {
182 Status = CdfsDispatch(IrpContext);
183 }
184
185 return Status;
186 }