硬盘
扇区编号顺序连贯的,对应磁盘上的物理位置就是不连贯的。
硬盘格式化
硬盘格式化包括硬格式化和软格式化,硬盘的硬格式化也叫硬格,软格式化也叫软格。
硬盘的硬格式化
硬盘在出厂时是已经硬格式化过的。所谓的硬格式化就是硬盘生产出来后,硬盘是新的,处于一种出厂时的状态,没有存任何信息。就像文件系统刚开始没有存任何文件等数据一样。然后经过硬格式化后,硬盘中虽然还是没有任何数据,但已经全部初始化为0,这就是硬盘经过硬格式化后的状态。
硬盘的软格式化
硬盘的软格式化就是在硬盘的硬格式化的基础上再次进行格式化为某种文件系统格式,如fat(fat12、fat16,fat32),ntf,ext(ext2,ext3,ext4)等格式。这个时候就是出于一种格式化为某种文件系统格式的状态。在经过软格式化后,就不再想硬格式化状态那样里边全是0, 而是里边已经有了上面的某种格式。通常在经过软格式化后,里边已经是个空的文件系统,里边没有任何文件,格式化成某些文件系统如ext,会自动创建一些文件或目录。
地址
CHS
通过CHS来表示地址。
LBA
包括28或48位LBA,也就是28或48位的地址。
28 bit LBA
// 2 2 2 1 1
// 7 4 3 6 5 8 7 0
// +----+--------+--------+--------+
// | | | | |
// +----+--------+--------+--------+
// |<-->|<------>|<------>|<------>|
// | | | |Sector Number Register (LBAlo)
// | | |Cylinder Low Register / (LBAmid)
// | |Cylinder High Register / (LBAhi)
// |bit0-3 of Drive / Head Register
48 bit LBA
// 4 4 3 3 3 2 2 1 1
// 7 0 9 2 1 4 3 6 5 8 7 0
// +--------+--------+--------+--------+--------+--------+
// | | | | | | |
// +--------+--------+--------+--------+--------+--------+
// |<--------------->|<--------------->|<--------------->|
// | | |Sector Number Register (LBAlo)
// | |Cylinder Low Register / (LBAmid)
// |Cylinder High Register / (LBAhi)
ATA
ATA即Advanced Technology Attachment
ATAPI
这个是一个ATA扩展,也叫PATA
SATA
SATA即Serial AT Attachment
PATA
Disk Controller
Disk Controller即磁盘控制器
寄存器
Data register
16位数据寄存器
// 5 8 7 0
// +----+----+----+----+
// | | | | |
// +----+----+----+----+
// |<------->|<------->|
// ^ ^
// | |Data(7:0)
// |Data(15:8)
Command register
命令寄存器
// +----+----+
// | | |
// +----+----+
// |<------->|
// ^
// |Command Code
Device register
设备寄存器,有些资料称之为Drive / Head Register,
// | |#| |D|####|
// | | | |E| |
// | | | |V| |
// +-+-+-+-+----+
// ^ ^ ^
// | | |DEV – Device select. Cleared to zero selects Device 0. Set to one selects Device 1.
// | |Obsolete – These bits are obsolete.
// |Obsolete – These bits are obsolete.
对于28 bit LBA模式:
// |/|1|/| | |
// +-+-+-+-+----+
// | ^ ^ ^|<-->|
// | | | | |bit24-27 of LBA
// | | | |Drive: 0: master(primary), this usually to be hard disk; 1: slave(secondary), this usually to be compact disc(CD)
// | | |Unused
// | |Mode: set to 1: LBA
// |Unused
对于CHS模式:
// |/|0|/| | |
// +-+-+-+-+----+
// | ^ ^ ^|<-->|
// | | | | |Head
// | | | |Drive: 0: master(primary), this usually to be hard disk; 1: slave(secondary), this usually to be compact disc(CD)
// | | |Unused
// | |Mode: set to 0: CHS
// |Unused
命令
CFA ERASE SECTORS
CFA REQUEST EXTENDED ERROR CODE
CFA TRANSLATE SECTOR
CFA WRITE MULTIPLE WITHOUT ERASE
CFA WRITE SECTORS WITHOUT ERASE
CHECK MEDIA CARD TYPE
CHECK POWER MODE
CONFIGURE STREAM
DEVICE CONFIGURATION
DEVICE RESET
DOWNLOAD MICROCODE
EXECUTE DEVICE DIAGNOSTIC
FLUSH CACHE
FLUSH CACHE EXT
GET MEDIA STATUS
IDENTIFY DEVICE
// Features Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: Features Register is optional to set.
//
// Sector Count Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: Sector Count Register is optional to set.
//
// LBA Low Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA Low Register is optional to set.
//
// LBA Mid Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA Mid Register is optional to set.
//
// LBA High Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA High Register is optional to set.
// Device Register:
// +-+-+-+-+----+
// |o| |o|D| |
// |b| |b|E| |
// |s| |s|V| |
// +-+-+-+-+----+
// ^ ^|<-->|
// | | |na
// | |DEV shall indicate the selected device.
// |na
//
// Obsolete – These bits are obsolete.
//
// Command Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |ECh
IDENTIFY DEVICE information
读取出来的信息类似这样的:
[bochs]:
0x0000000000017c9a:40 00 14 00 00 00 10 00 00 7E 00 02 3F 00 00 00
0x0000000000017caa:00 00 00 00 58 42 44 48 30 30 31 30 20 31 20 20
0x0000000000017cba:20 20 20 20 20 20 20 20 03 00 00 02 04 00 00 00
0x0000000000017cca:00 00 00 00 00 00 65 47 65 6E 69 72 20 63 32 31
0x0000000000017cda:34 33 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0x0000000000017cea:20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 00
0x0000000000017cfa:01 00 00 03 00 00 00 02 00 02 07 00 14 00 10 00
0x0000000000017d0a:3F 00 C0 4E 00 00 00 00 C0 4E 00 00 00 00 07 00
0x0000000000017d1a:00 00 78 00 78 00 78 00 78 00 00 00 00 00 00 00
0x0000000000017d2a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d3a:7E 00 00 00 00 40 00 74 00 40 00 40 00 74 00 40
0x0000000000017d4a:3F 00 00 00 00 00 00 00 00 00 01 60 00 00 00 00
0x0000000000017d5a:00 00 00 00 00 00 00 00 C0 4E 00 00 00 00 00 00
0x0000000000017d6a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d7a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d8a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d9a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017daa:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dba:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dca:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dda:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dea:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dfa:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e0a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e1a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e2a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e3a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e4a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e5a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e6a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e7a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e8a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
IDENTIFY PACKET DEVICE
// Features Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: Features Register is optional to set.
//
// Sector Count Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: Sector Count Register is optional to set.
//
// LBA Low Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA Low Register is optional to set.
//
// LBA Mid Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA Mid Register is optional to set.
//
// LBA High Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: LBA High Register is optional to set.
// Device Register:
// +-+-+-+-+----+
// |o| |o|D| |
// |b| |b|E| |
// |s| |s|V| |
// +-+-+-+-+----+
// ^ ^|<-->|
// | | |na
// | |DEV shall indicate the selected device.
// |na
//
// Obsolete – These bits are obsolete.
//
// Command Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |A1h
IDENTIFY PACKET DEVICE information
读取出来的信息类似这样的:和IDENTIFY DEVICE information差不多。
[bochs]:
0x0000000000017c9a:40 00 14 00 00 00 10 00 00 7E 00 02 3F 00 00 00
0x0000000000017caa:00 00 00 00 58 42 44 48 30 30 31 30 20 31 20 20
0x0000000000017cba:20 20 20 20 20 20 20 20 03 00 00 02 04 00 00 00
0x0000000000017cca:00 00 00 00 00 00 65 47 65 6E 69 72 20 63 32 31
0x0000000000017cda:34 33 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0x0000000000017cea:20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 00
0x0000000000017cfa:01 00 00 03 00 00 00 02 00 02 07 00 14 00 10 00
0x0000000000017d0a:3F 00 C0 4E 00 00 00 00 C0 4E 00 00 00 00 07 00
0x0000000000017d1a:00 00 78 00 78 00 78 00 78 00 00 00 00 00 00 00
0x0000000000017d2a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d3a:7E 00 00 00 00 40 00 74 00 40 00 40 00 74 00 40
0x0000000000017d4a:3F 00 00 00 00 00 00 00 00 00 01 60 00 00 00 00
0x0000000000017d5a:00 00 00 00 00 00 00 00 C0 4E 00 00 00 00 00 00
0x0000000000017d6a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d7a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d8a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017d9a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017daa:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dba:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dca:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dda:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dea:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017dfa:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e0a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e1a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e2a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e3a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e4a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e5a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e6a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e7a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0000000000017e8a:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
IDLE
IDLE IMMEDIATE
MEDIA EJECT
MEDIA LOCK
MEDIA UNLOCK
NOP
PACKET
READ BUFFER
READ DMA
READ DMA EXT
READ DMA QUEUED
READ DMA QUEUED EXT
READ LOG EXT
READ MULTIPLE
READ MULTIPLE EXT
READ NATIVE MAX ADDRESS
READ NATIVE MAX ADDRESS EXT
READ SECTOR(S)
//
// Features Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |na
// Note: Features Register is optional to set.
//
// Sector Count Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |Sector count
// LBA Low Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |LBA (7:0)
// LBA Mid Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |LBA (15:8)
// LBA High Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |LBA (23:16)
// Device Register:
// +-+-+-+-+----+
// |o|L|o|D| |
// |b|B|b|E| |
// |s|A|s|V| |
// +-+-+-+-+----+
// ^ ^|<-->|
// | | |LBA (27:24)
// | |DEV shall indicate the selected device.
// |Mode: set to 1: LBA
//
// Obsolete – These bits are obsolete.
//
// Command Register:
// +----+----+
// | | |
// +----+----+
// |<------->|
// |20h
READ SECTOR(S) EXT
READ STREAM DMA
READ STREAM PIO
READ VERIFY SECTOR(S)
READ VERIFY SECTOR(S) EXT
SECURITY DISABLE PASSWORD
SECURITY ERASE PREPARE
SECURITY ERASE UNIT
SECURITY FREEZE LOCK
SECURITY SET PASSWORD
SECURITY UNLOCK
SEEK
SERVICE
SET FEATURES
SET MAX
SET MAX ADDRESS EXT
SET MULTIPLE MODE
SLEEP
SMART
STANDBY
STANDBY IMMEDIATE
WRITE BUFFER
WRITE DMA
WRITE DMA EXT
WRITE DMA QUEUED
WRITE DMA QUEUED EXT
WRITE LOG EXT
WRITE MULTIPLE
WRITE MULTIPLE EXT
WRITE SECTOR(S)
WRITE SECTOR(S) EXT
WRITE STREAM DMA
WRITE STREAM PIO
寻址方式
CHS
CHS即Cylinder, Head, Sector mode,也就是柱面,磁头,扇区模式。这种寻址模式已经过时,但仍然在使用,尤其是在一些老硬盘中。
LBA
LBA包括LBA28和LBA48两种寻址模式。LBA表示Logic Block Addressing, 即逻辑块寻址。LBA也表示Logic Block Address,即逻辑块地址。LBA寻址模式也就是根据逻辑块地址进行寻址的一种寻址模式。
LBA28
LBA28即28 bit LBA,28位LBA模式
LBA48
LBA48即48 bit LBA,48位LBA模式
数据传输模式
硬盘读写时,数据传输也包括DMA和PIO两种传输模式。ATA规范规定所有符合ATA的驱动器必须PIO模式,并将PIO模式作为默认的数据传输机制。
DMA
PIO
硬盘操作
读操作
写操作
硬盘接口
相关结构和定义
typedef struct device { u2 dev_type; void* handle; int (* init) (struct device *dev, void *args); } dev_s; typedef dev_s dev_t;
// READ SECTORS #define COMMAND_READ_SECTORS 0x20 // READ SECTORS EXT #define COMMAND_READ_SECTORS_EXT 0x24 // WRITE SECTORS #define COMMAND_WRITE_SECTORS 0x30 // WRITE SECTORS EXT #define COMMAND_WRITE_SECTORS_EXT 0x34
void ata_read(dev_s *dev, disk_address_t *addr, char* dest);
void ata_write(dev_s *dev, disk_address_t *addr, char* src);
相关推荐
网管教程 从入门到精通软件篇 ★一。★详细的xp修复控制台命令和用法!!! 放入xp(2000)的光盘,安装时候选R,修复! Windows XP(包括 Windows 2000)的控制台命令是在系统出现一些意外情况下的一种非常有效的...
### 苹果电脑 Mac OS X 维护和保养 #### 一、运行日常维护脚本(Scripts) 在Unix系统(包括Mac OS X)中,维护脚本是非常重要的组成部分。它们通常位于`/etc/periodic/`目录下,用于执行一系列自动化任务,以确保...
#### 八、引导系统 1. **切换到硬盘操作系统** 使用`arch-chroot /mnt`命令切换到硬盘上的操作系统。 #### 九、系统配置 1. **配置时区** 使用`ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime`设置...
21. 硬盘维护:定期对硬盘进行磁盘检查和碎片整理可以提高数据处理速度,预防坏扇区,以及优化硬盘性能。 22. 快捷方式特性:一个快捷方式只能指向一个目标对象,但一个对象可以有多个快捷方式;任何对象都可以创建...
在第二版中,你将会看到,你已经可以通过交叉编译的方式为我们的实验性 OS编写应用程序了,也就是说,它已经具备操作系统的基本功能,虽然仍然极其简陋,但第一个圈,毕竟是已经圆起来了。第三,实践类的操作系统...
在第二版中,你将会看到,你已经可以通过交叉编译的方式为我们的实验性 OS编写应用程序了,也就是说,它已经具备操作系统的基本功能,虽然仍然极其简陋,但第一个圈,毕竟是已经圆起来了。第三,实践类的操作系统...
这里的IDE设备包括了IDE硬盘和IDE光驱,第一、第二组设备是指主板上的第一、第二根IDE数据线,一般来说靠近芯片的是第一组IDE设备,而主设备、从设备是指在一条IDE数据线上接的两个设备,大家知道每根数据线上可以接...
10. **OS (操作系统)**: 控制和管理计算机硬件资源的系统软件。 11. **Edit (编辑)**: 修改文件或数据的过程。 12. **Copy (复制)**: 创建文件或数据的一个副本。 13. **Move (移动)**: 改变文件的位置。 14. **...
18. diskmgmt.msc---磁盘管理实用程序 19. calc-----------启动计算器 20. dfrg.msc-------磁盘碎片整理程序 21. chkdsk.exe-----Chkdsk磁盘检查 22. devmgmt.msc--- 设备管理器 23. regsvr32 /u *.dll----停止...
25. 磁盘碎片整理程序可以用来整理磁盘碎片,提高硬盘性能。 26. 计算机病毒的特征包括传染性、破坏性、潜伏性、隐蔽性和不可预见性。 27. 卸载程序通常通过控制面板的"卸载程序"功能来完成。 28. 双击Setup.exe或...
9.1.18 set store——设置当前IPSec策略的存储位置 389 9.1.19 set batch——设置批更新模式 389 9.1.20 set rule——更改规则 390 9.1.21 show all——显示所有IPSec策略配置信息 391 9.1.22 show filteraction——...
9.1.18 set store——设置当前IPSec策略的存储位置 389 9.1.19 set batch——设置批更新模式 389 9.1.20 set rule——更改规则 390 9.1.21 show all——显示所有IPSec策略配置信息 391 9.1.22 show filteraction——...
9.1.18 set store——设置当前IPSec策略的存储位置 389 9.1.19 set batch——设置批更新模式 389 9.1.20 set rule——更改规则 390 9.1.21 show all——显示所有IPSec策略配置信息 391 9.1.22 show filteraction——...
9.1.18 set store——设置当前IPSec策略的存储位置 389 9.1.19 set batch——设置批更新模式 389 9.1.20 set rule——更改规则 390 9.1.21 show all——显示所有IPSec策略配置信息 391 9.1.22 show filteraction——...
1. ENIAC是世界上第一台电子计算机,它于1946年诞生,主要用于数值计算,加减运算速度达到每秒5000次。 2. 信息技术作为现代科技的核心,已经成为推动全球经济社会发展的新动力。 3. 1997年5月11日,IBM的超级...
9.1.18 set store——设置当前IPSec策略的存储位置 389 9.1.19 set batch——设置批更新模式 389 9.1.20 set rule——更改规则 390 9.1.21 show all——显示所有IPSec策略配置信息 391 9.1.22 show filteraction——...
根据给定的信息,本文将对IT领域内的一些新名词进行详细的解释与汇总,这些名词涵盖了技术、产品以及标准等各个方面。 ### 1. DVB-H **DVB-H(Digital Video Broadcasting - Handheld)**是一种专为手持设备设计的...