0

I am implementing USB as a host to read the files stored in the Flashdrive. To read I implement the read(10) command in SCSI. This command has a field called Logical Block Address, as in the address I want to read. Now, I know the sector number I want to read.

So, is the Logical Block Address and Sector Number the same?

I looked into Cylinder-Head-Sector(CHS) but I dont have information about cylinder or heads

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Anurag
  • 651
  • 4
  • 18
  • Do you mean read means `scsi_read()` right ? – Punit Vara Dec 06 '15 at 06:52
  • I am implementing the code from scratch, I am not using a library. In the SCSI command set the read command is called read(10), with 1 denoting the size of the command. Am guessing scsi_read() is a function call from some API. But am sure they do the same task. So yes if you have some helpful information – Anurag Dec 06 '15 at 07:52
  • http://stackoverflow.com/questions/11867612/scsi-read-10-and-write-10-with-the-scsi-generic-interface and http://www.pcguide.com/ref/hdd/bios/modesLBA-c.html Its seems these links are useful to you – Punit Vara Dec 06 '15 at 08:55
  • [Read](http://www.arsamandish.com/dl/ebook/Linux_eBooks_Collection/Course%20Technology%20Bootstrap%20Yourself%20with%20Linux-USB%20Stack,%20Design%20Develop%20Debug%20and%20Validate%20Embedded%20USB%20(2012).pdf) this book .It is also helpful for usb programming. I am just trying to help you . This might be not related to your question – Punit Vara Dec 06 '15 at 08:59

1 Answers1

1

In common usage in SCSI, a sector is the same as a Logical Block Address. It is very likely that your device has 512-byte sectors (512-byte logical blocks). There are some high-performance SSD's and large-capacity spinning media drives that have 4096-byte sectors. These drives are labelled as having "Advanced Formatting".

CHS addressing isn't supported by SCSI. So, if you somehow have just a sector number, it's probably the SCSI "sector" or logical block address.

All of those integer fields in the typical SCSI commands are in big-endian format. If you're on a typical x86 PC of some kind, your integers will be little-endian format. Before you put your sector number in the field in your READ(10) command, you'll need to convert it with htobe32() or htonl(). Likewise for the num field: (htobe16() or htons()).

Mike Andrews
  • 3,045
  • 18
  • 28
  • Also, from wikipedia (https://en.wikipedia.org/wiki/USB_flash_drive): Sectors are 512 bytes long, for compatibility with hard disk drives... – Mike Andrews Dec 06 '15 at 15:04
  • @gubblehozer I am working on reading a USB flashdrive by implementing USB as a host, using no libraries. And the board I am working on is little endian, I have taken care of the data transmission sequence for SCSI commands, by which I mean the endianess. Yes, my sector size is 512Bytes with 32 sectors in a cluster. Thanks for the clarification on sector being the logical block address. The problem I face right now is that when I read sector ZERO by doing an LBA 0x0000 I get some data which is not present on the flashdrive, i checked the contents of the flashdrive using a software called HXD. – Anurag Dec 11 '15 at 02:52
  • @gubblehozer I get in response the number of bytes that I ask for, and most of it is zeros but it isnt present on searching the flashdrive. Would you know what could be the problem here? Link to what my read(10) looks like- http://i.imgur.com/ky4FHlm.png Link to the response I get for reading it- http://imgur.com/jL6OEjE – Anurag Dec 11 '15 at 03:24
  • I'm not sure what might be going wrong in your case. That CDB looks formatted properly, for a one block read. – Mike Andrews Dec 11 '15 at 23:08
  • is one suppose to execute any other SCSI command before doing read(10) which might make it read right?? I got the image i shared for LBA 0x0000 if I do any other LBA then I get 512bytes of 0x00 back – Anurag Dec 12 '15 at 04:58