I understand that the linux kernel uses a driver to communicate with the hard disk device and that there is firmware code on the device to service the driver's requests. My questions are:
what kind of functionality (i.e. api) does the firmware expose? For example, does it only expose an address space that the kernel manages, or is there some code in the linux kernel that deals with some of the physics related to the hard drive (i.e. data layout on track/sector/platter etc...)
Does the kernel schedule the disk's head movement, or is it the firmware?
Is there a standard spec for the apis exposed by hard disk devices?
A computer shop can extract data from the hard drive by means not available to you. However, if they cannot extract data from the hard drive, you'll need to send the hard drive to a company that specializes in retrieving data from failed hard drives.
The hard drive contains a spinning platter with a thin magnetic coating. A "head" moves over the platter, writing 0's and 1's as tiny areas of magnetic North or South on the platter. To read the data back, the head goes to the same spot, notices the North and South spots flying by, and so deduces the stored 0's and 1's.
The interfaces of hard disk drives (HDDs) have been changed to serial interfaces to meet the demands for high-speed data transfer. The main interfaces involved are the Fibre Channel (FC), Serial ATA (SATA), and Serial Attached SCSI (SAS).
What Does a Hard Drive Do? A hard drive is the hardware component that stores all of your digital content. Your documents, pictures, music, videos, programs, application preferences, and operating system represent digital content stored on a hard drive.
SATA Hard Drive Definition and Technical Details SATA is an abbreviation of Serial Advanced Technology Attachment, a computer bus interface that connects host bus adapters to mass storage devices.
One end plugs into a port on the motherboard, usually labeled SATA, and the other into the back of a storage device like a SATA hard drive. External hard drives can also be used with SATA connections, given, of course, that the hard drive itself has a SATA connection, too. This is called eSATA.
Serial Advanced Technology Attachment or SATA is a type of storage drive interface that assists in read/write operations between a storage drive and your PC. In other words, it helps in connecting your storage device with the motherboard. The Serial-ATA interface has been used on HDDs and SSDs for over a decade.
SATA revision 1.0: The first version of the SATA interface was released in 2003, supporting communication rates of up to 1.5 Gbit/s. To ease the transition from older PATA hard drives, manufacturers at the time were using bridge chips to convert existing PATA designs for use with the SATA interface.
I understand that the linux kernel uses a driver to communicate with the hard disk device
That's true for all peripherals.
there is firmware code on the device to service the driver's requests
Modern HDDs (since the advent of IDE) have an integrated disk controller.
"Firmware" by itself isn't going to do anything, and is an ambiguous description. I.E. what is executing this "firmware"?
- what kind of functionality (i.e. api) does the firmware expose? For example, does it only expose an address space that the kernel manages, or is there some code in the linux kernel that deals with some of the physics related to the hard drive (i.e. data layout on track/sector/platter etc...)
SATA drives use the ATA Packet Interface, ATAPI.
The old SMD and ST506 drive interfaces used cylinder, head, and sector (aka CHS) addressing. Disk controllers for such drives typically kept a similar interface on the host side, so the operating system was obligated to be aware of the drive (physical) geometry. OSes would try to optimize performance by aligning partitions to cylinders, and minimize seek/access time by ordering requests by cylinder address.
Although the disk controller typically required CHS addressing, the higher layers of an OS would use a sequential logical sector address. Conversion between a logical sector address to cylinder, head, & sector address is straightforward so long as the drive geometry is known.
The SCSI and IDE (ATA) interfaces for the host side of the disk controller offered logical block addressing (block = sector) rather than CHS addressing. The OS no longer had to be aware of the physical geometry of the drive, and the disk controller was able to use the abstraction of logical addressing to implement a more consistent areal density per sector using zone-bit recording.
So the OS should only issue a read or write block operation with a logical block address, and not be too concerned with the drive's geometry.
For example, low-level format is no longer possible through the ATA interface, and the drive's geometry is variable (and unknown to the host) due to zone-bit recording. Bad sector management is typically under sole control of the integrated controller.
However you can probably still find some remnants of CHS optimization in various OSes (e.g. drive partitions aligned to a "cylinder").
- Does the kernel schedule the disk's head movement, or is it the firmware?
It's possible with a seek operation, but more likely the OS uses R/W operations with auto-seek or LBA R/W operations.
However with LBA and modern HDDs that have sizeable cache and zone-bit recording, such seek operations are not needed and can be counterproductive.
Ultimately the disk controller performs the actual seek.
- Is there a standard spec for the apis exposed by hard disk devices?
ATA/ATAPI is a published specification (although it seems to be in a "working draft" state for 20 years).
See http://www.t13.org/Documents/UploadedDocuments/docs2013/d2161r5-ATAATAPI_Command_Set_-_3.pdf
ABSTRACT This standard specifies the AT Attachment command set used to communicate between host systems and storage devices. This provides a common command set for systems manufacturers, system integrators, software suppliers, and suppliers of storage devices. The AT Attachment command set includes the PACKET feature set implemented by devices commonly known as ATAPI devices. This standard maintains a high degree of compatibility with the ATA/ATAPI Command Set - 2 (ACS-2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With