1*1709Smlf/* 2*1709Smlf * CDDL HEADER START 3*1709Smlf * 4*1709Smlf * The contents of this file are subject to the terms of the 5*1709Smlf * Common Development and Distribution License (the "License"). 6*1709Smlf * You may not use this file except in compliance with the License. 7*1709Smlf * 8*1709Smlf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1709Smlf * or http://www.opensolaris.org/os/licensing. 10*1709Smlf * See the License for the specific language governing permissions 11*1709Smlf * and limitations under the License. 12*1709Smlf * 13*1709Smlf * When distributing Covered Code, include this CDDL HEADER in each 14*1709Smlf * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1709Smlf * If applicable, add the following below this CDDL HEADER, with the 16*1709Smlf * fields enclosed by brackets "[]" replaced with your own identifying 17*1709Smlf * information: Portions Copyright [yyyy] [name of copyright owner] 18*1709Smlf * 19*1709Smlf * CDDL HEADER END 20*1709Smlf */ 21*1709Smlf 22*1709Smlf# 23*1709Smlf# Copyright 1999 Sun Microsystems, Inc. All rights reserved. 24*1709Smlf# Use is subject to license terms. 25*1709Smlf# 26*1709Smlf 27*1709Smlf# 28*1709Smlf#ident "%Z%%M% %I% %E% SMI" 29*1709Smlf# 30*1709Smlf 31*1709SmlfDan Mick, 2/16/1999 32*1709Smlf 33*1709SmlfI had to come up with some sort of synthetic device geometry in the 34*1709Smlfcase that a drive supports LBA access and therefore the BIOS's geometry 35*1709Smlfmay be wrong or too small. 36*1709Smlf 37*1709SmlfIn despair at reading the specs, I asked the x3t13 reflector 38*1709Smlfhow one is supposed to calculate capacity: 39*1709Smlf 40*1709Smlf== 41*1709SmlfX-Authentication-Warning: mage.dt.wdc.com: majordom set sender to owner-t13@dt.wdc.com using -f 42*1709SmlfDate: Thu, 11 Feb 1999 19:16:39 -0800 (PST) 43*1709SmlfFrom: Dan Mick <dan.mick@West> 44*1709SmlfSubject: Capacity? 45*1709SmlfTo: t13@dt.wdc.com 46*1709Smlf 47*1709SmlfSo, I'm sure I'm being naive in expecting there to be a way to 48*1709Smlfreliably calculate the capacity of an ATA drive, but I can't make 49*1709Smlfsense of the IDENTIFY DEVICE results, words 50*1709Smlf 51*1709Smlf1,3,6,53,54-58,60-61 52*1709Smlf 53*1709SmlfIs the right algorithm for making sense of all this written down 54*1709Smlfsomewhere? I *have* searched the specs and Hale's HIW docs and 55*1709Smlfthe "ATA FAQ" from Wehman and den Hahn, and I still don't understand 56*1709Smlfhow this can be so nondeterministic. 57*1709Smlf 58*1709SmlfEven assertions in the specs seem to be ignored; I have a drive for 59*1709Smlfwhich words 57-58 do *not* represent the product of words 54, 55, and 60*1709Smlf56, for instance... 61*1709Smlf== 62*1709Smlf 63*1709SmlfSeveral responses came; one from curtis_stevens@phoenix.com said "just 64*1709Smlfuse LBA", which of course doesn't answer the question about non-LBA 65*1709Smlfdrives. David_S_Thompson@notes.seagate.com said "read section 66*1709Smlf6.2.1 of ATA-4, rev 17 or above", which does help a bit. But 67*1709Smlfthe best pragmatic answer came from Hale Landis. I've tried to 68*1709Smlfimplement this algorithm in deriving the capacity and geometry 69*1709Smlffor ata, without using "Init Drive Parameters", since the driver 70*1709Smlfhasn't done that in recent incarnations, and I'm loath to mess 71*1709Smlfwith what the BIOS and the drive have figured out unless it 72*1709Smlfbecomes absolutely necessary. 73*1709Smlf 74*1709Smlf 75*1709SmlfFrom: "Hale Landis" <hlandis@ibm.net> 76*1709SmlfTo: "T13 Reflector" <t13@dt.wdc.com>, "Dan Mick" <dan.mick@West> 77*1709SmlfDate: Thu, 11 Feb 1999 23:46:59 -0700 78*1709SmlfSubject: Re: Capacity? 79*1709Smlf 80*1709SmlfDan Mick said... 81*1709Smlf>So, I'm sure I'm being naive in expecting there to be a way to 82*1709Smlf>reliably calculate the capacity of an ATA drive, but I can't make 83*1709Smlf>sense of the IDENTIFY DEVICE results, words 84*1709Smlf> 85*1709Smlf>1,3,6,53,54-58,60-61 86*1709Smlf> 87*1709Smlf>Is the right algorithm for making sense of all this written down 88*1709Smlf>somewhere? I *have* searched the specs and Hale's HIW docs and 89*1709Smlf>the "ATA FAQ" from Wehman and den Hahn, and I still don't understand 90*1709Smlf>how this can be so nondeterministic. 91*1709Smlf> 92*1709Smlf>Even assertions in the specs seem to be ignored; I have a drive for 93*1709Smlf>which words 57-58 do *not* represent the product of words 54, 55, and 94*1709Smlf>56, for instance... 95*1709Smlf 96*1709SmlfIf the words [54]*[55]*[56] don't match [57:58] then the drive is 97*1709Smlf"broken". Warning: some older drives have words 57:58 in big endian 98*1709Smlfformat (that is easy to verify!). 99*1709Smlf 100*1709SmlfOf course Read/Set Max do alter the drive's apparent capacity but assuming 101*1709Smlfthis feature is not being used or it is being used and implemented 102*1709Smlfcorrectly... 103*1709Smlf 104*1709SmlfIf you have no need to use CHS mode, then just ignore words 1, 3, 6 and 105*1709Smlf53:58. Words 60:61 are the drive capacity. But even if you must use CHS 106*1709Smlfmode, words 60:61 are still the true drive capacity but words 57:58 are 107*1709Smlfthe capacity that the current CHS geometry can address and [57:58] must be 108*1709Smlf<= [60:61]. Oh yea, if you find that 57:58 are big endian then 60:61 are 109*1709Smlfprobably big endian too. 110*1709Smlf 111*1709SmlfAn algorithm??? (I hope there aren't any typo's here)... 112*1709Smlf 113*1709Smlf1) If you are LBA only (don't use CHS) then words 60:61 are all you need, 114*1709Smlfyou are done. 115*1709Smlf 116*1709Smlf2) If you must use CHS then I suggest the following: 117*1709Smlf 118*1709Smlf2a) Check words 53:58... 119*1709Smlf does 53 indicate "valid", 120*1709Smlf is 1 <= [55] <= 16, 121*1709Smlf is 1 <= [56] <= 63, 122*1709Smlf and does [54]*[55]*[56] == [57:58]? 123*1709Smlf 124*1709Smlf - Yes, you know that current CHS geometry of the drive, you are done. 125*1709Smlf If you don't like this geometry then issue an Init Drv Params with 126*1709Smlf a different heads and sectors and repeat this step. 127*1709Smlf 128*1709Smlf - No, then go to 2b). 129*1709Smlf 130*1709Smlf2b) Does the drive support LBA and is [1]*[3]*[6] <= [60:61]? 131*1709Smlf 132*1709Smlf - Yes, assume 60:61 are correct, and go to 2c) 133*1709Smlf 134*1709Smlf - No, go to 2d) 135*1709Smlf 136*1709Smlf2c) Issue a Init Drv Params and set your favorite heads and sectors. 137*1709Smlf Compute the number of cylinders: 138*1709Smlf 139*1709Smlf num-cyl = [60:61] / (favorite heads) * (favorite sectors) 140*1709Smlf 141*1709Smlf The drive capacity is (num-cyl)*(favorite heads)*(favorite sectors). 142*1709Smlf And this value should be in 57:58 now. You are done. 143*1709Smlf 144*1709Smlf2d) Now you got a problem... 60:61 are no good, 53:58 are no good. 145*1709Smlf You don't have much choice but to assume that [1]*[3]*[6] is the 146*1709Smlf drive capacity. Issue an Init Drv Params to set the default geometry 147*1709Smlf from [3] and [6] -or- issue an Init Drv Params with your favorite 148*1709Smlf heads and sectors. Compute the number of cylinders: 149*1709Smlf 150*1709Smlf num-cyl = ([1]*[3]*[6]) / (num heads) * (num sectors) 151*1709Smlf 152*1709Smlf The drive capacity is (num-cyl)*(num-head)*(num-sectors). 153*1709Smlf 154*1709Smlf You are done. 155*1709Smlf 156*1709SmlfAnd one final thing... If you used Init Drv Params you must now verify 157*1709Smlfthat it worked. Issue a read command and make sure you can read what you 158*1709Smlfthink is the last sector on the drive. If this read fails with ABRT or 159*1709SmlfIDNF, you are in *BIG* trouble. 160*1709Smlf 161*1709SmlfAll we did here was find a CHS geometry and a drive capacity that should 162*1709Smlfwork. If the drive has a Master Boot Record then this geometry may not 163*1709Smlfhave a CHS translation that matches the CHS translation that was used in 164*1709Smlfthat Master Boot Record. But I'll not go into that here (I would probably 165*1709Smlfhave to say bad things about the documents published by some of my friends 166*1709Smlfa few years ago!). 167*1709Smlf 168*1709SmlfI'll say "sorry" now to all you hardware folks that read these reflector 169*1709Smlfmessages but I'm sure this will begin a long series of messages on the 170*1709Smlfreflector that will just bore you to near death! 171*1709Smlf 172*1709Smlf 173*1709Smlf+---------------+---------------------------+ 174*1709Smlf| Hale Landis | hlandis@ibm.net | 175*1709Smlf| Niwot, CO USA | hlandis@sugs.talisman.com | 176*1709Smlf+---------------+---------------------------+ 177*1709Smlf| !! Coming soon: www.talisman.com/sugs !! | 178*1709Smlf+-------------------------------------------+ 179