Page 1 of 1
ATA Identify Device
Posted: Mon Apr 30, 2007 10:11 am
by jsaiko
Hi All. Im attempting to write an ATA device driver and im having issues with the Identify Device command. Im just trying to get a sector count of connected drives. I read through the specs and all but it just isnt adding up. I dont have the code in front of me but It stats like bytes 59 and 60 are suppose to give the sector count. When I multiply this number I get by 512... (512 bytes per sector) The result is no where near the correct value of the disk size. Any idea what im doing wrong?
Posted: Mon Apr 30, 2007 2:23 pm
by mystran
What size is the disk, and what values are you getting?
If you are getting too small values for a large disk, there are various limit at various BIOS and such which cause you to get limited sizes.
Disk size with traditional addressing is cylinders*heads*sectors*blocksize, and without having bothered with ATA yet, I can tell that LBA32 or LBA48 addressing won't fit in 2 bytes... so get the cylinders and heads as well, or switch to LBA.
Posted: Mon Apr 30, 2007 4:50 pm
by jsaiko
Ok, Its actually bytes 60 and 61 but the values are too small... Im using a vmware 8gig disk. If it is not typical to get the size of the disk from the sector count using the ECh command please point me in the right direction.
Posted: Tue May 01, 2007 9:11 am
by jsaiko
Ok when I say bytes I actually mean 16bit words
So in theory LBA32 would be able to fit a sector count in 2 words... However this obviously wont work with LBA48.
Posted: Tue May 01, 2007 7:57 pm
by jsaiko
My dumb @$$ figured it out using the cylinders*heads*sectors*blocksize method. I was using 32bit integers and the math got messed up. using a double fixed it.
Posted: Thu May 03, 2007 11:42 am
by grimpy
Do you mean you used the C type 'double' ? You shouldn't do that in a kernel, because you'll screw up the fpu state for user apps.
Posted: Thu May 03, 2007 3:00 pm
by jsaiko
well if I cant use double what would be appropriate? a 32bit integer isnt large enough to hold a byte count.
Posted: Thu May 03, 2007 3:08 pm
by Aali
i know its not standard, but you could use long long, which is guaranteed to be atleast 64 bits
Posted: Fri May 04, 2007 4:59 am
by os64dev
Aali wrote:i know its not standard, but you could use long long, which is guaranteed to be atleast 64 bits
or if you use gcc + extensions use:
Code: Select all
typedef signed int64s __attribute__((mode(DI)));
Guaranteed to be 64 bits
![Wink :wink:](./images/smilies/icon_wink.gif)
Posted: Fri May 04, 2007 9:50 pm
by pcmattman
well if I cant use double what would be appropriate? a 32bit integer isnt large enough to hold a byte count.
It's not a byte count. It's a
sector count. In other words, the 'byte count' is:
Which, in a 512-byte allocation, is a maximum of 2097152 MB, or about 2048 GB, or 2 TB. (correct my maths if it's wrong).
The hardware has no notion of 'bytes per sector', it's giving you the count of sectors on the disk.
Edit: so far, desktop OS's don't have to handle anything more than really 500 GB... Once drive sizes are > 2 TB the whole ATA specification will have to be redone. Can't wait
![Razz :P](./images/smilies/icon_razz.gif)
Posted: Sat May 05, 2007 2:36 am
by Brendan
Hi,
pcmattman wrote:Edit: so far, desktop OS's don't have to handle anything more than really 500 GB... Once drive sizes are > 2 TB the whole ATA specification will have to be redone. Can't wait
![Razz :P](./images/smilies/icon_razz.gif)
Fortunately, you don't need to wait...
The current ATA specification already has support for 48-bit LBA addressing and 48-bit total number of sectors (see "words(103:100)" or the 8 bytes at offset 0xC8 in the "Identify Device" data structure). They won't need to change things until we reach 131072 TiB disks.
Even then the existing "Identify Device" data structure could easily handle a 64-bit total number of sectors, and the existing functions for 48-bit LBA could be extended to 52-bit LBA by defining 4 reserved flags.
Cheers,
Brendan
Posted: Sat May 05, 2007 2:42 am
by pcmattman
The way I use identify device it's 4 bytes for the total sector count (32-bit). Maybe I'm interpreting the specifications wrong.
I probably am, given the fact that my ATA code doesn't work on real PCs.
Posted: Sat May 05, 2007 8:08 am
by frank
Yeah it is 4 bytes for the Total Number of User Addressable sectors. Its location is at words 60 & 61.