Cylinder, Head, Sector or CHS vs. Logical Block Addressing or LBA give you two ways to find data on a disk.
You’ll learn about these two methods in this episode because the terms come up now and then when talking about filesystems. They don’t really have anything to do with a filesystem itself. They describe two different ways to specify exactly where on a disk that information an be found.
Listen to the full episode or read the full transcript below to hear one of my crazy examples where I compare CHS to book binding and then show how LBA is like a book’s page numbers.
You’ll learn about these two methods in this episode because the terms come up now and then when talking about filesystems. They don’t really have anything to do with a filesystem itself. They describe two different ways to specify exactly where on a disk that information can be found.
For that reason, they’re used by filesystems. And you should at least be familiar with the ideas.
Let me start with this example to help explain the concepts.
Have you ever tried making your own book? Or have you looked at books to see how the pages are bound together?
You could start with a stack of paper and staple the pages along one side. This will hold the pages together but gets a lot more difficult as the number of pages increase. It also makes it difficult to open the book because the staples don’t let the binding bend very well.
Instead if stapling directly through the pages, you get better results by folding the paper in half so that each sheet can form two pages. The staples then only need to go through half as many pages and the book is easier to open because the pages are already folded. Some magazines are made this way.
Or instead of staples, maybe string is used to thread through the pages. Regardless, you’ll still be limited in how many pages you can bind like this. And the pages at the outside will have a less crisp fold.
What about a writing pad? You know the kind with a cardboard back and pages glued together along either the top or side. The glue is designed to hold the pages until you want to tear one out. Then the page comes away fairly clean. There might be a little glue that breaks off and is still stuck to the page. But you don’t have to actually tear the paper itself to remove the page from the writing pad.
Either of these methods has problems for a book. You want a lot of pages that are easy to flip through and probably want the pages to remain in place. What if you combine them.
What if you first bind small groups of pages together with thread and then glue them together? The glue has more paper to hold on to with each group and the thread keeps individual pages from pulling out of the glue.
The book itself is bound tight and it can be opened easy. Job done, right?
Maybe for an empty book. But for a book with printing inside, you really need to print the pages before they get stitched and glued together. And this is where you need to know how many pages will make up each group in order to layout the pages for printing.
Not all books will group sheets of paper together before binding them. I’ve seen a lot of paperback books that look like they just have individual pages glued together with a thicker layer of glue than a typical writing pad. You’ll probably find a lot more hardback books that follow this stitching strategy.
When it’s all done though, do you want to number the pages by their group and then sheet number? No, you want consecutive page numbers because those are more natural.
Now let me take this example and put it in similar terms of hard drives and floppy drives.
Other than the fact you can remove a floppy disk, they’re quite similar to hard drives. And the same goes for CD and DVD drives. While other drive types could be different, it’s usually better to follow existing standards than try to create something new.
A floppy disk has a single spinning disk covered in magnetic material on both sides. There will be sensors that glide over the top and bottom surfaces. These sensors are connected together so they move to the same position on the top and bottom. The sensors have coils wire that can be used to detect magnetic fields as the disk spins under them. And they can also be used to change the magnetic fields on the disk.
Each of these sensors is called a head. And each side of the spinning disk is either called a surface for a non-removable hard drive or a side for a removable floppy. I don’t usually make a very big distinction between surface or side though and usually mix them up or refer to everything as a surface.
The biggest difference between a hard drive and a floppy drive is that hard drives have multiple disks called platters stacked on top of each other. This means that hard drives have more than two heads. There’s two heads for each platter. All the heads still move together no matter how many there are.
Just to be clear, the heads only need to move in towards the center of the disk or platters or out towards the edge. At the center of the disk or platters is the spindle. That’s the part that makes the surfaces spin. All the surfaces spin together at the same speed. By moving the heads in and out and spinning the disks, the heads can be positioned over the whole disk.
Data will be stored in the magnetic material and packed together. This means that any particular north or south magnetic field will fly past the head as it’s being read or written. Nothing can be done if the disks are not spinning. Everything has to be timed just right.
If you miss a particular location, then you have to wait for it to spin all the way around before it comes back again. This is one of the reasons that hard drives are so much slower than main memory. The heads first need to seek to the right position and then wait for the data to pass underneath. Even though the disks are spinning really fast to our eyes, the main memory is still a lot faster.
Now you might think to compare this to a vinyl record player where you put the needle down and it traces a spiral path from the outside of the record to the inside. As the record spins, the needle moves back and forth in a groove. These vibrations get converted to electrical signals that get amplified into music. But there’s some big differences. first, a record uses a single groove that spirals its way toward the center. The needle is like a disk head in that it picks up information that passed underneath it. But it’s different because the needle just follows the groove. It’s also different because the groove contains analog information instead of digital information.
A spinning computer disk has no groove to follow. Hard drives spin so fast that the heads never actually touch the surface. They float just above the surface. If the heads ever touch the platters, they would scratch the surface and ruin the drive. Any bits of dust or dirt could also scratch the surface. That’s why hard drives need to be sealed inside a hard shell. Floppy drives are less sensitive to dust but can still be scratched if you’re not careful. And optical drives use light instead of magnetic fields so they don’t need to tough anything but can still be ruined with scratches.
Because there’s no single groove to follow, all spinning disks use concentric circles to store information. Moving the heads needs to precisely align the heads over one of the circles or rings of information. If the heads don’t align properly, then they won’t match the circles and you won’t read or write the information you expect.
Each circle is called a track. Because hard drives have so many surfaces and the heads all move together, then seeking to a particular track on one surface actually aligns all the other heads to their tracks at the same time.
The tracks on each surface are related to each other like this. There’s no way to read from one head on one track while reading from another head on a different track. Because the heads are connected and move together, we can think of the tracks as being connected too.
The set of tracks on each surface that are connected together form what is called a cylinder. Each cylinder is just like the concentric tracks but includes all the matching tracks on each surface.
Okay, we’re almost done with the description. The only thing left is the sectors. Think of this like a pizza that gets cut into pie shapes. Each slice divides the pizza into a thin area at the center and a wider area at the edge. well, the surfaces of the disks are divided like this also but into usually more pieces than a typical pizza. You can have anywhere from 1 up to 63 sectors. Now, 63 is an odd number in programming. I’m not sure why that was chosen. 64 would have fit in better with a binary system. The only thing I can think of is that floppy disks have a hole cut into the spinning disk near the center. I’m not talking about the big hole that the spindle grabs onto and is used to spin the disk. There’s a small hole just outside of the large center hole and is used to track where the sectors start. This hole might be small but it’s a lot bigger than the area needed to store the magnetic bits. That means that it’s not very precise. It’s possible, and I’m just guessing here, that the drive uses a hidden sector to help it align the sectors even more precisely.
Alright, that was a lot, I know. How does that compare with the book binding in the beginning of this episode? Well, just like you had to know how many pages would be used for each group of sheets in order to plan out where to print each page of the book, you have to know how many sectors a disk uses plus how many cylinders are being used, plus how many heads exist in order to plan out where each bit will be found on the disk. It’s a little more complicated than book binding but I thought it would make for a good example. Plus, just like how a book then uses a simple page number system, disks have exposed a simpler numbering system for the past 20 years or so.
You can use the older cylinder, head, sector system to find and layout information on a disk. Or you can use the newer and easier logical block addressing system. The LBA method works just like page numbers in a book that increase sequentially. LBA numbers start at zero though. But other than that, they increase one at a time until the drive reaches its full capacity.
I’ll end by clarifying one more thing. Both sectors and logical blocks contain more than just one bit of information. It’s common for each to hold 512 bytes of information. A particular LBA number can be mapped to a specific cylinder, head, and sector. But LBA numbers are simpler because we can treat them as simple increasing numbers. Doing so, lets the drive figure out where some LBA number maps to on the surface of the disk.