How Does Computer Storage Work?
The storage disk is a circular object encased in a box. It stores data in bytes. For reference, 1
byte is enough to hold 1
character, like a number or a letter or a symbol → 3
or h
or %
The disk actually consists of 2 parts → the actual disk and the read-write head.
The disk stores data while the head spins the disk and moves backward and forward to read and write information to the disk. It's analogous to stereo record player where you place the record on the player and lay the needle atop the disk to play the song.
Data Storage
The disk is made up of many concentric circles, each one smaller in radius than the other. Each gutter created between two concentric circles is called a Track. It also has many vertical lines running from the edge to the center (like the radius line). The area created by two lines and the outer arc is called a Sector.
The read-write head (needle) spins the disk to move from sector to sector and shifts back and forth along the radius (from edge to center) to switch between tracks. If you visualise it, you'll understand what I'm saying here.
There are parts where these vertical lines intersect with the circumference of all the concentric circles. The area created between these intersection lines is alled a Block. These blocks store data in bytes. For theoretical purposes, assume that each block can hold 512
bytes of data.
To identify a block, we reference its track and sector ID. In this case, the purple block would be identified as [a, 6]
since it's found in track a
located in the 6th
sector.
When we zoom into a block, we see 512
bytes ready for use. To reference a specific byte in these 512 bytes, we use something called an Offset. For the purple byte below, the offset is 10
and for the red byte, the offset is 3
. You get the point.
We cannot directly manipulate data on the disk, which is why we have to read all the blocks to main memory (famously known as RAM). We use data structures and code to manipulate this information in the RAM and send back the changed data to the same blocks for persistent storage.