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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 *****************************************************************/
31 #include <ddk/ntddk.h>
39 /* FUNCTIONS ****************************************************************/
42 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject
,
48 PIO_STACK_LOCATION Stack
;
49 IO_STATUS_BLOCK IoStatus
;
56 KeInitializeEvent(&Event
,
60 Offset
.u
.LowPart
= DiskSector
<< 11;
61 Offset
.u
.HighPart
= DiskSector
>> 21;
63 BlockSize
= BLOCKSIZE
* SectorCount
;
65 DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
66 DeviceObject
, DiskSector
, Buffer
);
67 DPRINT("Offset %I64x BlockSize %ld\n",
71 DPRINT("Building synchronous FSD Request...\n");
72 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
81 DPRINT("IoBuildSynchronousFsdRequest failed\n");
82 return(STATUS_INSUFFICIENT_RESOURCES
);
87 Stack
= IoGetNextIrpStackLocation(Irp
);
88 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
91 DPRINT("Calling IO Driver... with irp %x\n", Irp
);
92 Status
= IoCallDriver(DeviceObject
, Irp
);
94 DPRINT("Waiting for IO Operation for %x\n", Irp
);
95 if (Status
== STATUS_PENDING
)
97 DPRINT("Operation pending\n");
98 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
99 DPRINT("Getting IO Status... for %x\n", Irp
);
100 Status
= IoStatus
.Status
;
103 if (!NT_SUCCESS(Status
))
105 if (Status
== STATUS_VERIFY_REQUIRED
)
107 PDEVICE_OBJECT DeviceToVerify
;
110 DPRINT1("STATUS_VERIFY_REQUIRED\n");
111 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
112 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
114 NewStatus
= IoVerifyVolume(DeviceToVerify
, FALSE
);
115 DPRINT1("IoVerifyVolume() retuned (Status %lx)\n", NewStatus
);
118 DPRINT("CdfsReadSectors() failed (Status %x)\n", Status
);
119 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
120 DeviceObject
, DiskSector
, Buffer
,
125 DPRINT("Block request succeeded for %x\n", Irp
);
127 return(STATUS_SUCCESS
);
132 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
134 IN PVOID InputBuffer
,
135 IN ULONG InputBufferSize
,
136 IN OUT PVOID OutputBuffer
,
137 IN OUT PULONG OutputBufferSize
,
140 PIO_STACK_LOCATION Stack
;
141 IO_STATUS_BLOCK IoStatus
;
146 DPRINT("CdfsDeviceIoControl(DeviceObject %x, CtlCode %x, "
147 "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
148 "POutputBufferSize %x (%x)\n", DeviceObject
, CtlCode
,
149 InputBuffer
, InputBufferSize
, OutputBuffer
, OutputBufferSize
,
150 OutputBufferSize
? *OutputBufferSize
: 0);
152 KeInitializeEvent (&Event
, NotificationEvent
, FALSE
);
154 DPRINT("Building device I/O control request ...\n");
155 Irp
= IoBuildDeviceIoControlRequest(CtlCode
,
160 (OutputBufferSize
!= NULL
) ? *OutputBufferSize
: 0,
166 DPRINT("IoBuildDeviceIoControlRequest failed\n");
167 return STATUS_INSUFFICIENT_RESOURCES
;
172 Stack
= IoGetNextIrpStackLocation(Irp
);
173 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
176 DPRINT ("Calling IO Driver... with irp %x\n", Irp
);
177 Status
= IoCallDriver(DeviceObject
, Irp
);
179 DPRINT ("Waiting for IO Operation for %x\n", Irp
);
180 if (Status
== STATUS_PENDING
)
182 DPRINT ("Operation pending\n");
183 KeWaitForSingleObject (&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
184 DPRINT ("Getting IO Status... for %x\n", Irp
);
186 Status
= IoStatus
.Status
;
189 if (OutputBufferSize
!= NULL
)
191 *OutputBufferSize
= IoStatus
.Information
;
194 if (Status
== STATUS_VERIFY_REQUIRED
)
196 PDEVICE_OBJECT DeviceToVerify
;
199 DPRINT1("STATUS_VERIFY_REQUIRED\n");
200 DeviceToVerify
= IoGetDeviceToVerify(PsGetCurrentThread());
201 IoSetDeviceToVerify(PsGetCurrentThread(), NULL
);
203 NewStatus
= IoVerifyVolume(DeviceToVerify
, FALSE
);
204 DPRINT1("IoVerifyVolume() retuned (Status %lx)\n", NewStatus
);
207 DPRINT("Returning Status %x\n", Status
);