?? diskmain.cpp
字號(hào):
}
else if(newDx == D3 || newDx == D4) {
bCmd = ATA_CMD_SLEEP;
}
else {
DEBUGMSG(ZONE_WARNING, (_T(
"CDisk::SetDiskPowerState> Invalid power state value(%u)\r\n"
), newDx));
return FALSE;
}
// update the disk power state
return SendDiskPowerCommand(bCmd);
}
// ----------------------------------------------------------------------------
// Function: WakeUp
// Wake the device up from sleep
//
// Parameters:
// None
// ----------------------------------------------------------------------------
BOOL
CDisk::WakeUp(
)
{
if (!ResetController(FALSE)) {
return FALSE;
}
return SendIdentifyDevice(IsAtapiDevice());
}
// ----------------------------------------------------------------------------
// Function: MainIoctl
// Process IOCTL_DISK_ and DISK_IOCTL_ I/O controls
//
// Parameters:
// pIOReq -
// ----------------------------------------------------------------------------
DWORD
CDisk::MainIoctl(
PIOREQ pIOReq
)
{
DWORD dwError = ERROR_SUCCESS;
DEBUGMSG(ZONE_IOCTL, (TEXT(
"Atapi!CDisk::MainIoctl> IOCTL(%x), device(%x)\r\n"
), pIOReq->dwCode, m_dwDeviceId));
// device is powering down; fail
if (m_dwDeviceFlags & DFLAGS_DEVICE_PWRDN) {
SetLastError(ERROR_DEVICE_NOT_AVAILABLE);
return FALSE;
}
switch(pIOReq->dwCode) {
case IOCTL_DISK_GETINFO:
case DISK_IOCTL_GETINFO:
if (IsCDRomDevice()) {
dwError = ERROR_BAD_COMMAND;
}
else {
dwError = GetDiskInfo(pIOReq);
}
break;
case IOCTL_DISK_DEVICE_INFO:
dwError = GetDeviceInfo(pIOReq);
break;
case DISK_IOCTL_GETNAME:
case IOCTL_DISK_GETNAME:
dwError = GetDiskName(pIOReq);
break;
case DISK_IOCTL_SETINFO:
case IOCTL_DISK_SETINFO:
dwError = SetDiskInfo(pIOReq);
break;
case DISK_IOCTL_READ:
case IOCTL_DISK_READ:
if (!ValidateSg((PSG_REQ)pIOReq->pInBuf,pIOReq->dwInBufSize)) {
dwError = ERROR_INVALID_PARAMETER;
}
else {
if (IsDMASupported()) {
dwError = ReadWriteDiskDMA(pIOReq, TRUE);
}
else {
dwError = ReadWriteDisk(pIOReq, TRUE);
}
}
break;
case DISK_IOCTL_WRITE:
case IOCTL_DISK_WRITE:
if (!ValidateSg((PSG_REQ)pIOReq->pInBuf,pIOReq->dwInBufSize)) {
dwError=ERROR_INVALID_PARAMETER;
}
else {
if (IsDMASupported()) {
dwError = ReadWriteDiskDMA(pIOReq, FALSE);
}
else {
dwError = ReadWriteDisk(pIOReq, FALSE);
}
}
break;
case IOCTL_DISK_GET_STORAGEID:
dwError = GetStorageId(pIOReq);
break;
case DISK_IOCTL_FORMAT_MEDIA:
case IOCTL_DISK_FORMAT_MEDIA:
dwError = ERROR_SUCCESS;
break;;
case IOCTL_DISK_FLUSH_CACHE:
dwError = FlushCache();
break;
default:
dwError = ERROR_NOT_SUPPORTED;
break;
}
return dwError;
}
// ----------------------------------------------------------------------------
// Function: PerformIoctl
// This is the top-most IOCTL processor and is used to trap IOCTL_POWER_
// I/O controls to pass to the associated power management object
//
// Parameters:
// pIOReq -
// ----------------------------------------------------------------------------
BOOL
CDisk::PerformIoctl(
PIOREQ pIOReq
)
{
DWORD dwError = ERROR_SUCCESS;
DEBUGMSG(ZONE_IOCTL, (TEXT(
"Atapi!CDisk::PerformIoctl> IOCTL(%x), device(%x)\r\n"
), pIOReq->dwCode, m_dwDeviceId));
if (pIOReq->pBytesReturned) {
*(pIOReq->pBytesReturned) = 0;
}
TakeCS();
m_pPort->TakeCS();
if (ZONE_CELOG) CeLogData(TRUE, CELID_ATAPI_STARTIOCTL, pIOReq, sizeof(*pIOReq), 0, CELZONE_ALWAYSON, 0, FALSE);
__try {
if (pIOReq->dwCode == IOCTL_POWER_CAPABILITIES) {
// instantiate DiskPower object on first use, if necessary
if (m_pDiskPower == NULL) {
CDiskPower *pDiskPower = GetDiskPowerInterface();
if (pDiskPower == NULL) {
DEBUGMSG(ZONE_WARNING, (_T(
"Atapi!CDisk::PerformIoctl> Failed to create power management object\r\n"
)));
}
else if (!pDiskPower->Init(this)) {
DEBUGMSG(ZONE_WARNING, (_T(
"Atapi!CDisk::PerformIoctl> Failed to initialize power management\r\n"
)));
delete pDiskPower;
}
else {
m_pDiskPower = pDiskPower;
}
}
}
if (m_pDiskPower != NULL) {
// is this a power IOCTL?
dwError = m_pDiskPower->DiskPowerIoctl(pIOReq);
if (dwError != ERROR_NOT_SUPPORTED) {
goto done;
}
// request that the disk spin up (if it's not up already)
if (!m_pDiskPower->RequestDevice()) {
// the disk is powered down
dwError = ERROR_RESOURCE_DISABLED;
goto done;
}
}
// call the driver
dwError = MainIoctl(pIOReq);
// indicate we're done with the disk
if (m_pDiskPower != NULL) {
m_pDiskPower->ReleaseDevice();
}
done:;
} __except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_GEN_FAILURE;
}
if (ZONE_CELOG) CeLogData(TRUE, CELID_ATAPI_COMPLETEIOCTL, &dwError, sizeof(dwError), 0, CELZONE_ALWAYSON, 0, FALSE);
m_pPort->ReleaseCS();
ReleaseCS();
if (dwError != ERROR_SUCCESS) {
SetLastError(dwError);
}
return (ERROR_SUCCESS == dwError);
}
// ----------------------------------------------------------------------------
// Function: PostInit
// This function facilitates backward compatibility
//
// Parameters:
// pPostInitBuf -
// ----------------------------------------------------------------------------
BOOL
CDisk::PostInit(
PPOST_INIT_BUF pPostInitBuf
)
{
DWORD dwError = ERROR_SUCCESS;
DEBUGMSG(ZONEID_INIT, (TEXT("Atapi!CDisk::PostInit> device(%d)\r\n"), m_dwDeviceId));
m_hDevice = pPostInitBuf->p_hDevice;
return (dwError == ERROR_SUCCESS);
}
// ----------------------------------------------------------------------------
// Function: GetDiskInfo
// Implement IOCTL_DISK_GETINFO
//
// Parameters:
// pIOReq -
// ----------------------------------------------------------------------------
DWORD
CDisk::GetDiskInfo(
PIOREQ pIOReq
)
{
DWORD dwError = ERROR_SUCCESS;
DISK_INFO *pInfo = NULL;
// for B/C, this call has three forms; only pInBuf, only pOutBuf, or both
// if both, then use pOutBuf
if (pIOReq->pInBuf) {
if (pIOReq->dwInBufSize != sizeof(DISK_INFO)) {
return ERROR_INVALID_PARAMETER;
}
pInfo = (DISK_INFO *)pIOReq->pInBuf;
}
if (pIOReq->pOutBuf) {
if (pIOReq->dwOutBufSize!= sizeof(DISK_INFO)) {
return ERROR_INVALID_PARAMETER;
}
pInfo = (DISK_INFO *)pIOReq->pOutBuf;
}
if (!pInfo) {
DEBUGMSG(ZONE_ERROR|ZONE_IOCTL, (_T(
"Atapi!CDisk::GetDiskInfo> bad argument; pInBuf/pOutBuf null\r\n")));
return ERROR_INVALID_PARAMETER;
}
// TODO: if device is ATAPI, call AtapiGetDiskInfo
if (ERROR_SUCCESS == dwError) {
__try {
memcpy(pInfo, &m_DiskInfo, sizeof(DISK_INFO));
pInfo->di_flags |= DISK_INFO_FLAG_PAGEABLE;
pInfo->di_flags &= ~DISK_INFO_FLAG_UNFORMATTED;
if (pIOReq->pBytesReturned){
*(pIOReq->pBytesReturned) = sizeof(DISK_INFO);
}
} __except(EXCEPTION_EXECUTE_HANDLER) {
dwError = ERROR_INVALID_PARAMETER;
}
}
return dwError;
}
// ----------------------------------------------------------------------------
// Function: SetDiskInfo
// Implement IOCTL_DISK_SETINFO
//
// Parameters:
// pSgReq -
// InBufLen -
// ----------------------------------------------------------------------------
DWORD
CDisk::SetDiskInfo(
PIOREQ pIOReq
)
{
DWORD dwError = ERROR_SUCCESS;
DISK_INFO *pInfo = (DISK_INFO *)pIOReq->pInBuf;
if ((pIOReq->pInBuf == NULL) || (pIOReq->dwInBufSize != sizeof(DISK_INFO))) {
return ERROR_INVALID_PARAMETER;
}
memcpy(&m_DiskInfo, pInfo, sizeof(DISK_INFO));
return dwError;
}
// ----------------------------------------------------------------------------
// Function: GetDeviceInfo
// IOCTL_DISK_DEVICE_INFO
//
// Parameters:
// pIOReq -
// ----------------------------------------------------------------------------
DWORD
CDisk::GetDeviceInfo(
PIOREQ pIOReq
)
{
PSTORAGEDEVICEINFO psdi = (PSTORAGEDEVICEINFO)pIOReq->pInBuf;
HKEY hKey;
if ((pIOReq->dwInBufSize == 0) || (pIOReq->pInBuf == NULL)) {
return ERROR_INVALID_PARAMETER;
}
if (pIOReq->pBytesReturned) {
*(pIOReq->pBytesReturned) = sizeof(STORAGEDEVICEINFO);
}
psdi->dwDeviceClass = 0;
psdi->dwDeviceType = 0;
psdi->dwDeviceFlags = 0;
PTSTR szProfile = psdi->szProfile;
wcscpy(szProfile, L"Default");
if (ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE, m_szDeviceKey, 0, 0, &hKey)) {
hKey = NULL;
}
if (IsAtapiDevice() && IsCDRomDevice()) {
psdi->dwDeviceClass = STORAGE_DEVICE_CLASS_MULTIMEDIA;
psdi->dwDeviceType |= STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA;
psdi->dwDeviceType |= STORAGE_DEVICE_TYPE_ATAPI;
psdi->dwDeviceType |= STORAGE_DEVICE_TYPE_PCIIDE;
psdi->dwDeviceFlags |= STORAGE_DEVICE_FLAG_MEDIASENSE;
psdi->dwDeviceFlags |= STORAGE_DEVICE_FLAG_READONLY;
if (!hKey || !AtaGetRegistryString(hKey, REG_VALUE_CDPROFILE, &szProfile, sizeof(psdi->szProfile))) {
wcscpy(psdi->szProfile, REG_VALUE_CDPROFILE);
}
}
else {
psdi->dwDeviceClass = STORAGE_DEVICE_CLASS_BLOCK;
psdi->dwDeviceType |= STORAGE_DEVICE_TYPE_PCIIDE;
psdi->dwDeviceType |= STORAGE_DEVICE_TYPE_ATA;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -