507c32411f3f101e90ca2120f042b5ee698ba1d5mlf/*
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * CDDL HEADER START
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf *
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * The contents of this file are subject to the terms of the
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * Common Development and Distribution License (the "License").
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * You may not use this file except in compliance with the License.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf *
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * or http://www.opensolaris.org/os/licensing.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * See the License for the specific language governing permissions
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * and limitations under the License.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf *
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * When distributing Covered Code, include this CDDL HEADER in each
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * If applicable, add the following below this CDDL HEADER, with the
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * fields enclosed by brackets "[]" replaced with your own identifying
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * information: Portions Copyright [yyyy] [name of copyright owner]
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf *
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf * CDDL HEADER END
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf */
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf#
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf# Copyright 1999 Sun Microsystems, Inc. All rights reserved.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf# Use is subject to license terms.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf#
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf#
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf#ident "%Z%%M% %I% %E% SMI"
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf#
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfDan Mick, 2/16/1999
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfI had to come up with some sort of synthetic device geometry in the
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfcase that a drive supports LBA access and therefore the BIOS's geometry
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfmay be wrong or too small.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfIn despair at reading the specs, I asked the x3t13 reflector
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfhow one is supposed to calculate capacity:
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf==
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfX-Authentication-Warning: mage.dt.wdc.com: majordom set sender to owner-t13@dt.wdc.com using -f
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfDate: Thu, 11 Feb 1999 19:16:39 -0800 (PST)
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfFrom: Dan Mick <dan.mick@West>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfSubject: Capacity?
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfTo: t13@dt.wdc.com
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfSo, I'm sure I'm being naive in expecting there to be a way to
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfreliably calculate the capacity of an ATA drive, but I can't make
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfsense of the IDENTIFY DEVICE results, words
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf1,3,6,53,54-58,60-61
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfIs the right algorithm for making sense of all this written down
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfsomewhere? I *have* searched the specs and Hale's HIW docs and
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthe "ATA FAQ" from Wehman and den Hahn, and I still don't understand
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfhow this can be so nondeterministic.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfEven assertions in the specs seem to be ignored; I have a drive for
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfwhich words 57-58 do *not* represent the product of words 54, 55, and
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf56, for instance...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf==
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfSeveral responses came; one from curtis_stevens@phoenix.com said "just
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfuse LBA", which of course doesn't answer the question about non-LBA
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfdrives. David_S_Thompson@notes.seagate.com said "read section
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf6.2.1 of ATA-4, rev 17 or above", which does help a bit. But
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthe best pragmatic answer came from Hale Landis. I've tried to
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfimplement this algorithm in deriving the capacity and geometry
507c32411f3f101e90ca2120f042b5ee698ba1d5mlffor ata, without using "Init Drive Parameters", since the driver
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfhasn't done that in recent incarnations, and I'm loath to mess
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfwith what the BIOS and the drive have figured out unless it
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfbecomes absolutely necessary.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfFrom: "Hale Landis" <hlandis@ibm.net>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfTo: "T13 Reflector" <t13@dt.wdc.com>, "Dan Mick" <dan.mick@West>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfDate: Thu, 11 Feb 1999 23:46:59 -0700
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfSubject: Re: Capacity?
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfDan Mick said...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>So, I'm sure I'm being naive in expecting there to be a way to
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>reliably calculate the capacity of an ATA drive, but I can't make
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>sense of the IDENTIFY DEVICE results, words
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>1,3,6,53,54-58,60-61
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>Is the right algorithm for making sense of all this written down
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>somewhere? I *have* searched the specs and Hale's HIW docs and
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>the "ATA FAQ" from Wehman and den Hahn, and I still don't understand
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>how this can be so nondeterministic.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>Even assertions in the specs seem to be ignored; I have a drive for
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>which words 57-58 do *not* represent the product of words 54, 55, and
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf>56, for instance...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfIf the words [54]*[55]*[56] don't match [57:58] then the drive is
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf"broken". Warning: some older drives have words 57:58 in big endian
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfformat (that is easy to verify!).
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfOf course Read/Set Max do alter the drive's apparent capacity but assuming
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthis feature is not being used or it is being used and implemented
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfcorrectly...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfIf you have no need to use CHS mode, then just ignore words 1, 3, 6 and
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf53:58. Words 60:61 are the drive capacity. But even if you must use CHS
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfmode, words 60:61 are still the true drive capacity but words 57:58 are
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthe capacity that the current CHS geometry can address and [57:58] must be
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf<= [60:61]. Oh yea, if you find that 57:58 are big endian then 60:61 are
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfprobably big endian too.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfAn algorithm??? (I hope there aren't any typo's here)...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf1) If you are LBA only (don't use CHS) then words 60:61 are all you need,
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfyou are done.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf2) If you must use CHS then I suggest the following:
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf2a) Check words 53:58...
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf does 53 indicate "valid",
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf is 1 <= [55] <= 16,
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf is 1 <= [56] <= 63,
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf and does [54]*[55]*[56] == [57:58]?
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf - Yes, you know that current CHS geometry of the drive, you are done.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf If you don't like this geometry then issue an Init Drv Params with
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf a different heads and sectors and repeat this step.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf - No, then go to 2b).
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf2b) Does the drive support LBA and is [1]*[3]*[6] <= [60:61]?
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf - Yes, assume 60:61 are correct, and go to 2c)
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf - No, go to 2d)
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf2c) Issue a Init Drv Params and set your favorite heads and sectors.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf Compute the number of cylinders:
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf num-cyl = [60:61] / (favorite heads) * (favorite sectors)
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf The drive capacity is (num-cyl)*(favorite heads)*(favorite sectors).
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf And this value should be in 57:58 now. You are done.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf2d) Now you got a problem... 60:61 are no good, 53:58 are no good.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf You don't have much choice but to assume that [1]*[3]*[6] is the
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf drive capacity. Issue an Init Drv Params to set the default geometry
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf from [3] and [6] -or- issue an Init Drv Params with your favorite
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf heads and sectors. Compute the number of cylinders:
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf num-cyl = ([1]*[3]*[6]) / (num heads) * (num sectors)
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf The drive capacity is (num-cyl)*(num-head)*(num-sectors).
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf You are done.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfAnd one final thing... If you used Init Drv Params you must now verify
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthat it worked. Issue a read command and make sure you can read what you
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthink is the last sector on the drive. If this read fails with ABRT or
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfIDNF, you are in *BIG* trouble.
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfAll we did here was find a CHS geometry and a drive capacity that should
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfwork. If the drive has a Master Boot Record then this geometry may not
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfhave a CHS translation that matches the CHS translation that was used in
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfthat Master Boot Record. But I'll not go into that here (I would probably
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfhave to say bad things about the documents published by some of my friends
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfa few years ago!).
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfI'll say "sorry" now to all you hardware folks that read these reflector
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfmessages but I'm sure this will begin a long series of messages on the
507c32411f3f101e90ca2120f042b5ee698ba1d5mlfreflector that will just bore you to near death!
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf+---------------+---------------------------+
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf| Hale Landis | hlandis@ibm.net |
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf| Niwot, CO USA | hlandis@sugs.talisman.com |
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf+---------------+---------------------------+
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf| !! Coming soon: www.talisman.com/sugs !! |
507c32411f3f101e90ca2120f042b5ee698ba1d5mlf+-------------------------------------------+