From 2d14c3e110af3a8740ead6cd68692e5ae0d9c94e Mon Sep 17 00:00:00 2001 From: Rex Jolliff Date: Fri, 1 Jan 1999 22:33:38 +0000 Subject: [PATCH] Changes to support the COFF driver loader svn path=/trunk/; revision=144 --- reactos/drivers/dd/ide/ide.c | 127 +++--- reactos/drivers/fs/vfat/blockdev.c | 18 +- reactos/drivers/fs/vfat/iface.c | 135 ++++--- reactos/ntoskrnl/io/buildirp.c | 10 +- reactos/ntoskrnl/io/create.c | 2 +- reactos/ntoskrnl/io/file.c | 1 + reactos/ntoskrnl/io/fs.c | 2 + reactos/ntoskrnl/io/irp.c | 622 +++++++++++++++-------------- reactos/ntoskrnl/io/rw.c | 1 + reactos/ntoskrnl/ldr/loader.c | 47 +-- 10 files changed, 511 insertions(+), 454 deletions(-) diff --git a/reactos/drivers/dd/ide/ide.c b/reactos/drivers/dd/ide/ide.c index 9aee837d067..529399af20d 100644 --- a/reactos/drivers/dd/ide/ide.c +++ b/reactos/drivers/dd/ide/ide.c @@ -1,66 +1,67 @@ -// -// IDE.C - IDE Disk driver -// written by Rex Jolliff -// with help from various documentation sources and a few peeks at -// linux and freebsd sources. -// -// This driver supports up to 4 controllers with up to 2 drives each. -// The device names are assigned as follows: -// \Devices\HarddiskX\Partition0 -// for the raw device, and -// \Devices\HarddiskX\PartitionY -// for partitions -// where: -// X is computed by counting the available drives from the following -// sequence: the controller number (0=0x1f0, 1=0x170, 2=0x1e8, -// 3=0x168) * 2 plus the drive number (0,1) -// Y is the partition number -// -// The driver exports the following function: -// -// DriverEntry() - NT device driver initialization routine -// -// And the following functions are exported implicitly: -// -// IDEStartIo() - called to start an I/O request packet -// IDEDispatchOpenClose() - Called to open/close the device. a NOOP -// IDEDispatchReadWrite() - Called to read/write the device. -// IDEDispatchQueryInformation() - Called to get device information -// IDEDispatchSetInformation() - Called to set device information -// IDEDispatchDeviceControl() - Called to execute device control requests -// -// Modification History: -// 05/25/98 RJJ Created. -// 05/30/98 RJJ Removed IRQ handler and inserted busy waits -// just to get something working... -// 07/18/98 RJJ Made drastic changes so that the driver -// resembles a WinNT driver. -// 08/05/98 RJJ Changed to .C extension -// 09/19/98 RJJ First release (run for cover!) -// -// Test List: -// 09/17/98 RJJ Pri/MST: 14.12X19 WDC AC31000H Test Passed -// Pri/SLV: None. -// -// -// To Do: -// FIXME: a timer should be used to watch for device timeouts and errors -// FIXME: errors should be retried -// FIXME: a drive reset/recalibrate should be attempted if errors occur -// FIXME: Use DMA for transfers if drives support it -// FIXME: should we support unloading of this driver??? -// FIXME: the device information should come from AUTODETECT (via registry) -// FIXME: really big devices need to be handled correctly -// FIXME: should get device info from the registry -// FIXME: should report hardware usage to iomgr -// FIXME: finish implementation of QueryInformation -// FIXME: finish implementation of SetInformation -// FIXME: finish implementation of DeviceControl -// FIXME: bring up to ATA-3 spec -// FIXME: add general support for ATAPI devices -// FIXME: add support for ATAPI CDROMs -// FIXME: add support for ATAPI ZIP drives/RHDs -// FIXME: add support for ATAPI tape drives +/* + * IDE.C - IDE Disk driver + * written by Rex Jolliff + * with help from various documentation sources and a few peeks at + * linux and freebsd sources. + * + * This driver supports up to 4 controllers with up to 2 drives each. + * The device names are assigned as follows: + * \Devices\HarddiskX\Partition0 + * for the raw device, and + * \Devices\HarddiskX\PartitionY + * for partitions + * where: + * X is computed by counting the available drives from the following + * sequence: the controller number (0=0x1f0, 1=0x170, 2=0x1e8, + * 3=0x168) * 2 plus the drive number (0,1) + * Y is the partition number + * + * The driver exports the following function: + * + * DriverEntry() - NT device driver initialization routine + * + * And the following functions are exported implicitly: + * + * IDEStartIo() - called to start an I/O request packet + * IDEDispatchOpenClose() - Called to open/close the device. a NOOP + * IDEDispatchReadWrite() - Called to read/write the device. + * IDEDispatchQueryInformation() - Called to get device information + * IDEDispatchSetInformation() - Called to set device information + * IDEDispatchDeviceControl() - Called to execute device control requests + * + * Modification History: + * 05/25/98 RJJ Created. + * 05/30/98 RJJ Removed IRQ handler and inserted busy waits + * just to get something working... + * 07/18/98 RJJ Made drastic changes so that the driver + * resembles a WinNT driver. + * 08/05/98 RJJ Changed to .C extension + * 09/19/98 RJJ First release (run for cover!) + * + * Test List: + * 09/17/98 RJJ Pri/MST: 14.12X19 WDC AC31000H Test Passed + * Pri/SLV: None. + * + * + * To Do: + * FIXME: a timer should be used to watch for device timeouts and errors + * FIXME: errors should be retried + * FIXME: a drive reset/recalibrate should be attempted if errors occur + * FIXME: Use DMA for transfers if drives support it + * FIXME: should we support unloading of this driver??? + * FIXME: the device information should come from AUTODETECT (via registry) + * FIXME: really big devices need to be handled correctly + * FIXME: should get device info from the registry + * FIXME: should report hardware usage to iomgr + * FIXME: finish implementation of QueryInformation + * FIXME: finish implementation of SetInformation + * FIXME: finish implementation of DeviceControl + * FIXME: bring up to ATA-3 spec + * FIXME: add general support for ATAPI devices + * FIXME: add support for ATAPI CDROMs + * FIXME: add support for ATAPI ZIP drives/RHDs + * FIXME: add support for ATAPI tape drives + */ #include diff --git a/reactos/drivers/fs/vfat/blockdev.c b/reactos/drivers/fs/vfat/blockdev.c index bd82ebad83d..6ecb42589f4 100644 --- a/reactos/drivers/fs/vfat/blockdev.c +++ b/reactos/drivers/fs/vfat/blockdev.c @@ -21,7 +21,7 @@ /* FUNCTIONS ***************************************************************/ BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, - IN ULONG DiskSector, + IN ULONG DiskSector, IN ULONG SectorCount, IN UCHAR* Buffer) { @@ -33,22 +33,28 @@ BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, ULONG sectorSize; 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_HIGH_PART(sectorNumber, DiskSector >> 23); 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); + 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) { return FALSE; } - DPRINT("Building synchronous FSD Request...\n"); irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, pDeviceObject, diff --git a/reactos/drivers/fs/vfat/iface.c b/reactos/drivers/fs/vfat/iface.c index ad3b38f5e5f..969ad86ee3b 100644 --- a/reactos/drivers/fs/vfat/iface.c +++ b/reactos/drivers/fs/vfat/iface.c @@ -26,7 +26,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include #include "vfat.h" @@ -668,18 +668,12 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, FileObject, FileName); -CHECKPOINT; string = FileName; -CHECKPOINT; ParentFcb = NULL; -CHECKPOINT; Fcb = ExAllocatePool(NonPagedPool, sizeof(FCB)); -CHECKPOINT; next = &string[0]; -CHECKPOINT; current = next+1; -CHECKPOINT; while (next!=NULL) { DPRINT("current %w next %x\n",current,next); @@ -692,7 +686,6 @@ CHECKPOINT; *next=0; } -CHECKPOINT; Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL); if (Status != STATUS_SUCCESS) { @@ -709,7 +702,6 @@ CHECKPOINT; Fcb = ParentFcb; } ParentFcb = Temp; -CHECKPOINT; } FileObject->FsContext = ParentFcb; DPRINT("file opn, fcb=%x\n",ParentFcb); @@ -724,7 +716,7 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount) * by this fsd */ { - BootSector* Boot; + BootSector *Boot; Boot = ExAllocatePool(NonPagedPool,512); @@ -738,7 +730,8 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount) return(TRUE); } ExFreePool(Boot); - return(FALSE); + + return FALSE; } NTSTATUS FsdMountDevice(PDEVICE_EXTENSION DeviceExt, @@ -844,19 +837,37 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PVOID Temp; 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, " - "Length %d, ReadOffset %d)\n",DeviceExt,FileObject,Buffer, - Length,ReadOffset); + "Length %d, ReadOffset %d)\n", + DeviceExt, + FileObject, + Buffer, + Length, + ReadOffset); + DPRINT("DeviceExt->BytesPerCluster %d\n", DeviceExt->BytesPerCluster); FirstCluster = ReadOffset / DeviceExt->BytesPerCluster; Fcb = FileObject->FsContext; if (DeviceExt->FatType == FAT32) - CurrentCluster = Fcb->entry.FirstCluster+Fcb->entry.FirstClusterHigh*65536; + { + CurrentCluster = Fcb->entry.FirstCluster + + Fcb->entry.FirstClusterHigh * 65536; + } else - CurrentCluster = Fcb->entry.FirstCluster; - if (CurrentCluster<2) - return STATUS_UNSUCCESSFUL;// FIXME : root of FAT16 ? - DPRINT("DeviceExt->BytesPerCluster %x\n",DeviceExt->BytesPerCluster); + { + CurrentCluster = Fcb->entry.FirstCluster; + } + if (CurrentCluster < 2) + { + /* FIXME : root of FAT16 ? */ + return STATUS_UNSUCCESSFUL; + } if (ReadOffset >= Fcb->entry.FileSize) { @@ -868,11 +879,11 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, } *LengthRead = 0; Temp = ExAllocatePool(NonPagedPool,DeviceExt->BytesPerCluster); + /* FIXME: optimize by remembering the last cluster read and using if possible */ for (FileOffset=0; FileOffset < FirstCluster; FileOffset++) - { - CurrentCluster = GetNextCluster(DeviceExt,CurrentCluster); - } - CHECKPOINT; + { + CurrentCluster = GetNextCluster(DeviceExt,CurrentCluster); + } if ((ReadOffset % DeviceExt->BytesPerCluster)!=0) { VFATLoadCluster(DeviceExt,Temp,CurrentCluster); @@ -888,7 +899,6 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, Length = Length - TempLength; Buffer = Buffer + TempLength; } - CHECKPOINT; while (Length > DeviceExt->BytesPerCluster) { VFATLoadCluster(DeviceExt, Buffer, CurrentCluster); @@ -904,7 +914,6 @@ NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, Buffer = Buffer + DeviceExt->BytesPerCluster; Length = Length - DeviceExt->BytesPerCluster; } - CHECKPOINT; if (Length > 0) { (*LengthRead) = (*LengthRead) + Length; @@ -1041,21 +1050,14 @@ NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp) Irp); Stack = IoGetCurrentIrpStackLocation(Irp); -CHECKPOINT; FileObject = Stack->FileObject; -CHECKPOINT; DeviceExt = DeviceObject->DeviceExtension; -CHECKPOINT; Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer); -CHECKPOINT; Irp->IoStatus.Status = Status; -CHECKPOINT; Irp->IoStatus.Information = 0; -CHECKPOINT; IoCompleteRequest(Irp, IO_NO_INCREMENT); -CHECKPOINT; return Status; } @@ -1097,14 +1099,23 @@ NTSTATUS FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp) ULONG Length; PVOID Buffer; ULONG Offset; - PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); - PFILE_OBJECT FileObject = Stack->FileObject; - PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension; + PIO_STACK_LOCATION Stack; + PFILE_OBJECT FileObject; + PDEVICE_EXTENSION DeviceExt; NTSTATUS Status; ULONG LengthRead; 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; Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); Offset = GET_LARGE_INTEGER_LOW_PART(Stack->Parameters.Read.ByteOffset); @@ -1143,7 +1154,8 @@ NTSTATUS FsdMount(PDEVICE_OBJECT DeviceToMount) DeviceObject->Vpb->Flags |= VPB_MOUNTED; DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject, DeviceToMount); - return(STATUS_SUCCESS); + + return STATUS_SUCCESS; } 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; 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)) { @@ -1182,9 +1196,17 @@ NTSTATUS FsdGetStandardInformation(PFCB FCB, PDEVICE_OBJECT DeviceObject, * FUNCTION: Retrieve the standard file information */ { - PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; + PDEVICE_EXTENSION DeviceExtension; 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)); /* 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 */ { - PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); - FILE_INFORMATION_CLASS FileInformationClass = - Stack->Parameters.QueryFile.FileInformationClass; - PFILE_OBJECT FileObject = NULL; - PFCB FCB = NULL; -// PCCB CCB = NULL; - - NTSTATUS RC = STATUS_SUCCESS; + NTSTATUS RC; + PIO_STACK_LOCATION Stack; + FILE_INFORMATION_CLASS FileInformationClass; + PFILE_OBJECT FileObject; + PFCB FCB; +// PCCB CCB; 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; // CCB = (PCCB)(FileObject->FsContext2); // 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) { case FileStandardInformation: RC = FsdGetStandardInformation(FCB, DeviceObject, SystemBuffer); - break; + break; + + default: + RC = STATUS_INVALID_PARAMETER; + break; } return RC; @@ -1264,7 +1301,7 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT _DriverObject, return(ret); } - DeviceObject->Flags=0; + DeviceObject->Flags = DO_DIRECT_IO; DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose; DriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate; DriverObject->MajorFunction[IRP_MJ_READ] = FsdRead; diff --git a/reactos/ntoskrnl/io/buildirp.c b/reactos/ntoskrnl/io/buildirp.c index de883d956e1..0a489e2daf4 100644 --- a/reactos/ntoskrnl/io/buildirp.c +++ b/reactos/ntoskrnl/io/buildirp.c @@ -67,7 +67,7 @@ PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction, PIRP Irp; PIO_STACK_LOCATION StackPtr; - Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE); + Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE); if (Irp==NULL) { return(NULL); @@ -83,6 +83,7 @@ PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction, StackPtr->Control = 0; StackPtr->DeviceObject = DeviceObject; StackPtr->FileObject = NULL; + StackPtr->CompletionRoutine = NULL; switch(MinorFunction) { @@ -144,6 +145,7 @@ PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction, StackPtr->Control = 0; StackPtr->DeviceObject = DeviceObject; StackPtr->FileObject = NULL; + StackPtr->CompletionRoutine = NULL; StackPtr->Parameters.Write.Length = Length; if (MajorFunction == IRP_MJ_READ || MajorFunction == IRP_MJ_WRITE) @@ -237,7 +239,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction, Irp->UserBuffer = (LPVOID)Buffer; Irp->UserEvent = Event; Irp->UserIosb = IoStatusBlock; - if (DeviceObject->Flags&DO_BUFFERED_IO) + if (DeviceObject->Flags & DO_BUFFERED_IO) { DPRINT("Doing buffer i/o\n"); Irp->AssociatedIrp.SystemBuffer = (PVOID) @@ -247,12 +249,13 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction, IoFreeIrp(Irp); return(NULL); } + /* FIXME: should copy buffer in on other ops */ if (MajorFunction == IRP_MJ_WRITE) { RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length); } } - if (DeviceObject->Flags&DO_DIRECT_IO) + if (DeviceObject->Flags & DO_DIRECT_IO) { DPRINT("Doing direct i/o\n"); @@ -276,6 +279,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction, StackPtr->Control = 0; StackPtr->DeviceObject = DeviceObject; StackPtr->FileObject = NULL; + StackPtr->CompletionRoutine = NULL; StackPtr->Parameters.Write.Length = Length; if (MajorFunction == IRP_MJ_READ) { diff --git a/reactos/ntoskrnl/io/create.c b/reactos/ntoskrnl/io/create.c index b79266db54a..827d1c8066e 100644 --- a/reactos/ntoskrnl/io/create.c +++ b/reactos/ntoskrnl/io/create.c @@ -17,7 +17,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include /* FUNCTIONS *************************************************************/ diff --git a/reactos/ntoskrnl/io/file.c b/reactos/ntoskrnl/io/file.c index 2c399ec1137..677d91a41f7 100644 --- a/reactos/ntoskrnl/io/file.c +++ b/reactos/ntoskrnl/io/file.c @@ -12,6 +12,7 @@ #include +#define NDEBUG #include /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/io/fs.c b/reactos/ntoskrnl/io/fs.c index 1bfa13262fd..151679376e2 100644 --- a/reactos/ntoskrnl/io/fs.c +++ b/reactos/ntoskrnl/io/fs.c @@ -155,7 +155,9 @@ NTSTATUS IoTryToMountStorageDevice(PDEVICE_OBJECT DeviceObject) current_entry = current_entry->Flink; } } +CHECKPOINT; KeReleaseSpinLock(&FileSystemListLock,oldlvl); +CHECKPOINT; return(STATUS_UNRECOGNIZED_VOLUME); } diff --git a/reactos/ntoskrnl/io/irp.c b/reactos/ntoskrnl/io/irp.c index e7108dc4190..3c8f2f32196 100644 --- a/reactos/ntoskrnl/io/irp.c +++ b/reactos/ntoskrnl/io/irp.c @@ -1,309 +1,313 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/io/irp.c - * PURPOSE: Handle IRPs - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * 24/05/98: Created - */ - -/* NOTES ******************************************************************* - * - * Layout of an IRP - * - * ################ - * # Headers # - * ################ - * # # - * # Variable # - * # length list # - * # of io stack # - * # locations # - * # # - * ################ - * - * - * - */ - -/* INCLUDES ****************************************************************/ - -#include -#include -#include - -//#define NDEBUG -#include - -/* FUNCTIONS ****************************************************************/ - -PDEVICE_OBJECT IoGetDeviceToVerify(PETHREAD Thread) -/* - * FUNCTION: Returns a pointer to the device, representing a removable-media - * device, that is the target of the given thread's I/O request - */ -{ - UNIMPLEMENTED; -} - -VOID IoFreeIrp(PIRP Irp) -/* - * FUNCTION: Releases a caller allocated irp - * ARGUMENTS: - * Irp = Irp to free - */ -{ - ExFreePool(Irp); -} - -PIRP IoMakeAssociatedIrp(PIRP Irp, CCHAR StackSize) -/* - * FUNCTION: Allocates and initializes an irp to associated with a master irp - * ARGUMENTS: - * Irp = Master irp - * StackSize = Number of stack locations to be allocated in the irp - * RETURNS: The irp allocated - */ -{ - PIRP AssocIrp; - - AssocIrp = IoAllocateIrp(StackSize,FALSE); - UNIMPLEMENTED; -} - -VOID IoMarkIrpPending(PIRP Irp) -/* - * FUNCTION: Marks the specified irp, indicating further processing will - * be required by other driver routines - * ARGUMENTS: - * Irp = Irp to mark - */ -{ - DPRINT("IoGetCurrentIrpStackLocation(Irp) %x\n", - IoGetCurrentIrpStackLocation(Irp)); - IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED; - Irp->Tail.Overlay.Thread = KeGetCurrentThread(); - DPRINT("IoGetCurrentIrpStackLocation(Irp)->Control %x\n", - IoGetCurrentIrpStackLocation(Irp)->Control); - DPRINT("SL_PENDING_RETURNED %x\n",SL_PENDING_RETURNED); -} - -USHORT IoSizeOfIrp(CCHAR StackSize) -/* - * FUNCTION: Determines the size of an IRP - * ARGUMENTS: - * StackSize = number of stack locations in the IRP - * RETURNS: The size of the IRP in bytes - */ -{ - return(sizeof(IRP)+((StackSize-1)*sizeof(IO_STACK_LOCATION))); -} - -VOID IoInitializeIrp(PIRP Irp, USHORT PacketSize, CCHAR StackSize) -/* - * FUNCTION: Initalizes an irp allocated by the caller - * ARGUMENTS: - * Irp = IRP to initalize - * PacketSize = Size in bytes of the IRP - * StackSize = Number of stack locations in the IRP - */ -{ - assert(Irp!=NULL); - memset(Irp,0,PacketSize); - Irp->StackCount=StackSize; - Irp->CurrentLocation=StackSize; - Irp->Tail.Overlay.CurrentStackLocation=IoGetCurrentIrpStackLocation(Irp); -} - -PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp) -/* - * FUNCTION: Gets a pointer to the callers location in the I/O stack in - * the given IRP - * ARGUMENTS: - * Irp = Points to the IRP - * RETURNS: A pointer to the stack location - */ -{ - DPRINT("IoGetCurrentIrpStackLocation: Irp %08lx CurLoc %d StkCnt %d\n", - Irp, - Irp->CurrentLocation, - Irp->StackCount); - - return &Irp->Stack[Irp->CurrentLocation]; -} - - -VOID IoSetNextIrpStackLocation(PIRP Irp) -{ - Irp->CurrentLocation--; - Irp->Tail.Overlay.CurrentStackLocation--; -} - -PIO_STACK_LOCATION IoGetNextIrpStackLocation(PIRP Irp) -/* - * FUNCTION: Gives a higher level driver access to the next lower driver's - * I/O stack location - * ARGUMENTS: - * Irp = points to the irp - * RETURNS: A pointer to the stack location - */ -{ - DPRINT("IoGetNextIrpStackLocation: Irp %08lx CurLoc %d StkCnt %d\n", - Irp, - Irp->CurrentLocation, - Irp->StackCount); - - assert(Irp!=NULL); - DPRINT("Irp %x Irp->StackPtr %x\n",Irp,Irp->CurrentLocation); - return(&Irp->Stack[Irp->CurrentLocation-1]); -} - -NTSTATUS IoCallDriver(PDEVICE_OBJECT DevObject, PIRP irp) -/* - * FUNCTION: Sends an IRP to the next lower driver - */ -{ - NTSTATUS Status; - PDRIVER_OBJECT drv = DevObject->DriverObject; - IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(irp); - - DPRINT("Deviceobject %x\n",DevObject); - DPRINT("Irp %x\n",irp); - - irp->Tail.Overlay.CurrentStackLocation--; - irp->CurrentLocation--; - - DPRINT("Io stack address %x\n",param); - DPRINT("Function %d Routine %x\n",param->MajorFunction, - drv->MajorFunction[param->MajorFunction]); - - Status = drv->MajorFunction[param->MajorFunction](DevObject,irp); - return Status; -} - -PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota) -/* - * FUNCTION: Allocates an IRP - * ARGUMENTS: - * StackSize = the size of the stack required for the irp - * ChargeQuota = Charge allocation to current threads quota - * RETURNS: Irp allocated - */ -{ - PIRP Irp; - - DPRINT("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",StackSize, - ChargeQuota); - if (ChargeQuota) - { - Irp = ExAllocatePoolWithQuota(NonPagedPool,IoSizeOfIrp(StackSize)); - } - else - { - Irp = ExAllocatePool(NonPagedPool,IoSizeOfIrp(StackSize)); - } - - if (Irp==NULL) - { - return(NULL); - } - - Irp->StackCount=StackSize; - Irp->CurrentLocation=StackSize; - - DPRINT("Irp %x Irp->StackPtr %d\n",Irp,Irp->CurrentLocation); - return(Irp); -} - -VOID IoSetCompletionRoutine(PIRP Irp, - PIO_COMPLETION_ROUTINE CompletionRoutine, - PVOID Context, - BOOLEAN InvokeOnSuccess, - BOOLEAN InvokeOnError, - BOOLEAN InvokeOnCancel) -{ - IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(Irp); - - param->CompletionRoutine=CompletionRoutine; - param->CompletionContext=Context; - if (InvokeOnSuccess) - { - param->Control = param->Control | SL_INVOKE_ON_SUCCESS; - } - if (InvokeOnError) - { - param->Control = param->Control | SL_INVOKE_ON_ERROR; - } - if (InvokeOnCancel) - { - param->Control = param->Control | SL_INVOKE_ON_CANCEL; - } -} - -VOID IopCompleteRequest(struct _KAPC* Apc, - PKNORMAL_ROUTINE* NormalRoutine, - PVOID* NormalContext, - PVOID* SystemArgument1, - PVOID* SystemArgument2) -{ - IoSecondStageCompletion((PIRP)(*NormalContext), - IO_NO_INCREMENT); -} - -VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost) -/* - * FUNCTION: Indicates the caller has finished all processing for a given - * I/O request and is returning the given IRP to the I/O manager - * ARGUMENTS: - * Irp = Irp to be cancelled - * PriorityBoost = Increment by which to boost the priority of the - * thread making the request - */ -{ - unsigned int i; - NTSTATUS Status; - - DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n", - Irp,PriorityBoost); - - for (i=0;iStackCount;i++) - { - DPRINT("&Irp->Stack[i] %x\n",&Irp->Stack[i]); - if (Irp->Stack[i].CompletionRoutine!=NULL) - { - Status = Irp->Stack[i].CompletionRoutine( - Irp->Stack[i].DeviceObject, - Irp, - Irp->Stack[i].CompletionContext); - if (Status == STATUS_MORE_PROCESSING_REQUIRED) - { - return; - } - } - DPRINT("Irp->Stack[i].Control %x\n",Irp->Stack[i].Control); - if (Irp->Stack[i].Control & SL_PENDING_RETURNED) - { - DPRINT("Setting PendingReturned flag\n"); - Irp->PendingReturned = TRUE; - } - } - - if (Irp->PendingReturned) - { - KeInitializeApc(&Irp->Tail.Apc, - &Irp->Tail.Overlay.Thread->Tcb, - 0, - IopCompleteRequest, - NULL, - NULL, - 0, - Irp); - KeInsertQueueApc(&Irp->Tail.Apc,NULL,NULL,0); - } - else - { - IoSecondStageCompletion(Irp,PriorityBoost); - } -} ->>>>>>> 1.7 +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/io/irp.c + * PURPOSE: Handle IRPs + * PROGRAMMER: David Welch (welch@mcmail.com) + * UPDATE HISTORY: + * 24/05/98: Created + */ + +/* NOTES ******************************************************************* + * + * Layout of an IRP + * + * ################ + * # Headers # + * ################ + * # # + * # Variable # + * # length list # + * # of io stack # + * # locations # + * # # + * ################ + * + * + * + */ + +/* INCLUDES ****************************************************************/ + +#include +#include +#include + +#define NDEBUG +#include + +/* FUNCTIONS ****************************************************************/ + +PDEVICE_OBJECT IoGetDeviceToVerify(PETHREAD Thread) +/* + * FUNCTION: Returns a pointer to the device, representing a removable-media + * device, that is the target of the given thread's I/O request + */ +{ + UNIMPLEMENTED; +} + +VOID IoFreeIrp(PIRP Irp) +/* + * FUNCTION: Releases a caller allocated irp + * ARGUMENTS: + * Irp = Irp to free + */ +{ + ExFreePool(Irp); +} + +PIRP IoMakeAssociatedIrp(PIRP Irp, CCHAR StackSize) +/* + * FUNCTION: Allocates and initializes an irp to associated with a master irp + * ARGUMENTS: + * Irp = Master irp + * StackSize = Number of stack locations to be allocated in the irp + * RETURNS: The irp allocated + */ +{ + PIRP AssocIrp; + + AssocIrp = IoAllocateIrp(StackSize,FALSE); + UNIMPLEMENTED; +} + +VOID IoMarkIrpPending(PIRP Irp) +/* + * FUNCTION: Marks the specified irp, indicating further processing will + * be required by other driver routines + * ARGUMENTS: + * Irp = Irp to mark + */ +{ + DPRINT("IoGetCurrentIrpStackLocation(Irp) %x\n", + IoGetCurrentIrpStackLocation(Irp)); + IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED; + Irp->Tail.Overlay.Thread = KeGetCurrentThread(); + DPRINT("IoGetCurrentIrpStackLocation(Irp)->Control %x\n", + IoGetCurrentIrpStackLocation(Irp)->Control); + DPRINT("SL_PENDING_RETURNED %x\n",SL_PENDING_RETURNED); +} + +USHORT IoSizeOfIrp(CCHAR StackSize) +/* + * FUNCTION: Determines the size of an IRP + * ARGUMENTS: + * StackSize = number of stack locations in the IRP + * RETURNS: The size of the IRP in bytes + */ +{ + return(sizeof(IRP)+((StackSize-1)*sizeof(IO_STACK_LOCATION))); +} + +VOID IoInitializeIrp(PIRP Irp, USHORT PacketSize, CCHAR StackSize) +/* + * FUNCTION: Initalizes an irp allocated by the caller + * ARGUMENTS: + * Irp = IRP to initalize + * PacketSize = Size in bytes of the IRP + * StackSize = Number of stack locations in the IRP + */ +{ + assert(Irp != NULL); + + memset(Irp,0,PacketSize); + Irp->StackCount=StackSize; + Irp->CurrentLocation=StackSize; + Irp->Tail.Overlay.CurrentStackLocation=IoGetCurrentIrpStackLocation(Irp); +} + +PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp) +/* + * FUNCTION: Gets a pointer to the callers location in the I/O stack in + * the given IRP + * ARGUMENTS: + * Irp = Points to the IRP + * RETURNS: A pointer to the stack location + */ +{ + DPRINT("IoGetCurrentIrpStackLocation: Irp %08lx CurLoc %d StkCnt %d\n", + Irp, + Irp->CurrentLocation, + Irp->StackCount); + + return &Irp->Stack[Irp->CurrentLocation]; +} + + +VOID IoSetNextIrpStackLocation(PIRP Irp) +{ + Irp->CurrentLocation--; + Irp->Tail.Overlay.CurrentStackLocation--; +} + +PIO_STACK_LOCATION IoGetNextIrpStackLocation(PIRP Irp) +/* + * FUNCTION: Gives a higher level driver access to the next lower driver's + * I/O stack location + * ARGUMENTS: + * Irp = points to the irp + * RETURNS: A pointer to the stack location + */ +{ + DPRINT("IoGetNextIrpStackLocation: Irp %08lx CurLoc %d StkCnt %d\n", + Irp, + Irp->CurrentLocation, + Irp->StackCount); + + assert(Irp!=NULL); + DPRINT("Irp %x Irp->StackPtr %x\n",Irp,Irp->CurrentLocation); + return(&Irp->Stack[Irp->CurrentLocation-1]); +} + +NTSTATUS IoCallDriver(PDEVICE_OBJECT DevObject, PIRP irp) +/* + * FUNCTION: Sends an IRP to the next lower driver + */ +{ + NTSTATUS Status; + PDRIVER_OBJECT drv = DevObject->DriverObject; + IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(irp); + + DPRINT("Deviceobject %x\n",DevObject); + DPRINT("Irp %x\n",irp); + + irp->Tail.Overlay.CurrentStackLocation--; + irp->CurrentLocation--; + + DPRINT("Io stack address %x\n",param); + DPRINT("Function %d Routine %x\n",param->MajorFunction, + drv->MajorFunction[param->MajorFunction]); + + Status = drv->MajorFunction[param->MajorFunction](DevObject,irp); + return Status; +} + +PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota) +/* + * FUNCTION: Allocates an IRP + * ARGUMENTS: + * StackSize = the size of the stack required for the irp + * ChargeQuota = Charge allocation to current threads quota + * RETURNS: Irp allocated + */ +{ + PIRP Irp; + + DPRINT("IoAllocateIrp(StackSize %d ChargeQuota %d)\n", + StackSize, + ChargeQuota); + if (ChargeQuota) + { + Irp = ExAllocatePoolWithQuota(NonPagedPool,IoSizeOfIrp(StackSize)); + } + else + { + Irp = ExAllocatePool(NonPagedPool,IoSizeOfIrp(StackSize)); + } + + if (Irp==NULL) + { + return(NULL); + } + + IoInitializeIrp(Irp, IoSizeOfIrp(StackSize), StackSize); + + DPRINT("Irp %x Irp->StackPtr %d\n", Irp, Irp->CurrentLocation); + + return Irp; +} + +VOID IoSetCompletionRoutine(PIRP Irp, + PIO_COMPLETION_ROUTINE CompletionRoutine, + PVOID Context, + BOOLEAN InvokeOnSuccess, + BOOLEAN InvokeOnError, + BOOLEAN InvokeOnCancel) +{ + IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(Irp); + + param->CompletionRoutine=CompletionRoutine; + param->CompletionContext=Context; + if (InvokeOnSuccess) + { + param->Control = param->Control | SL_INVOKE_ON_SUCCESS; + } + if (InvokeOnError) + { + param->Control = param->Control | SL_INVOKE_ON_ERROR; + } + if (InvokeOnCancel) + { + param->Control = param->Control | SL_INVOKE_ON_CANCEL; + } +} + +VOID IopCompleteRequest(struct _KAPC* Apc, + PKNORMAL_ROUTINE* NormalRoutine, + PVOID* NormalContext, + PVOID* SystemArgument1, + PVOID* SystemArgument2) +{ + IoSecondStageCompletion((PIRP)(*NormalContext), + IO_NO_INCREMENT); +} + +VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost) +/* + * FUNCTION: Indicates the caller has finished all processing for a given + * I/O request and is returning the given IRP to the I/O manager + * ARGUMENTS: + * Irp = Irp to be cancelled + * PriorityBoost = Increment by which to boost the priority of the + * thread making the request + */ +{ + unsigned int i; + NTSTATUS Status; + + DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n", + Irp,PriorityBoost); + + for (i=0;iStackCount;i++) + { + DPRINT("&Irp->Stack[%d].CompletionRoutine %08lx\n", + i, + Irp->Stack[i].CompletionRoutine); + if (Irp->Stack[i].CompletionRoutine != NULL) + { + Status = Irp->Stack[i].CompletionRoutine( + Irp->Stack[i].DeviceObject, + Irp, + Irp->Stack[i].CompletionContext); + if (Status == STATUS_MORE_PROCESSING_REQUIRED) + { + return; + } + } + DPRINT("Irp->Stack[%d].Control %08lx\n", i, Irp->Stack[i].Control); + if (Irp->Stack[i].Control & SL_PENDING_RETURNED) + { + DPRINT("Setting PendingReturned flag\n"); + Irp->PendingReturned = TRUE; + } + } + + if (Irp->PendingReturned) + { + KeInitializeApc(&Irp->Tail.Apc, + &Irp->Tail.Overlay.Thread->Tcb, + 0, + IopCompleteRequest, + NULL, + NULL, + 0, + Irp); + KeInsertQueueApc(&Irp->Tail.Apc,NULL,NULL,0); + } + else + { + IoSecondStageCompletion(Irp,PriorityBoost); + } +} + diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index 133dd3d21d2..bfe7e3537c1 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -72,6 +72,7 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, { return(Status); } + assert(FileObject != NULL); if (ByteOffset==NULL) { diff --git a/reactos/ntoskrnl/ldr/loader.c b/reactos/ntoskrnl/ldr/loader.c index 2376b7b6f0e..6437d7bda36 100644 --- a/reactos/ntoskrnl/ldr/loader.c +++ b/reactos/ntoskrnl/ldr/loader.c @@ -25,7 +25,7 @@ #include -//#define NDEBUG +#define NDEBUG #include /* MACROS ********************************************************************/ @@ -196,7 +196,7 @@ LdrPEProcessDriver(PVOID ModuleLoadBase) PIMAGE_FILE_HEADER PEFileHeader; 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 */ PEDosHeader = (PIMAGE_DOS_HEADER) ModuleLoadBase; @@ -223,18 +223,18 @@ LdrPEProcessDriver(PVOID ModuleLoadBase) /* FIXME: check/verify OS version number */ - DbgPrint("OptionalHdrMagic:%04x LinkVersion:%d.%d\n", - PEOptionalHeader->Magic, - PEOptionalHeader->MajorLinkerVersion, - PEOptionalHeader->MinorLinkerVersion); - DbgPrint("Size: CODE:%08lx(%d) DATA:%08lx(%d) BSS:%08lx(%d)\n", - PEOptionalHeader->SizeOfCode, - PEOptionalHeader->SizeOfCode, - PEOptionalHeader->SizeOfInitializedData, - PEOptionalHeader->SizeOfInitializedData, - PEOptionalHeader->SizeOfUninitializedData, - PEOptionalHeader->SizeOfUninitializedData); - DbgPrint("Entry Point:%08lx\n", PEOptionalHeader->AddressOfEntryPoint); + DPRINT("OptionalHdrMagic:%04x LinkVersion:%d.%d\n", + PEOptionalHeader->Magic, + PEOptionalHeader->MajorLinkerVersion, + PEOptionalHeader->MinorLinkerVersion); + DPRINT("Size: CODE:%08lx(%d) DATA:%08lx(%d) BSS:%08lx(%d)\n", + PEOptionalHeader->SizeOfCode, + PEOptionalHeader->SizeOfCode, + PEOptionalHeader->SizeOfInitializedData, + PEOptionalHeader->SizeOfInitializedData, + PEOptionalHeader->SizeOfUninitializedData, + PEOptionalHeader->SizeOfUninitializedData); + DPRINT("Entry Point:%08lx\n", PEOptionalHeader->AddressOfEntryPoint); CHECKPOINT; /* Determine the size of the module */ @@ -450,8 +450,9 @@ LdrCOFFDoRelocations(module *Module, unsigned int SectionIndex) for (j = 0; j < Section->s_nreloc; j++) { - DbgPrint("vaddr %x ", Relocation->r_vaddr); - DbgPrint("symndex %x ", Relocation->r_symndx); + DPRINT("vaddr %x symndex %x", + Relocation->r_vaddr, + Relocation->r_symndx); switch (Relocation->r_type) { @@ -470,10 +471,10 @@ LdrCOFFDoRelocations(module *Module, unsigned int SectionIndex) break; default: - DbgPrint("%.8s: Unknown relocation type %x at %d in module\n", - Module->scn_list[SectionIndex].s_name, - Relocation->r_type, - j); + DPRINT("%.8s: Unknown relocation type %x at %d in module\n", + Module->scn_list[SectionIndex].s_name, + Relocation->r_type, + j); return FALSE; } Relocation++; @@ -502,7 +503,7 @@ LdrCOFFDoAddr32Reloc(module *Module, SCNHDR *Section, RELOC *Relocation) Value = LdrCOFFGetSymbolValue(Module, Relocation->r_symndx); 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; return TRUE; @@ -596,7 +597,7 @@ LdrCOFFGetSymbolValue(module *Module, unsigned int Idx) char Name[255]; LdrCOFFGetSymbolName(Module, Idx, Name); - DbgPrint("name %s ", Name); + DPRINT("name %s ", Name); /* Check if the symbol is a section we have relocated */ if (strcmp(Name, ".text") == 0) @@ -714,7 +715,7 @@ NTSTATUS LdrLoadLibrary(HANDLE ProcessHandle, } else { - DbgPrint("Library already loaded\n"); + DPRINT("Library already loaded\n"); *Module = Library } RtlFreeUnicodeString(&umodName);