UBI Volume Table

本文介绍了UBI卷表的工作原理及其实现细节。卷表是一个包含每个卷信息的非闪存数据结构,它由一系列记录组成,每个记录描述了一个UBI卷。文章还详细解释了卷表更新算法和可靠性保障措施。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UBI Volume Table

Volume table is an on-flash data structure which contains information about each volume on this UBI device. The volume table is an array of volume table records. Each record contains the following information:

  • volume size;
  • volume name;
  • volume type (dynamic or static);
  • volume alignment;
  • update marker (set for volumes which had interrupted updates;
  • auto-resize flag;
  • CRC-32 checksum for this record.

卷表

Volume table 是一个flash数据结构, 该结构含有 UBI 设备上每一个卷的信息, Volume table 是一个数组, 存储volume记录, 每一条记录含有以下信息:

  • 卷 size
  • 卷 名字
  • 卷类型(dynamic 或 static)
  • 卷 对齐
  • 更新标记 (为被中断的更新设置)
  • 自动调整大小标记
  • 本记录的 CRC-32校验和


Each record describes one UBI volume and record index in the volume table array corresponds to the volume ID. I.e, UBI volume 0 is described by record 0 in the volume table, and so on. Count of records in the volume table is limited by the LEB size, but cannot be greater than 128. This means that UBI devices cannot have more than 128 volumes.

Every time an UBI volume is created, removed, re-sized, re-named or updated, the corresponding volume table record is changed. UBI maintains two copies of the volume for reliability and power-cut tolerance reasons.


每条记录描述一个 UBI 卷, 卷表中的记录索引与卷 ID 对应。例如, 卷 0 由表中的记录 0 描述。卷表中记录的数目受 LEB 大小限制, 但不能大于128. 这意味着 UBI 设备不会多于128个卷。

每当一个卷被创建、删除、调整大小、重命名或更新, 卷标中相应的记录会变更; 为了提供可靠性和容错性, UBI 为每一个卷创建两个备份。


Implementation details

Internally, the volume table resides in a special-purpose UBI volume which is called layout volume. This volume consists of 2 LEBs - one for each copy of the volume table. The layout volume is an "internal" UBI volume, and the users do not see it and cannot access it. When reading or writing the layout volume, UBI uses the same mechanisms which are used for normal user volumes.

UBI uses the following algorithm when updating a volume table record.

  • Prepare in-memory buffer with the new volume table contents.
  • Un-map LEB0 of the layout volume.
  • Write the new volume table to LEB0.
  • Un-map LEB1 of the layout volume.
  • Write the new volume table to LEB1.
  • Flush the UBI work queue to make sure the PEBs are corresponding to the un-mapped LEBs are erased.


实现细节

在内部, 卷标存储在称为 layout volume 的特殊UBI卷中, 该卷由2个LEB组成, 其中一个存储volume table的副本。 layout volume 是内部的, 对用户不可见, 用户不能访问。当读写layout volume 时, 使用与普通卷一样的机制。

在更新volume table记录时, UBI 采用 如下算法:

  • 准备volume table 内容的内存缓存
  • un-map layout volume 的 LEB0
  • 写新的volume table内容到 LEB0
  • un-map layout volume 的 LEB1
  • 写新的volume table 内容到 LEB1
  • 刷新 UBI 工作队列, 确保与un-mapped LEB 对应的PEB被擦除


When attaching the MTD device, UBI makes sure that the 2 volume table copies are equivalent. If they are not equivalent, which may be caused by an unclean reboot, UBI picks the one from LEB0 and copies it to LEB1 of the layout volume (because it is newer). If one of the volume table copies is corrupted, UBI restores it from the other volume table copy.


当attach到 MTD 设备时, UBI 确保两个卷表一致, 如果不一致,可能是由意外重启导致的, UBI 使用 LEB0 的数据更新 LEB1中的数据, 如果其中一个volume table 数据损坏了, UBI 使用另一个进行恢复。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值