SD卡中block和sector的含义

近期在写SD卡驱动程序。经查阅datasheet后,整理如下:

首先要了解的是: SD卡协议中 HardDisk(文件系统)的block和sector不一个意思。

SD可协议见《Part_1_Physical_Layer_Simplified_Specification_Ver_3.01_Final_100518.pdf》(点击下载

SD卡中block和sector的含义如下:

block :  A number of bytes, basic data transfer unit (SD中最小的读写单位)。

block length 可以被 SET_BLOCKLEN (CMD16)设置 。

SDHC and SDXC block length 是固定的512Bytes。

协议原文:

7.2.3 Data Read
The SPI mode supports single block read and Multiple Block read operations (CMD17 or CMD18 in the
SD Memory Card protocol). Upon reception of a valid read command the card will respond with a
response token followed by a data token (refer to Figure 7-3). In case of Standard Capacity Card, the
size in the data token is determined by the block length set by SET_BLOCKLEN (CMD16).  In case of
SDHC and SDXC Cards, block length is fixed to  512 Bytes regardless of the block length set by
CMD16.

sector:  A number of blocks, basic erase unit (SD擦除单位)

可以设置为N*block

协议原文:

 SECTOR_SIZE
The size of an erasable sector. The content of this register is a 7-bit binary coded value, defining the
number of write blocks (see WRITE_BL_LEN). The actual size is computed by increasing this number
by one. A value of zero means one write block, 127 means 128 write blocks.


Linux内核文件系统block与硬盘sector关系:

在系统运行过程中,有时会遇到下面打印信息,报告读写某个扇区错误

kernel: end_request: I/O error, dev sdg, sector 2252148039
kernel: end_request: I/O error, dev sdc, sector 3297222879

1、这个扇区(sector)的含义是什么?和硬盘上的sector是一回事吗?

2、Sector和文件系统中的Block有什么关系?

3、而在我们上层应用读写的是文件内偏移量pos,pos与block/Sector之间有什么关系?

 

 
 

文件偏移量pos,是针对文件本身而言,即文件内的偏移。

Block是文件系统上的概念,一般文件系统block大小为4K。

Sector是磁介质硬盘最小单元,一般为512字节。

Block值一般与sector值是不相等的。


/**********************************
*           专注于芯的博客               *
*     --电子设计知识库,软件库     *
**********************************/

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值