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
;
58 CdfsDispatch(PCDFS_IRP_CONTEXT IrpContext
)
60 PIRP Irp
= IrpContext
->Irp
;
61 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
63 DPRINT("CdfsDispatch()\n");
65 FsRtlEnterFileSystem();
67 CdfsIsIrpTopLevel(Irp
);
69 switch (IrpContext
->MajorFunction
)
71 case IRP_MJ_QUERY_VOLUME_INFORMATION
:
72 Status
= CdfsQueryVolumeInformation(IrpContext
);
75 case IRP_MJ_SET_VOLUME_INFORMATION
:
76 Status
= CdfsSetVolumeInformation(IrpContext
);
79 case IRP_MJ_QUERY_INFORMATION
:
80 Status
= CdfsQueryInformation(IrpContext
);
83 case IRP_MJ_SET_INFORMATION
:
84 Status
= CdfsSetInformation(IrpContext
);
87 case IRP_MJ_DIRECTORY_CONTROL
:
88 Status
= CdfsDirectoryControl(IrpContext
);
92 Status
= CdfsRead(IrpContext
);
95 case IRP_MJ_DEVICE_CONTROL
:
96 Status
= CdfsDeviceControl(IrpContext
);
100 Status
= CdfsWrite(IrpContext
);
104 Status
= CdfsClose(IrpContext
);
108 Status
= CdfsCreate(IrpContext
);
112 Status
= CdfsCleanup(IrpContext
);
115 case IRP_MJ_FILE_SYSTEM_CONTROL
:
116 Status
= CdfsFileSystemControl(IrpContext
);
120 ASSERT((!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
121 ((IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && !(IrpContext
->Flags
& IRPCONTEXT_QUEUE
)) ||
122 (!(IrpContext
->Flags
& IRPCONTEXT_COMPLETE
) && (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)));
124 if (IrpContext
->Flags
& IRPCONTEXT_COMPLETE
)
126 Irp
->IoStatus
.Status
= Status
;
127 IoCompleteRequest(Irp
, IrpContext
->PriorityBoost
);
130 if (IrpContext
->Flags
& IRPCONTEXT_QUEUE
)
132 /* Reset our status flags before queueing the IRP */
133 IrpContext
->Flags
|= IRPCONTEXT_COMPLETE
;
134 IrpContext
->Flags
&= ~IRPCONTEXT_QUEUE
;
135 Status
= CdfsQueueRequest(IrpContext
);
139 ExFreeToNPagedLookasideList(&CdfsGlobalData
->IrpContextLookasideList
, IrpContext
);
142 IoSetTopLevelIrp(NULL
);
143 FsRtlExitFileSystem();
151 CdfsDoRequest(PVOID IrpContext
)
153 InterlockedDecrement(&QueueCount
);
154 DPRINT("CdfsDoRequest(IrpContext %p), MajorFunction %x, %d\n",
155 IrpContext
, ((PCDFS_IRP_CONTEXT
)IrpContext
)->MajorFunction
, QueueCount
);
156 CdfsDispatch((PCDFS_IRP_CONTEXT
)IrpContext
);
160 * FUNCTION: This function manages IRP for various major functions
162 * DriverObject = object describing this driver
163 * Irp = IRP to be passed to internal functions
164 * RETURNS: Status of I/O Request
169 PDEVICE_OBJECT DeviceObject
,
172 PCDFS_IRP_CONTEXT IrpContext
= NULL
;
175 DPRINT("CdfsFsdDispatch()\n");
177 IrpContext
= CdfsAllocateIrpContext(DeviceObject
, Irp
);
178 if (IrpContext
== NULL
)
180 Status
= STATUS_INSUFFICIENT_RESOURCES
;
181 Irp
->IoStatus
.Status
= Status
;
182 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
186 Status
= CdfsDispatch(IrpContext
);