Lots of code clean-up; correctly copies files of any size to/from disk;

clean under prefast, lint, verifier, and checked win2k

svn path=/trunk/; revision=8657
This commit is contained in:
Vizzini 2004-03-11 23:12:03 +00:00
parent 304ff0ba96
commit abc17a4830
6 changed files with 92 additions and 62 deletions

View file

@ -56,29 +56,30 @@ KSEMAPHORE QueueSemaphore;
*/
VOID NTAPI CsqRemoveIrp(PIO_CSQ Csq,
VOID NTAPI CsqRemoveIrp(PIO_CSQ UnusedCsq,
PIRP Irp)
/*
* FUNCTION: Remove an IRP from the queue
* ARGUMENTS:
* Csq: Pointer to CSQ context structure
* UnusedCsq: Pointer to CSQ context structure
* Irp: Pointer to the IRP to remove from the queue
* NOTES:
* - Called under the protection of the queue lock
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
KdPrint(("CSQ: Removing IRP 0x%x\n", Irp));
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
}
PIRP NTAPI CsqPeekNextIrp(PIO_CSQ Csq,
PIRP NTAPI CsqPeekNextIrp(PIO_CSQ UnusedCsq,
PIRP Irp,
PVOID PeekContext)
/*
* FUNCTION: Remove the next IRP from the queue
* ARGUMENTS:
* Csq: Pointer to CSQ context structure
* UnusedCsq: Pointer to CSQ context structure
* Irp: Pointer to a starting IRP in the queue (i.e. start search here)
* PeekContext: Unused
* RETURNS:
@ -88,6 +89,8 @@ PIRP NTAPI CsqPeekNextIrp(PIO_CSQ Csq,
* - Called under the protection of the queue lock
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
UNREFERENCED_PARAMETER(PeekContext);
KdPrint(("CSQ: Peeking for next IRP\n"));
if(Irp)
@ -100,46 +103,49 @@ PIRP NTAPI CsqPeekNextIrp(PIO_CSQ Csq,
}
VOID NTAPI CsqAcquireLock(PIO_CSQ Csq,
VOID NTAPI CsqAcquireLock(PIO_CSQ UnusedCsq,
PKIRQL Irql)
/*
* FUNCTION: Acquire the queue lock
* ARGUMENTS:
* Csq: Pointer to CSQ context structure
* UnusedCsq: Pointer to CSQ context structure
* Irql: Pointer to a variable to store the old irql into
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
KdPrint(("CSQ: Acquiring spin lock\n"));
KeAcquireSpinLock(&IrpQueueLock, Irql);
}
VOID NTAPI CsqReleaseLock(PIO_CSQ Csq,
VOID NTAPI CsqReleaseLock(PIO_CSQ UnusedCsq,
KIRQL Irql)
/*
* FUNCTION: Release the queue lock
* ARGUMENTS:
* Csq: Pointer to CSQ context structure
* UnusedCsq: Pointer to CSQ context structure
* Irql: IRQL to lower to on release
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
KdPrint(("CSQ: Releasing spin lock\n"));
KeReleaseSpinLock(&IrpQueueLock, Irql);
}
VOID NTAPI CsqCompleteCanceledIrp(PIO_CSQ Csq,
VOID NTAPI CsqCompleteCanceledIrp(PIO_CSQ UnusedCsq,
PIRP Irp)
/*
* FUNCTION: Complete a canceled IRP
* ARGUMENTS:
* Csq: Pointer to CSQ context structure
* UnusedCsq: Pointer to CSQ context structure
* Irp: IRP to complete
* NOTES:
* - Perhaps we should complete with something besides NO_INCREMENT
* - MS misspelled CANCELLED... sigh...
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
KdPrint(("CSQ: Canceling irp 0x%x\n", Irp));
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;
@ -147,12 +153,12 @@ VOID NTAPI CsqCompleteCanceledIrp(PIO_CSQ Csq,
}
VOID NTAPI CsqInsertIrp(PIO_CSQ Csq,
VOID NTAPI CsqInsertIrp(PIO_CSQ UnusedCsq,
PIRP Irp)
/*
* FUNCTION: Queue an IRP
* ARGUMENTS:
* Csq: Unused
* UnusedCsq: Unused
* Irp: IRP to add to the queue
* NOTES:
* - Called under the protection of the queue lock
@ -164,6 +170,7 @@ VOID NTAPI CsqInsertIrp(PIO_CSQ Csq,
* that at least one IRP is canceled at some point
*/
{
UNREFERENCED_PARAMETER(UnusedCsq);
KdPrint(("CSQ: Inserting IRP 0x%x\n", Irp));
InsertTailList(&IrpQueue, &Irp->Tail.Overlay.ListEntry);
KeReleaseSemaphore(&QueueSemaphore, 0, 1, FALSE);

View file

@ -64,25 +64,22 @@
* will probably have only one, with four being a very unlikely maximum, a static
* global array is easiest to deal with.
*/
CONTROLLER_INFO gControllerInfo[MAX_CONTROLLERS];
ULONG gNumberOfControllers = 0;
static CONTROLLER_INFO gControllerInfo[MAX_CONTROLLERS];
static ULONG gNumberOfControllers = 0;
/* Queue thread management */
KEVENT QueueThreadTerminate;
PVOID ThreadObject;
/* ISR DPC */
KDPC Dpc;
static KEVENT QueueThreadTerminate;
static PVOID ThreadObject;
static VOID NTAPI MotorStopDpcFunc(PKDPC Dpc,
static VOID NTAPI MotorStopDpcFunc(PKDPC UnusedDpc,
PVOID DeferredContext,
PVOID SystemArgument1,
PVOID SystemArgument2)
/*
* FUNCTION: Stop the floppy motor
* ARGUMENTS:
* Dpc: DPC object that's going off
* UnusedDpc: DPC object that's going off
* DeferredContext: called with DRIVE_INFO for drive to turn off
* SystemArgument1: unused
* SystemArgument2: unused
@ -93,6 +90,10 @@ static VOID NTAPI MotorStopDpcFunc(PKDPC Dpc,
{
PCONTROLLER_INFO ControllerInfo = (PCONTROLLER_INFO)DeferredContext;
UNREFERENCED_PARAMETER(SystemArgument1);
UNREFERENCED_PARAMETER(SystemArgument2);
UNREFERENCED_PARAMETER(UnusedDpc);
ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
ASSERT(ControllerInfo);
@ -133,7 +134,8 @@ VOID NTAPI StartMotor(PDRIVE_INFO DriveInfo)
DriveInfo->ControllerInfo->StopDpcQueued = FALSE;
}
HwTurnOnMotor(DriveInfo);
if(HwTurnOnMotor(DriveInfo) != STATUS_SUCCESS)
KdPrint(("floppy: StartMotor(): warning: HwTurnOnMotor failed\n"));
}
@ -203,6 +205,8 @@ static NTSTATUS NTAPI CreateClose(PDEVICE_OBJECT DeviceObject,
* TODO: Figure out why this isn't getting called any more, and remove the ASSERT once that happens
*/
{
UNREFERENCED_PARAMETER(DeviceObject);
KdPrint(("floppy: CreateClose called\n"));
Irp->IoStatus.Status = STATUS_SUCCESS;
@ -239,7 +243,11 @@ static NTSTATUS NTAPI Recalibrate(PDRIVE_INFO DriveInfo)
/* set the data rate */
KdPrint(("floppy: FIXME: UN-HARDCODE DATA RATE\n"));
HwSetDataRate(DriveInfo->ControllerInfo, 0);
if(HwSetDataRate(DriveInfo->ControllerInfo, 0) != STATUS_SUCCESS)
{
KdPrint(("floppy: Recalibrate: HwSetDataRate failed\n"));
return STATUS_UNSUCCESSFUL;
}
/* clear the event just in case the last call forgot */
KeClearEvent(&DriveInfo->ControllerInfo->SynchEvent);
@ -313,7 +321,11 @@ NTSTATUS NTAPI ResetChangeFlag(PDRIVE_INFO DriveInfo)
WaitForControllerInterrupt(DriveInfo->ControllerInfo);
HwSenseInterruptStatus(DriveInfo->ControllerInfo);
if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS)
{
KdPrint(("floppy: ResetChangeFlag(): HwSenseInterruptStatus failed; bailing out\n"));
return STATUS_IO_DEVICE_ERROR;
}
/* Seek back to 0 */
if(HwSeek(DriveInfo, 1) != STATUS_SUCCESS)
@ -324,7 +336,11 @@ NTSTATUS NTAPI ResetChangeFlag(PDRIVE_INFO DriveInfo)
WaitForControllerInterrupt(DriveInfo->ControllerInfo);
HwSenseInterruptStatus(DriveInfo->ControllerInfo);
if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS)
{
KdPrint(("floppy: ResetChangeFlag(): HwSenseInterruptStatus #2 failed; bailing\n"));
return STATUS_IO_DEVICE_ERROR;
}
/* Check the change bit */
if(HwDiskChanged(DriveInfo, &DiskChanged) != STATUS_SUCCESS)
@ -354,6 +370,7 @@ static VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
ULONG i,j;
PAGED_CODE();
UNREFERENCED_PARAMETER(DriverObject);
KdPrint(("floppy: unloading\n"));
@ -380,7 +397,8 @@ static VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
/* Power down the controller */
HwPowerOff(&gControllerInfo[i]);
if(HwPowerOff(&gControllerInfo[i]) != STATUS_SUCCESS)
KdPrint(("floppy: unload: warning: HwPowerOff failed\n"));
}
}
@ -440,6 +458,13 @@ static NTSTATUS NTAPI ConfigCallback(PVOID Context,
UCHAR i;
PAGED_CODE();
UNREFERENCED_PARAMETER(PeripheralType);
UNREFERENCED_PARAMETER(PeripheralNumber);
UNREFERENCED_PARAMETER(BusInformation);
UNREFERENCED_PARAMETER(Context);
UNREFERENCED_PARAMETER(ControllerType);
UNREFERENCED_PARAMETER(PathName);
KdPrint(("floppy: ConfigCallback called with ControllerNumber %d\n", ControllerNumber));
@ -471,12 +496,19 @@ static NTSTATUS NTAPI ConfigCallback(PVOID Context,
ULONG AddressSpace = 0x1; /* I/O Port Range */
if(!HalTranslateBusAddress(BusType, BusNumber, PartialDescriptor->u.Port.Start, &AddressSpace, &TranslatedAddress))
ASSERT(0);
{
KdPrint(("floppy: HalTranslateBusAddress failed; returning\n"));
return STATUS_IO_DEVICE_ERROR;
}
if(AddressSpace == 0)
gControllerInfo[gNumberOfControllers].BaseAddress = MmMapIoSpace(TranslatedAddress, 8, FALSE); // symbolic constant?
{
gControllerInfo[gNumberOfControllers].BaseAddress = MmMapIoSpace(TranslatedAddress, 8, MmNonCached); // symbolic constant?
}
else
gControllerInfo[gNumberOfControllers].BaseAddress = (PUCHAR)TranslatedAddress.u.LowPart;
{
gControllerInfo[gNumberOfControllers].BaseAddress = (PUCHAR)TranslatedAddress.u.LowPart;
}
}
else if(PartialDescriptor->Type == CmResourceTypeDma)
@ -558,6 +590,8 @@ static BOOLEAN NTAPI Isr(PKINTERRUPT Interrupt,
{
PCONTROLLER_INFO ControllerInfo = (PCONTROLLER_INFO)ServiceContext;
UNREFERENCED_PARAMETER(Interrupt);
ASSERT(ControllerInfo);
KdPrint(("floppy: ISR called\n"));
@ -575,14 +609,14 @@ static BOOLEAN NTAPI Isr(PKINTERRUPT Interrupt,
}
VOID NTAPI DpcForIsr(PKDPC Dpc,
VOID NTAPI DpcForIsr(PKDPC UnusedDpc,
PVOID Context,
PVOID SystemArgument1,
PVOID SystemArgument2)
/*
* FUNCTION: This DPC gets queued by every ISR. Does the real per-interrupt work.
* ARGUMENTS:
* Dpc: Pointer to the DPC object that represents our function
* UnusedDpc: Pointer to the DPC object that represents our function
* DeviceObject: Device that this DPC is running for
* Irp: Unused
* Context: Pointer to our ControllerInfo struct
@ -598,6 +632,10 @@ VOID NTAPI DpcForIsr(PKDPC Dpc,
{
PCONTROLLER_INFO ControllerInfo = (PCONTROLLER_INFO)Context;
UNREFERENCED_PARAMETER(UnusedDpc);
UNREFERENCED_PARAMETER(SystemArgument1);
UNREFERENCED_PARAMETER(SystemArgument2);
ASSERT(ControllerInfo);
KdPrint(("floppy: DpcForIsr called\n"));
@ -868,7 +906,7 @@ static BOOLEAN NTAPI AddControllers(PDRIVER_OBJECT DriverObject)
* 14: 3,2
* 15: 3,3
*/
DriveNumber = i*4 + j;
DriveNumber = (UCHAR)(i*4 + j); /* loss of precision is OK; there are only 16 of 'em */
swprintf(DeviceNameBuf, L"\\Device\\Floppy%d", DriveNumber);
RtlInitUnicodeString(&DeviceName, DeviceNameBuf);
@ -962,7 +1000,7 @@ VOID NTAPI SignalMediaChanged(PDEVICE_OBJECT DeviceObject,
}
VOID NTAPI QueueThread(PVOID Context)
static VOID NTAPI QueueThread(PVOID Context)
/*
* FUNCTION: Thread that manages the queue and dispatches any queued requests
* ARGUMENTS:
@ -975,6 +1013,7 @@ VOID NTAPI QueueThread(PVOID Context)
PVOID Objects[2];
PAGED_CODE();
UNREFERENCED_PARAMETER(Context);
Objects[0] = &QueueSemaphore;
Objects[1] = &QueueThreadTerminate;
@ -1043,6 +1082,8 @@ NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject,
{
HANDLE ThreadHandle;
UNREFERENCED_PARAMETER(RegistryPath);
/*
* Set up dispatch routines
*/

View file

@ -55,6 +55,10 @@ int _cdecl swprintf(const WCHAR *, ...);
#define PAGED_CODE() {ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);}
#endif
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(x) { (x) = (x); }
#endif
struct _CONTROLLER_INFO;
typedef struct _DRIVE_INFO
@ -101,13 +105,6 @@ typedef struct _CONTROLLER_INFO
BOOLEAN StopDpcQueued;
} CONTROLLER_INFO, *PCONTROLLER_INFO;
NTSTATUS NTAPI ReadWrite(PDEVICE_OBJECT DeviceObject,
PIRP Irp);
VOID NTAPI QueueThread(PVOID Context);
extern KEVENT QueueThreadTerminate;
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath);

View file

@ -846,7 +846,7 @@ NTSTATUS NTAPI HwGetVersion(PCONTROLLER_INFO ControllerInfo)
if(Send_Byte(ControllerInfo, COMMAND_VERSION) != STATUS_SUCCESS)
{
KdPrint(("floppy: HwGetVersion: unable to write fifo\n"));
return STATUS_UNSUCCESSFUL;;
return STATUS_UNSUCCESSFUL;
}
if(Get_Byte(ControllerInfo, &Buffer) != STATUS_SUCCESS)
@ -1108,6 +1108,8 @@ VOID NTAPI HwDumpRegisters(PCONTROLLER_INFO ControllerInfo)
* ControllerInfo: Controller to dump registers from
*/
{
UNREFERENCED_PARAMETER(ControllerInfo);
KdPrint(("floppy: STATUS: "));
KdPrint(("STATUS_REGISTER_A = 0x%x ", READ_PORT_UCHAR(ControllerInfo->BaseAddress + STATUS_REGISTER_A)));
KdPrint(("STATUS_REGISTER_B = 0x%x ", READ_PORT_UCHAR(ControllerInfo->BaseAddress + STATUS_REGISTER_B)));

View file

@ -324,8 +324,6 @@ NTSTATUS NTAPI HwReadIdResult(PCONTROLLER_INFO ControllerInfo,
NTSTATUS NTAPI HwSetDataRate(PCONTROLLER_INFO ControllerInfo,
UCHAR DataRate);
NTSTATUS NTAPI HwRecalibrateResult(PCONTROLLER_INFO ControllerInfo);
NTSTATUS NTAPI HwReset(PCONTROLLER_INFO Controller);
NTSTATUS NTAPI HwPowerOff(PCONTROLLER_INFO ControllerInfo);

View file

@ -77,6 +77,8 @@ static IO_ALLOCATION_ACTION NTAPI MapRegisterCallback(PDEVICE_OBJECT DeviceObjec
*/
{
PCONTROLLER_INFO ControllerInfo = (PCONTROLLER_INFO)Context;
UNREFERENCED_PARAMETER(DeviceObject);
UNREFERENCED_PARAMETER(Irp);
KdPrint(("floppy: MapRegisterCallback Called\n"));
@ -104,14 +106,11 @@ NTSTATUS NTAPI ReadWrite(PDEVICE_OBJECT DeviceObject,
* it onto the irp queue
*/
{
PIO_STACK_LOCATION Stack;
KdPrint(("floppy: ReadWrite called\n"));
ASSERT(DeviceObject);
ASSERT(Irp);
Stack = IoGetCurrentIrpStackLocation(Irp);
if(!Irp->MdlAddress)
{
KdPrint(("floppy: ReadWrite(): MDL not found in IRP - Completing with STATUS_INVALID_PARAMETER\n"));
@ -502,26 +501,12 @@ VOID NTAPI ReadWritePassive(PDRIVE_INFO DriveInfo,
/* Set up parameters for read or write */
if(Stack->MajorFunction == IRP_MJ_READ)
{
/*
if(Stack->Parameters.Read.Length > PAGE_SIZE * DriveInfo->ControllerInfo->MapRegisters)
{
KdPrint(("floppy: ReadWritePassive(): unable to transfer; would have to split\n"));
ASSERT(0);
}
*/
Length = Stack->Parameters.Read.Length;
DiskByteOffset = Stack->Parameters.Read.ByteOffset.u.LowPart;
WriteToDevice = FALSE;
}
else
{
/*
if(Stack->Parameters.Write.Length > PAGE_SIZE * DriveInfo->ControllerInfo->MapRegisters)
{
KdPrint(("floppy: ReadWritePassive(): unable to transfer; would have to split\n"));
ASSERT(0);
}
*/
Length = Stack->Parameters.Write.Length;
DiskByteOffset = Stack->Parameters.Write.ByteOffset.u.LowPart;
WriteToDevice = TRUE;
@ -660,10 +645,10 @@ VOID NTAPI ReadWritePassive(PDRIVE_INFO DriveInfo,
KdPrint(("floppy: ReadWritePassive(): computing number of sectors to transfer (StartSector 0x%x): ", StartSector));
/* 1-based sector number */
if( (DriveInfo->DiskGeometry.SectorsPerTrack - StartSector + 1) <
if( ((DriveInfo->DiskGeometry.SectorsPerTrack - StartSector) + 1) <
(Length - TransferByteOffset) / DriveInfo->DiskGeometry.BytesPerSector)
{
CurrentTransferSectors = (UCHAR)DriveInfo->DiskGeometry.SectorsPerTrack - StartSector + 1;
CurrentTransferSectors = (UCHAR)(DriveInfo->DiskGeometry.SectorsPerTrack - StartSector) + 1;
}
else
{