vmdk spec 1.1 給出的 Hosted Sparse Extent Header (對應上圖的Sparse header) The following example shows the content of a sparse extent’s header from a VMware hosted product, such as VMware Workstation, VMware Player, VMware ACE, VMware Server, or VMware GSX Server: This structure (struct SparseExtentHeader) needs to be packed. If you use gcc to compile your application, you must use the keyword __attribute__((__packed__)). typedef uint64 SectorType; typedef uint8 Bool; struct vmdisk_header { uint32_t version; uint32_t flags; int64_t capacity;//代表這個extent的大小,以扇區數表示 int64_t granularity;//一個grain的大小,以扇區數表示 int64_t desc_offset;//描述符的偏移,以扇區為基數 int64_t desc_size; //描述符的大小,以扇區為基數 int32_t num_gtes_per_gte;//graintable的entry數目,規范上是512 就是每個GDE對應的GTE的數目 int64_t rgd_offset;//這里指向的是redundant grain directory的位置 int64_t gd_offset;// 這里指向的是grain directory的位置 int64_t grain_offset; char filler[1]; char check_bytes[4]; }; 通過下面這個圖可以找到需要的數據,其中數據都是以扇區為偏移的,在規范的11頁有詳細的計算方法 代碼主要是根據讀取文件來填充header結構體,然后根據header結構體,和上面這張圖,來讀取相應的位置的數據,如果是寫數據,就計算好位置,寫進去。 ----------------------------------------------------------------------------------------- 代碼部分: