2
$\begingroup$

I'm guessing I could replace the words "hard drive" with "random access medium" but let's be more specific here. Also for the sake of this question, let's not consider SSDs. Just plain old hard-drives with heads and magnetic discs.

I'd guess that the hard drive doesn't care about things as bytes and receives instructions from the OS on about where to move it's head, but that'd assume that the OS has knowledge of sectors, cylinders or whatever physical properties of the drive and it's stored data so that doesn't feel right.

So, how does this work?

$\endgroup$
2
  • 2
    $\begingroup$ What reading did you do? This should be easily answerable with common resources such as Wikipedia. $\endgroup$ Commented Sep 3, 2015 at 11:09
  • 1
    $\begingroup$ Very loosely speaking, physical bits on the hard drive are indexed by an integer, and are naturally grouped into groups of 8 forming bytes. As for the operating system, I believe that it reads data from the hard drive in larger chunks, of entire sectors (usually 512 bytes); but this is just a guess. $\endgroup$ Commented Sep 3, 2015 at 19:46

3 Answers 3

2
$\begingroup$

Simplified, the operating system sees disk storage as a randomly accessible set of sectors, each sector containing some fixed number of bytes. The OS asks the disk controller for a sector using some standard protocol and it is the responsibility of the disk controller to retrieve the sector with the bits and bytes in the same order in which they were written. The communication protocol (e.g. SCSI) specifies both bit and byte order for reads and writes so there is no space for confusion about where the data starts and stops.

Operating systems can and do take into account the characteristics of storage media for the sake of efficiency, such as existence of onboard cache, rotational delays, and head movement, but those things have no bearing on where bytes and sectors start.

$\endgroup$
2
  • $\begingroup$ So, if I understood correctly, both the OS (say, the driver) and the Controller-HDD system have knowledge of sector properties. The OS knows what sector contains the required data and the Controller-HDD system knows where this sector is located. After the sector is read and sent to the OS and then even counting bit by bit to find the beginning of each byte shouldn't be too expensive. Sounds really simple now $\endgroup$
    – Loupax
    Commented Sep 4, 2015 at 9:30
  • $\begingroup$ That is correct. $\endgroup$
    – Kyle Jones
    Commented Sep 4, 2015 at 22:44
1
$\begingroup$

Prior to the 1990s, disk drives were somewhat like a tape recorder with a short loop of tape, and an ability to move the drive head to select a track. Information is written to disks using sequences of magnetic pulses with varying amounts of time between them. Depending upon the physical properties of the media, there will be limits as to the minimum and maximum amounts of time between pulses, as well as the timing accuracy with which that time can be measured. To allow for this, bytes are encoded using different patterns of pulse lengths. Certain patterns of pulse lengths will never appear in data and are thus used as synchronization markers.

When a disk is low-level formatted, the head is moved to each track and set to record, at which time the drive will then write the sequence "sync marker + sector header, short gap, sync marker + sector data, longer gap" once per sector. Each sector header contains the sector number recorded within it; to read a sector, the drive starts by listening for a sector header with a proper sector number, and then once that is heard, listens for the next sync marker and captures the data that follows. To write a sector, the drive waits for the sync marker for the proper sector, switches to write mode, writes a sync marker along with the proper data and a small amount of trailing junk which is guaranteed not to look like a sync marker, and switches to read mode.

Note that while a drive is reading data, it can "round" pulse widths up or down so as to tolerate variations in rotation speed. When writing a sector, the widths of pulses will be fixed independent of rotation speed. Thus, speed variations may cause an overwritten sector to not precisely match the length of the original. The gaps between sectors make it possible for a drive to tolerate this imprecision, but such imprecision makes it impossible to write part of a sector. Effectively, every separately-writable area of the disk must be preceded by a sector header and followed by a gap. The more finely one wants to be able to update individual chunks of data, the larger the fraction of overall space that will be devoted to the headers and the gaps.

$\endgroup$
-1
$\begingroup$

I think that you should first bear in mind that computer architecture is based on the mechanism of abstraction in order to make it easier, for instance, to manage and access data, and avoid the hurdle of having to take care of the specific hardware that needs be accessed.

Having said that, you can understand that the OS itself can't be allowed, also for efficiency reasons, to make distinctions between an USB or an hard disk access and so on. This premise is to confute the fact that the hard disk "doesn't care about bytes" and that the resolution of the data address is all on the OS. In fact, the hard disk DOES have an internal controller and circuitry that needs to identify and translate the address that the OS requests in the number of disk, cylinder and sector, the xyz coordinates in HD technology. The operating system instead interfaces with a file system that is built based on the disk content, without overweighting it with more "circuitry matters"

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.