mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
205 lines
6.1 KiB
C
205 lines
6.1 KiB
C
/*
|
|
* ReactOS kernel
|
|
* Copyright (C) 2002 ReactOS Team
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS kernel
|
|
* FILE: drivers/filesystem/ntfs/blockdev.c
|
|
* PURPOSE: NTFS filesystem driver
|
|
* PROGRAMMER: Eric Kohl
|
|
*/
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
#include "ntfs.h"
|
|
|
|
#define NDEBUG
|
|
#include <debug.h>
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
NTSTATUS
|
|
NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
|
|
IN LONGLONG StartingOffset,
|
|
IN ULONG Length,
|
|
IN ULONG SectorSize,
|
|
IN OUT PUCHAR Buffer,
|
|
IN BOOLEAN Override)
|
|
{
|
|
PIO_STACK_LOCATION Stack;
|
|
IO_STATUS_BLOCK IoStatus;
|
|
LARGE_INTEGER Offset;
|
|
KEVENT Event;
|
|
PIRP Irp;
|
|
NTSTATUS Status;
|
|
ULONGLONG RealReadOffset;
|
|
ULONG RealLength;
|
|
BOOLEAN AllocatedBuffer = FALSE;
|
|
PUCHAR ReadBuffer = Buffer;
|
|
|
|
DPRINT("NtfsReadDisk(%p, %I64x, %u, %u, %p, %d)\n", DeviceObject, StartingOffset, Length, SectorSize, Buffer, Override);
|
|
|
|
KeInitializeEvent(&Event,
|
|
NotificationEvent,
|
|
FALSE);
|
|
|
|
RealReadOffset = (ULONGLONG)StartingOffset;
|
|
RealLength = Length;
|
|
|
|
if ((RealReadOffset % SectorSize) != 0 || (RealLength % SectorSize) != 0)
|
|
{
|
|
RealReadOffset = ROUND_DOWN(StartingOffset, SectorSize);
|
|
RealLength = ROUND_UP(Length, SectorSize);
|
|
|
|
ReadBuffer = ExAllocatePoolWithTag(NonPagedPool, RealLength + SectorSize, TAG_NTFS);
|
|
if (ReadBuffer == NULL)
|
|
{
|
|
DPRINT1("Not enough memory!\n");
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
}
|
|
AllocatedBuffer = TRUE;
|
|
}
|
|
|
|
Offset.QuadPart = RealReadOffset;
|
|
|
|
DPRINT("Building synchronous FSD Request...\n");
|
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
|
DeviceObject,
|
|
ReadBuffer,
|
|
RealLength,
|
|
&Offset,
|
|
&Event,
|
|
&IoStatus);
|
|
if (Irp == NULL)
|
|
{
|
|
DPRINT("IoBuildSynchronousFsdRequest failed\n");
|
|
|
|
if (AllocatedBuffer)
|
|
{
|
|
ExFreePoolWithTag(ReadBuffer, TAG_NTFS);
|
|
}
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
}
|
|
|
|
if (Override)
|
|
{
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
|
Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
|
|
}
|
|
|
|
DPRINT("Calling IO Driver... with irp %p\n", Irp);
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
DPRINT("Waiting for IO Operation for %p\n", Irp);
|
|
if (Status == STATUS_PENDING)
|
|
{
|
|
DPRINT("Operation pending\n");
|
|
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
|
|
DPRINT("Getting IO Status... for %p\n", Irp);
|
|
Status = IoStatus.Status;
|
|
}
|
|
|
|
if (AllocatedBuffer)
|
|
{
|
|
if (NT_SUCCESS(Status))
|
|
{
|
|
RtlCopyMemory(Buffer, ReadBuffer + (StartingOffset - RealReadOffset), Length);
|
|
}
|
|
|
|
ExFreePoolWithTag(ReadBuffer, TAG_NTFS);
|
|
}
|
|
|
|
DPRINT("NtfsReadDisk() done (Status %x)\n", Status);
|
|
|
|
return Status;
|
|
}
|
|
|
|
NTSTATUS
|
|
NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
|
|
IN ULONG DiskSector,
|
|
IN ULONG SectorCount,
|
|
IN ULONG SectorSize,
|
|
IN OUT PUCHAR Buffer,
|
|
IN BOOLEAN Override)
|
|
{
|
|
LONGLONG Offset;
|
|
ULONG BlockSize;
|
|
|
|
Offset = (LONGLONG)DiskSector * (LONGLONG)SectorSize;
|
|
BlockSize = SectorCount * SectorSize;
|
|
|
|
return NtfsReadDisk(DeviceObject, Offset, BlockSize, SectorSize, Buffer, Override);
|
|
}
|
|
|
|
|
|
NTSTATUS
|
|
NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
|
|
IN ULONG ControlCode,
|
|
IN PVOID InputBuffer,
|
|
IN ULONG InputBufferSize,
|
|
IN OUT PVOID OutputBuffer,
|
|
IN OUT PULONG OutputBufferSize,
|
|
IN BOOLEAN Override)
|
|
{
|
|
PIO_STACK_LOCATION Stack;
|
|
IO_STATUS_BLOCK IoStatus;
|
|
KEVENT Event;
|
|
PIRP Irp;
|
|
NTSTATUS Status;
|
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
DPRINT("Building device I/O control request ...\n");
|
|
Irp = IoBuildDeviceIoControlRequest(ControlCode,
|
|
DeviceObject,
|
|
InputBuffer,
|
|
InputBufferSize,
|
|
OutputBuffer,
|
|
(OutputBufferSize) ? *OutputBufferSize : 0,
|
|
FALSE,
|
|
&Event,
|
|
&IoStatus);
|
|
if (Irp == NULL)
|
|
{
|
|
DPRINT("IoBuildDeviceIoControlRequest() failed\n");
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
}
|
|
|
|
if (Override)
|
|
{
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
|
Stack->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
|
|
}
|
|
|
|
DPRINT("Calling IO Driver... with irp %p\n", Irp);
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
if (Status == STATUS_PENDING)
|
|
{
|
|
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
|
|
Status = IoStatus.Status;
|
|
}
|
|
|
|
if (OutputBufferSize)
|
|
{
|
|
*OutputBufferSize = IoStatus.Information;
|
|
}
|
|
|
|
return Status;
|
|
}
|
|
|
|
/* EOF */
|