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