3 * Copyright (C) 2002 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/blockdev.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Eric Kohl
26 /* INCLUDES *****************************************************************/
33 /* FUNCTIONS ****************************************************************/
36 NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject
,
37 IN LONGLONG StartingOffset
,
43 PIO_STACK_LOCATION Stack
;
44 IO_STATUS_BLOCK IoStatus
;
49 ULONGLONG RealReadOffset
;
51 BOOLEAN AllocatedBuffer
= FALSE
;
52 PUCHAR ReadBuffer
= Buffer
;
54 DPRINT("NtfsReadDisk(%p, %I64x, %u, %u, %p, %d)\n", DeviceObject
, StartingOffset
, Length
, SectorSize
, Buffer
, Override
);
56 KeInitializeEvent(&Event
,
60 RealReadOffset
= (ULONGLONG
)StartingOffset
;
63 if ((RealReadOffset
% SectorSize
) != 0 || (RealLength
% SectorSize
) != 0)
65 RealReadOffset
= ROUND_DOWN(StartingOffset
, SectorSize
);
66 RealLength
= ROUND_UP(Length
, SectorSize
);
68 ReadBuffer
= ExAllocatePoolWithTag(NonPagedPool
, RealLength
+ SectorSize
, TAG_NTFS
);
69 if (ReadBuffer
== NULL
)
71 DPRINT1("Not enough memory!\n");
72 return STATUS_INSUFFICIENT_RESOURCES
;
74 AllocatedBuffer
= TRUE
;
77 Offset
.QuadPart
= RealReadOffset
;
79 DPRINT("Building synchronous FSD Request...\n");
80 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
89 DPRINT("IoBuildSynchronousFsdRequest failed\n");
90 return STATUS_INSUFFICIENT_RESOURCES
;
95 Stack
= IoGetNextIrpStackLocation(Irp
);
96 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
99 DPRINT("Calling IO Driver... with irp %p\n", Irp
);
100 Status
= IoCallDriver(DeviceObject
, Irp
);
102 DPRINT("Waiting for IO Operation for %p\n", Irp
);
103 if (Status
== STATUS_PENDING
)
105 DPRINT("Operation pending\n");
106 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
107 DPRINT("Getting IO Status... for %p\n", Irp
);
108 Status
= IoStatus
.Status
;
111 if (NT_SUCCESS(Status
) && AllocatedBuffer
)
113 RtlCopyMemory(Buffer
, ReadBuffer
+ (StartingOffset
- RealReadOffset
), Length
);
114 ExFreePoolWithTag(ReadBuffer
, TAG_NTFS
);
117 DPRINT("NtfsReadDisk() done (Status %x)\n", Status
);
123 NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject
,
125 IN ULONG SectorCount
,
127 IN OUT PUCHAR Buffer
,
133 Offset
= (LONGLONG
)DiskSector
* (LONGLONG
)SectorSize
;
134 BlockSize
= SectorCount
* SectorSize
;
136 return NtfsReadDisk(DeviceObject
, Offset
, BlockSize
, SectorSize
, Buffer
, Override
);
141 NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject
,
142 IN ULONG ControlCode
,
143 IN PVOID InputBuffer
,
144 IN ULONG InputBufferSize
,
145 IN OUT PVOID OutputBuffer
,
146 IN OUT PULONG OutputBufferSize
,
149 PIO_STACK_LOCATION Stack
;
150 IO_STATUS_BLOCK IoStatus
;
155 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
157 DPRINT("Building device I/O control request ...\n");
158 Irp
= IoBuildDeviceIoControlRequest(ControlCode
,
163 (OutputBufferSize
) ? *OutputBufferSize
: 0,
169 DPRINT("IoBuildDeviceIoControlRequest() failed\n");
170 return STATUS_INSUFFICIENT_RESOURCES
;
175 Stack
= IoGetNextIrpStackLocation(Irp
);
176 Stack
->Flags
|= SL_OVERRIDE_VERIFY_VOLUME
;
179 DPRINT("Calling IO Driver... with irp %p\n", Irp
);
180 Status
= IoCallDriver(DeviceObject
, Irp
);
181 if (Status
== STATUS_PENDING
)
183 KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
184 Status
= IoStatus
.Status
;
187 if (OutputBufferSize
)
189 *OutputBufferSize
= IoStatus
.Information
;