📄 diskmain.h
字号:
inline void WriteWord(WORD wData) {
ATA_WRITE_WORD((PWORD)(m_pATAReg + m_dwDataDrvCtrlOffset), wData);
}
inline void WriteByteBuffer(PBYTE pBuffer, DWORD dwCount) {
WRITE_PORT_BUFFER_UCHAR(m_pATAReg+m_dwDataDrvCtrlOffset, pBuffer, dwCount);
}
inline void WriteWordBuffer(PWORD pBuffer, DWORD dwCount) {
WRITE_PORT_BUFFER_USHORT((PWORD)(m_pATAReg + m_dwDataDrvCtrlOffset), pBuffer, dwCount);
}
// Read/write Error/Feature register
inline BYTE GetError() {
return (BYTE) ATA_READ_BYTE(m_pATAReg + m_dwFeatureErrorOffset);
}
inline void WriteFeature(BYTE bFeature) {
ATA_WRITE_BYTE( m_pATAReg + m_dwFeatureErrorOffset, bFeature);
}
// Read/write Sector Count register
inline BYTE GetReason() {
return (BYTE) ATA_READ_BYTE(m_pATAReg + m_dwSectCntReasonOffset);
}
inline void WriteSectorCount(BYTE bValue) {
ATA_WRITE_BYTE(m_pATAReg + m_dwSectCntReasonOffset, bValue);
}
// Write Sector Number register
inline void WriteSectorNumber(BYTE bValue) {
ATA_WRITE_BYTE(m_pATAReg + m_dwSectNumOffset, bValue);
}
// Read/write Cylinder Low, Cylinder High register
inline BYTE GetLowCount() {
return ATA_READ_BYTE(m_pATAReg+ m_dwByteCountLowOffset);
}
inline void WriteLowCount(BYTE bValue) {
ATA_WRITE_BYTE(m_pATAReg + m_dwByteCountLowOffset, bValue);
}
inline BYTE GetHighCount() {
return ATA_READ_BYTE(m_pATAReg+ m_dwByteCountHighOffset);
}
inline void WriteHighCount(BYTE bValue) {
ATA_WRITE_BYTE(m_pATAReg + m_dwByteCountHighOffset, bValue);
}
inline WORD GetCount() {
return GetLowCount() + ((WORD)GetHighCount() << 8);
}
// Set DEV bit in Device/Head register
inline void SelectDevice() {
ATA_WRITE_BYTE(m_pATAReg + m_dwDrvHeadOffset, (m_dwDevice == 0 ) ? ATA_HEAD_DRIVE_1 : ATA_HEAD_DRIVE_2);
}
// Write Device/Head register
inline void SetDriveHead(BYTE bDriveHead) {
ATA_WRITE_BYTE(m_pATAReg + m_dwDrvHeadOffset, bDriveHead);
}
inline void WriteDriveHeadReg(BYTE bValue) {
ATA_WRITE_BYTE(m_pATAReg + m_dwDrvHeadOffset, bValue);
}
// Read Status register (does not clear pending interrupt)
inline BYTE GetBaseStatus() {
BYTE bStatus = ATA_READ_BYTE(m_pATAReg + m_dwCommandStatusOffset);
if (ZONE_CELOG) CeLogData(TRUE, CELID_ATAPI_BASESTATUS, &bStatus, sizeof(bStatus), 0, CELZONE_ALWAYSON, 0, FALSE);
return bStatus;
}
// Write Command register
inline void WriteCommand(BYTE bCommand) {
ATA_WRITE_BYTE(m_pATAReg + m_dwCommandStatusOffset, bCommand);
}
// Read/write Alternate Status register (read clears pending interrupt)
inline BYTE GetAltStatus() {
return (BYTE) ATA_READ_BYTE(m_pATARegAlt + m_dwAltStatusOffset);
}
inline void WriteAltDriveController(BYTE bData) {
ATA_WRITE_BYTE(m_pATARegAlt + m_dwAltDrvCtrl, bData);
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// DSK_Init calls this before Init; set up register blocks
virtual VOID ConfigureRegisterBlock(DWORD dwStride);
// Called by DSK_Init
virtual BOOL Init(HKEY hActiveKey);
// Reset controller, enable interrupts, call Identify
virtual BOOL InitController(BOOL fForce = FALSE);
// Return STORAGEDEVICEINFO structure
virtual DWORD GetDeviceInfo(PIOREQ pIOReq);
// Handle standard (diskio.h), non-CD, non-DVD IOCTL-s
virtual DWORD MainIoctl(PIOREQ pIOReq);
// Wait for Status register DRQ bit to assert
virtual BOOL WaitForDRQ();
// Wait for a specified Status register bit to assert/negate
virtual BOOL WaitForDisc(BYTE bStatusType, DWORD dwTimeOut, DWORD dwPeriod = 0);
// DMA I/O
virtual DWORD ReadWriteDiskDMA(PIOREQ pIOReq, BOOL fRead = TRUE);
// Instantiate a CDiskPower object
virtual CDiskPower *GetDiskPowerInterface(void);
// Eventually called in response to an IOCTL_POWER_SET
virtual BOOL SetDiskPowerState(CEDEVICE_POWER_STATE newDx);
// Base wake up function
virtual BOOL WakeUp();
// Acquire this instance's critical section
virtual void TakeCS();
// Release this instance's critical section
virtual void ReleaseCS();
// Called by DSK_Init; this information is used by CDiskPower
void SetActiveKey(TCHAR *szActiveKey);
// Called by DSK_Init; this information is used by CDiskPower
void SetDeviceKey(TCHAR *szDeviceKey);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Wait for interrupt
virtual BOOL WaitForInterrupt(DWORD dwTimeOut) = 0;
// Enable device interrupt
virtual void EnableInterrupt() = 0;
// Setup DMA transfer
virtual BOOL SetupDMA( PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead) = 0;
// Start DMA transfer
virtual BOOL BeginDMA(BOOL fRead) = 0;
// End DMA transfer
virtual BOOL EndDMA() = 0;
// Abort DMA transfer
virtual BOOL AbortDMA() = 0;
// Complete DMA transfer
virtual BOOL CompleteDMA(PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead) = 0;
virtual void SetDeviceTiming(DWORD dwDevice, BYTE dwPioMode, BYTE dwDmaMode, BYTE dwUdmaMode);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Core device/CDisk initialize function
BOOL Identify();
// Determine whether this device is present on the channel
BOOL IsDevicePresent();
// Wait for Status register BSY bit to negate
BYTE WaitOnBusy(BOOL fBase);
// Sleep for @dwTime milliseconds
void StallExecution(DWORD dwTime);
// Return interrupt state?
WORD CheckIntrState();
void AnalyzeDeviceCapabilities (PIDENTIFY_DATA pId, BYTE bTransferMode);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Perform ATA/ATAPI soft-reset
BOOL ResetController(BOOL bSoftReset = FALSE);
// This function sets the transfer mode to @dwMode; For more information
// on transfer mode encodings, see ATA/ATAPI-6 R3B 8.46.11 (Set transfer mode)
BOOL SetTransferMode(BYTE bMode);
// Send EXECUTE DEVICE DIAGNOSTIC command; Determine whether this device is
// an ATA device or an ATAPI device
BOOL SendExecuteDeviceDiagnostic(PBYTE pbDiagnosticCode, PBOOL pfIsAtapi);
// Send IDENTIFY DEVICE/IDENTIFY PACKET DEVICE command
BOOL SendIdentifyDevice(BOOL fIsAtapi);
// Enable write cache through SET FEATURES
BOOL SetWriteCacheMode(BOOL fEnable);
// Enable read look-ahead through SET FEATURES
BOOL SetLookAhead();
// Non-DMA I/O
DWORD ReadWriteDisk(PIOREQ pIOReq, BOOL fRead = TRUE);
// Issue FLUSH CACHE
DWORD FlushCache();
// Send read/write command
BOOL SendIOCommand(DWORD dwStartSector, DWORD dwNumberOfSectors, BYTE bCmd);
// Issue Power Management command and implements the non-data command protocol
BOOL SendDiskPowerCommand(BYTE bCmd, BYTE bParam = 0);
// Issue ATAPI soft-reset
void AtapiSoftReset();
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Increment m_dwOpenCount; references to device
void Open();
// Decrement m_dwOpenCount; references to device
void Close();
// Return DISK_INFO structure
DWORD GetDiskInfo(PIOREQ pIOReq);
// Set ISK_INFO structure
DWORD SetDiskInfo(PIOREQ pIOReq);
// Return mount name, e.g., "Hard Disk"
DWORD GetDiskName(PIOREQ pIOReq);
// Return STORAGE_IDENTIFICATION
DWORD GetStorageId(PIOREQ pIOReq);
// Handle DISK_IOCTL_INITIALIZED
BOOL PostInit(PPOST_INIT_BUF pPostInitBuf);
// Intercept IOCTL_POWER_Xxx-s (and instantiates a CDiskPower object during
// IOCTL_POWER_CAPABILITIES) and forwards all other IOCTL-s to MainIoctl
BOOL PerformIoctl(PIOREQ pIOReq);
// Validate pointers embedded in scatter/gather requests
BOOL static ValidateSg(PSG_REQ pSgReq, DWORD InBufLen);
BOOL static ValidateSg(PCDROM_READ pCdrom, DWORD InBufLen);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Determine if Power Management is supported by examining the IDENTIFY
// DEVICE information
BOOL IsPMSupported(void);
// Determines if Power Management is enabled by examining the IDENTIFY
// DEVICE information
BOOL IsPMEnabled(void);
void PowerUp() { m_dwDeviceFlags &= ~DFLAGS_DEVICE_PWRDN; }
void PowerDown() { m_dwDeviceFlags |= DFLAGS_DEVICE_PWRDN; }
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Return m_fAtapiDevice
BOOL IsAtapiDevice();
// Check the IDENTIFY DEVICE data to see if the device is a CD-ROM device
BOOL IsCDRomDevice();
// Check the IDENTIDY DEVICE data to see if the device is a disk device
BOOL IsDiskDevice();
// Check the IDENTIDY DEVICE data to see if the device is a removable media device
BOOL IsRemoveableDevice();
// Check the IDENTIFY DEVICE data to see if the device supports DMA and
// whether m_fDMAActive is TRUE
BOOL IsDMASupported();
// Check the IDENTIFY DEVICE data to see the packet size supported by the device
WORD GetPacketSize();
// Check the IDENTIFY DEVICE data to see if a portion of it is valid
BOOL IsValidCommandSupportInfo();
// Check the IDENTIFY DEVICE data to see if the device supports the write cache feature
BOOL IsWriteCacheSupported();
// Not used
BOOL IsDRQTypeIRQ();
// Not used
BOOL IsDVDROMDevice();
};
#endif // _DISKMAIN_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -