3 * Copyright (C) 2008 ReactOS Team
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.
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.
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.
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
26 /* INCLUDES *****************************************************************/
33 static LONG QueueCount
= 0;
35 /* FUNCTIONS ****************************************************************/
37 static WORKER_THREAD_ROUTINE CdfsDoRequest
;
41 CdfsQueueRequest(PCDFS_IRP_CONTEXT IrpContext
)
43 InterlockedIncrement(&QueueCount
);
44 DPRINT("CdfsQueueRequest(IrpContext %p), %d\n", IrpContext
, QueueCount
);
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
);
53 return STATUS_PENDING
;
59 IN PCDFS_IRP_CONTEXT IrpContext
)
64 DPRINT("CdfsLockControl(IrpContext %p)\n", IrpContext
);
66 if (IrpContext
->DeviceObject
== CdfsGlobalData
->CdFsDeviceObject
|| IrpContext
->DeviceObject
== CdfsGlobalData
->HddFsDeviceObject
)
68 return STATUS_INVALID_DEVICE_REQUEST
;
71 Fcb
= IrpContext
->FileObject
->FsContext
;
72 if (CdfsFCBIsDirectory(Fcb
))
74 return STATUS_INVALID_PARAMETER
;
77 IrpContext
->Flags
&= ~IRPCONTEXT_COMPLETE
;
78 Status
= FsRtlProcessFileLock(&Fcb
->FileLock
,
86 CdfsDispatch(PCDFS_IRP_CONTEXT IrpContext
)
88 PIRP Irp
= IrpContext
->Irp
;
89 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
91 DPRINT("CdfsDispatch()\n");
93 FsRtlEnterFileSystem();
95 CdfsIsIrpTopLevel(Irp
);
97 switch (IrpContext
->MajorFunction
)
99 case IRP_MJ_QUERY_VOLUME_INFORMATION
:
100 Status
= CdfsQueryVolumeInformation(IrpContext
);
103 case IRP_MJ_SET_VOLUME_INFORMATION
:
104 Status
= CdfsSetVolumeInformation(IrpContext
);
107 case IRP_MJ_QUERY_INFORMATION
:
108 Status
= CdfsQueryInformation(IrpContext
);
111 case IRP_MJ_SET_INFORMATION
:
112 Status
= CdfsSetInformation(IrpContext
);
115 case IRP_MJ_DIRECTORY_CONTROL
:
116 Status
= CdfsDirectoryControl(IrpContext
);
120 Status
= CdfsRead(IrpContext
);
123 case IRP_MJ_DEVICE_CONTROL
:
124 Status
= CdfsDeviceControl(IrpContext
);
128 Status
= CdfsWrite(IrpContext
);
132 Status
= CdfsClose(IrpContext
);
136 Status
= CdfsCreate(IrpContext
);
140 Status
= CdfsCleanup(IrpContext
);
143 case IRP_MJ_FILE_SYSTEM_CONTROL
:
144 Status
= CdfsFileSystemControl(IrpContext
);
147 case IRP_MJ_LOCK_CONTROL
:
148 Status
= CdfsLockControl(IrpContext
);
152 ASSERT((!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
153 ((IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
154 (!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)));
156 if (IrpContext
->Flags
& IRPCONTEXT_COMPLETE
)
158 Irp
->IoStatus
.Status
= Status
;
159 IoCompleteRequest(Irp
, IrpContext
->PriorityBoost
);
162 if (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)
164 /* Reset our status flags before queueing the IRP */
165 IrpContext
->Flags
|= IRPCONTEXT_COMPLETE
;
166 IrpContext
->Flags
&= ~IRPCONTEXT_QUEUE
;
167 Status
= CdfsQueueRequest(IrpContext
);
171 ExFreeToNPagedLookasideList(&CdfsGlobalData
->IrpContextLookasideList
, IrpContext
);
174 IoSetTopLevelIrp(NULL
);
175 FsRtlExitFileSystem();
183 CdfsDoRequest(PVOID IrpContext
)
185 InterlockedDecrement(&QueueCount
);
186 DPRINT("CdfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
187 IrpContext
, ((PCDFS_IRP_CONTEXT
)IrpContext
)->MajorFunction
, QueueCount
);
188 CdfsDispatch((PCDFS_IRP_CONTEXT
)IrpContext
);
192 * FUNCTION: This function manages IRP for various major functions
194 * DriverObject = object describing this driver
195 * Irp = IRP to be passed to internal functions
196 * RETURNS: Status of I/O Request
201 PDEVICE_OBJECT DeviceObject
,
204 PCDFS_IRP_CONTEXT IrpContext
= NULL
;
207 DPRINT("CdfsFsdDispatch()\n");
209 IrpContext
= CdfsAllocateIrpContext(DeviceObject
, Irp
);
210 if (IrpContext
== NULL
)
212 Status
= STATUS_INSUFFICIENT_RESOURCES
;
213 Irp
->IoStatus
.Status
= Status
;
214 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
218 Status
= CdfsDispatch(IrpContext
);