📄 ide.h
字号:
///////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright 1995 - 1998 OSR Open Systems Resources, Inc.
// All Rights Reserved
// Based on a previous work by Microsoft Corporation
// Copyright (c) 1991, 1992, 1993 Microsoft Corporation
//
// This sofware is supplied for instructional purposes only.
//
// OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
// for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
// THE IMPLIED WARRANTIES OF MECHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
// WITH YOU. OSR's entire liability and your exclusive remedy shall not
// exceed the price paid for this material. In no event shall OSR or its
// suppliers be liable for any damages whatsoever (including, without
// limitation, damages for loss of business profit, business interruption,
// loss of business information, or any other pecuniary loss) arising out
// of the use or inability to use this software, even if OSR has been
// advised of the possibility of such damages. Because some states/
// jurisdictions do not allow the exclusion or limitation of liability for
// consequential or incidental damages, the above limitation may not apply
// to you.
//
// This driver is the example Programmed I/O device driver that
// accompanies the book Windows NT Device Driver Development, by
// Peter Viscarola and W. Anthony Mason, (c) 1998 OSR Open Systems
// Resources, Inc. and published by MacMillan Technical Publishing
// ISBN 1578700582.
//
// MODULE:
//
// $Workfile: ide.h $
//
// ABSTRACT:
//
// This module handles the
//
// AUTHOR:
//
// Open Systems Resources, Inc.
//
// REVISION:
//
//
//
///////////////////////////////////////////////////////////////////////////////
//
// This module contains the global data structure definitions as well
// as the entry point declarations for ide.c
//
///////////////////////////////////////////////////////////////////////////////
//
//
// If the hardware state gets messed up, we'll retry the current packet.
// This says how many times we'll retry before giving up and returning
// an error. Note that the hardware invisibly retries 8 times.
//
#define MAXIMUM_IRP_RETRY_COUNT 10
//
// Longest transfer supported by this driver
//
#define MAXIMUM_TRANSFER_LENGTH 65536
//
// The CONTROLLER_DATA contains information/state of the controller
//
typedef struct _CONTROLLER_DATA {
PDEVICE_OBJECT DeviceObject;
PUCHAR ControllerAddress; // base addr of controller registers
PUCHAR ControlPortAddress;
BOOLEAN ControllerAddressMapped; // mapped addrs of controllers
BOOLEAN ControllerPortMapped;
CCHAR ResettingController; // >0 while controller is being reset
CCHAR ControlFlags; // OR into CONTROL_PORT
BOOLEAN InterruptRequiresDpc; // ISR need to queue DPC
LONG BusyCountDown; // counter for busy disk
PKINTERRUPT InterruptObject; // only one needed per controller
} CONTROLLER_DATA;
typedef CONTROLLER_DATA *PCONTROLLER_DATA;
// This is the disk extension, which is attached to all partition 0
// device objects (which represent the disk). NOTE THAT THE FIRST FOUR
// FIELDS ARE IDENTICAL TO THOSE OF THE PARTITION DATA, so that the
// same code can access the disk via partition 0 or partition n.
//
typedef struct _IDE_DEV_EXT {
PARTITION_INFORMATION Pi; // Partition info (MUST BE FIRST FIELD).
PVOID Partition0; // Pointer to self (MUST BE SECOND FIELD).
ULONG PartitionOrdinal; // Order partition appears on disk.
// (MUST BE THIRD FIELD)
PDEVICE_OBJECT NextPartition; // Pointer to next parititions object
// MUST BE FOURTH FIELD
PCONTROLLER_DATA ControllerData; // ptr to disk's controller
PDEVICE_OBJECT DeviceObject; // ptr to this disk's object
ULONG DiskNumber; // The index for this disk. This is
// corresponds to the value for the
// harddiskcount in the
// ioconfiguration record.
ULONG FirstSectorOfRequest; // start sector of whole request
// used as the sort key for removing
// requests from the device queue
ULONG FirstSectorOfTransfer; // start sector for current transfer
ULONG RemainingRequestLength; // # of sectors left in current op
ULONG TotalTransferLength; // length of current transfer
ULONG RemainingTransferLength; // length left in current transfer
ULONG SequenceNumber; // Sequence number that is incremented
// on every new irp for this device.
HANDLE DirectoryHandle; // handle to disk's device directory
PCCHAR CurrentAddress; // working address in user's buffer
USHORT BytesPerSector; // disk-specific values
USHORT SectorsPerTrack; // ...
USHORT PretendSectorsPerTrack; // ...
USHORT NumberOfCylinders; // ...
USHORT PretendNumberOfCylinders; // ...
USHORT TracksPerCylinder; // ...
USHORT PretendTracksPerCylinder; // ...
USHORT WritePrecomp; // ...
USHORT BytesPerInterrupt; // ...
CCHAR ByteShiftToSector; // ...
CCHAR ReadCommand; // ...
CCHAR WriteCommand; // ...
CCHAR VerifyCommand; // ...
CCHAR OperationType; // current command (ie IRP_MJ_READ)
UCHAR DeviceUnit; // which disk we are to the controller
CCHAR IrpRetryCount; // count of retries by driver
BOOLEAN PacketIsBeingRetried; // if packet is being retried
} IDE_DEV_EXT, * PIDE_DEV_EXT;
//
// This is the partition extension, which is attached to all partition
// "n" device objects - except for partition 0, which gets a disk
// extension, which has this structure imbeded.
//
// NOTE THIS SHOULD BE EXACTLY THE SAME AS THE FIRST FOUR FIELDS OF THE
// DISK DATA.
//
typedef struct _PARTITION_DATA {
PARTITION_INFORMATION Pi; // Standard partition information structure
PVOID Partition0; // Pointer back to the Pi for the 0
// (whole disk) partition.
ULONG PartitionOrdinal; // Order partition appears on disk.
PDEVICE_OBJECT NextPartition; // ptr to next partition's object
} PARTITION_DATA;
typedef PARTITION_DATA *PPARTITION_DATA;
//
//
// sprintf for some of the modules
//
int
sprintf(
char *s,
const char *format,
...
);
//
// External declaration of routines
//
NTSTATUS
IdeDispatchCreateClose(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
NTSTATUS
IdeDispatchDeviceControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
NTSTATUS
IdeDispatchReadWrite(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
VOID
IdeStartIo(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
BOOLEAN
IdeStartThisRequestOnDevice(
IN PVOID Context
);
BOOLEAN
IdeISR(
IN PKINTERRUPT Interrupt,
IN PVOID Context
);
VOID
IdeDPC(
IN PKDPC Dpc,
IN PVOID DeferredContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -