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
;
53 KeInitializeEvent(&Event
,
57 Offset
.u
.LowPart
= DiskSector
<< 11;
58 Offset
.u
.HighPart
= DiskSector
>> 21;
60 BlockSize
= BLOCKSIZE
* SectorCount
;
62 DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
63 DeviceObject
, DiskSector
, Buffer
);
64 DPRINT("Offset %I64x BlockSize %ld\n",
68 DPRINT("Building synchronous FSD Request...\n");
69 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
78 DPRINT("IoBuildSynchronousFsdRequest failed\n");
79 return(STATUS_INSUFFICIENT_RESOURCES
);
84 Stack
= IoGetNextIrpStackLocation(Irp
);
85 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
88 DPRINT("Calling IO Driver... with irp %x\n", Irp
);
89 Status
= IoCallDriver(DeviceObject
, Irp
);
91 DPRINT("Waiting for IO Operation for %x\n", Irp
);
92 if (Status
== STATUS_PENDING
)
94 DPRINT("Operation pending\n");
95 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
96 DPRINT("Getting IO Status... for %x\n", Irp
);
97 Status
= IoStatus
.Status
;
100 if (!NT_SUCCESS(Status
))
102 if (Status
== STATUS_VERIFY_REQUIRED
)
104 PDEVICE_OBJECT DeviceToVerify
;
107 DPRINT1("STATUS_VERIFY_REQUIRED\n");
108 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
109 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
111 NewStatus
= IoVerifyVolume(DeviceToVerify
, FALSE
);
112 DPRINT1("IoVerifyVolume() returned (Status %lx)\n", NewStatus
);
115 DPRINT("CdfsReadSectors() failed (Status %x)\n", Status
);
116 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
117 DeviceObject
, DiskSector
, Buffer
,
122 DPRINT("Block request succeeded for %x\n", Irp
);
124 return(STATUS_SUCCESS
);
129 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
131 IN PVOID InputBuffer
,
132 IN ULONG InputBufferSize
,
133 IN OUT PVOID OutputBuffer
,
134 IN OUT PULONG OutputBufferSize
,
137 PIO_STACK_LOCATION Stack
;
138 IO_STATUS_BLOCK IoStatus
;
143 DPRINT("CdfsDeviceIoControl(DeviceObject %x, CtlCode %x, "
144 "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
145 "POutputBufferSize %x (%x)\n", DeviceObject
, CtlCode
,
146 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
,
147 OutputBufferSize
? *OutputBufferSize
: 0);
149 KeInitializeEvent (&Event
, NotificationEvent
, FALSE
);
151 DPRINT("Building device I/O control request ...\n");
152 Irp
= IoBuildDeviceIoControlRequest(CtlCode
,
157 (OutputBufferSize
!= NULL
) ? *OutputBufferSize
: 0,
163 DPRINT("IoBuildDeviceIoControlRequest failed\n");
164 return STATUS_INSUFFICIENT_RESOURCES
;
169 Stack
= IoGetNextIrpStackLocation(Irp
);
170 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
173 DPRINT ("Calling IO Driver... with irp %x\n", Irp
);
174 Status
= IoCallDriver(DeviceObject
, Irp
);
176 DPRINT ("Waiting for IO Operation for %x\n", Irp
);
177 if (Status
== STATUS_PENDING
)
179 DPRINT ("Operation pending\n");
180 KeWaitForSingleObject (&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
181 DPRINT ("Getting IO Status... for %x\n", Irp
);
183 Status
= IoStatus
.Status
;
186 if (OutputBufferSize
!= NULL
)
188 *OutputBufferSize
= IoStatus
.Information
;
191 if (Status
== STATUS_VERIFY_REQUIRED
)
193 PDEVICE_OBJECT DeviceToVerify
;
196 DPRINT1("STATUS_VERIFY_REQUIRED\n");
197 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
198 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
202 NewStatus
= IoVerifyVolume(DeviceToVerify
, FALSE
);
203 DPRINT1("IoVerifyVolume() returned (Status %lx)\n", NewStatus
);
207 DPRINT("Returning Status %x\n", Status
);