mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Changes to support the COFF driver loader
svn path=/trunk/; revision=144
This commit is contained in:
parent
02e3d7b08e
commit
2d14c3e110
10 changed files with 511 additions and 454 deletions
|
@ -1,66 +1,67 @@
|
||||||
//
|
/*
|
||||||
// IDE.C - IDE Disk driver
|
* IDE.C - IDE Disk driver
|
||||||
// written by Rex Jolliff
|
* written by Rex Jolliff
|
||||||
// with help from various documentation sources and a few peeks at
|
* with help from various documentation sources and a few peeks at
|
||||||
// linux and freebsd sources.
|
* linux and freebsd sources.
|
||||||
//
|
*
|
||||||
// This driver supports up to 4 controllers with up to 2 drives each.
|
* This driver supports up to 4 controllers with up to 2 drives each.
|
||||||
// The device names are assigned as follows:
|
* The device names are assigned as follows:
|
||||||
// \Devices\HarddiskX\Partition0
|
* \Devices\HarddiskX\Partition0
|
||||||
// for the raw device, and
|
* for the raw device, and
|
||||||
// \Devices\HarddiskX\PartitionY
|
* \Devices\HarddiskX\PartitionY
|
||||||
// for partitions
|
* for partitions
|
||||||
// where:
|
* where:
|
||||||
// X is computed by counting the available drives from the following
|
* X is computed by counting the available drives from the following
|
||||||
// sequence: the controller number (0=0x1f0, 1=0x170, 2=0x1e8,
|
* sequence: the controller number (0=0x1f0, 1=0x170, 2=0x1e8,
|
||||||
// 3=0x168) * 2 plus the drive number (0,1)
|
* 3=0x168) * 2 plus the drive number (0,1)
|
||||||
// Y is the partition number
|
* Y is the partition number
|
||||||
//
|
*
|
||||||
// The driver exports the following function:
|
* The driver exports the following function:
|
||||||
//
|
*
|
||||||
// DriverEntry() - NT device driver initialization routine
|
* DriverEntry() - NT device driver initialization routine
|
||||||
//
|
*
|
||||||
// And the following functions are exported implicitly:
|
* And the following functions are exported implicitly:
|
||||||
//
|
*
|
||||||
// IDEStartIo() - called to start an I/O request packet
|
* IDEStartIo() - called to start an I/O request packet
|
||||||
// IDEDispatchOpenClose() - Called to open/close the device. a NOOP
|
* IDEDispatchOpenClose() - Called to open/close the device. a NOOP
|
||||||
// IDEDispatchReadWrite() - Called to read/write the device.
|
* IDEDispatchReadWrite() - Called to read/write the device.
|
||||||
// IDEDispatchQueryInformation() - Called to get device information
|
* IDEDispatchQueryInformation() - Called to get device information
|
||||||
// IDEDispatchSetInformation() - Called to set device information
|
* IDEDispatchSetInformation() - Called to set device information
|
||||||
// IDEDispatchDeviceControl() - Called to execute device control requests
|
* IDEDispatchDeviceControl() - Called to execute device control requests
|
||||||
//
|
*
|
||||||
// Modification History:
|
* Modification History:
|
||||||
// 05/25/98 RJJ Created.
|
* 05/25/98 RJJ Created.
|
||||||
// 05/30/98 RJJ Removed IRQ handler and inserted busy waits
|
* 05/30/98 RJJ Removed IRQ handler and inserted busy waits
|
||||||
// just to get something working...
|
* just to get something working...
|
||||||
// 07/18/98 RJJ Made drastic changes so that the driver
|
* 07/18/98 RJJ Made drastic changes so that the driver
|
||||||
// resembles a WinNT driver.
|
* resembles a WinNT driver.
|
||||||
// 08/05/98 RJJ Changed to .C extension
|
* 08/05/98 RJJ Changed to .C extension
|
||||||
// 09/19/98 RJJ First release (run for cover!)
|
* 09/19/98 RJJ First release (run for cover!)
|
||||||
//
|
*
|
||||||
// Test List:
|
* Test List:
|
||||||
// 09/17/98 RJJ Pri/MST: 14.12X19 WDC AC31000H Test Passed
|
* 09/17/98 RJJ Pri/MST: 14.12X19 WDC AC31000H Test Passed
|
||||||
// Pri/SLV: None.
|
* Pri/SLV: None.
|
||||||
//
|
*
|
||||||
//
|
*
|
||||||
// To Do:
|
* To Do:
|
||||||
// FIXME: a timer should be used to watch for device timeouts and errors
|
* FIXME: a timer should be used to watch for device timeouts and errors
|
||||||
// FIXME: errors should be retried
|
* FIXME: errors should be retried
|
||||||
// FIXME: a drive reset/recalibrate should be attempted if errors occur
|
* FIXME: a drive reset/recalibrate should be attempted if errors occur
|
||||||
// FIXME: Use DMA for transfers if drives support it
|
* FIXME: Use DMA for transfers if drives support it
|
||||||
// FIXME: should we support unloading of this driver???
|
* FIXME: should we support unloading of this driver???
|
||||||
// FIXME: the device information should come from AUTODETECT (via registry)
|
* FIXME: the device information should come from AUTODETECT (via registry)
|
||||||
// FIXME: really big devices need to be handled correctly
|
* FIXME: really big devices need to be handled correctly
|
||||||
// FIXME: should get device info from the registry
|
* FIXME: should get device info from the registry
|
||||||
// FIXME: should report hardware usage to iomgr
|
* FIXME: should report hardware usage to iomgr
|
||||||
// FIXME: finish implementation of QueryInformation
|
* FIXME: finish implementation of QueryInformation
|
||||||
// FIXME: finish implementation of SetInformation
|
* FIXME: finish implementation of SetInformation
|
||||||
// FIXME: finish implementation of DeviceControl
|
* FIXME: finish implementation of DeviceControl
|
||||||
// FIXME: bring up to ATA-3 spec
|
* FIXME: bring up to ATA-3 spec
|
||||||
// FIXME: add general support for ATAPI devices
|
* FIXME: add general support for ATAPI devices
|
||||||
// FIXME: add support for ATAPI CDROMs
|
* FIXME: add support for ATAPI CDROMs
|
||||||
// FIXME: add support for ATAPI ZIP drives/RHDs
|
* FIXME: add support for ATAPI ZIP drives/RHDs
|
||||||
// FIXME: add support for ATAPI tape drives
|
* FIXME: add support for ATAPI tape drives
|
||||||
|
*/
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
|
|
|
@ -33,22 +33,28 @@ BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
|
||||||
ULONG sectorSize;
|
ULONG sectorSize;
|
||||||
PULONG mbr;
|
PULONG mbr;
|
||||||
|
|
||||||
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
|
||||||
pDeviceObject,DiskSector,Buffer);
|
|
||||||
|
|
||||||
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 */
|
||||||
|
|
||||||
mbr = ExAllocatePool(NonPagedPool, sectorSize);
|
mbr = ExAllocatePool(NonPagedPool, sectorSize);
|
||||||
|
|
||||||
|
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
|
||||||
|
pDeviceObject,
|
||||||
|
DiskSector,
|
||||||
|
Buffer);
|
||||||
|
DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n",
|
||||||
|
(unsigned long int)GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
|
||||||
|
(unsigned long int)GET_LARGE_INTEGER_LOW_PART(sectorNumber),
|
||||||
|
sectorSize);
|
||||||
|
|
||||||
if (!mbr) {
|
if (!mbr) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DPRINT("Building synchronous FSD Request...\n");
|
DPRINT("Building synchronous FSD Request...\n");
|
||||||
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
pDeviceObject,
|
pDeviceObject,
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <wstring.h>
|
#include <wstring.h>
|
||||||
#include <ddk/cctypes.h>
|
#include <ddk/cctypes.h>
|
||||||
|
|
||||||
//#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
#include "vfat.h"
|
#include "vfat.h"
|
||||||
|
@ -668,18 +668,12 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
FileObject,
|
FileObject,
|
||||||
FileName);
|
FileName);
|
||||||
|
|
||||||
CHECKPOINT;
|
|
||||||
string = FileName;
|
string = FileName;
|
||||||
CHECKPOINT;
|
|
||||||
ParentFcb = NULL;
|
ParentFcb = NULL;
|
||||||
CHECKPOINT;
|
|
||||||
Fcb = ExAllocatePool(NonPagedPool, sizeof(FCB));
|
Fcb = ExAllocatePool(NonPagedPool, sizeof(FCB));
|
||||||
CHECKPOINT;
|
|
||||||
next = &string[0];
|
next = &string[0];
|
||||||
CHECKPOINT;
|
|
||||||
current = next+1;
|
current = next+1;
|
||||||
|
|
||||||
CHECKPOINT;
|
|
||||||
while (next!=NULL)
|
while (next!=NULL)
|
||||||
{
|
{
|
||||||
DPRINT("current %w next %x\n",current,next);
|
DPRINT("current %w next %x\n",current,next);
|
||||||
|
@ -692,7 +686,6 @@ CHECKPOINT;
|
||||||
*next=0;
|
*next=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECKPOINT;
|
|
||||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
||||||
if (Status != STATUS_SUCCESS)
|
if (Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
|
@ -709,7 +702,6 @@ CHECKPOINT;
|
||||||
Fcb = ParentFcb;
|
Fcb = ParentFcb;
|
||||||
}
|
}
|
||||||
ParentFcb = Temp;
|
ParentFcb = Temp;
|
||||||
CHECKPOINT;
|
|
||||||
}
|
}
|
||||||
FileObject->FsContext = ParentFcb;
|
FileObject->FsContext = ParentFcb;
|
||||||
DPRINT("file opn, fcb=%x\n",ParentFcb);
|
DPRINT("file opn, fcb=%x\n",ParentFcb);
|
||||||
|
@ -724,7 +716,7 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
|
||||||
* by this fsd
|
* by this fsd
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
BootSector* Boot;
|
BootSector *Boot;
|
||||||
|
|
||||||
Boot = ExAllocatePool(NonPagedPool,512);
|
Boot = ExAllocatePool(NonPagedPool,512);
|
||||||
|
|
||||||
|
@ -738,7 +730,8 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
ExFreePool(Boot);
|
ExFreePool(Boot);
|
||||||
return(FALSE);
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS FsdMountDevice(PDEVICE_EXTENSION DeviceExt,
|
NTSTATUS FsdMountDevice(PDEVICE_EXTENSION DeviceExt,
|
||||||
|
@ -844,19 +837,37 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
PVOID Temp;
|
PVOID Temp;
|
||||||
ULONG TempLength;
|
ULONG TempLength;
|
||||||
|
|
||||||
|
/* PRECONDITION */
|
||||||
|
assert(DeviceExt != NULL);
|
||||||
|
assert(DeviceExt->BytesPerCluster != 0);
|
||||||
|
assert(FileObject != NULL);
|
||||||
|
assert(FileObject->FsContext != NULL);
|
||||||
|
|
||||||
DPRINT("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
|
DPRINT("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
|
||||||
"Length %d, ReadOffset %d)\n",DeviceExt,FileObject,Buffer,
|
"Length %d, ReadOffset %d)\n",
|
||||||
Length,ReadOffset);
|
DeviceExt,
|
||||||
|
FileObject,
|
||||||
|
Buffer,
|
||||||
|
Length,
|
||||||
|
ReadOffset);
|
||||||
|
DPRINT("DeviceExt->BytesPerCluster %d\n", DeviceExt->BytesPerCluster);
|
||||||
|
|
||||||
FirstCluster = ReadOffset / DeviceExt->BytesPerCluster;
|
FirstCluster = ReadOffset / DeviceExt->BytesPerCluster;
|
||||||
Fcb = FileObject->FsContext;
|
Fcb = FileObject->FsContext;
|
||||||
if (DeviceExt->FatType == FAT32)
|
if (DeviceExt->FatType == FAT32)
|
||||||
CurrentCluster = Fcb->entry.FirstCluster+Fcb->entry.FirstClusterHigh*65536;
|
{
|
||||||
|
CurrentCluster = Fcb->entry.FirstCluster +
|
||||||
|
Fcb->entry.FirstClusterHigh * 65536;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
CurrentCluster = Fcb->entry.FirstCluster;
|
CurrentCluster = Fcb->entry.FirstCluster;
|
||||||
if (CurrentCluster<2)
|
}
|
||||||
return STATUS_UNSUCCESSFUL;// FIXME : root of FAT16 ?
|
if (CurrentCluster < 2)
|
||||||
DPRINT("DeviceExt->BytesPerCluster %x\n",DeviceExt->BytesPerCluster);
|
{
|
||||||
|
/* FIXME : root of FAT16 ? */
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
if (ReadOffset >= Fcb->entry.FileSize)
|
if (ReadOffset >= Fcb->entry.FileSize)
|
||||||
{
|
{
|
||||||
|
@ -868,11 +879,11 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
}
|
}
|
||||||
*LengthRead = 0;
|
*LengthRead = 0;
|
||||||
Temp = ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster);
|
Temp = ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster);
|
||||||
|
/* FIXME: optimize by remembering the last cluster read and using if possible */
|
||||||
for (FileOffset=0; FileOffset < FirstCluster; FileOffset++)
|
for (FileOffset=0; FileOffset < FirstCluster; FileOffset++)
|
||||||
{
|
{
|
||||||
CurrentCluster = GetNextCluster(DeviceExt,CurrentCluster);
|
CurrentCluster = GetNextCluster(DeviceExt,CurrentCluster);
|
||||||
}
|
}
|
||||||
CHECKPOINT;
|
|
||||||
if ((ReadOffset % DeviceExt->BytesPerCluster)!=0)
|
if ((ReadOffset % DeviceExt->BytesPerCluster)!=0)
|
||||||
{
|
{
|
||||||
VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
|
VFATLoadCluster(DeviceExt,Temp,CurrentCluster);
|
||||||
|
@ -888,7 +899,6 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
Length = Length - TempLength;
|
Length = Length - TempLength;
|
||||||
Buffer = Buffer + TempLength;
|
Buffer = Buffer + TempLength;
|
||||||
}
|
}
|
||||||
CHECKPOINT;
|
|
||||||
while (Length > DeviceExt->BytesPerCluster)
|
while (Length > DeviceExt->BytesPerCluster)
|
||||||
{
|
{
|
||||||
VFATLoadCluster(DeviceExt, Buffer, CurrentCluster);
|
VFATLoadCluster(DeviceExt, Buffer, CurrentCluster);
|
||||||
|
@ -904,7 +914,6 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
Buffer = Buffer + DeviceExt->BytesPerCluster;
|
Buffer = Buffer + DeviceExt->BytesPerCluster;
|
||||||
Length = Length - DeviceExt->BytesPerCluster;
|
Length = Length - DeviceExt->BytesPerCluster;
|
||||||
}
|
}
|
||||||
CHECKPOINT;
|
|
||||||
if (Length > 0)
|
if (Length > 0)
|
||||||
{
|
{
|
||||||
(*LengthRead) = (*LengthRead) + Length;
|
(*LengthRead) = (*LengthRead) + Length;
|
||||||
|
@ -1041,21 +1050,14 @@ NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
Irp);
|
Irp);
|
||||||
|
|
||||||
Stack = IoGetCurrentIrpStackLocation(Irp);
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
CHECKPOINT;
|
|
||||||
FileObject = Stack->FileObject;
|
FileObject = Stack->FileObject;
|
||||||
CHECKPOINT;
|
|
||||||
DeviceExt = DeviceObject->DeviceExtension;
|
DeviceExt = DeviceObject->DeviceExtension;
|
||||||
CHECKPOINT;
|
|
||||||
Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
|
Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
|
||||||
CHECKPOINT;
|
|
||||||
|
|
||||||
Irp->IoStatus.Status = Status;
|
Irp->IoStatus.Status = Status;
|
||||||
CHECKPOINT;
|
|
||||||
Irp->IoStatus.Information = 0;
|
Irp->IoStatus.Information = 0;
|
||||||
CHECKPOINT;
|
|
||||||
|
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
CHECKPOINT;
|
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -1097,14 +1099,23 @@ NTSTATUS FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
ULONG Length;
|
ULONG Length;
|
||||||
PVOID Buffer;
|
PVOID Buffer;
|
||||||
ULONG Offset;
|
ULONG Offset;
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
PIO_STACK_LOCATION Stack;
|
||||||
PFILE_OBJECT FileObject = Stack->FileObject;
|
PFILE_OBJECT FileObject;
|
||||||
PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
|
PDEVICE_EXTENSION DeviceExt;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG LengthRead;
|
ULONG LengthRead;
|
||||||
|
|
||||||
DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
|
DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
|
||||||
|
|
||||||
|
/* Precondition / Initialization */
|
||||||
|
assert(Irp != NULL);
|
||||||
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
|
assert(Stack != NULL);
|
||||||
|
FileObject = Stack->FileObject;
|
||||||
|
assert(FileObject != NULL);
|
||||||
|
DeviceExt = DeviceObject->DeviceExtension;
|
||||||
|
assert(DeviceExt != NULL);
|
||||||
|
|
||||||
Length = Stack->Parameters.Read.Length;
|
Length = Stack->Parameters.Read.Length;
|
||||||
Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
|
Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
|
||||||
Offset = GET_LARGE_INTEGER_LOW_PART(Stack->Parameters.Read.ByteOffset);
|
Offset = GET_LARGE_INTEGER_LOW_PART(Stack->Parameters.Read.ByteOffset);
|
||||||
|
@ -1143,7 +1154,8 @@ NTSTATUS FsdMount(PDEVICE_OBJECT DeviceToMount)
|
||||||
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
|
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
|
||||||
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
||||||
DeviceToMount);
|
DeviceToMount);
|
||||||
return(STATUS_SUCCESS);
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
NTSTATUS FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
|
@ -1156,7 +1168,9 @@ NTSTATUS FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
|
PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("VFAT FSC\n");
|
DPRINT("FsdFileSystemControl(DevObj %08lx, Irp %08lx)\n", DeviceObject, Irp);
|
||||||
|
|
||||||
|
/* FIXME: should make sure that this is actually a mount request! */
|
||||||
|
|
||||||
if (FsdHasFileSystem(DeviceToMount))
|
if (FsdHasFileSystem(DeviceToMount))
|
||||||
{
|
{
|
||||||
|
@ -1182,9 +1196,17 @@ NTSTATUS FsdGetStandardInformation(PFCB FCB, PDEVICE_OBJECT DeviceObject,
|
||||||
* FUNCTION: Retrieve the standard file information
|
* FUNCTION: Retrieve the standard file information
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
PDEVICE_EXTENSION DeviceExtension;
|
||||||
unsigned long AllocSize;
|
unsigned long AllocSize;
|
||||||
|
|
||||||
|
DeviceExtension = DeviceObject->DeviceExtension;
|
||||||
|
|
||||||
|
/* PRECONDITION */
|
||||||
|
assert(DeviceExtension != NULL);
|
||||||
|
assert(DeviceExtension->BytesPerCluster != 0);
|
||||||
|
assert(StandardInfo != NULL);
|
||||||
|
assert(FCB != NULL);
|
||||||
|
|
||||||
RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
|
RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
|
||||||
|
|
||||||
/* Make allocsize a rounded up multiple of BytesPerCluster */
|
/* Make allocsize a rounded up multiple of BytesPerCluster */
|
||||||
|
@ -1210,27 +1232,42 @@ NTSTATUS FsdQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
* FUNCTION: Retrieve the specified file information
|
* FUNCTION: Retrieve the specified file information
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
NTSTATUS RC;
|
||||||
FILE_INFORMATION_CLASS FileInformationClass =
|
PIO_STACK_LOCATION Stack;
|
||||||
Stack->Parameters.QueryFile.FileInformationClass;
|
FILE_INFORMATION_CLASS FileInformationClass;
|
||||||
PFILE_OBJECT FileObject = NULL;
|
PFILE_OBJECT FileObject;
|
||||||
PFCB FCB = NULL;
|
PFCB FCB;
|
||||||
// PCCB CCB = NULL;
|
// PCCB CCB;
|
||||||
|
|
||||||
NTSTATUS RC = STATUS_SUCCESS;
|
|
||||||
void *SystemBuffer;
|
void *SystemBuffer;
|
||||||
|
|
||||||
|
/* PRECONDITION */
|
||||||
|
assert(DeviceObject != NULL);
|
||||||
|
assert(Irp != NULL);
|
||||||
|
|
||||||
|
/* INITIALIZATION */
|
||||||
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||||
|
FileInformationClass = Stack->Parameters.QueryFile.FileInformationClass;
|
||||||
|
FileObject = NULL;
|
||||||
|
FCB = NULL;
|
||||||
|
// PCCB CCB = NULL;
|
||||||
|
RC = STATUS_SUCCESS;
|
||||||
FileObject = Stack->FileObject;
|
FileObject = Stack->FileObject;
|
||||||
// CCB = (PCCB)(FileObject->FsContext2);
|
// CCB = (PCCB)(FileObject->FsContext2);
|
||||||
// FCB = CCB->Buffer; // Should be CCB->FCB???
|
// FCB = CCB->Buffer; // Should be CCB->FCB???
|
||||||
FCB=(PFCB)(FileObject->FsContext);
|
FCB = (PFCB)(FileObject->FsContext);
|
||||||
|
SystemBuffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
|
||||||
|
// SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
||||||
|
|
||||||
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
DPRINT("FsdQueryInformation(DevObj %08lx, Irp %08lx)\n", DeviceObject, Irp);
|
||||||
|
|
||||||
switch(FileInformationClass) {
|
switch(FileInformationClass) {
|
||||||
case FileStandardInformation:
|
case FileStandardInformation:
|
||||||
RC = FsdGetStandardInformation(FCB, DeviceObject, SystemBuffer);
|
RC = FsdGetStandardInformation(FCB, DeviceObject, SystemBuffer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
RC = STATUS_INVALID_PARAMETER;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RC;
|
return RC;
|
||||||
|
@ -1264,7 +1301,7 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT _DriverObject,
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceObject->Flags=0;
|
DeviceObject->Flags = DO_DIRECT_IO;
|
||||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose;
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose;
|
||||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate;
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate;
|
||||||
DriverObject->MajorFunction[IRP_MJ_READ] = FsdRead;
|
DriverObject->MajorFunction[IRP_MJ_READ] = FsdRead;
|
||||||
|
|
|
@ -67,7 +67,7 @@ PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction,
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
PIO_STACK_LOCATION StackPtr;
|
PIO_STACK_LOCATION StackPtr;
|
||||||
|
|
||||||
Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
|
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
|
||||||
if (Irp==NULL)
|
if (Irp==NULL)
|
||||||
{
|
{
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -83,6 +83,7 @@ PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction,
|
||||||
StackPtr->Control = 0;
|
StackPtr->Control = 0;
|
||||||
StackPtr->DeviceObject = DeviceObject;
|
StackPtr->DeviceObject = DeviceObject;
|
||||||
StackPtr->FileObject = NULL;
|
StackPtr->FileObject = NULL;
|
||||||
|
StackPtr->CompletionRoutine = NULL;
|
||||||
|
|
||||||
switch(MinorFunction)
|
switch(MinorFunction)
|
||||||
{
|
{
|
||||||
|
@ -144,6 +145,7 @@ PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction,
|
||||||
StackPtr->Control = 0;
|
StackPtr->Control = 0;
|
||||||
StackPtr->DeviceObject = DeviceObject;
|
StackPtr->DeviceObject = DeviceObject;
|
||||||
StackPtr->FileObject = NULL;
|
StackPtr->FileObject = NULL;
|
||||||
|
StackPtr->CompletionRoutine = NULL;
|
||||||
StackPtr->Parameters.Write.Length = Length;
|
StackPtr->Parameters.Write.Length = Length;
|
||||||
|
|
||||||
if (MajorFunction == IRP_MJ_READ || MajorFunction == IRP_MJ_WRITE)
|
if (MajorFunction == IRP_MJ_READ || MajorFunction == IRP_MJ_WRITE)
|
||||||
|
@ -237,7 +239,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||||
Irp->UserBuffer = (LPVOID)Buffer;
|
Irp->UserBuffer = (LPVOID)Buffer;
|
||||||
Irp->UserEvent = Event;
|
Irp->UserEvent = Event;
|
||||||
Irp->UserIosb = IoStatusBlock;
|
Irp->UserIosb = IoStatusBlock;
|
||||||
if (DeviceObject->Flags&DO_BUFFERED_IO)
|
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
||||||
{
|
{
|
||||||
DPRINT("Doing buffer i/o\n");
|
DPRINT("Doing buffer i/o\n");
|
||||||
Irp->AssociatedIrp.SystemBuffer = (PVOID)
|
Irp->AssociatedIrp.SystemBuffer = (PVOID)
|
||||||
|
@ -247,12 +249,13 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||||
IoFreeIrp(Irp);
|
IoFreeIrp(Irp);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
/* FIXME: should copy buffer in on other ops */
|
||||||
if (MajorFunction == IRP_MJ_WRITE)
|
if (MajorFunction == IRP_MJ_WRITE)
|
||||||
{
|
{
|
||||||
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
|
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DeviceObject->Flags&DO_DIRECT_IO)
|
if (DeviceObject->Flags & DO_DIRECT_IO)
|
||||||
{
|
{
|
||||||
DPRINT("Doing direct i/o\n");
|
DPRINT("Doing direct i/o\n");
|
||||||
|
|
||||||
|
@ -276,6 +279,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||||
StackPtr->Control = 0;
|
StackPtr->Control = 0;
|
||||||
StackPtr->DeviceObject = DeviceObject;
|
StackPtr->DeviceObject = DeviceObject;
|
||||||
StackPtr->FileObject = NULL;
|
StackPtr->FileObject = NULL;
|
||||||
|
StackPtr->CompletionRoutine = NULL;
|
||||||
StackPtr->Parameters.Write.Length = Length;
|
StackPtr->Parameters.Write.Length = Length;
|
||||||
if (MajorFunction == IRP_MJ_READ)
|
if (MajorFunction == IRP_MJ_READ)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#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>
|
||||||
|
|
||||||
/* FUNCTIONS *************************************************************/
|
/* FUNCTIONS *************************************************************/
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
|
@ -155,7 +155,9 @@ NTSTATUS IoTryToMountStorageDevice(PDEVICE_OBJECT DeviceObject)
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CHECKPOINT;
|
||||||
KeReleaseSpinLock(&FileSystemListLock,oldlvl);
|
KeReleaseSpinLock(&FileSystemListLock,oldlvl);
|
||||||
|
CHECKPOINT;
|
||||||
return(STATUS_UNRECOGNIZED_VOLUME);
|
return(STATUS_UNRECOGNIZED_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include <internal/io.h>
|
#include <internal/io.h>
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
//#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
@ -109,7 +109,8 @@ VOID IoInitializeIrp(PIRP Irp, USHORT PacketSize, CCHAR StackSize)
|
||||||
* StackSize = Number of stack locations in the IRP
|
* StackSize = Number of stack locations in the IRP
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
assert(Irp!=NULL);
|
assert(Irp != NULL);
|
||||||
|
|
||||||
memset(Irp,0,PacketSize);
|
memset(Irp,0,PacketSize);
|
||||||
Irp->StackCount=StackSize;
|
Irp->StackCount=StackSize;
|
||||||
Irp->CurrentLocation=StackSize;
|
Irp->CurrentLocation=StackSize;
|
||||||
|
@ -193,7 +194,8 @@ PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota)
|
||||||
{
|
{
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
|
|
||||||
DPRINT("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",StackSize,
|
DPRINT("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",
|
||||||
|
StackSize,
|
||||||
ChargeQuota);
|
ChargeQuota);
|
||||||
if (ChargeQuota)
|
if (ChargeQuota)
|
||||||
{
|
{
|
||||||
|
@ -209,11 +211,11 @@ PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Irp->StackCount=StackSize;
|
IoInitializeIrp(Irp, IoSizeOfIrp(StackSize), StackSize);
|
||||||
Irp->CurrentLocation=StackSize;
|
|
||||||
|
|
||||||
DPRINT("Irp %x Irp->StackPtr %d\n",Irp,Irp->CurrentLocation);
|
DPRINT("Irp %x Irp->StackPtr %d\n", Irp, Irp->CurrentLocation);
|
||||||
return(Irp);
|
|
||||||
|
return Irp;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID IoSetCompletionRoutine(PIRP Irp,
|
VOID IoSetCompletionRoutine(PIRP Irp,
|
||||||
|
@ -269,8 +271,10 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||||
|
|
||||||
for (i=0;i<Irp->StackCount;i++)
|
for (i=0;i<Irp->StackCount;i++)
|
||||||
{
|
{
|
||||||
DPRINT("&Irp->Stack[i] %x\n",&Irp->Stack[i]);
|
DPRINT("&Irp->Stack[%d].CompletionRoutine %08lx\n",
|
||||||
if (Irp->Stack[i].CompletionRoutine!=NULL)
|
i,
|
||||||
|
Irp->Stack[i].CompletionRoutine);
|
||||||
|
if (Irp->Stack[i].CompletionRoutine != NULL)
|
||||||
{
|
{
|
||||||
Status = Irp->Stack[i].CompletionRoutine(
|
Status = Irp->Stack[i].CompletionRoutine(
|
||||||
Irp->Stack[i].DeviceObject,
|
Irp->Stack[i].DeviceObject,
|
||||||
|
@ -281,7 +285,7 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DPRINT("Irp->Stack[i].Control %x\n",Irp->Stack[i].Control);
|
DPRINT("Irp->Stack[%d].Control %08lx\n", i, Irp->Stack[i].Control);
|
||||||
if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
|
if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
|
||||||
{
|
{
|
||||||
DPRINT("Setting PendingReturned flag\n");
|
DPRINT("Setting PendingReturned flag\n");
|
||||||
|
@ -306,4 +310,4 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||||
IoSecondStageCompletion(Irp,PriorityBoost);
|
IoSecondStageCompletion(Irp,PriorityBoost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>>>>>>> 1.7
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
|
||||||
{
|
{
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
assert(FileObject != NULL);
|
||||||
|
|
||||||
if (ByteOffset==NULL)
|
if (ByteOffset==NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
|
|
||||||
//#define NDEBUG
|
#define NDEBUG
|
||||||
#include <internal/debug.h>
|
#include <internal/debug.h>
|
||||||
|
|
||||||
/* MACROS ********************************************************************/
|
/* MACROS ********************************************************************/
|
||||||
|
@ -196,7 +196,7 @@ LdrPEProcessDriver(PVOID ModuleLoadBase)
|
||||||
PIMAGE_FILE_HEADER PEFileHeader;
|
PIMAGE_FILE_HEADER PEFileHeader;
|
||||||
PIMAGE_OPTIONAL_HEADER PEOptionalHeader;
|
PIMAGE_OPTIONAL_HEADER PEOptionalHeader;
|
||||||
|
|
||||||
DbgPrint("Processing PE Driver at module base:%08lx\n", ModuleLoadBase);
|
DPRINT("Processing PE Driver at module base:%08lx\n", ModuleLoadBase);
|
||||||
|
|
||||||
/* Get header pointers */
|
/* Get header pointers */
|
||||||
PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase;
|
PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase;
|
||||||
|
@ -223,18 +223,18 @@ LdrPEProcessDriver(PVOID ModuleLoadBase)
|
||||||
|
|
||||||
/* FIXME: check/verify OS version number */
|
/* FIXME: check/verify OS version number */
|
||||||
|
|
||||||
DbgPrint("OptionalHdrMagic:%04x LinkVersion:%d.%d\n",
|
DPRINT("OptionalHdrMagic:%04x LinkVersion:%d.%d\n",
|
||||||
PEOptionalHeader->Magic,
|
PEOptionalHeader->Magic,
|
||||||
PEOptionalHeader->MajorLinkerVersion,
|
PEOptionalHeader->MajorLinkerVersion,
|
||||||
PEOptionalHeader->MinorLinkerVersion);
|
PEOptionalHeader->MinorLinkerVersion);
|
||||||
DbgPrint("Size: CODE:%08lx(%d) DATA:%08lx(%d) BSS:%08lx(%d)\n",
|
DPRINT("Size: CODE:%08lx(%d) DATA:%08lx(%d) BSS:%08lx(%d)\n",
|
||||||
PEOptionalHeader->SizeOfCode,
|
PEOptionalHeader->SizeOfCode,
|
||||||
PEOptionalHeader->SizeOfCode,
|
PEOptionalHeader->SizeOfCode,
|
||||||
PEOptionalHeader->SizeOfInitializedData,
|
PEOptionalHeader->SizeOfInitializedData,
|
||||||
PEOptionalHeader->SizeOfInitializedData,
|
PEOptionalHeader->SizeOfInitializedData,
|
||||||
PEOptionalHeader->SizeOfUninitializedData,
|
PEOptionalHeader->SizeOfUninitializedData,
|
||||||
PEOptionalHeader->SizeOfUninitializedData);
|
PEOptionalHeader->SizeOfUninitializedData);
|
||||||
DbgPrint("Entry Point:%08lx\n", PEOptionalHeader->AddressOfEntryPoint);
|
DPRINT("Entry Point:%08lx\n", PEOptionalHeader->AddressOfEntryPoint);
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
|
|
||||||
/* Determine the size of the module */
|
/* Determine the size of the module */
|
||||||
|
@ -450,8 +450,9 @@ LdrCOFFDoRelocations(module *Module, unsigned int SectionIndex)
|
||||||
|
|
||||||
for (j = 0; j < Section->s_nreloc; j++)
|
for (j = 0; j < Section->s_nreloc; j++)
|
||||||
{
|
{
|
||||||
DbgPrint("vaddr %x ", Relocation->r_vaddr);
|
DPRINT("vaddr %x symndex %x",
|
||||||
DbgPrint("symndex %x ", Relocation->r_symndx);
|
Relocation->r_vaddr,
|
||||||
|
Relocation->r_symndx);
|
||||||
|
|
||||||
switch (Relocation->r_type)
|
switch (Relocation->r_type)
|
||||||
{
|
{
|
||||||
|
@ -470,7 +471,7 @@ LdrCOFFDoRelocations(module *Module, unsigned int SectionIndex)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DbgPrint("%.8s: Unknown relocation type %x at %d in module\n",
|
DPRINT("%.8s: Unknown relocation type %x at %d in module\n",
|
||||||
Module->scn_list[SectionIndex].s_name,
|
Module->scn_list[SectionIndex].s_name,
|
||||||
Relocation->r_type,
|
Relocation->r_type,
|
||||||
j);
|
j);
|
||||||
|
@ -502,7 +503,7 @@ LdrCOFFDoAddr32Reloc(module *Module, SCNHDR *Section, RELOC *Relocation)
|
||||||
|
|
||||||
Value = LdrCOFFGetSymbolValue(Module, Relocation->r_symndx);
|
Value = LdrCOFFGetSymbolValue(Module, Relocation->r_symndx);
|
||||||
Location = (unsigned int *)(Module->base + Relocation->r_vaddr);
|
Location = (unsigned int *)(Module->base + Relocation->r_vaddr);
|
||||||
DbgPrint("ADDR32 loc %x value %x *loc %x ", Location, Value, *Location);
|
DPRINT("ADDR32 loc %x value %x *loc %x\n", Location, Value, *Location);
|
||||||
*Location = (*Location) + Module->base;
|
*Location = (*Location) + Module->base;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -596,7 +597,7 @@ LdrCOFFGetSymbolValue(module *Module, unsigned int Idx)
|
||||||
char Name[255];
|
char Name[255];
|
||||||
|
|
||||||
LdrCOFFGetSymbolName(Module, Idx, Name);
|
LdrCOFFGetSymbolName(Module, Idx, Name);
|
||||||
DbgPrint("name %s ", Name);
|
DPRINT("name %s ", Name);
|
||||||
|
|
||||||
/* Check if the symbol is a section we have relocated */
|
/* Check if the symbol is a section we have relocated */
|
||||||
if (strcmp(Name, ".text") == 0)
|
if (strcmp(Name, ".text") == 0)
|
||||||
|
@ -714,7 +715,7 @@ NTSTATUS LdrLoadLibrary(HANDLE ProcessHandle,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DbgPrint("Library already loaded\n");
|
DPRINT("Library already loaded\n");
|
||||||
*Module = Library
|
*Module = Library
|
||||||
}
|
}
|
||||||
RtlFreeUnicodeString(&umodName);
|
RtlFreeUnicodeString(&umodName);
|
||||||
|
|
Loading…
Reference in a new issue