LBA和集群

发布于 2024-11-03 07:23:44 字数 613 浏览 3 评论 0原文

我想知道 LBA 和簇号。

我的问题是:

  1. LBA 0 总是集群 2吗?

  2. 那么簇 0 和 1 是做什么用的?

  3. 集群和LBA之间的唯一区别只是它们从磁盘的哪里开始?

  4. CHS、LBA、簇数之间的关系?

  5. 在下面的代码中,add ax, WORD [datasector] 代码的作用是什么?

    <前><代码>;************************************************ *****; ;将 CHS 转换为 LBA ; LBA = (簇 - 2) * 每个簇的扇区数 ;****************************************************; 集群LBA: 子轴,0x0002;零碱基簇数 异或 CX, CX mov cl, BYTE [bpbSectorsPerCluster] ;将字节转换为字 乘数 添加 ax, WORD [数据扇区] ;基础数据部门 雷特

I wonder about LBA and cluster number.

My question is this:

  1. is LBA 0 always cluster 2?

  2. then what does cluster 0 and 1 for?

  3. only difference between cluster and LBA is just where do they start from the disk?

  4. relation among CHS, LBA, cluster nubmer?

  5. and in the flowing code, what does add ax, WORD [datasector] code for?

    ;************************************************;
    ; Convert CHS to LBA
    ; LBA = (cluster - 2) * sectors per cluster
    ;************************************************;
    
    
    ClusterLBA:
              sub     ax, 0x0002                          ; zero base cluster number
              xor     cx, cx
              mov     cl, BYTE [bpbSectorsPerCluster]     ; convert byte to word
              mul     cx
              add     ax, WORD [datasector]               ; base data sector
              ret
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

子栖 2024-11-10 07:23:44

磁盘驱动器上有许多扇区编号方案。最早的之一是CHS(气缸盖扇区)。可以通过指定柱面(磁道)、读/写磁头和每磁道扇区三元组来选择一个扇区。此编号方案取决于磁盘驱动器的实际物理特性。

第一个逻辑扇区位于柱面 0、磁头 0、扇区 1。第二个逻辑扇区位于扇区 2,依此类推。如果磁盘上没有更多扇区(例如,在 1.44M 软盘上,每个磁道有 18 个扇区),则应用下一个磁头,再次从扇区 1 开始,依此类推。

您可以通过一些数学运算将 CHS 地址转换为绝对(或逻辑)扇区号:

L = (C * Nh + H) * Ns + S - 1

其中 CHS 是柱面,根据 CHS 寻址的磁头数和扇区数,而 NhNs 分别是每个磁道(柱面)的磁头数和扇区数。反向计算(将LBA转换为CHS)就是这么简单。

在这种称为LBA(逻辑块寻址)的编号方案中,每个扇区都可以通过单个编号来标识。第一个逻辑扇区是 LBA 0,第二个逻辑扇区是 LBA 1,依此类推。该方案是线性的并且更容易处理。

只是磁盘上连续扇区组,它们由操作系统和文件系统一起处理,以减少磁盘碎片和文件所需的磁盘空间系统元数据(例如,描述在磁盘上的哪些扇区可以找到特定文件)。一个簇可能仅包含 1 个扇区(512 字节)、最多 128 个扇区(64 KB)或更多,具体取决于磁盘的容量。

同样,簇的第一个扇区的逻辑扇区号可以很容易地计算出来:

L = ((U - Sc) * Nc) + Sd

其中U是簇号,Nc是簇中的扇区数,< Strong>Sc是第一个有效簇号,Sd是可用于通用文件数据的第一个逻辑扇区号。后两个参数(Sc 和 Sd)完全是文件系统和操作系统特定的值。

某些文件系统(例如 FAT16 和整个 FAT 系列)保留簇号 0 和 1 用于特殊目的,这就是为什么第一个实际簇是簇号 2(在本例中 Sc = 2)。同样,磁盘的开头可能有一些保留扇区,不允许向其中写入和读取数据。该保留区域的范围可以从几个扇区(例如引导记录)到数百万个扇区(例如硬盘上分区之前的完全不同的分区)。

