remove whitespace from end of lines
[reactos.git] / reactos / drivers / fs / cdfs / common.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2003 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id$
20 *
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
26 * Eric Kohl
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include <ddk/ntddk.h>
32
33 #define NDEBUG
34 #include <debug.h>
35
36 #include "cdfs.h"
37
38
39 /* FUNCTIONS ****************************************************************/
40
41 NTSTATUS
42 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
43 IN ULONG DiskSector,
44 IN ULONG SectorCount,
45 IN OUT PUCHAR Buffer,
46 IN BOOLEAN Override)
47 {
48 PIO_STACK_LOCATION Stack;
49 IO_STATUS_BLOCK IoStatus;
50 LARGE_INTEGER Offset;
51 ULONG BlockSize;
52 KEVENT Event;
53 PIRP Irp;
54 NTSTATUS Status;
55
56 KeInitializeEvent(&Event,
57 NotificationEvent,
58 FALSE);
59
60 Offset.u.LowPart = DiskSector << 11;
61 Offset.u.HighPart = DiskSector >> 21;
62
63 BlockSize = BLOCKSIZE * SectorCount;
64
65 DPRINT("CdfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
66 DeviceObject, DiskSector, Buffer);
67 DPRINT("Offset %I64x BlockSize %ld\n",
68 Offset.QuadPart,
69 BlockSize);
70
71 DPRINT("Building synchronous FSD Request...\n");
72 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
73 DeviceObject,
74 Buffer,
75 BlockSize,
76 &Offset,
77 &Event,
78 &IoStatus);
79 if (Irp == NULL)
80 {
81 DPRINT("IoBuildSynchronousFsdRequest failed\n");
82 return(STATUS_INSUFFICIENT_RESOURCES);
83 }
84
85 if (Override)
86 {
87 Stack = IoGetNextIrpStackLocation(Irp);
88 Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
89 }
90
91 DPRINT("Calling IO Driver... with irp %x\n", Irp);
92 Status = IoCallDriver(DeviceObject, Irp);
93
94 DPRINT("Waiting for IO Operation for %x\n", Irp);
95 if (Status == STATUS_PENDING)
96 {
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;
101 }
102
103 if (!NT_SUCCESS(Status))
104 {
105 if (Status == STATUS_VERIFY_REQUIRED)
106 {
107 PDEVICE_OBJECT DeviceToVerify;
108 NTSTATUS NewStatus;
109
110 DPRINT1("STATUS_VERIFY_REQUIRED\n");
111 DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread());
112 IoSetDeviceToVerify(PsGetCurrentThread(), NULL);
113
114 NewStatus = IoVerifyVolume(DeviceToVerify, FALSE);
115 DPRINT1("IoVerifyVolume() retuned (Status %lx)\n", NewStatus);
116 }
117
118 DPRINT("CdfsReadSectors() failed (Status %x)\n", Status);
119 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
120 DeviceObject, DiskSector, Buffer,
121 Offset.QuadPart);
122 return(Status);
123 }
124
125 DPRINT("Block request succeeded for %x\n", Irp);
126
127 return(STATUS_SUCCESS);
128 }
129
130
131 NTSTATUS
132 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject,
133 IN ULONG CtlCode,
134 IN PVOID InputBuffer,
135 IN ULONG InputBufferSize,
136 IN OUT PVOID OutputBuffer,
137 IN OUT PULONG OutputBufferSize,
138 IN BOOLEAN Override)
139 {
140 PIO_STACK_LOCATION Stack;
141 IO_STATUS_BLOCK IoStatus;
142 KEVENT Event;
143 PIRP Irp;
144 NTSTATUS Status;
145
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);
151
152 KeInitializeEvent (&Event, NotificationEvent, FALSE);
153
154 DPRINT("Building device I/O control request ...\n");
155 Irp = IoBuildDeviceIoControlRequest(CtlCode,
156 DeviceObject,
157 InputBuffer,
158 InputBufferSize,
159 OutputBuffer,
160 (OutputBufferSize != NULL) ? *OutputBufferSize : 0,
161 FALSE,
162 &Event,
163 &IoStatus);
164 if (Irp == NULL)
165 {
166 DPRINT("IoBuildDeviceIoControlRequest failed\n");
167 return STATUS_INSUFFICIENT_RESOURCES;
168 }
169
170 if (Override)
171 {
172 Stack = IoGetNextIrpStackLocation(Irp);
173 Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
174 }
175
176 DPRINT ("Calling IO Driver... with irp %x\n", Irp);
177 Status = IoCallDriver(DeviceObject, Irp);
178
179 DPRINT ("Waiting for IO Operation for %x\n", Irp);
180 if (Status == STATUS_PENDING)
181 {
182 DPRINT ("Operation pending\n");
183 KeWaitForSingleObject (&Event, Suspended, KernelMode, FALSE, NULL);
184 DPRINT ("Getting IO Status... for %x\n", Irp);
185
186 Status = IoStatus.Status;
187 }
188
189 if (OutputBufferSize != NULL)
190 {
191 *OutputBufferSize = IoStatus.Information;
192 }
193
194 if (Status == STATUS_VERIFY_REQUIRED)
195 {
196 PDEVICE_OBJECT DeviceToVerify;
197 NTSTATUS NewStatus;
198
199 DPRINT1("STATUS_VERIFY_REQUIRED\n");
200 DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread());
201 IoSetDeviceToVerify(PsGetCurrentThread(), NULL);
202
203 NewStatus = IoVerifyVolume(DeviceToVerify, FALSE);
204 DPRINT1("IoVerifyVolume() retuned (Status %lx)\n", NewStatus);
205 }
206
207 DPRINT("Returning Status %x\n", Status);
208
209 return Status;
210 }
211
212 /* EOF */