3 * Copyright (C) 2002, 2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: drivers/fs/cdfs/common.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Art Yerkes
29 /* INCLUDES *****************************************************************/
36 /* FUNCTIONS ****************************************************************/
39 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject
,
45 PIO_STACK_LOCATION Stack
;
46 IO_STATUS_BLOCK IoStatus
;
54 KeInitializeEvent(&Event
,
58 Offset
.u
.LowPart
= DiskSector
<< 11;
59 Offset
.u
.HighPart
= DiskSector
>> 21;
61 BlockSize
= BLOCKSIZE
* SectorCount
;
63 DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
64 DeviceObject
, DiskSector
, Buffer
);
65 DPRINT("Offset %I64x BlockSize %ld\n",
69 DPRINT("Building synchronous FSD Request...\n");
70 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
79 DPRINT("IoBuildSynchronousFsdRequest failed\n");
80 return(STATUS_INSUFFICIENT_RESOURCES
);
85 Stack
= IoGetNextIrpStackLocation(Irp
);
86 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
89 DPRINT("Calling IO Driver... with irp %x\n", Irp
);
90 Status
= IoCallDriver(DeviceObject
, Irp
);
92 DPRINT("Waiting for IO Operation for %x\n", Irp
);
93 if (Status
== STATUS_PENDING
)
95 DPRINT("Operation pending\n");
96 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
97 DPRINT("Getting IO Status... for %x\n", Irp
);
98 Status
= IoStatus
.Status
;
101 if (!NT_SUCCESS(Status
))
103 if (Status
== STATUS_VERIFY_REQUIRED
)
105 PDEVICE_OBJECT DeviceToVerify
;
107 DPRINT1("STATUS_VERIFY_REQUIRED\n");
108 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
109 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
111 Status
= IoVerifyVolume(DeviceToVerify
, FALSE
);
112 DPRINT1("IoVerifyVolume() returned (Status %lx)\n", Status
);
114 if (NT_SUCCESS(Status
))
116 DPRINT1("Volume verify succeeded; trying request again\n");
121 DPRINT("CdfsReadSectors() failed (Status %x)\n", Status
);
122 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
123 DeviceObject
, DiskSector
, Buffer
,
128 DPRINT("Block request succeeded for %x\n", Irp
);
130 return(STATUS_SUCCESS
);
135 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
137 IN PVOID InputBuffer
,
138 IN ULONG InputBufferSize
,
139 IN OUT PVOID OutputBuffer
,
140 IN OUT PULONG OutputBufferSize
,
143 PIO_STACK_LOCATION Stack
;
144 IO_STATUS_BLOCK IoStatus
;
149 DPRINT("CdfsDeviceIoControl(DeviceObject %x, CtlCode %x, "
150 "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
151 "POutputBufferSize %x (%x)\n", DeviceObject
, CtlCode
,
152 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
,
153 OutputBufferSize
? *OutputBufferSize
: 0);
156 KeInitializeEvent (&Event
, NotificationEvent
, FALSE
);
158 DPRINT("Building device I/O control request ...\n");
159 Irp
= IoBuildDeviceIoControlRequest(CtlCode
,
164 (OutputBufferSize
!= NULL
) ? *OutputBufferSize
: 0,
170 DPRINT("IoBuildDeviceIoControlRequest failed\n");
171 return STATUS_INSUFFICIENT_RESOURCES
;
176 Stack
= IoGetNextIrpStackLocation(Irp
);
177 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
180 DPRINT ("Calling IO Driver... with irp %x\n", Irp
);
181 Status
= IoCallDriver(DeviceObject
, Irp
);
183 DPRINT ("Waiting for IO Operation for %x\n", Irp
);
184 if (Status
== STATUS_PENDING
)
186 DPRINT ("Operation pending\n");
187 KeWaitForSingleObject (&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
188 DPRINT ("Getting IO Status... for %x\n", Irp
);
190 Status
= IoStatus
.Status
;
193 if (OutputBufferSize
!= NULL
)
195 *OutputBufferSize
= IoStatus
.Information
;
198 if (Status
== STATUS_VERIFY_REQUIRED
)
200 PDEVICE_OBJECT DeviceToVerify
;
202 DPRINT1("STATUS_VERIFY_REQUIRED\n");
203 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
204 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
208 Status
= IoVerifyVolume(DeviceToVerify
, FALSE
);
209 DPRINT1("IoVerifyVolume() returned (Status %lx)\n", Status
);
212 if (NT_SUCCESS(Status
))
214 DPRINT1("Volume verify succeeded; trying request again\n");
219 DPRINT("Returning Status %x\n", Status
);