Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>CHS refers to cylinders, heads and sectors from the days when disks literally did access data that way - choosing a cylinder, head and sector to read.</p> <p>LBA is a newish scheme which basically addresses the disk as a continually increasing number of blocks.</p> <p>The conversion scheme essentially gets you from one to the other. Firstly, the equation gives you placeholders for some values you need to know - how many heads per cylinder, and how many sectors per head.</p> <p>So, now imagine you have some data like this:</p> <pre><code>Cylinder number Head Number Sector Number Data LBA ================================================================================ 0 0 0 A 1 0 0 1 B 2 0 0 2 A 3 0 1 0 B 4 0 1 1 A 5 0 1 2 B 6 </code></pre> <p>This is a deliberately contrived scheme in which there are only three tracks per head. How, we've chosen to order the LBAs such that each track number we go up by increases the number. However, when we switch heads, we also need to increment the track number. Thus, we could say:</p> <pre><code>LBA = sectors per head * current head + current sector number </code></pre> <p>So now to find LBA 4, we know in CHS notation that equals <code>(0,1,0)</code>. Wth three sectors per head, <code>3*1+0=4</code>.</p> <p>Note, I've deliberately missed off the <code>-1</code> so you focus on the idea - that's used because LBAs are zero-offset. </p> <p>Anyway, so this works fine for heads and sectors, but what about cylinders? Well, if the cylinder number goes up by one we have jumped <code>number of heads per cylinder</code> heads forward on the disk, which is <code>number of heads per cylinder times number of sectors per head</code> sectors on the disk. If we're given a cylinder, head, sector tuple we can work out how many sectors that might add up to:</p> <pre><code>LBA = (((cylinder number * heads per cylinder) + head number) * * sector per head) + sector number - 1 </code></pre> <p>Working from left to right, the first part of the equation converts the cylinder number to the number of heads required to jump; the next part adds the current head number to that and converts it into a number of sector. Finally, you add the current sector number and subtract one from zero indexing.</p> <p>I'm sort of repeating myself here and for good reason - this is just one of those concepts. If it helps, draw a parallel - convert from hex to decimal. Assume I've given you FED and want to know what that is in decimal. Well, the conversion would be:</p> <pre><code>dec = (((15*16)+14)*16)+13 </code></pre> <p>How did I work that out? Well, from left to right in FED, there are 16 "hundreds" per "ten" and we have the digit 15. To that we add the number of "tens", which is 14. This we multiply by 16 again because there are 16 "tens" per unit. Finally, we add on the extra 13 units.</p> <p>The thing is, you do this kind of thing every day with decimal numbers - the only difficulty here is that the base, or <a href="http://simple.wikipedia.org/wiki/Base_(mathematics)" rel="nofollow">radix</a> is a number that <em>isn't</em> ten and therefore makes sense in our natural notation.</p> <hr> <p>Edit: it's just occurred to me you are in fact asking about the opposite direction. That's <em>much</em> easier!</p> <p>Firstly, the modulus operator - this means the remainder of a given value when divided by another value. So if we have <code>r = X mod Y</code> then r is the remainder when X is divided by Y. </p> <p>This is commonly referred to as clock arithmetic, on account of the fact that like a clock, these values go around in a circular fashion as you increase <code>X</code>.</p> <p>We can also calculate the quotient of a divisor - given a pair <code>X</code>,<code>Y</code> and computing <code>X/Y</code>, that's the largest value of <code>A</code> such that <code>X &gt; AY</code>.</p> <p>Put it all together and if you're asked to compute the quotient and remainder of 32 divided by 5, we see that 2 = 32 mod 5, since 5 divides 30. Then, 30=6*5, so the quotient is 6.</p> <p>Right, now onto the formula. Given an LBA address, we know that if we multiply tracks per head by heads per cylinder, that gives us the number of tracks a given cylinder number "covers" - all the remainders in this range use the same cylinder nunber. Practical example using the contrived table above: there are three tracks per head and let's say 6 heads per cylinder - so 6*3=18. Now take an LBA, say 5 - 5/18 = 0 remainder 5. So we take that quotient value to be the cylinder number, which it is.</p> <p>So the next question takes the LBA number and divides that by the sectors per track you have - why? Well remember, our LBA counts "tracks". Dividing by this value and taking the floor (since each individual track accounts for all the possible remainders) converts us to heads. We then take that value modulo the number of heads per cylinder so that, for example, if we have 6 heads per cylinder and a head value of 8, we correctly report the head number as 2 (the cylinder number being 1, accounting for the first 6).</p> <p>Finally, the sector number is a simple LBA divided by sectors per track (plus one to offset the zero indexing) remainder. Why? Well, each track can only contain a certain number of sectors before a different head/track is needed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload