merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / drivers / fs / ntfs / 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$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/ntfs/blockdev.c
24 * PURPOSE: NTFS filesystem 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 "ntfs.h"
36
37
38 /* FUNCTIONS ****************************************************************/
39
40 NTSTATUS
41 NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
42 IN ULONG DiskSector,
43 IN ULONG SectorCount,
44 IN ULONG SectorSize,
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.QuadPart = (LONGLONG)DiskSector * (LONGLONG)SectorSize;
61 BlockSize = SectorCount * SectorSize;
62
63 DPRINT("NtfsReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
64 DeviceObject, DiskSector, Buffer);
65 DPRINT("Offset %I64x BlockSize %ld\n",
66 Offset.QuadPart,
67 BlockSize);
68
69 DPRINT("Building synchronous FSD Request...\n");
70 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
71 DeviceObject,
72 Buffer,
73 BlockSize,
74 &Offset,
75 &Event,
76 &IoStatus);
77 if (Irp == NULL)
78 {
79 DPRINT("IoBuildSynchronousFsdRequest failed\n");
80 return STATUS_INSUFFICIENT_RESOURCES;
81 }
82
83 if (Override)
84 {
85 Stack = IoGetNextIrpStackLocation(Irp);
86 Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
87 }
88
89 DPRINT("Calling IO Driver... with irp %x\n", Irp);
90 Status = IoCallDriver(DeviceObject, Irp);
91
92 DPRINT("Waiting for IO Operation for %x\n", Irp);
93 if (Status == STATUS_PENDING)
94 {
95 DPRINT("Operation pending\n");
96 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
97 DPRINT("Getting IO Status... for %x\n", Irp);
98 Status = IoStatus.Status;
99 }
100
101 DPRINT("NtfsReadSectors() done (Status %x)\n", Status);
102
103 return Status;
104 }
105
106
107 NTSTATUS
108 NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
109 IN ULONG ControlCode,
110 IN PVOID InputBuffer,
111 IN ULONG InputBufferSize,
112 IN OUT PVOID OutputBuffer,
113 IN OUT PULONG OutputBufferSize,
114 IN BOOLEAN Override)
115 {
116 PIO_STACK_LOCATION Stack;
117 IO_STATUS_BLOCK IoStatus;
118 KEVENT Event;
119 PIRP Irp;
120 NTSTATUS Status;
121
122 KeInitializeEvent(&Event, NotificationEvent, FALSE);
123
124 DPRINT("Building device I/O control request ...\n");
125 Irp = IoBuildDeviceIoControlRequest(ControlCode,
126 DeviceObject,
127 InputBuffer,
128 InputBufferSize,
129 OutputBuffer,
130 (OutputBufferSize) ? *OutputBufferSize : 0,
131 FALSE,
132 &Event,
133 &IoStatus);
134 if (Irp == NULL)
135 {
136 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
137 return STATUS_INSUFFICIENT_RESOURCES;
138 }
139
140 if (Override)
141 {
142 Stack = IoGetNextIrpStackLocation(Irp);
143 Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
144 }
145
146 DPRINT("Calling IO Driver... with irp %x\n", Irp);
147 Status = IoCallDriver(DeviceObject, Irp);
148 if (Status == STATUS_PENDING)
149 {
150 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
151 Status = IoStatus.Status;
152 }
153
154 if (OutputBufferSize)
155 {
156 *OutputBufferSize = IoStatus.Information;
157 }
158
159 return Status;
160 }
161
162 /* EOF */