?? mass.c
字號:
}
if((SenseData.ASC==0x28)&&(SenseData.ASCQ==0x00))
{/* NOT READY TO READY TRANSITION-MEDIA CHANGED */
}
}
}
else
return NULL;
}
else
return hMedLUNPtr; /* 正常退出 */
}
}
return NULL;
}
//********************************************************************************
//函數名稱:Creat_Medium
//輸入參數:hMedLUNPtr,邏輯單元描述符指針
// LUNIndex,邏輯單元索引,0為第1個邏輯單元
//輸出參數:無
//功能描述:關閉邏輯單元
//********************************************************************************
void Close_Medium(hMedLUN *hMedLUNPtr,unsigned char LUNIndex)
{
if(hMedLUNPtr==NULL)
return;
if(hMedLUNPtr->MSC ==NULL) /* 檢驗類描述結構指針*/
return ;
if(hMedLUNPtr->MSC->LUN < LUNIndex) /* 檢驗邏輯單元索引 */
return ;
hMedLUNPtr->MSC->LUN_infor_ptr[LUNIndex]->LastLogicalBlookAddress =0;
hMedLUNPtr->MSC->LUN_infor_ptr[LUNIndex]->BlockLengthInBytes=0;
}
//******************************************************************************************
// 函數名稱:CommandBlockHandle
// 輸入參數:tr_with_rbc_ptr,傳輸控制描述信息數據結構指針
// 輸出參數:COMMAND_PASSED,命令完成
// COMMAND_FAILED,命令失敗
// PHASE_ERROR,相位出錯
// PERSISTENT_FAILURE,嚴重出錯
// 功能描述:大容量命令塊處理,包括Bulk_Only和CBI-Only兩個協議。
//******************************************************************************************
uint8 CommandBlockHandle(TR_With_RBC *tr_with_rbc_ptr)
{
uint8 Statue;
/* 單批量傳輸協議*/
if( 0x50 == tr_with_rbc_ptr->MSC->ProtocolCode)
{
Statue = BulkOnlyComHandle( tr_with_rbc_ptr);
}
else
/* CBI傳輸協議 */
{
Statue = CBIOnlyComHandle( tr_with_rbc_ptr);
}
return Statue;
}
//******************************************************************************************
//函數名稱:GetThisInquiryData
//輸入參數:hMedLUNPtr,邏輯單元描述符指針
// DataBuff_ptr,查詢數據存放的結構指針
//輸出參數:COMMAND_PASSED,命令完成
// COMMAND_FAILED,命令失敗
// PHASE_ERROR,相位出錯
// PERSISTENT_FAILURE,嚴重出錯
//功能描述:查詢媒介信息,如廠商信息、產品信息及產品版本號。
//******************************************************************************************
unsigned char GetThisInquiryData(hMedLUN * hMedLUNPtr )
{
TR_With_RBC tr_with_rbc;
unsigned char InquiryDataBuf[36];
unsigned char Status;
if(hMedLUNPtr->MSC==NULL)
return PERSISTENT_FAILURE;
MCom_INQUIRY(hMedLUNPtr->MSC->RBC_BuffPtr); // 命令設置
tr_with_rbc.MSC = hMedLUNPtr->MSC;
tr_with_rbc.LUN = hMedLUNPtr->LUN;
tr_with_rbc.CBLength = (hMedLUNPtr->MSC->ProtocolCode==0x50)? 6:12;
tr_with_rbc.DataTransferLength = 36;
tr_with_rbc.Data_BuffPtr = InquiryDataBuf;
tr_with_rbc.RBC_BuffPtr = hMedLUNPtr->MSC->RBC_BuffPtr;
tr_with_rbc.TrDirection = IN_DATA;
Status = CommandBlockHandle( &tr_with_rbc );
if( Status == COMMAND_PASSED)
{
memcpy(hMedLUNPtr->VendorInfo, &InquiryDataBuf[8], 8);
memcpy(hMedLUNPtr->ProductInfo, &InquiryDataBuf[16], 16);
memcpy(hMedLUNPtr->ProductRev, &InquiryDataBuf[32], 4);
}
else
{ memset(hMedLUNPtr->VendorInfo,0,8) ;
memset(hMedLUNPtr->ProductInfo,0,8) ;
memset(hMedLUNPtr->ProductRev,0,8) ;
}
return Status;
}
//*****************************************************************************
//功能描述:GetThisMediumCapacity
//輸入參數:hMedLUNPtr
//輸出參數:COMMAND_PASSED,命令完成
// COMMAND_FAILED,命令失敗
// PHASE_ERROR,相位出錯
// PERSISTENT_FAILURE,嚴重出錯
//功能描述:獲取媒介的容量,塊字節數及最后塊地址.
//****************************************************************************
unsigned char GetThisMediumCapacity(hMedLUN * hMedLUNPtr )
{
TR_With_RBC tr_with_rbc;
unsigned char CapacityDataBuf[8];
unsigned char Status;
if(hMedLUNPtr->MSC==NULL)
return PERSISTENT_FAILURE;
MCom_ReadCapacity(hMedLUNPtr->MSC->RBC_BuffPtr);
tr_with_rbc.MSC = hMedLUNPtr->MSC;
tr_with_rbc.LUN = hMedLUNPtr->LUN;
tr_with_rbc.CBLength = (hMedLUNPtr->MSC->ProtocolCode==0x50)? 10:12; /* 命令長度 */
tr_with_rbc.DataTransferLength = 0x08; /* 傳輸數據長度為8字節 */
tr_with_rbc.Data_BuffPtr = CapacityDataBuf;
tr_with_rbc.RBC_BuffPtr = hMedLUNPtr->MSC->RBC_BuffPtr;
tr_with_rbc.TrDirection = IN_DATA;
Status = CommandBlockHandle( &tr_with_rbc );
if( Status == COMMAND_PASSED)
{
hMedLUNPtr->BlockLengthInBytes // 媒介塊長度(字節數)
= CapacityDataBuf[7] +
CapacityDataBuf[6]*0x100 +
CapacityDataBuf[5]*0x10000+
CapacityDataBuf[4]*0x1000000;
hMedLUNPtr->LastLogicalBlookAddress // 媒介最后塊地址
= CapacityDataBuf[3] +
CapacityDataBuf[2]*0x100 +
CapacityDataBuf[1]*0x10000+
CapacityDataBuf[0]*0x1000000;
}
else
{
hMedLUNPtr->BlockLengthInBytes = 0;
hMedLUNPtr->LastLogicalBlookAddress =0;
}
return Status;
}
//*****************************************************************************
//功能描述:GetRequestSense
//輸入參數:hMedLUNPtr,邏輯單元描述數據結構指針
// SenseDataPtr,判別代碼數據結構批針,保存返回數據
//輸出參數:COMMAND_PASSED,命令完成
// COMMAND_FAILED,命令失敗
// PHASE_ERROR,相位出錯
// PERSISTENT_FAILURE,嚴重出錯
//功能描述:獲取媒介的容量,塊字節數及最后塊地址.
//****************************************************************************
unsigned char GetRequestSense(hMedLUN * hMedLUNPtr, SENSE_DATA *SenseDataPtr)
{
TR_With_RBC tr_with_rbc;
unsigned char SenseDataBuf[18];
unsigned char Status;
if(hMedLUNPtr->MSC==NULL)
return PERSISTENT_FAILURE;
MCom_RequestSense(hMedLUNPtr->MSC->RBC_BuffPtr);
tr_with_rbc.MSC = hMedLUNPtr->MSC;
tr_with_rbc.LUN = hMedLUNPtr->LUN;
tr_with_rbc.CBLength = (hMedLUNPtr->MSC->ProtocolCode==0x50)? 0x0c:12; /* 命令長度 */
tr_with_rbc.DataTransferLength = 0x12; /* 傳輸數據長度為8字節 */
tr_with_rbc.Data_BuffPtr = SenseDataBuf;
tr_with_rbc.RBC_BuffPtr = hMedLUNPtr->MSC->RBC_BuffPtr;
tr_with_rbc.TrDirection = IN_DATA;
Status = CommandBlockHandle( &tr_with_rbc );
if( Status == COMMAND_PASSED)
{
SenseDataPtr->SenseKey = SenseDataBuf[2]&0x0f;
SenseDataPtr->ASC = SenseDataBuf[12];
SenseDataPtr->ASCQ = SenseDataBuf[13];
}
return Status;
}
//****************************************************************************
//函數名稱:ReadBlockData
//輸入參數:MediumPtr,操作媒體句柄
// BufferPtr,存緩數據緩沖區指針
// LBA,邏輯塊地址
// TrBLength,邏輯塊數目(1~0xffff)。
//輸出參數:實際讀入的字節數,設備不存在或未準備好返回0.
//功能描述:讀邏輯單元塊數據。
//***************************************************************************
unsigned short ReadBlockData(hMedLUN *MediumPtr,
unsigned char *BufferPtr,
unsigned int LBA,
unsigned short TrBLength)
{
TR_With_RBC tr_with_rbc;
unsigned char Status;
SENSE_DATA SenseData;
if(MediumPtr->MSC==NULL)
return 0;
if( (MediumPtr->BlockLengthInBytes==0x00)||
(MediumPtr->LastLogicalBlookAddress == 0x00) )
return (0);
MCom_Read10(MediumPtr->MSC->RBC_BuffPtr, LBA, TrBLength);
tr_with_rbc.MSC = MediumPtr->MSC;
tr_with_rbc.LUN = MediumPtr->LUN;
tr_with_rbc.CBLength = (MediumPtr->MSC->ProtocolCode==0x50)? 0x0A:12; /* 命令長度 */
tr_with_rbc.DataTransferLength = TrBLength * MediumPtr->BlockLengthInBytes; /* 傳輸數據長度為8字節 */
tr_with_rbc.Data_BuffPtr = BufferPtr;
tr_with_rbc.RBC_BuffPtr = MediumPtr->MSC->RBC_BuffPtr;
tr_with_rbc.TrDirection = IN_DATA;
Status = CommandBlockHandle( &tr_with_rbc );
if( Status == COMMAND_PASSED)
{
return tr_with_rbc.DataTransferLength; // 返回傳輸的數據長度(字節)
}
else
{
if(GetRequestSense(MediumPtr, &SenseData))
return NULL;
else
{ /* 這里分析出錯原因 */
if((SenseData.ASC==0x3a)&&(SenseData.ASCQ==0x00))
{/* MEDIUM NOT PRESENT */
MediumPtr->BlockLengthInBytes = NULL;
MediumPtr->LastLogicalBlookAddress = NULL;
}
}
}
return (0); // 出錯返回0
}
//****************************************************************************
//函數名稱:WriteBlockData
//輸入參數:MediumPtr,操作媒體句柄
// BufferPtr,存緩數據緩沖區指針
// LBA,邏輯塊地址
// TrBLength,邏輯塊數目(1~0xffff)。
//輸出參數:實際讀入的字節數,設備不存在或未準備好返回NULL.
//功能描述:寫邏輯單元塊數據。
//***************************************************************************
unsigned short WriteBlockData(hMedLUN *MediumPtr,
unsigned char *BufferPtr,
unsigned int LBA,
unsigned short TrBLength)
{
TR_With_RBC tr_with_rbc;
unsigned char Status;
SENSE_DATA SenseData;
if(MediumPtr->MSC==NULL)
return (0);
if( (MediumPtr->BlockLengthInBytes==0x00)||
(MediumPtr->LastLogicalBlookAddress == 0x00) )
return (0);
MCom_Write10(MediumPtr->MSC->RBC_BuffPtr, LBA, TrBLength);
tr_with_rbc.MSC = MediumPtr->MSC;
tr_with_rbc.LUN = MediumPtr->LUN;
tr_with_rbc.CBLength = (MediumPtr->MSC->ProtocolCode==0x50)? 0x0A:12; /* 命令長度 */
tr_with_rbc.DataTransferLength = TrBLength * MediumPtr->BlockLengthInBytes; /* 傳輸數據長度為8字節 */
tr_with_rbc.Data_BuffPtr = BufferPtr;
tr_with_rbc.RBC_BuffPtr = MediumPtr->MSC->RBC_BuffPtr;
tr_with_rbc.TrDirection = OUT_DATA;
Status = CommandBlockHandle( &tr_with_rbc );
if( Status == COMMAND_PASSED)
{
return tr_with_rbc.DataTransferLength; // 返回傳輸的數據長度(字節)
}
else
{
if(GetRequestSense(MediumPtr, &SenseData))
return NULL;
else
{ /* 這里分析出錯原因 */
if((SenseData.ASC==0x3a)&&(SenseData.ASCQ==0x00))
{/* MEDIUM NOT PRESENT */
MediumPtr->BlockLengthInBytes = NULL;
MediumPtr->LastLogicalBlookAddress = NULL;
}
}
}
return (0); // 出錯返回0
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -