mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
cancel changes from david welch : write operations dangerous
remove allocations, use directly buffers svn path=/trunk/; revision=159
This commit is contained in:
parent
b0cbc91ce1
commit
523aba9a89
1 changed files with 153 additions and 171 deletions
|
@ -1,171 +1,153 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: services/fs/vfat/blockdev.c
|
* FILE: services/fs/vfat/blockdev.c
|
||||||
* PURPOSE: Temporary sector reading support
|
* PURPOSE: Temporary sector reading support
|
||||||
* PROGRAMMER: David Welch (welch@mcmail.com)
|
* PROGRAMMER: David Welch (welch@mcmail.com)
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <internal/string.h>
|
#include <internal/string.h>
|
||||||
#include <wstring.h>
|
#include <wstring.h>
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
#include "vfat.h"
|
#include "vfat.h"
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
|
BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
|
||||||
IN ULONG DiskSector,
|
IN ULONG DiskSector,
|
||||||
IN ULONG SectorCount,
|
IN ULONG SectorCount,
|
||||||
IN UCHAR* Buffer)
|
IN UCHAR* Buffer)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER sectorNumber;
|
LARGE_INTEGER sectorNumber;
|
||||||
PIRP irp;
|
PIRP irp;
|
||||||
IO_STATUS_BLOCK ioStatus;
|
IO_STATUS_BLOCK ioStatus;
|
||||||
KEVENT event;
|
KEVENT event;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
ULONG sectorSize;
|
ULONG sectorSize;
|
||||||
|
|
||||||
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
|
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
|
||||||
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
|
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
|
||||||
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
||||||
sectorSize = BLOCKSIZE * SectorCount;
|
sectorSize = BLOCKSIZE * SectorCount;
|
||||||
|
|
||||||
/* FIXME: this routine does not need to alloc mem and copy */
|
|
||||||
|
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
||||||
|
pDeviceObject,
|
||||||
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
DiskSector,
|
||||||
pDeviceObject,
|
Buffer);
|
||||||
DiskSector,
|
DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n",
|
||||||
Buffer);
|
(unsigned long int)GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
|
||||||
DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n",
|
(unsigned long int)GET_LARGE_INTEGER_LOW_PART(sectorNumber),
|
||||||
(unsigned long int)GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
|
sectorSize);
|
||||||
(unsigned long int)GET_LARGE_INTEGER_LOW_PART(sectorNumber),
|
|
||||||
sectorSize);
|
|
||||||
|
DPRINT("Building synchronous FSD Request...\n");
|
||||||
|
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
DPRINT("Building synchronous FSD Request...\n");
|
pDeviceObject,
|
||||||
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
Buffer,
|
||||||
pDeviceObject,
|
sectorSize,
|
||||||
Buffer,
|
§orNumber,
|
||||||
sectorSize,
|
&event,
|
||||||
§orNumber,
|
&ioStatus );
|
||||||
&event,
|
|
||||||
&ioStatus );
|
if (!irp) {
|
||||||
|
DbgPrint("READ failed!!!\n");
|
||||||
if (!irp) {
|
return FALSE;
|
||||||
DbgPrint("READ failed!!!\n");
|
}
|
||||||
return FALSE;
|
|
||||||
}
|
DPRINT("Calling IO Driver...\n");
|
||||||
|
status = IoCallDriver(pDeviceObject,
|
||||||
DPRINT("Calling IO Driver...\n");
|
irp);
|
||||||
status = IoCallDriver(pDeviceObject,
|
|
||||||
irp);
|
DPRINT("Waiting for IO Operation...\n");
|
||||||
|
if (status == STATUS_PENDING) {
|
||||||
DPRINT("Waiting for IO Operation...\n");
|
KeWaitForSingleObject(&event,
|
||||||
if (status == STATUS_PENDING) {
|
Suspended,
|
||||||
KeWaitForSingleObject(&event,
|
KernelMode,
|
||||||
Suspended,
|
FALSE,
|
||||||
KernelMode,
|
NULL);
|
||||||
FALSE,
|
DPRINT("Getting IO Status...\n");
|
||||||
NULL);
|
status = ioStatus.Status;
|
||||||
DPRINT("Getting IO Status...\n");
|
}
|
||||||
status = ioStatus.Status;
|
|
||||||
}
|
if (!NT_SUCCESS(status)) {
|
||||||
|
DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status);
|
||||||
if (!NT_SUCCESS(status)) {
|
DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
|
||||||
DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status);
|
pDeviceObject,
|
||||||
DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
|
DiskSector,
|
||||||
pDeviceObject,
|
Buffer,
|
||||||
DiskSector,
|
GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
|
||||||
Buffer,
|
GET_LARGE_INTEGER_LOW_PART(sectorNumber));
|
||||||
GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
|
return FALSE;
|
||||||
GET_LARGE_INTEGER_LOW_PART(sectorNumber));
|
}
|
||||||
return FALSE;
|
DPRINT("Block request succeeded\n");
|
||||||
}
|
return TRUE;
|
||||||
|
}
|
||||||
DPRINT("Copying memory...\n");
|
|
||||||
DPRINT("Block request succeeded\n");
|
BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
|
||||||
return TRUE;
|
IN ULONG DiskSector,
|
||||||
}
|
IN ULONG SectorCount,
|
||||||
|
IN UCHAR* Buffer)
|
||||||
BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
|
{
|
||||||
IN ULONG DiskSector,
|
LARGE_INTEGER sectorNumber;
|
||||||
IN ULONG SectorCount,
|
PIRP irp;
|
||||||
IN UCHAR* Buffer)
|
IO_STATUS_BLOCK ioStatus;
|
||||||
{
|
KEVENT event;
|
||||||
LARGE_INTEGER sectorNumber;
|
NTSTATUS status;
|
||||||
PIRP irp;
|
ULONG sectorSize;
|
||||||
IO_STATUS_BLOCK ioStatus;
|
|
||||||
KEVENT event;
|
DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
||||||
NTSTATUS status;
|
pDeviceObject,DiskSector,Buffer);
|
||||||
ULONG sectorSize;
|
|
||||||
PULONG mbr;
|
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
|
||||||
|
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
|
||||||
DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
|
||||||
pDeviceObject,DiskSector,Buffer);
|
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
||||||
|
|
||||||
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
|
sectorSize = BLOCKSIZE*SectorCount;
|
||||||
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
|
|
||||||
|
DPRINT("Building synchronous FSD Request...\n");
|
||||||
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
|
||||||
|
pDeviceObject,
|
||||||
sectorSize = BLOCKSIZE*SectorCount;
|
Buffer,
|
||||||
|
sectorSize,
|
||||||
mbr = ExAllocatePool(NonPagedPool, sectorSize);
|
§orNumber,
|
||||||
|
&event,
|
||||||
if (!mbr) {
|
&ioStatus );
|
||||||
return FALSE;
|
|
||||||
}
|
if (!irp) {
|
||||||
|
DbgPrint("WRITE failed!!!\n");
|
||||||
|
return FALSE;
|
||||||
DPRINT("Building synchronous FSD Request...\n");
|
}
|
||||||
irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
|
|
||||||
pDeviceObject,
|
DPRINT("Calling IO Driver...\n");
|
||||||
mbr,
|
status = IoCallDriver(pDeviceObject,
|
||||||
sectorSize,
|
irp);
|
||||||
§orNumber,
|
|
||||||
&event,
|
DPRINT("Waiting for IO Operation...\n");
|
||||||
&ioStatus );
|
if (status == STATUS_PENDING) {
|
||||||
|
KeWaitForSingleObject(&event,
|
||||||
if (!irp) {
|
Suspended,
|
||||||
DbgPrint("WRITE failed!!!\n");
|
KernelMode,
|
||||||
ExFreePool(mbr);
|
FALSE,
|
||||||
return FALSE;
|
NULL);
|
||||||
}
|
DPRINT("Getting IO Status...\n");
|
||||||
|
status = ioStatus.Status;
|
||||||
DPRINT("Calling IO Driver...\n");
|
}
|
||||||
status = IoCallDriver(pDeviceObject,
|
|
||||||
irp);
|
if (!NT_SUCCESS(status)) {
|
||||||
|
DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
|
||||||
DPRINT("Waiting for IO Operation...\n");
|
return FALSE;
|
||||||
if (status == STATUS_PENDING) {
|
}
|
||||||
KeWaitForSingleObject(&event,
|
|
||||||
Suspended,
|
DPRINT("Block request succeeded\n");
|
||||||
KernelMode,
|
return TRUE;
|
||||||
FALSE,
|
}
|
||||||
NULL);
|
|
||||||
DPRINT("Getting IO Status...\n");
|
|
||||||
status = ioStatus.Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NT_SUCCESS(status)) {
|
|
||||||
DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
|
|
||||||
ExFreePool(mbr);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("Copying memory...\n");
|
|
||||||
RtlCopyMemory(Buffer,mbr,sectorSize);
|
|
||||||
|
|
||||||
ExFreePool(mbr);
|
|
||||||
DPRINT("Block request succeeded\n");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue