/**

 * 寫磁碟扇區命令

 * @param sect 物理扇區號

 * @param *buf 資料緩衝區指標

 * @return 0 – 成功

 */

short ufiWriteSect(DWORD sect, BYTE *buf)

{

    WRITE_10 *write10;

    CBW *cbw;

 

    //設定Bulk-Only協議引數

    cbw = &ufiCmdRunning.cbw;

    cbw->dCBW_Signature = CBW_SIGNATURE;

    cbw->dCBW_Tag = 0x60a624de;

    cbw->dCBW_DataXferLen = 512;

    cbw->bCBW_Flag=0x00;

    cbw->bCBW_LUN=0;

    cbw->bCBW_CDBLen = 16;//sizeof(CDB_RBC);

 

    //設定UFI命令引數

    write10 = &(cbw->cdbRBC.ufiWrite10);

    write10->OperationCode = 0x2A;

    write10->LBA_0 = byteInInt(sect, 0);

    write10->LBA_1 = byteInInt(sect, 1);

    write10->LBA_2 = byteInInt(sect, 2);

    write10->LBA_3 = byteInInt(sect, 3);

    write10->XferLen_0 = 0x01;

    write10->XferLen_1 = 0x00;

 

    //設定狀態掃描函式所需要的引數

    ufiCmdRunning.funUfiCmd = bulkWrite;

    ufiCmdRunning.pBuf = buf;

    ufiCmdRunning.state = UFI_STATE_BEGIN;

 

    //通過Bulk埠傳送寫命令

    bulkWrite((unsigned char *)&ufiCmdRunning.cbw, buf, (unsigned char
*)&ufiCmdRunning.
csw);

 

    return 0;

}