linux block的含义,SD卡中block和sector的含义
近期在写SD卡驱动程序。经查阅datasheet后,整理如下:
首先要了解的是: SD卡协议中 与HardDisk(文件系统)的block和sector不一个意思。
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值是不相等的。 /********************************** * 专注于芯的博客 * * --电子设计知识库,软件库 * **********************************/
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)