IDEMA capacity adjustment
RFC 1/1 IDEMA capacity adjustment
IDEMA, the International Disk Drive Equipment and Materials Association, publishes a specification that defines how to translate from LBA count to "marketing" gigabytes used to label drives.
This patch updates the size calculations in sd.c so that the base 10 size is adjusted according to the IDEMA spec.
---
drivers/scsi/sd.c +31 -1
@@ -1416,6 +1416,34 @@ static int read_capacity_10(struct scsi_return sector_size; } +u64 sd_idema_capacity (u64 lba_count,unsigned int sector_size) +{ +/* This looks like black magic but these numbers are mandated in +* the IDEMA LBA specification that drive manufacturers use to +* indicate drive capacity. As of revision 1.3 these sizes are +* also mandatory for SCSI-class drives. +*/ +u64 capacity; +unsigned int idema_sub =97696368 ; +unsigned int idema_div =1953504 ; +unsigned int scale = sector_size; + +do_div (scale,512 ); +do_div (idema_sub, scale); +do_div (idema_div, scale); + +/* The adjustments only work for drives > 50GB */ +if (lba_count <= idema_sub) +return lba_count <<ilog2 (sector_size); + + capacity = lba_count - idema_sub; +do_div (capacity, idema_div); + capacity +=50 ; + capacity *=1000 *1000 *1000 ; + +return capacity; +} +/* * read disk capacity */
@@ -1505,10 +1533,12 @@ got_data: {char cap_str_2[10 ], cap_str_10[10 ];u64 sz = (u64 )sdkp->capacity <<ilog2 (sector_size); +u64 idema_sz =sd_idema_capacity ((u64 )sdkp->capacity, + sector_size);string_get_size (sz,STRING_UNITS_2 , cap_str_2,sizeof (cap_str_2)); -string_get_size (sz,STRING_UNITS_10 , cap_str_10, +string_get_size (idema_sz,STRING_UNITS_10 , cap_str_10,sizeof (cap_str_10)); sd_printk(KERN_NOTICE, sdkp,
James Bottomley
maintainerQuoted 6 lines · Martin K. Petersen
IDEMA, the International Disk Drive Equipment and Materials Association, publishes a specification that defines how to translate from LBA count to "marketing" gigabytes used to label drives.
This patch updates the size calculations in
sd.cso that the base 10 size is adjusted according to the IDEMA spec.
We already show the power of 10 size as GiB ... how does the IDEMA spec actually differ from that? It's one thing to display the truth in a more positive light (as in use power of 10 GiB etc.) it's quite another to display incorrect sizes ... is the IDEMA spec just optimistic but not unreasonable rounding, or is it actually inflating sizes wrongly?
James
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"James" == James Bottomley <[email protected]> writes:
James> We already show the power of 10 size as GiB ... how does the James> IDEMA spec actually differ from that?
The intent was for the capacity printed to be exactly the same number as on the drive label.
James> It's one thing to display the truth in a more positive light (as James> in use power of 10 GiB etc.) it's quite another to display James> incorrect sizes ... is the IDEMA spec just optimistic but not James> unreasonable rounding, or is it actually inflating sizes wrongly?
It's slightly deflating the capacity compared to power of 10. For new drives that adhere to the IDEMA spec it's about 0.02%. For older drives with "proprietary" LBA counts the difference is bigger.
I tested the patch on a few SCSI drives before sending it out. They went from being printed as 73.4 GB to 73GB.
However, I just collected data from a bunch of recent drives and there it doesn't make a difference at all thanks to your rounding in string_get_size().
So maybe just drop this for now. The code was initially done for a different project. I applied it to sd.c because I could and it made a difference in my initial test case.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering