minor corrections by M.Taguchi
[reactos.git] / reactos / drivers / fs / fs_rec / blockdev.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 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: blockdev.c,v 1.4 2003/11/13 15:25:28 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/fs_rec/blockdev.c
24 * PURPOSE: Filesystem recognizer driver
25 * PROGRAMMER: Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <ddk/ntddk.h>
31
32 #define NDEBUG
33 #include <debug.h>
34
35 #include "fs_rec.h"
36
37
38 /* FUNCTIONS ****************************************************************/
39
40 NTSTATUS
41 FsRecReadSectors(IN PDEVICE_OBJECT DeviceObject,
42 IN ULONG DiskSector,
43 IN ULONG SectorCount,
44 IN ULONG SectorSize,
45 IN OUT PUCHAR Buffer)
46 {
47 IO_STATUS_BLOCK IoStatus;
48 LARGE_INTEGER Offset;
49 ULONG BlockSize;
50 PKEVENT Event;
51 PIRP Irp;
52 NTSTATUS Status;
53
54 Event = ExAllocatePool(NonPagedPool, sizeof(KEVENT));
55 if (Event == NULL)
56 {
57 return(STATUS_INSUFFICIENT_RESOURCES);
58 }
59
60 KeInitializeEvent(Event,
61 NotificationEvent,
62 FALSE);
63
64 Offset.QuadPart = (LONGLONG)DiskSector * (LONGLONG)SectorSize;
65 BlockSize = SectorCount * SectorSize;
66
67 DPRINT("FsrecReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
68 DeviceObject, DiskSector, Buffer);
69 DPRINT("Offset %I64x BlockSize %ld\n",
70 Offset.QuadPart,
71 BlockSize);
72
73 DPRINT("Building synchronous FSD Request...\n");
74 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
75 DeviceObject,
76 Buffer,
77 BlockSize,
78 &Offset,
79 Event,
80 &IoStatus);
81 if (Irp == NULL)
82 {
83 DPRINT("IoBuildSynchronousFsdRequest failed\n");
84 ExFreePool(Event);
85 return(STATUS_INSUFFICIENT_RESOURCES);
86 }
87
88 DPRINT("Calling IO Driver... with irp %x\n", Irp);
89 Status = IoCallDriver(DeviceObject, Irp);
90 if (Status == STATUS_PENDING)
91 {
92 DPRINT("Operation pending\n");
93 KeWaitForSingleObject(Event, Suspended, KernelMode, FALSE, NULL);
94 Status = IoStatus.Status;
95 }
96
97 ExFreePool(Event);
98
99 return(STATUS_SUCCESS);
100 }
101
102
103 NTSTATUS
104 FsRecDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
105 IN ULONG ControlCode,
106 IN PVOID InputBuffer,
107 IN ULONG InputBufferSize,
108 IN OUT PVOID OutputBuffer,
109 IN OUT PULONG OutputBufferSize)
110 {
111 ULONG BufferSize = 0;
112 PKEVENT Event;
113 PIRP Irp;
114 IO_STATUS_BLOCK IoStatus;
115 NTSTATUS Status;
116
117 if (OutputBufferSize != NULL)
118 {
119 BufferSize = *OutputBufferSize;
120 }
121
122 Event = ExAllocatePool(NonPagedPool, sizeof(KEVENT));
123 if (Event == NULL)
124 {
125 return(STATUS_INSUFFICIENT_RESOURCES);
126 }
127
128 KeInitializeEvent(Event, NotificationEvent, FALSE);
129
130 DPRINT("Building device I/O control request ...\n");
131 Irp = IoBuildDeviceIoControlRequest(ControlCode,
132 DeviceObject,
133 InputBuffer,
134 InputBufferSize,
135 OutputBuffer,
136 BufferSize,
137 FALSE,
138 Event,
139 &IoStatus);
140 if (Irp == NULL)
141 {
142 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
143 ExFreePool(Event);
144 return(STATUS_INSUFFICIENT_RESOURCES);
145 }
146
147 DPRINT("Calling IO Driver... with irp %x\n", Irp);
148 Status = IoCallDriver(DeviceObject, Irp);
149 if (Status == STATUS_PENDING)
150 {
151 KeWaitForSingleObject(Event, Suspended, KernelMode, FALSE, NULL);
152 Status = IoStatus.Status;
153 }
154
155 if (OutputBufferSize != NULL)
156 {
157 *OutputBufferSize = IoStatus.Information;
158 }
159
160 ExFreePool(Event);
161
162 return(Status);
163 }
164
165 /* EOF */