我想计算 VHD 中父定位器的结束偏移量。这是 VHD 标头的一部分:
Cookie: cxsparse
Data offset: 0xffffffffffffffff
Table offset: 0x2000
Header version: 0x00010000
Max table entries: 10240
Block size: 0x200000
Checksum: 4294956454
Parent Unique Id: 0x9678bf077e719640b55e40826ce5d178
Parent time stamp: 525527478
Reserved: 0
Parent Unicode name:
Parent locator 1:
- platform code: 0x57326b75
- platform_data_space: 4096
- platform_data_length: 86
- reserved: 0
- platform_data_offset: 0x1000
Parent locator 2:
- platform code: 0x57327275
- platform_data_space: 65536
- platform_data_length: 34
- reserved: 0
- platform_data_offset: 0xc000
Run Code Online (Sandbox Code Playgroud)
虚拟硬盘映像格式规范中的一些定义:
”Table Offset:该字段存储文件中块分配表(BAT)的绝对字节偏移量。 Platform Data Space:该字段存储存储父硬盘定位器所需的512字节扇区数。 Platform Data Offset:此字段以字节为单位存储绝对文件偏移量,其中存储平台特定的文件定位器数据。平台数据长度。此字段以字节为单位存储父硬盘定位器的实际长度。
基于此,两个父定位器的结束偏移量应为:数据偏移量 + 512 * 数据空间:
0x1000 + 512 * 4096 = 0x201000
0xc000 + 512 * 65536 = 0x200c000
Run Code Online (Sandbox Code Playgroud)
但是如果只使用数据偏移+数据空间:
0x1000 + 4096 = 0x2000 //end of parent locator 1, begin of BAT
0xc000 + 65536 = 0x1c000
Run Code Online (Sandbox Code Playgroud)
后一种计算更有意义:第一个父定位器的结尾是 BAT 的开头(参见上面的标题数据);并且由于第一个 BAT 条目是 0xe7(扇区偏移),这对应于文件偏移 0x1ce00(扇区偏移 * 512),如果第二个父定位器以 0x1c000 结尾,则可以。
但是如果使用公式数据偏移量 + 512 * 数据空间,他最终会在父定位器中写入其他数据。(但是,在这个例子中不会有数据损坏,因为平台数据长度非常小)
那么这是规范中的错误吗,这句话
“平台数据空间:该字段存储存储父硬盘定位器所需的 512 字节扇区数。”
应该
“平台数据空间:该字段存储了存储父硬盘定位器所需的字节数。”?
显然微软并不关心纠正他们的错误,这已经被 Virtualbox 开发人员发现了。VHD.cpp包含以下注释:
/*
* The VHD spec states that the DataSpace field holds the number of sectors
* required to store the parent locator path.
* As it turned out VPC and Hyper-V store the amount of bytes reserved for the
* path and not the number of sectors.
*/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
360 次 |
| 最近记录: |