Scsi_write10 & invalid address for write

vbimport

#1

Hi everyone. Write simply ASPI application


//  MODE  SELECT 10

//         ......
    buf[8]=0x05;
    buf[9]=0x32;
    buf[10]=0x01;
    buf[11]=0x46;
    buf[12]=0x08;
//        .......
    Srex.CDBByte[0]=SCSI_MODE_SEL10;
    Srex.CDBByte[1]=0x10;
    Srex.CDBByte[7]=0x01;
    Srex.CDBByte[8]=0x00;

// Write

BYTE write(BYTE adap, BYTE targ, char *st){
    DWORD Sendcom, size;
    HANDLE hel, hev;
    unsigned char buf[2048];
    long lba=0;                     // first sector
    SRB_ExecSCSICmd Srex;
    hel=CreateFile(st,GENERIC_READ|GENERIC_WRITE,NULL,NULL,OPEN_EXISTING,N  ULL,NULL); 
    if(hel==INVALID_HANDLE_VALUE){cout<<"Handle create fail!!"<<endl;}
    size=GetFileSize(hel,NULL);
    for(DWORD sect=0;sect<size/2048;sect++){
        hev=CreateEvent(NULL,TRUE,FALSE,NUL  L);
        if(!hev){cout<<"Event fail!!!"<<endl;}
        memset(&Srex,0,sizeof(SRB_ExecSCSIC  md));
        memset(&buf,0,2048);
       
        if (!ReadFile(hel,&buf,sizeof(buf),&count,NULL))cout<<"Read fail!!!   "<<GetLastError()<<endl;
        Srex.SRB_Cmd=SC_EXEC_SCSI_CMD;
        Srex.SRB_Flags=SRB_DIR_OUT|SRB_EVEN  T_NOTIFY;
        Srex.SRB_HaId=adap;
        Srex.SRB_Target=targ;
        Srex.SRB_SenseLen=SENSE_LEN;
        Srex.SRB_CDBLen=10;
        Srex.SRB_Lun=0;
        Srex.SRB_BufPointer=buf;
        Srex.SRB_BufLen=2048;
        Srex.SRB_PostProc=(LPVOID)hev;
        Srex.CDBByte[0]=SCSI_WRITE10;
        Srex.CDBByte[1]=0x00;
        Srex.CDBByte[2]=(lba>>24);
        Srex.CDBByte[3]=(lba>>16);
        Srex.CDBByte[4]=(lba>>8);
        Srex.CDBByte[5]=lba; 
        Srex.CDBByte[8]=0x01;
        ResetEvent(hev);
        Sendcom=SendASPI32Command((LPSRB)&S  rex);
        if(Sendcom==SS_PENDING){
            if (WAIT_TIMEOUT!=WaitForSingleObject(hev,INFINITE)){
            CloseHandle(hev);break;}
        }
        if(Sendcom==SS_COMP){CloseHandle(hev);break;}
                 lba++;       //next sector
        if(Gta==SS_ERR && Srex.SRB_TargStat==STATUS_CHKCOND){
            cout<<"Write sense key: "<<(DWORD*)(Srex.SenseArea[2])<<endl;
            cout<<"Write ASC: "<<(DWORD*)Srex.SenseArea[12]<<endl;
            cout<<"Write ASCQ: "<<(DWORD*)Srex.SenseArea[13]<<endl;
            return Srex.SRB_Status;
        }

    }
    return Srex.SRB_Status;

}

The first sector is recorded properly. Next sector 05 21 02 INVALID ADDRESS FOR WRITE

Why? Please help!