呵呵,这是一个很长的答案。毕竟,您的问题的简短答案可以总结如下:

  1. 不,LBA 0 并不总是簇 2,它是特定于文件系统的(在 FAT 的情况下,簇 2 是磁盘上的第一个可用扇区,但不是始终为 LBA 0 - 请参阅答案 5)。

  2. 簇号 0 和 1 的解释也是特定于文件系统的(在 FAT 的情况下,簇号 0 表示文件分配表中的空簇,簇号 1 被保留)。

  3. 不,主要区别在于簇号寻址一组连续扇区,而 LBA 寻址磁盘上的单个扇区。

  4. 请参阅上面的长答案中的公式(公式?)以及随附的描述。

  5. 很难从这么短的汇编代码中看出,但我最好的猜测是分区开头的保留扇区数(由上面公式中的 Sd 标注)。

There are many sector numbering schemes on disk drives. One of the earliest was CHS (Cylinder-Head-Sector). One sector can be selected by specifying the cylinder (track), read/write head and sector per track triplet. This numbering scheme depends on the actual physical characteristics of the disk drive.

The first logical sector resides on cylinder 0, head 0, sector 1. The second is on sector 2, and so on. If there isn't any more sectors on the disk (eg. on a 1.44M floppy disk there's 18 sectors per track), then the next head is applied, starting on sector 1 again, and so on.

You can convert CHS addresses to an absolute (or logical) sector number with a little math:

L = (C * Nh + H) * Ns + S - 1

where C, H ans S are the cylinder, head and sector numbers according to CHS adressing, while Nh and Ns are the number of heads and number of sectors per track (cylinder), respectively. The reverse calculation (to convert LBA to CHS) is as simple as this.

In this numbering scheme, which is called LBA (Logical Block Addressing), each sector can be identified by a single number. The first logical sector is LBA 0, the second is LBA 1, and so on. This scheme is linear and easier to deal with.

Clusters are simply groups of continuous sectors on the disk, which are treated together by the operating system and the file system, in order to reduce disk fragmentation and disk space needed for file system metadata (eg. to describe in which sectors could a specific file found on the disk). A cluster may consist of only 1 sector (512 bytes), up to 128 sectors (64 kilobytes) or more, depending on the capacity of the disk.

Again, the logical sector number of the first sector of a cluster can be easily calculated:

L = ((U - Sc) * Nc) + Sd

where U is the cluster number, Nc is the number of sectors in a cluster, Sc is the first valid cluster number, and Sd is the number of the first logical sector available for generic file data. The latter two parameters (Sc and Sd) are completely filesystem and operating system specific values.

Some filesystems (for example FAT16, and the whole FAT-family) reserve cluster number 0 and 1 for special purposes, that's why the first actual cluster is cluster number two (Sc = 2 in this case). Similarly, there may be some reserved sectors in the beginning of the disk, where no data is allowed to be written to and read from. This reserved area can range from a few sectors (e.g. a boot record) to millions of sectors (e.g. a completely different partition which preceeds our partition on the hard disk).

Huh, this was the long answer. After all, the short answers to your questions can be summarized as follows:

  1. No, LBA 0 is not always cluster 2, it's filesystem specific (in case of FAT, cluster 2 is the first available sector on the disk, but not always LBA 0 - see answer 5).

  2. Interpretation of cluster number 0 and 1 are also filesystem specific (in case of FAT, cluster number 0 represents an empty cluster in the File Allocation Table, and cluster number 1 is reserved).

  3. No, the main difference is that a cluster number addresses a group of continous sectors, while LBA addresses a single sector on the disk.

  4. See the formulas (formulae?), and the accompanying description in the long answer above.

  5. It's hard to tell from such a short assembly code, but my best guess would be the number of reserved sectors in the beginning of the partition (noted by Sd in the formula above).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文