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.
19 /* $Id: common.c 55057 2012-01-21 22:16:46Z cgutman $
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
;
52 BOOLEAN LastChance
= FALSE
;
55 KeInitializeEvent(&Event
,
59 Offset
.u
.LowPart
= DiskSector
<< 11;
60 Offset
.u
.HighPart
= DiskSector
>> 21;
62 BlockSize
= BLOCKSIZE
* SectorCount
;
64 DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
65 DeviceObject
, DiskSector
, Buffer
);
66 DPRINT("Offset %I64x BlockSize %ld\n",
70 DPRINT("Building synchronous FSD Request...\n");
71 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
80 DPRINT("IoBuildSynchronousFsdRequest failed\n");
81 return(STATUS_INSUFFICIENT_RESOURCES
);
86 Stack
= IoGetNextIrpStackLocation(Irp
);
87 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
90 DPRINT("Calling IO Driver... with irp %x\n", Irp
);
91 Status
= IoCallDriver(DeviceObject
, Irp
);
93 DPRINT("Waiting for IO Operation for %x\n", Irp
);
94 if (Status
== STATUS_PENDING
)
96 DPRINT("Operation pending\n");
97 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
98 DPRINT("Getting IO Status... for %x\n", Irp
);
99 Status
= IoStatus
.Status
;
102 if (!NT_SUCCESS(Status
))
104 if (Status
== STATUS_VERIFY_REQUIRED
)
106 PDEVICE_OBJECT DeviceToVerify
;
108 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
109 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
111 Status
= IoVerifyVolume(DeviceToVerify
, FALSE
);
113 if (NT_SUCCESS(Status
) && !LastChance
)
115 DPRINT("Volume verify succeeded; trying request again\n");
119 else if (NT_SUCCESS(Status
))
121 DPRINT1("Failed to read after successful verify, aborting\n");
122 Status
= STATUS_DEVICE_NOT_READY
;
126 DPRINT1("IoVerifyVolume() failed (Status %lx)\n", Status
);
130 DPRINT("CdfsReadSectors() failed (Status %x)\n", Status
);
131 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
132 DeviceObject
, DiskSector
, Buffer
,
137 DPRINT("Block request succeeded for %x\n", Irp
);
139 return(STATUS_SUCCESS
);
144 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
146 IN PVOID InputBuffer
,
147 IN ULONG InputBufferSize
,
148 IN OUT PVOID OutputBuffer
,
149 IN OUT PULONG OutputBufferSize
,
152 PIO_STACK_LOCATION Stack
;
153 IO_STATUS_BLOCK IoStatus
;
157 BOOLEAN LastChance
= FALSE
;
159 DPRINT("CdfsDeviceIoControl(DeviceObject %x, CtlCode %x, "
160 "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
161 "POutputBufferSize %x (%x)\n", DeviceObject
, CtlCode
,
162 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
,
163 OutputBufferSize
? *OutputBufferSize
: 0);
166 KeInitializeEvent (&Event
, NotificationEvent
, FALSE
);
168 DPRINT("Building device I/O control request ...\n");
169 Irp
= IoBuildDeviceIoControlRequest(CtlCode
,
174 (OutputBufferSize
!= NULL
) ? *OutputBufferSize
: 0,
180 DPRINT("IoBuildDeviceIoControlRequest failed\n");
181 return STATUS_INSUFFICIENT_RESOURCES
;
186 Stack
= IoGetNextIrpStackLocation(Irp
);
187 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
190 DPRINT ("Calling IO Driver... with irp %x\n", Irp
);
191 Status
= IoCallDriver(DeviceObject
, Irp
);
193 DPRINT ("Waiting for IO Operation for %x\n", Irp
);
194 if (Status
== STATUS_PENDING
)
196 DPRINT ("Operation pending\n");
197 KeWaitForSingleObject (&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
198 DPRINT ("Getting IO Status... for %x\n", Irp
);
200 Status
= IoStatus
.Status
;
203 if (OutputBufferSize
!= NULL
)
205 *OutputBufferSize
= IoStatus
.Information
;
208 if (Status
== STATUS_VERIFY_REQUIRED
)
210 PDEVICE_OBJECT DeviceToVerify
;
212 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
213 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
217 Status
= IoVerifyVolume(DeviceToVerify
, FALSE
);
218 DPRINT("IoVerifyVolume() returned (Status %lx)\n", Status
);
221 if (NT_SUCCESS(Status
) && !LastChance
)
223 DPRINT1("Volume verify succeeded; trying request again\n");
227 else if (NT_SUCCESS(Status
))
229 DPRINT1("Failed to read after successful verify, aborting\n");
230 Status
= STATUS_DEVICE_NOT_READY
;
234 DPRINT1("IoVerifyVolume() failed (Status %lx)\n", Status
);
238 DPRINT("Returning Status %x\n", Status
);