gpt4 book ai didi

linux - sata 硬盘暴露什么样的 api?

转载 作者:可可西里 更新时间:2023-11-01 11:45:31 25 4
gpt4 key购买 nike

我知道 linux 内核使用驱动程序与硬盘设备通信,并且设备上有固件代码来为驱动程序的请求提供服务。我的问题是:

  1. 固件公开了什么样的功能(即 api)?例如,它是否只公开内核管理的地址空间,或者 linux 内核中是否有一些代码处理与硬盘驱动器相关的一些物理(即磁道/扇区/盘片等上的数据布局...... )

  2. 是内核安排磁盘的磁头移动,还是固件?

  3. 是否有针对硬盘设备公开的 api 的标准规范?

最佳答案

I understand that the linux kernel uses a driver to communicate with the hard disk device

所有外围设备都是如此。

there is firmware code on the device to service the driver's requests

现代 HDD(自 IDE 出现以来)具有集成磁盘 Controller 。
固件”本身不会做任何事情,而且是一个模棱两可的描述。 IE。什么在执行这个“固件”

  1. 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 驱动器使用 ATA Packet Interface, ATAPI .

旧的 SMD 和 ST506 驱动器接口(interface)使用柱面、磁头和扇区(也称为 CHS)寻址。此类驱动器的磁盘 Controller 通常在主机端保持类似的接口(interface),因此操作系统有义务了解驱动器的(物理)几何结构。操作系统将尝试通过将分区与柱面对齐来优化性能,并通过按柱面地址对请求进行排序来最小化查找/访问时间。

虽然磁盘 Controller 通常需要 CHS 寻址,但操作系统的较高层会使用顺序逻辑扇区地址。只要驱动器的几何结构已知,逻辑扇区地址到柱面、磁头和扇区地址之间的转换就很简单。

磁盘 Controller 主机端的 SCSI 和 IDE (ATA) 接口(interface)提供逻辑 block 寻址( block = 扇区)而不是 CHS 寻址。操作系统不再需要知道驱动器的物理几何形状,并且磁盘 Controller 能够使用逻辑寻址的抽象来使用区域位记录实现每个扇区更一致的面密度。

因此操作系统应该只使用逻辑 block 地址发出读取或写入 block 操作,而不要太关心驱动器的几何形状。
例如,不再可能通过 ATA 接口(interface)进行低级格式化,并且由于区域位记录,驱动器的几何结构是可变的(主机不知道)。坏扇区管理通常由集成 Controller 单独控制。但是,您可能仍然可以在各种操作系统中找到 CHS 优化的一些残余(例如,驱动器分区与“圆柱体”对齐)。

  1. Does the kernel schedule the disk's head movement, or is it the firmware?

使用寻道操作是可能的,但更可能是操作系统将 R/W 操作与自动寻道或 LBA R/W 操作一起使用。
然而,对于具有大量缓存和区域位记录的 LBA 和现代 HDD,不需要此类寻道操作,而且可能会适得其反。

最终磁盘 Controller 执行实际寻道。

  1. Is there a standard spec for the apis exposed by hard disk devices?

ATA/ATAPI 是已发布的规范(虽然它似乎处于“工作草案”状态已有 20 年)。
参见 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).

关于linux - sata 硬盘暴露什么样的 api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38578259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com