1

There is a need to write into each LBA on the disk using SCSI CDB. Here i have constructed a while/for loop for writing into each LBA. I am using 10 byte CDB .

How do i represent 32 bit LBA so that it iterates from LBA 0 to Maximun LBA . What should be the data Tranfer lenght if i am planning to write on each LBA . Each LBA size 512 bytes.

for(i=0;i<=max_lba;i++)
{
    ccb->cam_flags = DATA_OUT;
    ccb->cdb[0] = 0x2A;     /*  0x2A SCSI Opcode for write 10  CDB */
    ccb->cdb[1] = 0;
    ccb->cdb[2] = ?? ( LBA )
    ccb->cdb[3] = ?? ( LBA )
    ccb->cdb[4] = ?? ( LBA )       
    ccb->cdb[5] = ?? ( LBA )
    ccb->cdb[6] = 0;
    ccb->cdb[7] = ??      /* Data Transfer Length */
    ccb->cdb[8] = ??      /* Data Transfer Length */ 
    ccb->cdb[9] = 0;

    ccb->ccb_address = (long)ccb;
    ptr_data = (byte *)(buffer  + ccb->data_buf_ptr);

    data_pattern = i + (i << 4);
    buffer[ccb->data_buf_ptr ] = data_pattern;
}
Andrew Falanga
  • 2,274
  • 4
  • 26
  • 51
arun
  • 41
  • 1
  • 6

1 Answers1

0

Assign the lba similar to this (but note that it will be really slow if you are going to write all of a large drive ... so it would be better if you write a large number of blocks, perhaps 1MB then adjust the next LBA accordingly).

cdb[2] = (i & 0xFF000000) >> 24;
cdb[3] = (i &   0xFF0000) >> 16;
cdb[4] = (i &     0xFF00) >> 8;
cdb[5] = (i &       0xFF);

For the above, set the number of blocks to 1: cdb[7] = 0; cdb[8] = 1;

Again, you will be waiting all day for a large drive so make the changes to write a large number of blocks in each iteration of the loop.

eddyq
  • 879
  • 1
  • 13
  • 25
  • Hmm, looking again I don't see where you did the write in each iteration. Don't forget to do that. – eddyq Aug 26 '13 at 15:48
  • ccb->cam_flags = DATA_OUT; ccb->cdb[0] = 0x2A; ccb->cdb[1] = 0; ccb->cdb[2] = (i & 0xFF000000) >> 24; ccb->cdb[3] = (i & 0xFF0000) >> 16; ccb->cdb[4] = (i & 0xFF00) >> 8; ccb->cdb[5] = (i & 0xFF); ccb->cdb[6] = 0; ccb->cdb[7] = 0; /* Data Transfer Length */ ccb->cdb[8] = 1; /* Data Transfer Length of 1 block */ ccb->cdb[9] = 0; ccb->ccb_address = (long)ccb; ptr_data = (byte *)(buffer + ccb->data_buf_ptr); data_pattern = i + (i << 4); buffer[ccb->data_buf_ptr ] = data_pattern; – arun Aug 27 '13 at 06:44
  • Many thanks for the help . Can I contact you directly for SCSI CDB related queries ? I will really appreciate if you can share your Email id. – arun Aug 27 '13 at 09:44